public HandlingEvent createHandlingEvent(
        Date completionTime,
        TrackingId trackingId,
        CarrierMovementId carrierMovementId,
        UnLocode unlocode,
        HandlingEvent.Type type)
        throws UnknownTrackingIdException, UnknownCarrierMovementIdException,
            UnknownLocationException {
      Cargo cargo = validateCargoExists(trackingId);
      CarrierMovement carrierMovement = findCarrierMovement(carrierMovementId);
      Location location = findLocation(unlocode);
      Date registrationTime = new Date();

      // Create entity
      UnitOfWork uow = uowf.currentUnitOfWork();
      EntityBuilder<HandlingEvent> builder = uow.newEntityBuilder(HandlingEvent.class);
      HandlingEventState state = builder.instanceFor(HandlingEventState.class);
      state.cargo().set(cargo);

      // TODO: remove next line when query + association is implemented
      state.cargoTrackingId().set(trackingId.idString());

      state.carrierMovement().set(carrierMovement);
      state.location().set(location);
      state.registrationTime().set(registrationTime);
      state.completionTime().set(completionTime);
      state.eventType().set(type);

      return builder.newInstance();
    }
Exemplo n.º 2
0
 public School findSchoolByName(String schoolName) {
   QueryBuilder<School> builder = qbf.newQueryBuilder(School.class);
   SchoolEntity.SchoolState template = templateFor(SchoolEntity.SchoolState.class);
   builder.where(eq(template.name(), schoolName));
   Query<School> query = builder.newQuery(uowf.currentUnitOfWork());
   return query.find();
 }
Exemplo n.º 3
0
 @Override
 public void passivate() throws Exception {
   UnitOfWork uow = uowf.newUnitOfWork();
   try {
     RootEntity root = rootEntity();
     LOGGER.info("Existing RootEntity: " + root.identity().get());
   } catch (NoSuchEntityException ex) {
     LOGGER.info("No RootEntity");
   }
   uow.complete();
 }
Exemplo n.º 4
0
 @Override
 public void activate() throws Exception {
   UnitOfWork uow = uowf.newUnitOfWork();
   try {
     RootEntity root = rootEntity();
     LOGGER.info("Will use RootEntity: " + root.identity().get());
   } catch (NoSuchEntityException ex) {
     EntityBuilder<RootEntity> builder =
         uow.newEntityBuilder(RootEntity.class, RootEntity.IDENTITY);
     RootEntity root = builder.newInstance();
     LOGGER.info("Created new RootEntity: " + root.identity().get());
   }
   uow.complete();
 }
Exemplo n.º 5
0
 public Cargo create(String originUnLocode, String destinationUnLocode, Date arrivalDeadline) {
   TrackingId trackingId = cargoRepository.nextTrackingId();
   Location origin = locationRepository.findLocationByUnLocode(originUnLocode);
   Location destination = locationRepository.findLocationByUnLocode(destinationUnLocode);
   RouteSpecification routeSpecification =
       routeSpecificationFactory.create(origin, destination, arrivalDeadline);
   UnitOfWork uow = uowf.currentUnitOfWork();
   EntityBuilder<Cargo> builder = uow.newEntityBuilder(Cargo.class, trackingId.id().get());
   Cargo.State instanceState = builder.instanceFor(Cargo.State.class);
   instanceState.routeSpecification().set(routeSpecification);
   instanceState.origin().set(origin);
   Cargo cargo = builder.newInstance();
   logger.info("Booked new cargo with tracking id " + cargo.trackingId().id().get());
   return cargo;
 }
Exemplo n.º 6
0
    public void activate() throws Exception {
      UnitOfWork unitOfWork = uowf.newUnitOfWork();
      try {
        {
          ValueBuilder<TestValue> valueBuilder = vbf.newValueBuilder(TestValue.class);
          valueBuilder.prototype().longList().get().add(42L);
          valueBuilder.prototype().string().set("Foo bar value");
          valueBuilder.prototype().map().set(new HashMap());

          EntityBuilder<TestEntity> builder =
              unitOfWork.newEntityBuilder(TestEntity.class, "test1");
          builder.instance().name().set("Foo bar");
          builder.instance().age().set(42);
          builder.instance().value().set(valueBuilder.newInstance());
          TestEntity testEntity = builder.newInstance();

          EntityBuilder<TestEntity> builder2 =
              unitOfWork.newEntityBuilder(TestEntity.class, "test2");
          builder2.instance().name().set("Xyzzy");
          builder2.instance().age().set(12);
          builder2.instance().association().set(testEntity);
          builder2.instance().manyAssociation().add(0, testEntity);
          builder2.instance().manyAssociation().add(0, testEntity);

          EntityBuilder<TestRole> builder3 = unitOfWork.newEntityBuilder(TestRole.class);
          builder3.instance().name().set("A role");
          TestRole testRole = builder3.newInstance();

          builder2.newInstance();
        }

        {
          EntityBuilder<TestEntity2> builder =
              unitOfWork.newEntityBuilder(TestEntity2.class, "test3");
          builder.instance().name().set("Test3");
          builder.newInstance();
        }

        unitOfWork.complete();
      } catch (Exception e) {
        unitOfWork.discard();
        throw e;
      }
    }
Exemplo n.º 7
0
 public Query<School> findAll() {
   return qbf.newQueryBuilder(School.class).newQuery(uowf.currentUnitOfWork());
 }
Exemplo n.º 8
0
 @Override
 public RootEntity rootEntity() {
   return uowf.currentUnitOfWork().get(RootEntity.class, RootEntity.IDENTITY);
 }
Exemplo n.º 9
0
    public void activate() throws Exception {
      Usecase usecase = UsecaseBuilder.newUsecase("Populate Sample Voyages");
      UnitOfWork uow = uowf.newUnitOfWork(usecase);
      try {

        final Location HONGKONG = locationRepository.findLocationByUnLocode("CNHKG");
        final Location TOKYO = locationRepository.findLocationByUnLocode("JNTKO");
        final Location NEWYORK = locationRepository.findLocationByUnLocode("USNYC");
        final Location CHICAGO = locationRepository.findLocationByUnLocode("USCHI");
        final Location STOCKHOLM = locationRepository.findLocationByUnLocode("SESTO");
        final Location ROTTERDAM = locationRepository.findLocationByUnLocode("NLRTM");
        final Location MELBOURNE = locationRepository.findLocationByUnLocode("AUMEL");
        final Location HAMBURG = locationRepository.findLocationByUnLocode("DEHAM");
        final Location HELSINKI = locationRepository.findLocationByUnLocode("FIHEL");
        final Location DALLAS = locationRepository.findLocationByUnLocode("USDAL");
        final Location HANGZOU = locationRepository.findLocationByUnLocode("CNHGH");
        final Location SHANGHAI = locationRepository.findLocationByUnLocode("CNSHA");

        Voyage v100 =
            new VoyageRepository.Builder(vbf, uow, "V100", HONGKONG)
                .addMovement(TOKYO, toDate("2009-03-03"), toDate("2009-03-05"))
                .addMovement(NEWYORK, toDate("2009-03-06"), toDate("2009-03-09"))
                .build();
        Voyage v200 =
            new VoyageRepository.Builder(vbf, uow, "V200", TOKYO)
                .addMovement(NEWYORK, toDate("2009-03-06"), toDate("2009-03-08"))
                .addMovement(CHICAGO, toDate("2009-03-10"), toDate("2009-03-14"))
                .addMovement(STOCKHOLM, toDate("2009-03-14"), toDate("2009-03-16"))
                .build();
        Voyage v300 =
            new VoyageRepository.Builder(vbf, uow, "V300", TOKYO)
                .addMovement(ROTTERDAM, toDate("2009-03-22"), toDate("2009-03-25"))
                .addMovement(HAMBURG, toDate("2009-03-25"), toDate("2009-03-26"))
                .addMovement(MELBOURNE, toDate("2009-03-28"), toDate("2009-04-03"))
                .addMovement(TOKYO, toDate("2009-04-03"), toDate("2009-04-06"))
                .build();
        Voyage v400 =
            new VoyageRepository.Builder(vbf, uow, "V400", HAMBURG)
                .addMovement(STOCKHOLM, toDate("2009-03-14"), toDate("2009-03-15"))
                .addMovement(HELSINKI, toDate("2009-03-15"), toDate("2009-03-16"))
                .addMovement(HAMBURG, toDate("2009-03-20"), toDate("2009-03-22"))
                .build();

        /*
         * Voyage number 0100S (by ship)
         * <p/>
         * Hongkong - Hangzou - Tokyo - Melbourne - New York
         */
        Voyage HONGKONG_TO_NEW_YORK =
            new VoyageRepository.Builder(vbf, uow, "0100S", HONGKONG)
                .addMovement(HANGZOU, toDate("2008-10-01", "12:00"), toDate("2008-10-03", "14:30"))
                .addMovement(TOKYO, toDate("2008-10-03", "21:00"), toDate("2008-10-06", "06:15"))
                .addMovement(
                    MELBOURNE, toDate("2008-10-06", "11:00"), toDate("2008-10-12", "11:30"))
                .addMovement(NEWYORK, toDate("2008-10-14", "12:00"), toDate("2008-10-23", "23:10"))
                .build();

        /*
         * Voyage number 0200T (by train)
         * <p/>
         * New York - Chicago - Dallas
         */
        Voyage NEW_YORK_TO_DALLAS =
            new VoyageRepository.Builder(vbf, uow, "0200T", NEWYORK)
                .addMovement(CHICAGO, toDate("2008-10-24", "07:00"), toDate("2008-10-24", "17:45"))
                .addMovement(DALLAS, toDate("2008-10-24", "21:25"), toDate("2008-10-25", "19:30"))
                .build();

        /*
         * Voyage number 0300A (by airplane)
         * <p/>
         * Dallas - Hamburg - Stockholm - Helsinki
         */
        Voyage DALLAS_TO_HELSINKI =
            new VoyageRepository.Builder(vbf, uow, "0300A", DALLAS)
                .addMovement(HAMBURG, toDate("2008-10-29", "03:30"), toDate("2008-10-31", "14:00"))
                .addMovement(
                    STOCKHOLM, toDate("2008-11-01", "15:20"), toDate("2008-11-01", "18:40"))
                .addMovement(HELSINKI, toDate("2008-11-02", "09:00"), toDate("2008-11-02", "11:15"))
                .build();

        /*
         * Voyage number 0301S (by ship)
         * <p/>
         * Dallas - Hamburg - Stockholm - Helsinki, alternate route
         */
        Voyage DALLAS_TO_HELSINKI_ALT =
            new VoyageRepository.Builder(vbf, uow, "0301S", DALLAS)
                .addMovement(HELSINKI, toDate("2008-10-29", "03:30"), toDate("2008-11-05", "15:45"))
                .build();

        /*
         * Voyage number 0400S (by ship)
         * <p/>
         * Helsinki - Rotterdam - Shanghai - Hongkong
         */
        Voyage HELSINKI_TO_HONGKONG =
            new VoyageRepository.Builder(vbf, uow, "0400S", HELSINKI)
                .addMovement(
                    ROTTERDAM, toDate("2008-11-04", "05:50"), toDate("2008-11-06", "14:10"))
                .addMovement(SHANGHAI, toDate("2008-11-10", "21:45"), toDate("2008-11-22", "16:40"))
                .addMovement(HONGKONG, toDate("2008-11-24", "07:00"), toDate("2008-11-28", "13:37"))
                .build();
        uow.complete();
      } catch (RuntimeException e) {
        uow.discard();
        throw e;
      }
    }
Exemplo n.º 10
0
 public Voyage findVoyageByVoyageIdentity(final String voyageIdentity) {
   UnitOfWork uow = uowf.currentUnitOfWork();
   return uow.get(Voyage.class, Builder.createVoyageIdentity(voyageIdentity));
 }