super( new PageParameters().set( 0, trackingId ) );
IModel<CargoDTO> cargoModel = new CommonQueries().cargo( trackingId );
CargoDTO cargo = cargoModel.getObject();
Delivery delivery = cargo.delivery().get();
TransportStatus transportStatus = delivery.transportStatus().get();
RouteSpecification routeSpecification = cargo.routeSpecification().get();
final RoutingStatus routingStatus = delivery.routingStatus().get();
boolean isMisrouted = routingStatus == MISROUTED;
boolean isReRouted = !cargo.origin().get().getCode().equals( routeSpecification.origin().get().getCode() );
add( new PrevNext( "prevNext", CargoDetailsPage.class, trackingId ) );
add( new Label( "trackingId", trackingId ) );
// Show both cargo origin and new route spec origin when re-routed during transport
if( isReRouted )
{
Fragment originFragment = new Fragment( "origin", "re-routed-originFragment", this );
originFragment.add( new Label( "cargoOrigin", cargo.origin().get().getString() ) );
originFragment.add( new Label( "routeOrigin", routeSpecification.origin()
.get()
.getString() ).add( new CorrectColor( isMisrouted ) ) );
add( originFragment );
}
else
{
Fragment originFragment = new Fragment( "origin", "originFragment", this );
originFragment.add( new Label( "cargoOrigin", cargo.origin().get().getString() ) );
add( originFragment );
}
add( new Label( "departure", Model.of( routeSpecification.earliestDeparture().get() ) ) );
add( new Label( "destination", routeSpecification.destination()
.get()
.getString() ).add( new CorrectColor( isMisrouted ) ) );
add( new Label( "deadline", Model.of( routeSpecification.arrivalDeadline().get() ) ) );
add( new Label( "routingStatus", routingStatus.toString() ).add( new ErrorColor( isMisrouted ) ) );
add( new LinkPanel( "changeDestination", ChangeDestinationPage.class, trackingId, "Change destination" ) );
if( transportStatus.equals( CLAIMED ) )
{
// Can't re-route claimed cargo
add( new Label( "routingAction" ) );
add( new DeliveryFragment( delivery ) );
add( new ItineraryFragment( cargoModel, routingStatus ) );