Skip to content

Commit c98b45b

Browse files
committed
Using routing status instead of nullcheck against itinerary
1 parent cb73e35 commit c98b45b

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/cargo/Cargo.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public CustomsZone customsZone() {
214214
* @return Customs clearance point.
215215
*/
216216
public Location customsClearancePoint() {
217-
if (itinerary == null) {
217+
if (routingStatus() == NOT_ROUTED) {
218218
return Location.NONE;
219219
} else {
220220
return customsZone().entryPoint(itinerary.locations());
@@ -247,7 +247,7 @@ public HandlingActivity mostRecentHandlingActivity() {
247247
public Location earliestReroutingLocation() {
248248
if (isMisdirected()) {
249249
if (transportStatus() == ONBOARD_CARRIER) {
250-
return currentVoyage().arrivalLocationAfterDepartureFrom(lastKnownLocation());
250+
return currentVoyage().arrivalLocationWhenDepartedFrom(lastKnownLocation());
251251
} else {
252252
return lastKnownLocation();
253253
}
@@ -262,13 +262,11 @@ public Location earliestReroutingLocation() {
262262
* that describes a continuous route even if the cargo is currently misdirected.
263263
*/
264264
public Itinerary itineraryMergedWith(final Itinerary other) {
265-
if (this.itinerary == null) {
265+
if (routingStatus() == NOT_ROUTED) {
266266
return other;
267-
}
268-
269-
if (isMisdirected() && transportStatus() == ONBOARD_CARRIER) {
267+
} else if (isMisdirected() && transportStatus() == ONBOARD_CARRIER) {
270268
final Leg currentLeg = Leg.deriveLeg(
271-
currentVoyage(), lastKnownLocation(), currentVoyage().arrivalLocationAfterDepartureFrom(lastKnownLocation())
269+
currentVoyage(), lastKnownLocation(), currentVoyage().arrivalLocationWhenDepartedFrom(lastKnownLocation())
272270
);
273271

274272
return this.itinerary().
@@ -284,7 +282,9 @@ public Itinerary itineraryMergedWith(final Itinerary other) {
284282

285283
private boolean succedsMostRecentActivity(final HandlingActivity newHandlingActivity) {
286284
if (delivery.hasBeenHandled()) {
287-
final HandlingActivity priorActivity = itinerary.strictlyPriorOf(delivery.mostRecentPhysicalHandlingActivity(), newHandlingActivity);
285+
final HandlingActivity priorActivity = itinerary.strictlyPriorOf(
286+
delivery.mostRecentPhysicalHandlingActivity(), newHandlingActivity
287+
);
288288
return !newHandlingActivity.sameValueAs(priorActivity);
289289
} else {
290290
return true;

dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/cargo/Delivery.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,15 @@ boolean isOnRoute(final Itinerary itinerary, final RouteSpecification routeSpeci
152152
return routingStatus(itinerary, routeSpecification) == ROUTED && !isMisdirected(itinerary);
153153
}
154154

155+
boolean isUnloadedIn(final Location location) {
156+
return hasBeenHandled() &&
157+
mostRecentHandlingActivity.location().sameAs(location) &&
158+
mostRecentHandlingActivity().type() == UNLOAD;
159+
}
160+
155161
Delivery() {
156162
// Needed by Hibernate
157163
lastUpdatedOn = null;
158164
mostRecentHandlingActivity = mostRecentPhysicalHandlingActivity = null;
159165
}
160-
161-
boolean isUnloadedIn(Location customsClearancePoint) {
162-
return hasBeenHandled() &&
163-
mostRecentHandlingActivity.location().sameAs(customsClearancePoint) &&
164-
mostRecentHandlingActivity().type() == UNLOAD;
165-
}
166166
}

0 commit comments

Comments
 (0)