|
|
@@ -1,231 +0,0 @@
|
|
1
|
|
-package se.citerus.dddsample.tracking.core.interfaces.tracking;
|
|
2
|
|
-
|
|
3
|
|
-import org.springframework.context.MessageSource;
|
|
4
|
|
-import se.citerus.dddsample.tracking.core.domain.model.cargo.Cargo;
|
|
5
|
|
-import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent;
|
|
6
|
|
-import se.citerus.dddsample.tracking.core.domain.model.location.Location;
|
|
7
|
|
-import se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity;
|
|
8
|
|
-import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
|
|
9
|
|
-
|
|
10
|
|
-import java.text.SimpleDateFormat;
|
|
11
|
|
-import java.util.*;
|
|
12
|
|
-
|
|
13
|
|
-/**
|
|
14
|
|
- * View adapter for displaying a cargo in a tracking context.
|
|
15
|
|
- */
|
|
16
|
|
-public final class CargoTrackingViewAdapter {
|
|
17
|
|
-
|
|
18
|
|
- private final Cargo cargo;
|
|
19
|
|
- private final MessageSource messageSource;
|
|
20
|
|
- private final Locale locale;
|
|
21
|
|
- private final List<HandlingEventViewAdapter> events;
|
|
22
|
|
- private final String FORMAT = "yyyy-MM-dd hh:mm z";
|
|
23
|
|
-
|
|
24
|
|
- /**
|
|
25
|
|
- * Constructor.
|
|
26
|
|
- *
|
|
27
|
|
- * @param cargo
|
|
28
|
|
- * @param messageSource
|
|
29
|
|
- * @param locale
|
|
30
|
|
- * @param handlingEvents
|
|
31
|
|
- */
|
|
32
|
|
- public CargoTrackingViewAdapter(Cargo cargo, MessageSource messageSource, Locale locale, List<HandlingEvent> handlingEvents) {
|
|
33
|
|
- this.messageSource = messageSource;
|
|
34
|
|
- this.locale = locale;
|
|
35
|
|
- this.cargo = cargo;
|
|
36
|
|
-
|
|
37
|
|
- this.events = new ArrayList<HandlingEventViewAdapter>(handlingEvents.size());
|
|
38
|
|
- for (HandlingEvent handlingEvent : handlingEvents) {
|
|
39
|
|
- events.add(new HandlingEventViewAdapter(handlingEvent));
|
|
40
|
|
- }
|
|
41
|
|
- }
|
|
42
|
|
-
|
|
43
|
|
- /**
|
|
44
|
|
- * @param location a location
|
|
45
|
|
- * @return A formatted string for displaying the location.
|
|
46
|
|
- */
|
|
47
|
|
- private String getDisplayText(Location location) {
|
|
48
|
|
- return location.name();
|
|
49
|
|
- }
|
|
50
|
|
-
|
|
51
|
|
- /**
|
|
52
|
|
- * @return An unmodifiable list of handling event view adapters.
|
|
53
|
|
- */
|
|
54
|
|
- public List<HandlingEventViewAdapter> getEvents() {
|
|
55
|
|
- return Collections.unmodifiableList(events);
|
|
56
|
|
- }
|
|
57
|
|
-
|
|
58
|
|
- /**
|
|
59
|
|
- * @return A translated string describing the cargo status.
|
|
60
|
|
- */
|
|
61
|
|
- public String getStatusText() {
|
|
62
|
|
- final String code = "cargo.status." + cargo.transportStatus().name();
|
|
63
|
|
-
|
|
64
|
|
- final Object[] args;
|
|
65
|
|
- switch (cargo.transportStatus()) {
|
|
66
|
|
- case IN_PORT:
|
|
67
|
|
- args = new Object[]{getDisplayText(cargo.lastKnownLocation())};
|
|
68
|
|
- break;
|
|
69
|
|
- case ONBOARD_CARRIER:
|
|
70
|
|
- args = new Object[]{cargo.currentVoyage().voyageNumber().stringValue()};
|
|
71
|
|
- break;
|
|
72
|
|
- case CLAIMED:
|
|
73
|
|
- case NOT_RECEIVED:
|
|
74
|
|
- case UNKNOWN:
|
|
75
|
|
- default:
|
|
76
|
|
- args = null;
|
|
77
|
|
- break;
|
|
78
|
|
- }
|
|
79
|
|
-
|
|
80
|
|
- return messageSource.getMessage(code, args, "[Unknown status]", locale);
|
|
81
|
|
- }
|
|
82
|
|
-
|
|
83
|
|
- /**
|
|
84
|
|
- * @return Cargo destination location.
|
|
85
|
|
- */
|
|
86
|
|
- public String getDestination() {
|
|
87
|
|
- return getDisplayText(cargo.routeSpecification().destination());
|
|
88
|
|
- }
|
|
89
|
|
-
|
|
90
|
|
- /**
|
|
91
|
|
- * @return Cargo origin location.
|
|
92
|
|
- */
|
|
93
|
|
- public String getOrigin() {
|
|
94
|
|
- return getDisplayText(cargo.routeSpecification().origin());
|
|
95
|
|
- }
|
|
96
|
|
-
|
|
97
|
|
- /**
|
|
98
|
|
- * @return Cargo tracking id.
|
|
99
|
|
- */
|
|
100
|
|
- public String getTrackingId() {
|
|
101
|
|
- return cargo.trackingId().stringValue();
|
|
102
|
|
- }
|
|
103
|
|
-
|
|
104
|
|
- public String getEta() {
|
|
105
|
|
- Date eta = cargo.estimatedTimeOfArrival();
|
|
106
|
|
-
|
|
107
|
|
- if (eta == null) return "?";
|
|
108
|
|
- else {
|
|
109
|
|
- Location destination = cargo.routeSpecification().destination();
|
|
110
|
|
- SimpleDateFormat dateFormat = new SimpleDateFormat(FORMAT);
|
|
111
|
|
- dateFormat.setTimeZone(destination.timeZone());
|
|
112
|
|
- return dateFormat.format(eta);
|
|
113
|
|
- }
|
|
114
|
|
- }
|
|
115
|
|
-
|
|
116
|
|
- public String getNextExpectedActivity() {
|
|
117
|
|
- HandlingActivity activity = cargo.nextExpectedActivity();
|
|
118
|
|
- if (activity == null) {
|
|
119
|
|
- return "";
|
|
120
|
|
- }
|
|
121
|
|
-
|
|
122
|
|
- String text = "Next expected activity is to ";
|
|
123
|
|
- HandlingEvent.Type type = activity.type();
|
|
124
|
|
- if (type.sameValueAs(HandlingEvent.Type.LOAD)) {
|
|
125
|
|
- return
|
|
126
|
|
- text + type.name().toLowerCase() + " cargo onto voyage " + activity.voyage().voyageNumber() +
|
|
127
|
|
- " in " + activity.location().name();
|
|
128
|
|
- } else if (type.sameValueAs(HandlingEvent.Type.UNLOAD)) {
|
|
129
|
|
- return
|
|
130
|
|
- text + type.name().toLowerCase() + " cargo off of " + activity.voyage().voyageNumber() +
|
|
131
|
|
- " in " + activity.location().name();
|
|
132
|
|
- } else {
|
|
133
|
|
- return text + type.name().toLowerCase() + " cargo in " + activity.location().name();
|
|
134
|
|
- }
|
|
135
|
|
- }
|
|
136
|
|
-
|
|
137
|
|
- /**
|
|
138
|
|
- * @return True if cargo is misdirected.
|
|
139
|
|
- */
|
|
140
|
|
- public boolean isMisdirected() {
|
|
141
|
|
- return cargo.isMisdirected();
|
|
142
|
|
- }
|
|
143
|
|
-
|
|
144
|
|
- /**
|
|
145
|
|
- * Handling event view adapter component.
|
|
146
|
|
- */
|
|
147
|
|
- public final class HandlingEventViewAdapter {
|
|
148
|
|
-
|
|
149
|
|
- private final HandlingEvent handlingEvent;
|
|
150
|
|
-
|
|
151
|
|
- /**
|
|
152
|
|
- * Constructor.
|
|
153
|
|
- *
|
|
154
|
|
- * @param handlingEvent handling event
|
|
155
|
|
- */
|
|
156
|
|
- public HandlingEventViewAdapter(HandlingEvent handlingEvent) {
|
|
157
|
|
- this.handlingEvent = handlingEvent;
|
|
158
|
|
- }
|
|
159
|
|
-
|
|
160
|
|
- /**
|
|
161
|
|
- * @return Location where the event occurred.
|
|
162
|
|
- */
|
|
163
|
|
- public String getLocation() {
|
|
164
|
|
- return handlingEvent.location().name();
|
|
165
|
|
- }
|
|
166
|
|
-
|
|
167
|
|
- /**
|
|
168
|
|
- * @return Time when the event was completed.
|
|
169
|
|
- */
|
|
170
|
|
- public String getTime() {
|
|
171
|
|
- SimpleDateFormat dateFormat = new SimpleDateFormat(FORMAT);
|
|
172
|
|
- dateFormat.setTimeZone(handlingEvent.location().timeZone());
|
|
173
|
|
-
|
|
174
|
|
- return dateFormat.format(handlingEvent.completionTime());
|
|
175
|
|
- }
|
|
176
|
|
-
|
|
177
|
|
- /**
|
|
178
|
|
- * @return Type of event.
|
|
179
|
|
- */
|
|
180
|
|
- public String getType() {
|
|
181
|
|
- return handlingEvent.type().toString();
|
|
182
|
|
- }
|
|
183
|
|
-
|
|
184
|
|
- /**
|
|
185
|
|
- * @return Voyage number, or empty string if not applicable.
|
|
186
|
|
- */
|
|
187
|
|
- public String getVoyageNumber() {
|
|
188
|
|
- final Voyage voyage = handlingEvent.voyage();
|
|
189
|
|
- return voyage.voyageNumber().stringValue();
|
|
190
|
|
- }
|
|
191
|
|
-
|
|
192
|
|
- /**
|
|
193
|
|
- * @return True if the event was expected, according to the cargo's itinerary.
|
|
194
|
|
- */
|
|
195
|
|
- public boolean isExpected() {
|
|
196
|
|
- return cargo.itinerary().isExpected(handlingEvent.activity());
|
|
197
|
|
- }
|
|
198
|
|
-
|
|
199
|
|
- public String getDescription() {
|
|
200
|
|
- Object[] args;
|
|
201
|
|
-
|
|
202
|
|
- switch (handlingEvent.type()) {
|
|
203
|
|
- case LOAD:
|
|
204
|
|
- case UNLOAD:
|
|
205
|
|
- args = new Object[]{
|
|
206
|
|
- handlingEvent.voyage().voyageNumber().stringValue(),
|
|
207
|
|
- handlingEvent.location().name(),
|
|
208
|
|
- handlingEvent.completionTime()
|
|
209
|
|
- };
|
|
210
|
|
- break;
|
|
211
|
|
-
|
|
212
|
|
- case RECEIVE:
|
|
213
|
|
- case CLAIM:
|
|
214
|
|
- args = new Object[]{
|
|
215
|
|
- handlingEvent.location().name(),
|
|
216
|
|
- handlingEvent.completionTime()
|
|
217
|
|
- };
|
|
218
|
|
- break;
|
|
219
|
|
-
|
|
220
|
|
- default:
|
|
221
|
|
- args = new Object[]{};
|
|
222
|
|
- }
|
|
223
|
|
-
|
|
224
|
|
- String key = "deliveryHistory.eventDescription." + handlingEvent.type().name();
|
|
225
|
|
-
|
|
226
|
|
- return messageSource.getMessage(key, args, locale);
|
|
227
|
|
- }
|
|
228
|
|
-
|
|
229
|
|
- }
|
|
230
|
|
-
|
|
231
|
|
-}
|