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();
 }
    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();
    }
Exemple #3
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;
 }
 public Query<School> findAll() {
   return qbf.newQueryBuilder(School.class).newQuery(uowf.currentUnitOfWork());
 }
 @Override
 public RootEntity rootEntity() {
   return uowf.currentUnitOfWork().get(RootEntity.class, RootEntity.IDENTITY);
 }
 public Voyage findVoyageByVoyageIdentity(final String voyageIdentity) {
   UnitOfWork uow = uowf.currentUnitOfWork();
   return uow.get(Voyage.class, Builder.createVoyageIdentity(voyageIdentity));
 }