|
|
@@ -21,38 +21,28 @@ public class CargoUpdater {
|
|
21
|
21
|
private final Log logger = LogFactory.getLog(getClass());
|
|
22
|
22
|
|
|
23
|
23
|
@Autowired
|
|
24
|
|
- public CargoUpdater(final SystemEvents systemEvents,
|
|
25
|
|
- final CargoRepository cargoRepository,
|
|
26
|
|
- final HandlingEventRepository handlingEventRepository) {
|
|
|
24
|
+ public CargoUpdater(SystemEvents systemEvents,
|
|
|
25
|
+ CargoRepository cargoRepository,
|
|
|
26
|
+ HandlingEventRepository handlingEventRepository) {
|
|
27
|
27
|
this.systemEvents = systemEvents;
|
|
28
|
28
|
this.cargoRepository = cargoRepository;
|
|
29
|
29
|
this.handlingEventRepository = handlingEventRepository;
|
|
30
|
30
|
}
|
|
31
|
31
|
|
|
32
|
32
|
@Transactional
|
|
33
|
|
- public void updateCargo(final EventSequenceNumber eventSequenceNumber) {
|
|
34
|
|
- final HandlingEvent handlingEvent = handlingEventRepository.find(eventSequenceNumber);
|
|
|
33
|
+ public void updateCargo(final EventSequenceNumber sequenceNumber) {
|
|
|
34
|
+ final HandlingEvent handlingEvent = handlingEventRepository.find(sequenceNumber);
|
|
|
35
|
+ if (handlingEvent == null) {
|
|
|
36
|
+ logger.error("Could not find any handling event with sequence number " + sequenceNumber);
|
|
|
37
|
+ return;
|
|
|
38
|
+ }
|
|
|
39
|
+
|
|
35
|
40
|
final HandlingActivity activity = handlingEvent.activity();
|
|
36
|
41
|
final Cargo cargo = handlingEvent.cargo();
|
|
37
|
42
|
|
|
38
|
43
|
cargo.handled(activity);
|
|
39
|
|
-
|
|
40
|
|
- // TODO create domain events and deal with them as a result of the handling
|
|
41
|
|
- /*
|
|
42
|
|
- Here's an idea:
|
|
43
|
|
-
|
|
44
|
|
- ResultOfHandling result = cargo.effectOf(activity);
|
|
45
|
|
- cargo.apply(result);
|
|
46
|
|
-
|
|
47
|
|
- or
|
|
48
|
|
-
|
|
49
|
|
- cargo.handled(activity);
|
|
50
|
|
- Delivery delivery = cargo.currentDelivery();
|
|
51
|
|
- send all delivery.events();
|
|
52
|
|
-
|
|
53
|
|
- */
|
|
54
|
|
-
|
|
55
|
44
|
cargoRepository.store(cargo);
|
|
|
45
|
+
|
|
56
|
46
|
systemEvents.notifyOfCargoUpdate(cargo);
|
|
57
|
47
|
logger.info("Updated cargo " + cargo);
|
|
58
|
48
|
}
|