Package org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo

Examples of org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.Cargo


                // Deviation 3b
                try
                {
                    // Will throw NoSuchEntityException if not found in store
                    Cargo cargo = uow.get( Cargo.class, context.trackingIdString );
                    trackingId = cargo.trackingId().get();

                    // Deviation 3c
                    if( cargo.itinerary().get() == null )
                    {
                        throw new IllegalArgumentException( "Can't create handling event for non-routed cargo '"
                                                            + context.trackingIdString + "'." );
                    }
                }
View Full Code Here


        UnitOfWork uow = module.currentUnitOfWork();
        RouteSpecification routeSpec = routeSpecification( HONGKONG, STOCKHOLM, day( 20 ) );
        Cargos CARGOS = uow.get( Cargos.class, CargosEntity.CARGOS_ID );
        Delivery delivery = new BuildDeliverySnapshot( routeSpec ).get();
        Cargo cargo = CARGOS.createCargo( routeSpec, delivery, "ABCD" );

        // Same as previous test (just build from cargo instead)
        assertThat( delivery.timestamp().get().after( TODAY ), is( equalTo( true ) ) ); // TODAY is set first
        assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.NOT_ROUTED ) ) );
        assertThat( delivery.transportStatus().get(), is( equalTo( TransportStatus.NOT_RECEIVED ) ) );
View Full Code Here

        Cargos CARGOS = uow.get( Cargos.class, CargosEntity.CARGOS_ID );
        // Create cargo with valid input from customer
        TrackingId trackingId = new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, day( 17 ) ).book();

        // Retrieve created cargo from store
        Cargo cargo = uow.get( Cargo.class, trackingId.id().get() );

        // Test cargo data
        assertThat( cargo.trackingId().get(), is( equalTo( trackingId ) ) );
        assertThat( cargo.origin().get(), is( equalTo( HONGKONG ) ) );

        // Test route specification
        assertThat( cargo.routeSpecification().get().destination().get(), is( equalTo( STOCKHOLM ) ) );
        // day(17) here is calculated a few milliseconds after initial day(17), so it will be later...
        assertThat( cargo.routeSpecification().get().arrivalDeadline().get(),  equalTo( day( 17 )  ));

        // (Itinerary is not assigned yet)

        // Test derived delivery snapshot
        Delivery delivery = cargo.delivery().get();
        assertThat( delivery.timestamp().get().after( TODAY ), is( equalTo( true ) ) ); // TODAY is set first
        assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.NOT_ROUTED ) ) );
        assertThat( delivery.transportStatus().get(), is( equalTo( TransportStatus.NOT_RECEIVED ) ) );
        assertThat( delivery.nextExpectedHandlingEvent().get().handlingEventType().get(), is( equalTo( HandlingEventType.RECEIVE ) ) );
        assertThat( delivery.nextExpectedHandlingEvent().get().location().get(), is( equalTo( HONGKONG ) ) );
View Full Code Here

        UnitOfWork uow = module.currentUnitOfWork();
        Location HONGKONG = uow.get( Location.class, CNHKG.code().get() );
        Location STOCKHOLM = uow.get( Location.class, SESTO.code().get() );
        Cargos CARGOS = uow.get( Cargos.class, CargosEntity.CARGOS_ID );
        TrackingId trackingId = new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, day( 1 ) ).book();
        Cargo cargo = uow.get( Cargo.class, trackingId.id().get() );

        // No routes will be found
        new BookNewCargo( cargo ).routeCandidates();
    }
View Full Code Here

        Location STOCKHOLM = uow.get( Location.class, SESTO.code().get() );
        Cargos CARGOS = uow.get( Cargos.class, CargosEntity.CARGOS_ID );

        // Create valid cargo
        TrackingId trackingId = new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, day( 30 ) ).book();
        Cargo cargo = uow.get( Cargo.class, trackingId.id().get() );

        // Step 3 - Find possible routes
        List<Itinerary> routeCandidates = new BookNewCargo( cargo ).routeCandidates();

        // Check possible routes
        for (Itinerary itinerary : routeCandidates)
        {
            assertThat( "First load location equals origin location.",
                        itinerary.firstLeg().loadLocation().get(),
                        is( equalTo( cargo.routeSpecification().get().origin().get() ) ) );
            assertThat( "Last unload location equals destination location.",
                        itinerary.lastLeg().unloadLocation().get(),
                        is( equalTo( cargo.routeSpecification().get().destination().get() ) ) );
            assertThat( "Cargo will be delivered in time.",
                        itinerary.finalArrivalDate().before( cargo.routeSpecification().get().arrivalDeadline().get() ),
                        is( equalTo( true ) ) );
        }
    }
View Full Code Here

        Cargos CARGOS = uow.get( Cargos.class, CargosEntity.CARGOS_ID );

        // Create valid cargo
        Date deadline = day( 30 );
        TrackingId trackingId = new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, deadline ).book();
        Cargo cargo = uow.get( Cargo.class, trackingId.id().get() );

        List<Itinerary> routeCandidates = new BookNewCargo( cargo ).routeCandidates();

        // Get first route found
        // Would normally be found with an Itinerary id from customer selection
        Itinerary itinerary = routeCandidates.get( 0 );

        // Use case step 5 - System assigns cargo to route
        new BookNewCargo( cargo, itinerary ).assignCargoToRoute();

        assertThat( "Itinerary has been assigned to cargo.", itinerary, is( equalTo( cargo.itinerary().get() ) ) );

        // BuildDeliverySnapshot will check if itinerary is valid. No need to check it here.

        // Check values set in new delivery snapshot
        Delivery delivery = cargo.delivery().get();
        assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.ROUTED ) ) );

        // ETA (= Unload time of last Leg) is before Deadline (set in previous test)
        assertTrue( delivery.eta().get().before( deadline ) );
    }
View Full Code Here

                // Build delivery snapshot from route specification
                Delivery delivery = new BuildDeliverySnapshot( routeSpec ).get();

                // Create cargo
                Cargo cargo = cargos.createCargo( routeSpec, delivery, trackingIdString );

                return cargo.trackingId().get();
            }
View Full Code Here

*/
public class TrackingQueries extends Queries
{
    public List<String> routedCargos()
    {
        Cargo cargoEntity = templateFor( CargoEntity.class );

        QueryBuilder<CargoEntity> qb = qbf.newQueryBuilder( CargoEntity.class )
            .where( isNotNull( cargoEntity.itinerary() ) );
        Query<CargoEntity> cargos = uowf.currentUnitOfWork().newQuery( qb )
            .orderBy( orderBy( cargoEntity.trackingId().get().id() ) );

        List<String> cargoList = new ArrayList<String>();
        for( CargoEntity cargo : cargos )
        {
            cargoList.add( cargo.trackingId().get().id().get() );
View Full Code Here

        RoutingService routingService;

        public List<IModel<Itinerary>> routeCandidates( final String trackingIdString )
            throws FoundNoRoutesException
        {
            Cargo cargo = uowf.currentUnitOfWork().get( Cargo.class, trackingIdString );
            List<Itinerary> routes = routingService.fetchRoutesForSpecification( cargo.routeSpecification().get() );

            List<IModel<Itinerary>> modelList = new ArrayList<IModel<Itinerary>>();
            for( Itinerary itinerary : routes )
            {
                modelList.add( JSONModel.of( itinerary ) );
View Full Code Here

TOP

Related Classes of org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.Cargo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.