@Override
  @Transactional
  public void inspectCargo(final TrackingId trackingId) {
    Validate.notNull(trackingId, "Tracking ID is required");

    final Cargo cargo = cargoRepository.find(trackingId);
    if (cargo == null) {
      logger.warn("Can't inspect non-existing cargo " + trackingId);
      return;
    }

    final HandlingHistory handlingHistory =
        handlingEventRepository.lookupHandlingHistoryOfCargo(trackingId);

    cargo.deriveDeliveryProgress(handlingHistory);

    if (cargo.delivery().isMisdirected()) {
      applicationEvents.cargoWasMisdirected(cargo);
    }

    if (cargo.delivery().isUnloadedAtDestination()) {
      applicationEvents.cargoHasArrived(cargo);
    }

    cargoRepository.store(cargo);
  }
Ejemplo n.º 2
0
 public CargoRoutingDTO toDTO(final Cargo cargo) {
   final CargoRoutingDTO dto =
       new CargoRoutingDTO(
           cargo.trackingId().idString(),
           cargo.origin().unLocode().idString(),
           cargo.destination().unLocode().idString());
   for (Leg leg : cargo.itinerary().legs()) {
     dto.addLeg(
         leg.carrierMovement().carrierMovementId().idString(),
         leg.from().unLocode().idString(),
         leg.to().unLocode().idString());
   }
   return dto;
 }