|
|
@@ -4,8 +4,6 @@ import org.apache.commons.lang.Validate;
|
|
4
|
4
|
import org.apache.commons.logging.Log;
|
|
5
|
5
|
import org.apache.commons.logging.LogFactory;
|
|
6
|
6
|
import org.springframework.transaction.annotation.Transactional;
|
|
7
|
|
-import se.citerus.dddsample.application.CargoLockingService;
|
|
8
|
|
-import se.citerus.dddsample.application.CargoLockingServiceInMem;
|
|
9
|
7
|
import se.citerus.dddsample.domain.model.cargo.*;
|
|
10
|
8
|
import se.citerus.dddsample.domain.model.location.Location;
|
|
11
|
9
|
import se.citerus.dddsample.domain.model.location.LocationRepository;
|
|
|
@@ -22,7 +20,6 @@ public final class BookingServiceImpl implements BookingService {
|
|
22
|
20
|
private final CargoFactory cargoFactory;
|
|
23
|
21
|
private final CargoRepository cargoRepository;
|
|
24
|
22
|
private final LocationRepository locationRepository;
|
|
25
|
|
- private final CargoLockingService cargoLockingService;
|
|
26
|
23
|
private final Log logger = LogFactory.getLog(getClass());
|
|
27
|
24
|
|
|
28
|
25
|
public BookingServiceImpl(final RoutingService routingService,
|
|
|
@@ -33,7 +30,6 @@ public final class BookingServiceImpl implements BookingService {
|
|
33
|
30
|
this.cargoFactory = cargoFactory;
|
|
34
|
31
|
this.cargoRepository = cargoRepository;
|
|
35
|
32
|
this.locationRepository = locationRepository;
|
|
36
|
|
- this.cargoLockingService = new CargoLockingServiceInMem();
|
|
37
|
33
|
}
|
|
38
|
34
|
|
|
39
|
35
|
@Override
|
|
|
@@ -63,23 +59,17 @@ public final class BookingServiceImpl implements BookingService {
|
|
63
|
59
|
@Override
|
|
64
|
60
|
@Transactional
|
|
65
|
61
|
public void assignCargoToRoute(final Itinerary itinerary, final TrackingId trackingId) {
|
|
66
|
|
- cargoLockingService.assertLocked(trackingId);
|
|
67
|
|
-
|
|
68
|
62
|
final Cargo cargo = cargoRepository.find(trackingId);
|
|
69
|
63
|
Validate.notNull(cargo, "Can't assign itinerary to non-existing cargo " + trackingId);
|
|
70
|
64
|
cargo.assignToRoute(itinerary);
|
|
71
|
65
|
cargoRepository.store(cargo);
|
|
72
|
66
|
|
|
73
|
67
|
logger.info("Assigned cargo " + trackingId + " to new route");
|
|
74
|
|
-
|
|
75
|
|
- cargoLockingService.unlock(trackingId);
|
|
76
|
68
|
}
|
|
77
|
69
|
|
|
78
|
70
|
@Override
|
|
79
|
71
|
@Transactional
|
|
80
|
72
|
public void changeDestination(final TrackingId trackingId, final UnLocode unLocode) {
|
|
81
|
|
- cargoLockingService.assertLocked(trackingId);
|
|
82
|
|
-
|
|
83
|
73
|
final Cargo cargo = cargoRepository.find(trackingId);
|
|
84
|
74
|
Validate.notNull(cargo, "Can't change destination of non-existing cargo " + trackingId);
|
|
85
|
75
|
final Location newDestination = locationRepository.find(unLocode);
|
|
|
@@ -89,18 +79,12 @@ public final class BookingServiceImpl implements BookingService {
|
|
89
|
79
|
|
|
90
|
80
|
cargoRepository.store(cargo);
|
|
91
|
81
|
logger.info("Changed destination for cargo " + trackingId + " to " + routeSpecification.destination());
|
|
92
|
|
-
|
|
93
|
|
- cargoLockingService.unlock(trackingId);
|
|
94
|
82
|
}
|
|
95
|
83
|
|
|
96
|
84
|
@Override
|
|
97
|
85
|
@Transactional(readOnly = true)
|
|
98
|
86
|
public Cargo loadCargoForRouting(final TrackingId trackingId) {
|
|
99
|
|
- final Cargo cargo = cargoRepository.find(trackingId);
|
|
100
|
|
- if (cargo != null) {
|
|
101
|
|
- cargoLockingService.lock(trackingId);
|
|
102
|
|
- }
|
|
103
|
|
- return cargo;
|
|
|
87
|
+ return cargoRepository.find(trackingId);
|
|
104
|
88
|
}
|
|
105
|
89
|
|
|
106
|
90
|
}
|