// Current itinerary progress
newDelivery.itineraryProgressIndex().set( c.itineraryProgressIndex );
// Step 3 - Verify cargo is on track
Leg plannedCarrierMovement = c.itinerary.leg( c.itineraryProgressIndex );
if( plannedCarrierMovement == null )
{
throw new InspectionFailedException( "Itinerary progress index '" + c.itineraryProgressIndex + "' is invalid!" );
}
Integer itineraryProgressIndex;
// if (c.wasMisdirected && c.unloadLocation.equals( c.routeSpecification.origin().get() ))
if( c.unloadLocation.equals( c.routeSpecification.origin().get() ) )
// if (c.itineraryProgressIndex == -1)
{
/**
* Unloading in the origin of a route specification of a misdirected cargo
* tells us that the cargo has been re-routed (re-routing while on board a
* carrier sets new origin of route specification to arrival location of
* current carrier movement).
*
* Since the current unload was related to the old itinerary, we don't verify
* the misdirection status against the new itinerary.
*
* The itinerary index starts over from the first leg of the new itinerary
* */
itineraryProgressIndex = 0;
}
else if( !plannedCarrierMovement.unloadLocation().get().equals( c.unloadLocation ) )
{
newDelivery.isMisdirected().set( true );
cargo.delivery().set( newDeliveryBuilder.newInstance() );
throw new CargoMisdirectedException( c.unloadEvent, "Itinerary expected unload in "
+ plannedCarrierMovement.unloadLocation()
.get() );
}
else if( !plannedCarrierMovement.voyage().get().equals( c.voyage ) )
{
// Do we care if cargo unloads from an unexpected carrier?
itineraryProgressIndex = c.itineraryProgressIndex + 1;
}
else
{
// Cargo delivery has progressed and we expect a load in next itinerary leg load location
itineraryProgressIndex = c.itineraryProgressIndex + 1;
}
newDelivery.isMisdirected().set( false );
// Modify itinerary progress index according to misdirection status
newDelivery.itineraryProgressIndex().set( itineraryProgressIndex );
// Step 4 - Determine next expected handling event
Leg nextCarrierMovement = c.itinerary.leg( itineraryProgressIndex );
ValueBuilder<NextHandlingEvent> nextHandlingEvent = vbf.newValueBuilder( NextHandlingEvent.class );
nextHandlingEvent.prototype().handlingEventType().set( LOAD );
nextHandlingEvent.prototype().location().set( nextCarrierMovement.loadLocation().get() );
nextHandlingEvent.prototype().time().set( nextCarrierMovement.loadTime().get() );
nextHandlingEvent.prototype().voyage().set( nextCarrierMovement.voyage().get() );
newDelivery.nextHandlingEvent().set( nextHandlingEvent.newInstance() );
// Step 5 - Save cargo delivery snapshot
cargo.delivery().set( newDeliveryBuilder.newInstance() );