|
|
@@ -8,13 +8,14 @@ import se.citerus.dddsample.domain.*;
|
|
8
|
8
|
import se.citerus.dddsample.repository.CargoRepository;
|
|
9
|
9
|
import se.citerus.dddsample.repository.LocationRepository;
|
|
10
|
10
|
|
|
11
|
|
-import java.util.ArrayList;
|
|
|
11
|
+import java.util.Date;
|
|
12
|
12
|
import java.util.List;
|
|
13
|
13
|
|
|
14
|
14
|
public final class BookingServiceImpl implements BookingService {
|
|
15
|
15
|
|
|
16
|
16
|
private CargoRepository cargoRepository;
|
|
17
|
17
|
private LocationRepository locationRepository;
|
|
|
18
|
+ private RoutingService routingService;
|
|
18
|
19
|
|
|
19
|
20
|
private final Log logger = LogFactory.getLog(getClass());
|
|
20
|
21
|
|
|
|
@@ -35,23 +36,6 @@ public final class BookingServiceImpl implements BookingService {
|
|
35
|
36
|
}
|
|
36
|
37
|
|
|
37
|
38
|
@Transactional(readOnly = true)
|
|
38
|
|
- public List<UnLocode> listShippingLocations() {
|
|
39
|
|
- final List<Location> allLocations = locationRepository.findAll();
|
|
40
|
|
- final List<UnLocode> unlocodes = new ArrayList<UnLocode>(allLocations.size());
|
|
41
|
|
- for (Location location : allLocations) {
|
|
42
|
|
- unlocodes.add(location.unLocode());
|
|
43
|
|
- }
|
|
44
|
|
- return unlocodes;
|
|
45
|
|
- }
|
|
46
|
|
-
|
|
47
|
|
- @Transactional(readOnly = true)
|
|
48
|
|
- public List<Cargo> listAllCargos() {
|
|
49
|
|
- final List<Cargo> allCargos = cargoRepository.findAll();
|
|
50
|
|
- // TODO: specification pattern might be useful here, too
|
|
51
|
|
- return allCargos;
|
|
52
|
|
- }
|
|
53
|
|
-
|
|
54
|
|
- @Transactional(readOnly = true)
|
|
55
|
39
|
public Cargo loadCargoForRouting(final TrackingId trackingId) {
|
|
56
|
40
|
Validate.notNull(trackingId);
|
|
57
|
41
|
|
|
|
@@ -61,6 +45,14 @@ public final class BookingServiceImpl implements BookingService {
|
|
61
|
45
|
return cargo;
|
|
62
|
46
|
}
|
|
63
|
47
|
|
|
|
48
|
+ @Transactional(readOnly = true)
|
|
|
49
|
+ public List<Itinerary> requestPossibleRoutesForCargo(TrackingId trackingId) {
|
|
|
50
|
+ final Cargo cargo = loadCargoForRouting(trackingId);
|
|
|
51
|
+ final RouteSpecification routeSpecification = RouteSpecification.forCargo(cargo, new Date());
|
|
|
52
|
+
|
|
|
53
|
+ return routingService.fetchRoutesForSpecification(routeSpecification);
|
|
|
54
|
+ }
|
|
|
55
|
+
|
|
64
|
56
|
@Transactional(readOnly = false)
|
|
65
|
57
|
public void assignCargoToRoute(final TrackingId trackingId, final Itinerary newItinerary) {
|
|
66
|
58
|
Validate.notNull(trackingId);
|
|
|
@@ -71,7 +63,6 @@ public final class BookingServiceImpl implements BookingService {
|
|
71
|
63
|
throw new IllegalArgumentException("Can't assign itinerary to non-existing cargo " + trackingId);
|
|
72
|
64
|
}
|
|
73
|
65
|
|
|
74
|
|
- // Assign the new itinerary to the cargo
|
|
75
|
66
|
cargo.attachItinerary(newItinerary);
|
|
76
|
67
|
cargoRepository.save(cargo);
|
|
77
|
68
|
|
|
|
@@ -88,4 +79,7 @@ public final class BookingServiceImpl implements BookingService {
|
|
88
|
79
|
this.locationRepository = locationRepository;
|
|
89
|
80
|
}
|
|
90
|
81
|
|
|
|
82
|
+ public void setRoutingService(RoutingService routingService) {
|
|
|
83
|
+ this.routingService = routingService;
|
|
|
84
|
+ }
|
|
91
|
85
|
}
|