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

Examples of org.qi4j.sample.dcicargo.sample_a.data.shipping.location.Location$Mixin


        final static int MAX_TRIES = 10;

        public List<Itinerary> fetchRoutesForSpecification( RouteSpecification routeSpecification )
            throws FoundNoRoutesException
        {
            final Location origin = routeSpecification.origin().get();
            final Location destination = routeSpecification.destination().get();

            List<TransitPath> transitPaths;
            List<Itinerary> itineraries = new ArrayList<Itinerary>();

            // Try a MAX_TRIES times to avoid empty results too often
            int tries = 0;
            do
            {
                try
                {
                    transitPaths = graphTraversalService.findShortestPath( origin.getCode(), destination.getCode() );
                }
                catch( RemoteException e )
                {
                    logger.error( e.getMessage(), e );
                    return Collections.emptyList();
                }

                // The returned result is then translated back into our domain model.
                for( TransitPath transitPath : transitPaths )
                {
                    final Itinerary itinerary = toItinerary( transitPath );

                    // Use the specification to safe-guard against invalid itineraries
                    // We can use the side-effects free method of the RouteSpecification data object
                    if( routeSpecification.isSatisfiedBy( itinerary ) )
                    {
                        itineraries.add( itinerary );
                    }
                }
            }
            while( tries++ < MAX_TRIES && itineraries.size() == 0 );

            if( itineraries.size() == 0 )
            {
                throw new FoundNoRoutesException( destination.name().get(),
                                                  new LocalDate( routeSpecification.arrivalDeadline().get() ) );
            }

            return itineraries;
        }
View Full Code Here


    public void beforeEachTest()
        throws Exception
    {
        UnitOfWork uow = module.currentUnitOfWork();
        Cargos CARGOS = uow.get( Cargos.class, CargosEntity.CARGOS_ID );
        Location HONGKONG = uow.get( Location.class, CNHKG.code().get() );
        SHANGHAI = uow.get( Location.class, CNSHA.code().get() );
        STOCKHOLM = uow.get( Location.class, SESTO.code().get() );
        Location NEWYORK = uow.get( Location.class, USNYC.code().get() );
        DALLAS = uow.get( Location.class, USDAL.code().get() );
        Voyage V100S = uow.get( Voyage.class, "V100S" );
        V200T = uow.get( Voyage.class, "V200T" );
        V300A = uow.get( Voyage.class, "V300A" );
View Full Code Here

                {
                    ExpectedHandlingEvent expectedEvent = context.itinerary
                        .expectedEventAfterUnloadAt( lastKnownLocation );
                    context.newDeliverySnapshot.nextExpectedHandlingEvent().set( expectedEvent );

                    Location expectedDestination = ( (RouteSpecification) context.factory ).destination().get();
                    context.newDeliverySnapshot
                        .isUnloadedAtDestination()
                        .set( lastKnownLocation.equals( expectedDestination ) );
                }
            }
View Full Code Here

            // Deviation 4d
            private void cargoInCustoms()
            {
                context.newDeliverySnapshot.transportStatus().set( TransportStatus.IN_PORT );

                Location expectedDestination = ( (RouteSpecification) context.factory ).destination().get();
                context.newDeliverySnapshot
                    .isUnloadedAtDestination()
                    .set( lastKnownLocation.equals( expectedDestination ) );
            }
View Full Code Here

            // Deviation 4e
            private void cargoClaimed()
            {
                context.newDeliverySnapshot.transportStatus().set( TransportStatus.CLAIMED );

                Location expectedDestination = ( (RouteSpecification) context.factory ).destination().get();
                context.newDeliverySnapshot
                    .isUnloadedAtDestination()
                    .set( lastKnownLocation.equals( expectedDestination ) );

                if( !context.itinerary.expectsDestination( lastKnownLocation ) )
View Full Code Here

    @Test( expected = RouteException.class )
    public void deviation2a_OriginAndDestinationSame() throws Exception
    {
        UnitOfWork uow = module.currentUnitOfWork();
        Location HONGKONG = uow.get( Location.class, CNHKG.code().get() );
        Cargos CARGOS = uow.get( Cargos.class, CargosEntity.CARGOS_ID );
        new BookNewCargo( CARGOS, HONGKONG, HONGKONG, day( 17 ) ).book();
    }
View Full Code Here

    @Test( expected = RouteException.class )
    public void deviation_2b_1_DeadlineInThePastNotAccepted() throws Exception
    {
        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 );
        new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, day( -1 ) ).book();
    }
View Full Code Here

    @Test( expected = RouteException.class )
    public void deviation_2b_2_DeadlineTodayIsTooEarly() throws Exception
    {
        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 );
        new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, day( 0 ) ).book();
    }
View Full Code Here

    @Test
    public void deviation_2b_3_DeadlineTomorrowIsOkay() throws Exception
    {
        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 );
        new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, day( 1 ) ).book();
    }
View Full Code Here

    @Test
    public void step_2_CreateNewCargo() throws Exception
    {
        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 );
        // Create cargo with valid input from customer
        TrackingId trackingId = new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, day( 17 ) ).book();

        // Retrieve created cargo from store
View Full Code Here

TOP

Related Classes of org.qi4j.sample.dcicargo.sample_a.data.shipping.location.Location$Mixin

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.