int i = 11; // starting at 11 for sortable tracking id prefix in lists
QueryBuilder<Cargo> qb = qbf.newQueryBuilder( Cargo.class );
for( Cargo cargo : uow.newQuery( qb ) )
{
String trackingId = cargo.trackingId().get().id().get();
ExpectedHandlingEvent nextEvent;
Date time;
String port;
String voyage;
HandlingEventType type;
// BOOK cargo with no handling (i == 11)
// ROUTE
if( i > 11 )
{
Itinerary itinerary = new BookNewCargo( cargo ).routeCandidates().get( 0 );
new BookNewCargo( cargo, itinerary ).assignCargoToRoute();
}
// RECEIVE
if( i > 12 )
{
nextEvent = cargo.delivery().get().nextExpectedHandlingEvent().get();
port = nextEvent.location().get().getCode();
Date mockTime = new Date();
new RegisterHandlingEvent( mockTime, mockTime, trackingId, "RECEIVE", port, null ).register();
}
// LOAD
if( i > 13 )
{
nextEvent = cargo.delivery().get().nextExpectedHandlingEvent().get();
time = nextEvent.time().get();
port = nextEvent.location().get().getCode();
voyage = nextEvent.voyage().get().voyageNumber().get().number().get();
new RegisterHandlingEvent( time, time, trackingId, "LOAD", port, voyage ).register();
}
// UNLOAD
if( i > 14 )
{
nextEvent = cargo.delivery().get().nextExpectedHandlingEvent().get();
time = nextEvent.time().get();
port = nextEvent.location().get().getCode();
voyage = nextEvent.voyage().get().voyageNumber().get().number().get();
new RegisterHandlingEvent( time, time, trackingId, "UNLOAD", port, voyage ).register();
}
// Cargo is now in port
nextEvent = cargo.delivery().get().nextExpectedHandlingEvent().get();
time = nextEvent.time().get();
port = nextEvent.location().get().getCode();
type = nextEvent.handlingEventType().get();
// MISDIRECTED: Unexpected customs handling before reaching destination
if( i == 16 )
{
new RegisterHandlingEvent( time, time, trackingId, "CUSTOMS", port, null ).register();
}
// MISDIRECTED: Unexpected claim before reaching destination
if( i == 17 )
{
new RegisterHandlingEvent( time, time, trackingId, "CLAIM", port, null ).register();
}
// MISDIRECTED: LOAD in wrong port
if( i == 18 )
{
String wrongPort = port.equals( "USDAL" ) ? "USCHI" : "USDAL";
voyage = nextEvent.voyage().get().voyageNumber().get().number().get();
new RegisterHandlingEvent( time, time, trackingId, "LOAD", wrongPort, voyage ).register();
}
// MISDIRECTED: LOAD onto wrong carrier
if( i == 19 )
{
voyage = nextEvent.voyage().get().voyageNumber().get().number().get();
String wrongVoyage = voyage.equals( "V100S" ) ? "V200T" : "V100S";
new RegisterHandlingEvent( time, time, trackingId, "LOAD", port, wrongVoyage ).register();
}
// MISDIRECTED: LOAD onto wrong carrier in wrong port
if( i == 20 )
{
String wrongPort = port.equals( "USDAL" ) ? "USCHI" : "USDAL";
voyage = nextEvent.voyage().get().voyageNumber().get().number().get();
String wrongVoyage = voyage.equals( "V100S" ) ? "V200T" : "V100S";
new RegisterHandlingEvent( time, time, trackingId, "LOAD", wrongPort, wrongVoyage ).register();
}
// MISDIRECTED: UNLOAD in wrong port
if( i == 21 )
{
String wrongPort = port.equals( "USDAL" ) ? "USCHI" : "USDAL";
voyage = nextEvent.voyage().get().voyageNumber().get().number().get();
new RegisterHandlingEvent( time, time, trackingId, "UNLOAD", wrongPort, voyage ).register();
}
// MISDIRECTED: UNLOAD from wrong carrier
if( i == 22 )
{
voyage = nextEvent.voyage().get().voyageNumber().get().number().get();
String wrongVoyage = voyage.equals( "V100S" ) ? "V200T" : "V100S";
new RegisterHandlingEvent( time, time, trackingId, "UNLOAD", port, wrongVoyage ).register();
}
// MISDIRECTED: UNLOAD from wrong carrier in wrong port
if( i == 23 )
{
String wrongPort = port.equals( "USDAL" ) ? "USCHI" : "USDAL";
voyage = nextEvent.voyage().get().voyageNumber().get().number().get();
String wrongVoyage = voyage.equals( "V100S" ) ? "V200T" : "V100S";
new RegisterHandlingEvent( time, time, trackingId, "UNLOAD", wrongPort, wrongVoyage ).register();
}
// Complete all LOAD/UNLOADS
if( i > 23 )
{
do
{
voyage = nextEvent.voyage().get().voyageNumber().get().number().get();
new RegisterHandlingEvent( time, time, trackingId, type.name(), port, voyage ).register();
nextEvent = cargo.delivery().get().nextExpectedHandlingEvent().get();
time = nextEvent.time().get();
port = nextEvent.location().get().getCode();
type = nextEvent.handlingEventType().get();
}
while( type != HandlingEventType.CLAIM );
}
// CLAIM at destination - this ends the life cycle of the cargo delivery