|
|
@@ -18,6 +18,7 @@ public class HandlingEventServiceImpl implements HandlingEventService {
|
|
18
|
18
|
|
|
19
|
19
|
@Transactional(readOnly = false)
|
|
20
|
20
|
public void register(Date completionTime, TrackingId trackingId, CarrierMovementId carrierMovementId, UnLocode unlocode, HandlingEvent.Type type) throws UnknownCarrierMovementIdException, UnknownTrackingIdException, UnknownLocationException {
|
|
|
21
|
+ // Carrier movement may be null for certain event types
|
|
21
|
22
|
Validate.noNullElements(new Object[] {trackingId, unlocode, type});
|
|
22
|
23
|
|
|
23
|
24
|
Cargo cargo = cargoRepository.find(trackingId);
|
|
|
@@ -28,23 +29,18 @@ public class HandlingEventServiceImpl implements HandlingEventService {
|
|
28
|
29
|
Date registrationTime = new Date();
|
|
29
|
30
|
HandlingEvent event = new HandlingEvent(cargo, completionTime, registrationTime, type, location, carrierMovement);
|
|
30
|
31
|
|
|
31
|
|
- //DeliveryHistory deliveryHistory = deliveryHistoryRepository.findByTrackingId(trackingId);
|
|
32
|
|
- //DeliveryHistory deliveryHistory = cargo.deliveryHistory();
|
|
33
|
|
-
|
|
34
|
|
- //deliveryHistory.addEvent(event);
|
|
35
|
|
- //deliveryHistoryRepository.save(deliveryHistory);
|
|
36
|
|
-
|
|
37
|
|
- /*
|
|
38
|
|
- HandlingEvent event;
|
|
39
|
|
- if (carrierMovement != null) {
|
|
40
|
|
- event = new HandlingEvent(cargo, completionTime, registrationTime, type, location, carrierMovement);
|
|
41
|
|
- } else {
|
|
42
|
|
- event = new HandlingEvent(cargo, completionTime, registrationTime, type, location);
|
|
43
|
|
- }
|
|
44
|
|
- */
|
|
45
|
32
|
handlingEventRepository.save(event);
|
|
46
|
33
|
|
|
47
|
|
- //assert cargo.deliveryHistory().eventsOrderedByCompletionTime().contains(event); // <- FALSE here
|
|
|
34
|
+ /*
|
|
|
35
|
+ NOTE:
|
|
|
36
|
+ The cargo instance that's loaded and associated with the handling event is
|
|
|
37
|
+ in an inconsitent state, because the cargo delivery history's collection of
|
|
|
38
|
+ events does not contain the event created here. However, this is not a problem,
|
|
|
39
|
+ because cargo is in a different aggregate from handling event.
|
|
|
40
|
+ The rules of an aggregate dictate that all consistency rules within the aggregate
|
|
|
41
|
+ are enforced synchronously in the transaction, but consistency rules of other aggregates
|
|
|
42
|
+ are enforced by asynchronous updates, after the commit of this transaction.
|
|
|
43
|
+ */
|
|
48
|
44
|
}
|
|
49
|
45
|
|
|
50
|
46
|
private CarrierMovement findCarrierMovement(CarrierMovementId carrierMovementId) throws UnknownCarrierMovementIdException {
|