Package org.qi4j.api.unitofwork

Examples of org.qi4j.api.unitofwork.UnitOfWork


    @Test
    public void deviation_3a_CargoIsMisdirected()
        throws Exception
    {
        // Create misdirected handling event for cargo (receipt in Shanghai is unexpected)
        UnitOfWork uow = module.currentUnitOfWork();
        HandlingEventsEntity HANDLING_EVENTS = uow.get( HandlingEventsEntity.class, HandlingEventsEntity.HANDLING_EVENTS_ID );
        handlingEvent = HANDLING_EVENTS.createHandlingEvent( day( 0 ), day( 0 ), trackingId, HandlingEventType.RECEIVE, SHANGHAI, null );
        Delivery delivery = new BuildDeliverySnapshot( cargo, handlingEvent ).get();
        cargo.delivery().set( delivery );
        assertThat( cargo.delivery().get().isMisdirected().get(), is( equalTo( true ) ) );
View Full Code Here


    @Test
    public void deviation_3b_CargoHasArrived()
        throws Exception
    {
        UnitOfWork uow = module.currentUnitOfWork();
        HandlingEventsEntity HANDLING_EVENTS = uow.get( HandlingEventsEntity.class, HandlingEventsEntity.HANDLING_EVENTS_ID );
        handlingEvent = HANDLING_EVENTS.createHandlingEvent( day( 15 ), day( 15 ), trackingId, HandlingEventType.UNLOAD, STOCKHOLM, V300A );
        Delivery delivery = new BuildDeliverySnapshot( cargo, handlingEvent ).get();
        cargo.delivery().set( delivery );
        assertThat( cargo.delivery().get().isUnloadedAtDestination().get(), is( equalTo( true ) ) );
View Full Code Here

    }

    @After
    public void concludeTest()
    {
        UnitOfWork uow = module.currentUnitOfWork();
        if( uow != null && uow.isOpen() )
            uow.discard();
        if( module != null && module.isUnitOfWorkActive() )
        {
            while( module.isUnitOfWorkActive() )
            {
                uow = module.currentUnitOfWork();
                if( uow.isOpen() )
                {
                    System.err.println( "UnitOfWork not cleaned up:" + uow.usecase().name() );
                    uow.discard();
                }
                else
                {
                    throw new InternalError( "I have seen a case where a UoW is on the stack, but not opened. First is: " + uow.usecase().name() );
                }
            }
            new Exception( "UnitOfWork not properly cleaned up" ).printStackTrace();
        }
View Full Code Here

    @Test
    public void step_3_CargoIsCorrectlyInTransit()
        throws Exception
    {
        logger.info( "  Handling cargo 'ABC' (unloaded in Dallas):" );
        UnitOfWork uow = module.currentUnitOfWork();
        HandlingEventsEntity HANDLING_EVENTS = uow.get( HandlingEventsEntity.class, HandlingEventsEntity.HANDLING_EVENTS_ID );
        handlingEvent = HANDLING_EVENTS.createHandlingEvent( day( 12 ), day( 12 ), trackingId, HandlingEventType.UNLOAD, DALLAS, V200T );
        cargo.delivery().set( new BuildDeliverySnapshot( cargo, handlingEvent ).get() );
        assertThat( cargo.delivery().get().isMisdirected().get(), is( equalTo( false ) ) );
        new InspectCargo( handlingEvent ).inspect();
View Full Code Here

        public Node car( QuikitContext context )
        {
            Document dom = context.dom();
            Element result = dom.createElementNS( Page.XHTML, "div" );
            String bookingId = context.path();
            UnitOfWork uow = uowf.currentUnitOfWork();
            Booking booking = uow.get( Booking.class, bookingId );
            Car car = booking.car().get();
            createChildNode( dom, result, car.model().get() );
            createChildNode( dom, result, car.licensePlate().get() );
            createChildNode( dom, result, car.category().get().name().get() );
            return result;
View Full Code Here

        public Node customer( QuikitContext context )
        {
            Document dom = context.dom();
            Element result = dom.createElementNS( Page.XHTML, "div" );
            String bookingId = context.path();
            UnitOfWork uow = uowf.currentUnitOfWork();
            Booking booking = uow.get( Booking.class, bookingId );
            Customer customer = booking.customer().get();
            createChildNode( dom, result, customer.name().get() );
            createChildNode( dom, result, customer.address().get().line1().get() );
            createChildNode( dom, result, customer.address().get().line2().get() );
            createChildNode( dom, result, customer.address().get().zipCode().get() + " " + customer.address()
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

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

            return unlocode.newInstance();
        }

        protected Location location( UnLocode unlocode, String locationStr )
        {
            UnitOfWork uow = module.currentUnitOfWork();
            EntityBuilder<Location> location = uow.newEntityBuilder( Location.class, unlocode.code().get() );
            location.instance().unLocode().set( unlocode );
            location.instance().name().set( locationStr );
            return location.newInstance();
        }
View Full Code Here

            return location.newInstance();
        }

        protected Voyage voyage( String voyageNumberStr, Schedule schedule )
        {
            UnitOfWork uow = module.currentUnitOfWork();
            EntityBuilder<Voyage> voyage = uow.newEntityBuilder( Voyage.class, voyageNumberStr );

            // VoyageNumber
            ValueBuilder<VoyageNumber> voyageNumber = module.newValueBuilder( VoyageNumber.class );
            voyageNumber.prototype().number().set( voyageNumberStr );
            voyage.instance().voyageNumber().set( voyageNumber.newInstance() );
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.