|
|
@@ -4,11 +4,15 @@ import org.apache.commons.logging.Log;
|
|
4
|
4
|
import org.apache.commons.logging.LogFactory;
|
|
5
|
5
|
import se.citerus.dddsample.domain.*;
|
|
6
|
6
|
import se.citerus.dddsample.domain.HandlingEvent.Type;
|
|
|
7
|
+import static se.citerus.dddsample.domain.SampleLocations.*;
|
|
7
|
8
|
|
|
8
|
9
|
import java.text.DateFormat;
|
|
9
|
10
|
import java.text.ParseException;
|
|
10
|
11
|
import java.text.SimpleDateFormat;
|
|
11
|
|
-import java.util.*;
|
|
|
12
|
+import java.util.ArrayList;
|
|
|
13
|
+import java.util.Date;
|
|
|
14
|
+import java.util.HashMap;
|
|
|
15
|
+import java.util.List;
|
|
12
|
16
|
|
|
13
|
17
|
public class HandlingEventRepositoryInMem implements HandlingEventRepository {
|
|
14
|
18
|
private final Log logger = LogFactory.getLog(getClass());
|
|
|
@@ -23,10 +27,8 @@ public class HandlingEventRepositoryInMem implements HandlingEventRepository {
|
|
23
|
27
|
* @throws ParseException
|
|
24
|
28
|
*/
|
|
25
|
29
|
public void init() throws ParseException {
|
|
26
|
|
-/*
|
|
27
|
|
-
|
|
28
|
30
|
// CargoXYZ
|
|
29
|
|
- final Cargo cargoXYZ = new Cargo(new TrackingId("XYZ"), new Location("SESTO"), new Location("AUMEL"));
|
|
|
31
|
+ final Cargo cargoXYZ = new Cargo(new TrackingId("XYZ"), STOCKHOLM, MELBOURNE);
|
|
30
|
32
|
registerEvent(cargoXYZ, "2007-11-30", HandlingEvent.Type.RECEIVE, null);
|
|
31
|
33
|
|
|
32
|
34
|
final CarrierMovement stockholmToHamburg = carrierMovementRepository.find(new CarrierMovementId("SESTO_DEHAM"));
|
|
|
@@ -38,7 +40,7 @@ public class HandlingEventRepositoryInMem implements HandlingEventRepository {
|
|
38
|
40
|
registerEvent(cargoXYZ, "2007-12-05", HandlingEvent.Type.UNLOAD, hamburgToHongKong);
|
|
39
|
41
|
|
|
40
|
42
|
//CargoZYX
|
|
41
|
|
- final Cargo cargoZYX = new Cargo(new TrackingId("ZYX"), new Location("AUMEL"), new Location("SESTO"));
|
|
|
43
|
+ final Cargo cargoZYX = new Cargo(new TrackingId("ZYX"), MELBOURNE, STOCKHOLM);
|
|
42
|
44
|
registerEvent(cargoZYX, "2007-12-09", HandlingEvent.Type.RECEIVE, null);
|
|
43
|
45
|
|
|
44
|
46
|
final CarrierMovement melbourneToTokyo = carrierMovementRepository.find(new CarrierMovementId("AUMEL_JPTOK"));
|
|
|
@@ -49,25 +51,23 @@ public class HandlingEventRepositoryInMem implements HandlingEventRepository {
|
|
49
|
51
|
registerEvent(cargoZYX, "2007-12-13", HandlingEvent.Type.LOAD, tokyoToLosAngeles);
|
|
50
|
52
|
|
|
51
|
53
|
//CargoABC
|
|
52
|
|
- final Cargo cargoABC = new Cargo(new TrackingId("ABC"), new Location("SESTO"), new Location("FIHEL"));
|
|
|
54
|
+ final Cargo cargoABC = new Cargo(new TrackingId("ABC"), STOCKHOLM, HELSINKI);
|
|
53
|
55
|
registerEvent(cargoABC, "2008-01-01", HandlingEvent.Type.RECEIVE, null);
|
|
54
|
56
|
|
|
55
|
57
|
final CarrierMovement stockholmToHelsinki = new CarrierMovement(
|
|
56
|
|
- new CarrierMovementId("CAR_001"), new Location("SESTO"), new Location("FIHEL"));
|
|
|
58
|
+ new CarrierMovementId("CAR_001"), STOCKHOLM, HELSINKI);
|
|
57
|
59
|
|
|
58
|
60
|
registerEvent(cargoABC, "2008-01-02", HandlingEvent.Type.LOAD, stockholmToHelsinki);
|
|
59
|
61
|
registerEvent(cargoABC, "2008-01-03", HandlingEvent.Type.UNLOAD, stockholmToHelsinki);
|
|
60
|
62
|
registerEvent(cargoABC, "2008-01-05", HandlingEvent.Type.CLAIM, null);
|
|
61
|
63
|
|
|
62
|
64
|
//CargoCBA
|
|
63
|
|
- final Cargo cargoCBA = new Cargo(new TrackingId("CBA"), new Location("FIHEL"), new Location("SESTO"));
|
|
|
65
|
+ final Cargo cargoCBA = new Cargo(new TrackingId("CBA"), HELSINKI, STOCKHOLM);
|
|
64
|
66
|
registerEvent(cargoCBA, "2008-01-10", HandlingEvent.Type.RECEIVE, null);
|
|
65
|
|
-*/
|
|
66
|
67
|
}
|
|
67
|
68
|
|
|
68
|
69
|
private void registerEvent(Cargo cargo, String date, Type type, CarrierMovement carrierMovement) throws ParseException {
|
|
69
|
70
|
HandlingEvent event = new HandlingEvent(cargo, getDate(date), new Date(), type, null, carrierMovement);
|
|
70
|
|
- //cargo.handle(event);
|
|
71
|
71
|
String id = cargo.trackingId() + "_" + type + "_" + date;
|
|
72
|
72
|
|
|
73
|
73
|
logger.debug("Adding event " + id + "(" + event + ")");
|
|
|
@@ -75,6 +75,14 @@ public class HandlingEventRepositoryInMem implements HandlingEventRepository {
|
|
75
|
75
|
}
|
|
76
|
76
|
|
|
77
|
77
|
|
|
|
78
|
+ public void save(HandlingEvent event) {
|
|
|
79
|
+ eventDB.put(event.cargo().trackingId().idString(), event);
|
|
|
80
|
+ }
|
|
|
81
|
+
|
|
|
82
|
+ public List<HandlingEvent> findEventsForCargo(TrackingId trackingId) {
|
|
|
83
|
+ return new ArrayList();
|
|
|
84
|
+ }
|
|
|
85
|
+
|
|
78
|
86
|
/**
|
|
79
|
87
|
* Parse an ISO 8601 (YYYY-MM-DD) String to Date
|
|
80
|
88
|
*
|
|
|
@@ -87,47 +95,8 @@ public class HandlingEventRepositoryInMem implements HandlingEventRepository {
|
|
87
|
95
|
return dateFormat.parse(isoFormat);
|
|
88
|
96
|
}
|
|
89
|
97
|
|
|
90
|
|
- public HandlingEvent find(final String handlingEventId) {
|
|
91
|
|
- return eventDB.get(handlingEventId);
|
|
92
|
|
- }
|
|
93
|
|
-
|
|
94
|
|
- public void save(final HandlingEvent event) {
|
|
95
|
|
- // Mimmick saving to database
|
|
96
|
|
- /*
|
|
97
|
|
- for (Cargo cargo : event.registerdCargos()) {
|
|
98
|
|
- cargo.handle(event);
|
|
99
|
|
- }
|
|
100
|
|
- */
|
|
101
|
|
- }
|
|
102
|
|
-
|
|
103
|
|
- public List<HandlingEvent> findEventsForCargo(final TrackingId trackingId) {
|
|
104
|
|
- return new ArrayList<HandlingEvent>(eventDB.values());
|
|
105
|
|
- }
|
|
106
|
|
-
|
|
107
|
|
- public DeliveryHistory findDeliveryHistory(final TrackingId trackingId) {
|
|
108
|
|
- return null; //To change body of implemented methods use File | Settings | File Templates.
|
|
109
|
|
- }
|
|
110
|
|
-
|
|
111
|
|
- @SuppressWarnings("unchecked")
|
|
112
|
|
- public Set<HandlingEvent> findByTrackingId(final TrackingId trackingId) {
|
|
113
|
|
- final Set<HandlingEvent> events = new HashSet<HandlingEvent>();
|
|
114
|
|
- for (HandlingEvent event : eventDB.values()) {
|
|
115
|
|
- /*
|
|
116
|
|
- for (Cargo cargo : event.registerdCargos()) {
|
|
117
|
|
- if (cargo.trackingId().equals(trackingId)) {
|
|
118
|
|
- events.add(event);
|
|
119
|
|
- break;
|
|
120
|
|
- }
|
|
121
|
|
- }
|
|
122
|
|
- */
|
|
123
|
|
- }
|
|
124
|
|
-
|
|
125
|
|
- logger.debug("findByTrackingId " + trackingId + " finds " + events);
|
|
126
|
|
-
|
|
127
|
|
- return events;
|
|
128
|
|
- }
|
|
129
|
|
-
|
|
130
|
98
|
public void setCarrierRepository(final CarrierMovementRepository carrierMovementRepository) {
|
|
131
|
99
|
this.carrierMovementRepository = carrierMovementRepository;
|
|
132
|
100
|
}
|
|
|
101
|
+
|
|
133
|
102
|
}
|