|
|
@@ -1,10 +1,7 @@
|
|
1
|
1
|
package se.citerus.dddsample.service;
|
|
2
|
2
|
|
|
3
|
3
|
import org.springframework.transaction.annotation.Transactional;
|
|
4
|
|
-import se.citerus.dddsample.domain.Cargo;
|
|
5
|
|
-import se.citerus.dddsample.domain.CarrierMovement;
|
|
6
|
|
-import se.citerus.dddsample.domain.HandlingEvent;
|
|
7
|
|
-import se.citerus.dddsample.domain.TrackingId;
|
|
|
4
|
+import se.citerus.dddsample.domain.*;
|
|
8
|
5
|
import se.citerus.dddsample.repository.CargoRepository;
|
|
9
|
6
|
import se.citerus.dddsample.service.dto.CargoWithHistoryDTO;
|
|
10
|
7
|
import se.citerus.dddsample.service.dto.HandlingEventDTO;
|
|
|
@@ -22,30 +19,22 @@ public class CargoServiceImpl implements CargoService {
|
|
22
|
19
|
return null;
|
|
23
|
20
|
}
|
|
24
|
21
|
|
|
25
|
|
- HandlingEvent lastEvent = cargo.deliveryHistory().lastEvent();
|
|
|
22
|
+ DeliveryHistory deliveryHistory = cargo.deliveryHistory();
|
|
26
|
23
|
|
|
27
|
24
|
//CargoWithHistoryDTO
|
|
28
|
25
|
|
|
29
|
|
- String currentLocationId = null;
|
|
30
|
|
- String carrierMovementId = null;
|
|
31
|
|
-
|
|
32
|
|
- if (lastEvent.type() == HandlingEvent.Type.UNLOAD || lastEvent.type() == HandlingEvent.Type.RECEIVE)
|
|
33
|
|
- currentLocationId = cargo.lastKnownLocation().unLocode().idString();
|
|
34
|
|
-
|
|
35
|
|
- if (lastEvent.type() == HandlingEvent.Type.LOAD)
|
|
36
|
|
- carrierMovementId = lastEvent.carrierMovement().carrierId().idString();
|
|
37
|
|
-
|
|
38
|
|
-
|
|
|
26
|
+ Location currentLocation = deliveryHistory.currentLocation();
|
|
|
27
|
+ CarrierMovement currentCarrierMovement = deliveryHistory.currentCarrierMovement();
|
|
39
|
28
|
final CargoWithHistoryDTO dto = new CargoWithHistoryDTO(
|
|
40
|
29
|
cargo.trackingId().idString(),
|
|
41
|
30
|
cargo.origin().toString(),
|
|
42
|
31
|
cargo.finalDestination().toString(),
|
|
43
|
|
- statusForLastEvent(lastEvent),
|
|
44
|
|
- currentLocationId,
|
|
45
|
|
- carrierMovementId
|
|
|
32
|
+ deliveryHistory.status(),
|
|
|
33
|
+ currentLocation == null ? null : currentLocation.unLocode().idString(),
|
|
|
34
|
+ currentCarrierMovement == null ? null : currentCarrierMovement.carrierId().idString()
|
|
46
|
35
|
);
|
|
47
|
36
|
|
|
48
|
|
- final List<HandlingEvent> events = cargo.deliveryHistory().eventsOrderedByCompletionTime();
|
|
|
37
|
+ final List<HandlingEvent> events = deliveryHistory.eventsOrderedByCompletionTime();
|
|
49
|
38
|
for (HandlingEvent event : events) {
|
|
50
|
39
|
CarrierMovement cm = event.carrierMovement();
|
|
51
|
40
|
String carrierIdString = (cm == null) ? "" : cm.carrierId().idString();
|
|
|
@@ -64,25 +53,4 @@ public class CargoServiceImpl implements CargoService {
|
|
64
|
53
|
this.cargoRepository = cargoRepository;
|
|
65
|
54
|
}
|
|
66
|
55
|
|
|
67
|
|
- public CargoWithHistoryDTO.StatusCode statusForLastEvent(HandlingEvent lastEvent) {
|
|
68
|
|
-
|
|
69
|
|
- if (lastEvent == null)
|
|
70
|
|
- return CargoWithHistoryDTO.StatusCode.notReceived;
|
|
71
|
|
-
|
|
72
|
|
- HandlingEvent.Type type = lastEvent.type();
|
|
73
|
|
- if (type == HandlingEvent.Type.LOAD)
|
|
74
|
|
- return CargoWithHistoryDTO.StatusCode.onBoardCarrier;
|
|
75
|
|
-
|
|
76
|
|
- if (type == HandlingEvent.Type.UNLOAD)
|
|
77
|
|
- return CargoWithHistoryDTO.StatusCode.inPort;
|
|
78
|
|
-
|
|
79
|
|
- if (type == HandlingEvent.Type.RECEIVE)
|
|
80
|
|
- return CargoWithHistoryDTO.StatusCode.inPort;
|
|
81
|
|
-
|
|
82
|
|
- if (type == HandlingEvent.Type.CLAIM)
|
|
83
|
|
- return CargoWithHistoryDTO.StatusCode.claimed;
|
|
84
|
|
-
|
|
85
|
|
-
|
|
86
|
|
- return null;
|
|
87
|
|
- }
|
|
88
|
56
|
}
|