Package org.qi4j.api.unitofwork

Examples of org.qi4j.api.unitofwork.UnitOfWork


        public Cargo createCargo( RouteSpecification routeSpecification, Delivery delivery, String id )
        {
            TrackingId trackingId = buildTrackingId( id );

            UnitOfWork uow = uowf.currentUnitOfWork();
            EntityBuilder<Cargo> cargoBuilder = uow.newEntityBuilder( Cargo.class, trackingId.id().get() );
            cargoBuilder.instance().trackingId().set( trackingId );
            cargoBuilder.instance().origin().set( routeSpecification.origin().get() );
            cargoBuilder.instance().routeSpecification().set( routeSpecification );
            cargoBuilder.instance().delivery().set( delivery );
View Full Code Here


            return itinerary.newInstance();
        }

        private Leg toLeg( TransitEdge edge )
        {
            UnitOfWork uow = uowf.currentUnitOfWork();

            // Build Leg value object
            ValueBuilder<Leg> leg = vbf.newValueBuilder( Leg.class );
            leg.prototype().voyage().set( uow.get( Voyage.class, edge.getVoyageNumber() ) );
            leg.prototype().loadLocation().set( uow.get( Location.class, edge.getFromUnLocode() ) );
            leg.prototype().unloadLocation().set( uow.get( Location.class, edge.getToUnLocode() ) );
            leg.prototype().loadTime().set( edge.getFromDate() );
            leg.prototype().unloadTime().set( edge.getToDate() );

            return leg.newInstance();
        }
View Full Code Here

                        "'" + context.eventTypeString + "' is not a valid handling event type. Valid types are: "
                        + Arrays.toString( HandlingEventType.values() ) );
                }

                // Verifications against data store
                UnitOfWork uow = uowf.currentUnitOfWork();

                // 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 + "'." );
                    }
                }
                catch( NoSuchEntityException e )
                {
                    throw new IllegalArgumentException( "Found no cargo with tracking id '" + context.trackingIdString + "'." );
                }

                // Deviation 3d
                try
                {
                    location = uow.get( Location.class, context.unLocodeString );
                }
                catch( NoSuchEntityException e )
                {
                    throw new IllegalArgumentException( "Unknown location: " + context.unLocodeString );
                }

                // Deviation 3e
                if( handlingEventType.requiresVoyage() )
                {
                    // Deviation 3e1a
                    if( context.voyageNumberString == null )
                    {
                        throw new IllegalArgumentException( "Handling event " + handlingEventType.toString() +
                                                            " requires a voyage. No voyage number submitted." );
                    }

                    // Deviation 3e1b
                    try
                    {
                        voyage = uow.get( Voyage.class, context.voyageNumberString );
                    }
                    catch( NoSuchEntityException e )
                    {
                        throw new IllegalArgumentException(
                            "Found no voyage with voyage number '" + context.voyageNumberString + "'." );
View Full Code Here

    @Before
    public void prepareTest()
        throws Exception
    {
        super.prepareTest();
        UnitOfWork uow = module.currentUnitOfWork();
        HONGKONG = uow.get( Location.class, CNHKG.code().get() );
        STOCKHOLM = uow.get( Location.class, SESTO.code().get() );
        SHANGHAI = uow.get( Location.class, CNSHA.code().get() );
        TOKYO = uow.get( Location.class, JNTKO.code().get() );
        NEWYORK = uow.get( Location.class, USNYC.code().get() );
        DALLAS = uow.get( Location.class, USDAL.code().get() );
        HANGZHOU = uow.get( Location.class, CNHGH.code().get() );
        HELSINKI = uow.get( Location.class, FIHEL.code().get() );
        HAMBURG = uow.get( Location.class, DEHAM.code().get() );
        V100S = uow.get( Voyage.class, "V100S" );
        V200T = uow.get( Voyage.class, "V200T" );
        V300A = uow.get( Voyage.class, "V300A" );
        V400S = uow.get( Voyage.class, "V400S" );
        V500S = uow.get( Voyage.class, "V500S" );

        Cargos CARGOS = uow.get( Cargos.class, CargosEntity.CARGOS_ID );
        trackingId = new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, day( 17 ) ).createCargo( "ABC" );
        cargo = uow.get( Cargo.class, trackingId.id().get() );

        itinerary = itinerary(
            leg( V100S, HONGKONG, NEWYORK, day( 1 ), day( 8 ) ),
            leg( V200T, NEWYORK, DALLAS, day( 9 ), day( 12 ) ),
            leg( V300A, DALLAS, STOCKHOLM, day( 13 ), day( 16 ) )
View Full Code Here

                logger.debug( "================================" );
                logger.debug( "REQUEST start" );
                logger.debug( requestCycle.getRequest().toString() );
                logger.debug( requestCycle.getRequest().getRequestParameters().toString() );

                UnitOfWork uow = uowf.newUnitOfWork( UsecaseBuilder.newUsecase( "REQUEST" ) );
                logger.debug( "  ### NEW " + uow + "   ### MODULE: " + qi4jModule );
            }

            @Override
            public void onEndRequest( final RequestCycle requestCycle )
            {
                UnitOfWork uow = uowf.currentUnitOfWork();
                if( uow != null )
                {
                    try
                    {
                        if( "POST".equals( ( (HttpServletRequest) requestCycle.getRequest()
                            .getContainerRequest() ).getMethod() ) )
                        {
                            // "Save"
                            logger.debug( "  ### COMPLETE " + uow + "   ### MODULE: " + qi4jModule );
                            uow.complete();
                        }
                        else
                        {
                            // GET requests
                            logger.debug( "  ### DISCARD " + uow + "   ### MODULE: " + qi4jModule );
                            uow.discard();
                        }
                    }
                    catch( ConcurrentEntityModificationException e )
                    {
                        logger.error( "  ### DISCARD " + uow + "   ### MODULE: " + qi4jModule );
                        uow.discard();
                        e.printStackTrace();
                    }
                    catch( UnitOfWorkCompletionException e )
                    {
                        logger.error( "  ### DISCARD " + uow + "   ### MODULE: " + qi4jModule );
                        uow.discard();
                        e.printStackTrace();
                    }
                }
                logger.debug( "REQUEST end" );
                logger.debug( "------------------------------------" );
View Full Code Here

    @Test
    public void deviation_2c_ItineraryIsUnknown_buildFromNonRoutedCargo() throws Exception
    {
        deviation_2c_ItineraryIsUnknown_buildFromRouteSpecification();

        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
View Full Code Here

    @Test
    public void deviation_4a_RECEIVE_1a_UnexpectedPort() throws Exception
    {
        deviation_3a_CargoHasNoHandlingHistory();

        UnitOfWork uow = module.currentUnitOfWork();
        HandlingEventsEntity HANDLING_EVENTS = uow.get( HandlingEventsEntity.class, HandlingEventsEntity.HANDLING_EVENTS_ID );
        // Unexpected receipt in Shanghai
        HandlingEvent handlingEvent = HANDLING_EVENTS.createHandlingEvent( day( 1 ), day( 1 ), trackingId, HandlingEventType.RECEIVE, SHANGHAI, null );
        Delivery delivery = new BuildDeliverySnapshot( cargo, handlingEvent ).get();

        // We don't know what's next for a misdirected cargo
View Full Code Here

    @Test
    public void deviation_4a_RECEIVE_1b_ExpectedPort() throws Exception
    {
        deviation_4a_RECEIVE_1a_UnexpectedPort();

        UnitOfWork uow = module.currentUnitOfWork();
        HandlingEventsEntity HANDLING_EVENTS = uow.get( HandlingEventsEntity.class, HandlingEventsEntity.HANDLING_EVENTS_ID );
        // Expected receipt in Hong Kong
        HandlingEvent handlingEvent = HANDLING_EVENTS.createHandlingEvent( day( 1 ), day( 1 ), trackingId, HandlingEventType.RECEIVE, HONGKONG, null );
        Delivery delivery = new BuildDeliverySnapshot( cargo, handlingEvent ).get();

        assertThat( delivery.isMisdirected().get(), is( equalTo( false ) ) );
View Full Code Here

    @Test
    public void deviation_4b_LOAD_2a_UnexpectedPort() throws Exception
    {
        deviation_4a_RECEIVE_1b_ExpectedPort();

        UnitOfWork uow = module.currentUnitOfWork();
        HandlingEventsEntity HANDLING_EVENTS = uow.get( HandlingEventsEntity.class, HandlingEventsEntity.HANDLING_EVENTS_ID );
        // Unexpected load in Tokyo
        HandlingEvent handlingEvent = HANDLING_EVENTS.createHandlingEvent( day( 1 ), day( 1 ), trackingId, LOAD, TOKYO, V100S );
        Delivery delivery = new BuildDeliverySnapshot( cargo, handlingEvent ).get();

        assertThat( delivery.isMisdirected().get(), is( equalTo( true ) ) );
View Full Code Here

    @Test
    public void deviation_4b_LOAD_2b_ExpectedPort() throws Exception
    {
        deviation_4b_LOAD_2a_UnexpectedPort();

        UnitOfWork uow = module.currentUnitOfWork();
        HandlingEventsEntity HANDLING_EVENTS = uow.get( HandlingEventsEntity.class, HandlingEventsEntity.HANDLING_EVENTS_ID );
        // Expected load in Hong Kong
        HandlingEvent handlingEvent = HANDLING_EVENTS.createHandlingEvent( day( 1 ), day( 1 ), trackingId, LOAD, HONGKONG, V100S );
        Delivery delivery = new BuildDeliverySnapshot( cargo, handlingEvent ).get();

        assertThat( delivery.isMisdirected().get(), is( equalTo( false ) ) );
View Full Code Here

TOP

Related Classes of org.qi4j.api.unitofwork.UnitOfWork

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.