|
|
@@ -120,12 +120,6 @@ public class Cargo extends EntitySupport<Cargo,TrackingId> {
|
|
120
|
120
|
return itinerary.activitySucceding(delivery.mostRecentPhysicalHandlingActivity());
|
|
121
|
121
|
}
|
|
122
|
122
|
|
|
123
|
|
- private boolean unloadedInCustomsClearancePoint() {
|
|
124
|
|
- return mostRecentHandlingActivity() != null &&
|
|
125
|
|
- mostRecentHandlingActivity().location().sameAs(customsClearancePoint()) &&
|
|
126
|
|
- mostRecentHandlingActivity().type() == UNLOAD;
|
|
127
|
|
- }
|
|
128
|
|
-
|
|
129
|
123
|
/**
|
|
130
|
124
|
* @return True if cargo is misdirected.
|
|
131
|
125
|
*/
|
|
|
@@ -162,6 +156,29 @@ public class Cargo extends EntitySupport<Cargo,TrackingId> {
|
|
162
|
156
|
}
|
|
163
|
157
|
|
|
164
|
158
|
/**
|
|
|
159
|
+ * Updates all aspects of the cargo aggregate status
|
|
|
160
|
+ * based on the current route specification, itinerary and handling of the cargo.
|
|
|
161
|
+ * <p/>
|
|
|
162
|
+ * When either of those three changes, i.e. when a new route is specified for the cargo,
|
|
|
163
|
+ * the cargo is assigned to a route or when the cargo is handled, the status must be
|
|
|
164
|
+ * re-calculated.
|
|
|
165
|
+ * <p/>
|
|
|
166
|
+ * {@link RouteSpecification} and {@link Itinerary} are both inside the Cargo
|
|
|
167
|
+ * aggregate, so changes to them cause the status to be updated <b>synchronously</b>,
|
|
|
168
|
+ * but handling cause the status update to happen <b>asynchronously</b>
|
|
|
169
|
+ * since {@link HandlingEvent} is in a different aggregate.
|
|
|
170
|
+ *
|
|
|
171
|
+ * @param handlingActivity handling activity
|
|
|
172
|
+ */
|
|
|
173
|
+ public void handled(final HandlingActivity handlingActivity) {
|
|
|
174
|
+ Validate.notNull(handlingActivity, "Handling activity is required");
|
|
|
175
|
+
|
|
|
176
|
+ if (succedsMostRecentActivity(handlingActivity)) {
|
|
|
177
|
+ this.delivery = delivery.onHandling(handlingActivity);
|
|
|
178
|
+ }
|
|
|
179
|
+ }
|
|
|
180
|
+
|
|
|
181
|
+ /**
|
|
165
|
182
|
* Specifies a new route for this cargo.
|
|
166
|
183
|
*
|
|
167
|
184
|
* @param routeSpecification route specification.
|
|
|
@@ -222,10 +239,15 @@ public class Cargo extends EntitySupport<Cargo,TrackingId> {
|
|
222
|
239
|
return delivery.mostRecentHandlingActivity();
|
|
223
|
240
|
}
|
|
224
|
241
|
|
|
|
242
|
+ /**
|
|
|
243
|
+ * @return The earliest rerouting location.
|
|
|
244
|
+ * If the cargo is in port, it's the current location.
|
|
|
245
|
+ * If it's onboard a carrier it's the next arrival location.
|
|
|
246
|
+ */
|
|
225
|
247
|
public Location earliestReroutingLocation() {
|
|
226
|
248
|
if (isMisdirected()) {
|
|
227
|
249
|
if (transportStatus() == ONBOARD_CARRIER) {
|
|
228
|
|
- return currentVoyage().nextArrivalLocation(lastKnownLocation());
|
|
|
250
|
+ return currentVoyage().arrivalLocationAfterDepartureFrom(lastKnownLocation());
|
|
229
|
251
|
} else {
|
|
230
|
252
|
return lastKnownLocation();
|
|
231
|
253
|
}
|
|
|
@@ -235,32 +257,14 @@ public class Cargo extends EntitySupport<Cargo,TrackingId> {
|
|
235
|
257
|
}
|
|
236
|
258
|
|
|
237
|
259
|
/**
|
|
238
|
|
- * Updates all aspects of the cargo aggregate status
|
|
239
|
|
- * based on the current route specification, itinerary and handling of the cargo.
|
|
240
|
|
- * <p/>
|
|
241
|
|
- * When either of those three changes, i.e. when a new route is specified for the cargo,
|
|
242
|
|
- * the cargo is assigned to a route or when the cargo is handled, the status must be
|
|
243
|
|
- * re-calculated.
|
|
244
|
|
- * <p/>
|
|
245
|
|
- * {@link RouteSpecification} and {@link Itinerary} are both inside the Cargo
|
|
246
|
|
- * aggregate, so changes to them cause the status to be updated <b>synchronously</b>,
|
|
247
|
|
- * but handling cause the status update to happen <b>asynchronously</b>
|
|
248
|
|
- * since {@link HandlingEvent} is in a different aggregate.
|
|
249
|
|
- *
|
|
250
|
|
- * @param handlingActivity handling activity
|
|
|
260
|
+ * @param other itinerary
|
|
|
261
|
+ * @return An merge between the current itinerary and the provided itinerary
|
|
|
262
|
+ * that describes a continuous route even if the cargo is currently misdirected.
|
|
251
|
263
|
*/
|
|
252
|
|
- public void handled(final HandlingActivity handlingActivity) {
|
|
253
|
|
- Validate.notNull(handlingActivity, "Handling activity is required");
|
|
254
|
|
-
|
|
255
|
|
- if (isSignificant(handlingActivity)) {
|
|
256
|
|
- this.delivery = delivery.onHandling(handlingActivity);
|
|
257
|
|
- }
|
|
258
|
|
- }
|
|
259
|
|
-
|
|
260
|
264
|
public Itinerary itineraryMergedWith(final Itinerary other) {
|
|
261
|
265
|
if (isMisdirected() && transportStatus() == ONBOARD_CARRIER) {
|
|
262
|
266
|
final Leg currentLeg = Leg.deriveLeg(
|
|
263
|
|
- currentVoyage(), lastKnownLocation(), currentVoyage().nextArrivalLocation(lastKnownLocation())
|
|
|
267
|
+ currentVoyage(), lastKnownLocation(), currentVoyage().arrivalLocationAfterDepartureFrom(lastKnownLocation())
|
|
264
|
268
|
);
|
|
265
|
269
|
|
|
266
|
270
|
return this.itinerary().
|
|
|
@@ -274,10 +278,6 @@ public class Cargo extends EntitySupport<Cargo,TrackingId> {
|
|
274
|
278
|
}
|
|
275
|
279
|
}
|
|
276
|
280
|
|
|
277
|
|
- private boolean isSignificant(final HandlingActivity newHandlingActivity) {
|
|
278
|
|
- return succedsMostRecentActivity(newHandlingActivity);
|
|
279
|
|
- }
|
|
280
|
|
-
|
|
281
|
281
|
private boolean succedsMostRecentActivity(final HandlingActivity newHandlingActivity) {
|
|
282
|
282
|
if (delivery.hasBeenHandled()) {
|
|
283
|
283
|
final HandlingActivity priorActivity = itinerary.strictlyPriorOf(delivery.mostRecentPhysicalHandlingActivity(), newHandlingActivity);
|
|
|
@@ -287,6 +287,12 @@ public class Cargo extends EntitySupport<Cargo,TrackingId> {
|
|
287
|
287
|
}
|
|
288
|
288
|
}
|
|
289
|
289
|
|
|
|
290
|
+ private boolean unloadedInCustomsClearancePoint() {
|
|
|
291
|
+ return mostRecentHandlingActivity() != null &&
|
|
|
292
|
+ mostRecentHandlingActivity().location().sameAs(customsClearancePoint()) &&
|
|
|
293
|
+ mostRecentHandlingActivity().type() == UNLOAD;
|
|
|
294
|
+ }
|
|
|
295
|
+
|
|
290
|
296
|
@Override
|
|
291
|
297
|
public String toString() {
|
|
292
|
298
|
return trackingId + " (" + routeSpecification + ")";
|