public void createBaseData()
throws Exception
{
logger.debug( "CREATING BASIC DATA..." );
UnitOfWork uow = module.newUnitOfWork( newUsecase( "Create base data" ) );
// Create locations
location( unlocode( "AUMEL" ), "Melbourne" );
location( unlocode( "CNHGH" ), "Hangzhou" );
location( unlocode( "CNHKG" ), "Hongkong" );
location( unlocode( "CNSHA" ), "Shanghai" );
location( unlocode( "DEHAM" ), "Hamburg" );
location( unlocode( "FIHEL" ), "Helsinki" );
location( unlocode( "JNTKO" ), "Tokyo" );
location( unlocode( "NLRTM" ), "Rotterdam" );
location( unlocode( "SEGOT" ), "Gothenburg" );
location( unlocode( "SESTO" ), "Stockholm" );
location( unlocode( "SOMGQ" ), "Mogadishu" );
location( unlocode( "USCHI" ), "Chicago" );
location( unlocode( "USDAL" ), "Dallas" );
location( unlocode( "USNYC" ), "New York" );
// Create voyages
try
{
for( TransitPath voyagePath : graphTraversalService.getVoyages() )
{
String voyageNumber = null;
List<CarrierMovement> carrierMovements = new ArrayList<>();
for( TransitEdge voyageEdge : voyagePath.getTransitEdges() )
{
voyageNumber = voyageEdge.getVoyageNumber();
Location from = uow.get( Location.class, voyageEdge.getFromUnLocode() );
Location to = uow.get( Location.class, voyageEdge.getToUnLocode() );
carrierMovements.add( carrierMovement( from, to, voyageEdge.getFromDate(), voyageEdge.getToDate() ) );
}
ValueBuilder<Schedule> schedule = module.newValueBuilder( Schedule.class );
schedule.prototype().carrierMovements().set( carrierMovements );
voyage( voyageNumber, schedule.newInstance() );
}
}
catch( RemoteException e )
{
e.printStackTrace();
}
// Cargo and HandlingEvent aggregate roots
uow.newEntity( CargoAggregateRoot.class, CargoAggregateRoot.CARGOS_ID );
uow.newEntity( HandlingEventAggregateRoot.class, HandlingEventAggregateRoot.HANDLING_EVENTS_ID );
try
{
uow.complete();
logger.debug( "BASIC DATA CREATED" );
}
catch( UnitOfWorkCompletionException ex )
{
uow.discard();
logger.error( "UNABLE TO CREATE BASIC DATA" );
throw ex;
}
}