Skip to content

Commit

Permalink
Google Java Format
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Jan 28, 2021
1 parent 4606309 commit 1d352f4
Show file tree
Hide file tree
Showing 114 changed files with 6,622 additions and 6,432 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
*/
public interface ApplicationEvents {

void cargoWasHandled(HandlingEvent event);
void cargoWasHandled(HandlingEvent event);

void cargoWasMisdirected(Cargo cargo);
void cargoWasMisdirected(Cargo cargo);

void cargoHasArrived(Cargo cargo);
void cargoHasArrived(Cargo cargo);

void receivedHandlingEventRegistrationAttempt(HandlingEventRegistrationAttempt attempt);
void receivedHandlingEventRegistrationAttempt(HandlingEventRegistrationAttempt attempt);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
// TODO [Jakarta EE 8] Adopt the Date-Time API.
public interface BookingService {

/** Registers a new cargo in the tracking system, not yet routed. */
TrackingId bookNewCargo(UnLocode origin, UnLocode destination, LocalDate arrivalDeadline);
/** Registers a new cargo in the tracking system, not yet routed. */
TrackingId bookNewCargo(UnLocode origin, UnLocode destination, LocalDate arrivalDeadline);

/**
* Requests a list of itineraries describing possible routes for this cargo.
*
* @param trackingId Cargo tracking ID
* @return A list of possible itineraries for this cargo
*/
List<Itinerary> requestPossibleRoutesForCargo(TrackingId trackingId);
/**
* Requests a list of itineraries describing possible routes for this cargo.
*
* @param trackingId Cargo tracking ID
* @return A list of possible itineraries for this cargo
*/
List<Itinerary> requestPossibleRoutesForCargo(TrackingId trackingId);

void assignCargoToRoute(Itinerary itinerary, TrackingId trackingId);
void assignCargoToRoute(Itinerary itinerary, TrackingId trackingId);

void changeDestination(TrackingId trackingId, UnLocode unLocode);
void changeDestination(TrackingId trackingId, UnLocode unLocode);

void changeDeadline(TrackingId trackingId, LocalDate deadline);
void changeDeadline(TrackingId trackingId, LocalDate deadline);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

public interface CargoInspectionService {

/**
* Inspect cargo and send relevant notifications to interested parties, for example if a cargo has
* been misdirected, or unloaded at the final destination.
*/
public void inspectCargo(@NotNull(message = "Tracking ID is required") TrackingId trackingId);
/**
* Inspect cargo and send relevant notifications to interested parties, for example if a cargo
* has been misdirected, or unloaded at the final destination.
*/
public void inspectCargo(@NotNull(message = "Tracking ID is required") TrackingId trackingId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

public interface HandlingEventService {

/**
* Registers a handling event in the system, and notifies interested parties that a cargo has been
* handled.
*/
void registerHandlingEvent(
LocalDateTime completionTime,
TrackingId trackingId,
VoyageNumber voyageNumber,
UnLocode unLocode,
HandlingEvent.Type type)
throws CannotCreateHandlingEventException;
/**
* Registers a handling event in the system, and notifies interested parties that a cargo has
* been handled.
*/
void registerHandlingEvent(
LocalDateTime completionTime,
TrackingId trackingId,
VoyageNumber voyageNumber,
UnLocode unLocode,
HandlingEvent.Type type)
throws CannotCreateHandlingEventException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,82 +19,88 @@
@Stateless
public class DefaultBookingService implements BookingService {

@Inject private CargoRepository cargoRepository;
@Inject private LocationRepository locationRepository;
@Inject private RoutingService routingService;
@Inject private Logger logger;

@Override
public TrackingId bookNewCargo(
UnLocode originUnLocode, UnLocode destinationUnLocode, LocalDate arrivalDeadline) {
TrackingId trackingId = cargoRepository.nextTrackingId();
Location origin = locationRepository.find(originUnLocode);
Location destination = locationRepository.find(destinationUnLocode);
RouteSpecification routeSpecification =
new RouteSpecification(origin, destination, arrivalDeadline);

Cargo cargo = new Cargo(trackingId, routeSpecification);

cargoRepository.store(cargo);
logger.log(
Level.INFO, "Booked new cargo with tracking ID {0}", cargo.getTrackingId().getIdString());

return cargo.getTrackingId();
}

@Override
public List<Itinerary> requestPossibleRoutesForCargo(TrackingId trackingId) {
Cargo cargo = cargoRepository.find(trackingId);

if (cargo == null) {
return Collections.emptyList();
@Inject private CargoRepository cargoRepository;
@Inject private LocationRepository locationRepository;
@Inject private RoutingService routingService;
@Inject private Logger logger;

@Override
public TrackingId bookNewCargo(
UnLocode originUnLocode, UnLocode destinationUnLocode, LocalDate arrivalDeadline) {
TrackingId trackingId = cargoRepository.nextTrackingId();
Location origin = locationRepository.find(originUnLocode);
Location destination = locationRepository.find(destinationUnLocode);
RouteSpecification routeSpecification =
new RouteSpecification(origin, destination, arrivalDeadline);

Cargo cargo = new Cargo(trackingId, routeSpecification);

cargoRepository.store(cargo);
logger.log(
Level.INFO,
"Booked new cargo with tracking ID {0}",
cargo.getTrackingId().getIdString());

return cargo.getTrackingId();
}

return routingService.fetchRoutesForSpecification(cargo.getRouteSpecification());
}
@Override
public List<Itinerary> requestPossibleRoutesForCargo(TrackingId trackingId) {
Cargo cargo = cargoRepository.find(trackingId);

@Override
public void assignCargoToRoute(Itinerary itinerary, TrackingId trackingId) {
Cargo cargo = cargoRepository.find(trackingId);
if (cargo == null) {
return Collections.emptyList();
}

cargo.assignToRoute(itinerary);
cargoRepository.store(cargo);
return routingService.fetchRoutesForSpecification(cargo.getRouteSpecification());
}

@Override
public void assignCargoToRoute(Itinerary itinerary, TrackingId trackingId) {
Cargo cargo = cargoRepository.find(trackingId);

cargo.assignToRoute(itinerary);
cargoRepository.store(cargo);

logger.log(Level.INFO, "Assigned cargo {0} to new route", trackingId);
}
logger.log(Level.INFO, "Assigned cargo {0} to new route", trackingId);
}

@Override
public void changeDestination(TrackingId trackingId, UnLocode unLocode) {
Cargo cargo = cargoRepository.find(trackingId);
Location newDestination = locationRepository.find(unLocode);
@Override
public void changeDestination(TrackingId trackingId, UnLocode unLocode) {
Cargo cargo = cargoRepository.find(trackingId);
Location newDestination = locationRepository.find(unLocode);

RouteSpecification routeSpecification =
new RouteSpecification(
cargo.getOrigin(), newDestination, cargo.getRouteSpecification().getArrivalDeadline());
cargo.specifyNewRoute(routeSpecification);
RouteSpecification routeSpecification =
new RouteSpecification(
cargo.getOrigin(),
newDestination,
cargo.getRouteSpecification().getArrivalDeadline());
cargo.specifyNewRoute(routeSpecification);

cargoRepository.store(cargo);
cargoRepository.store(cargo);

logger.log(
Level.INFO,
"Changed destination for cargo {0} to {1}",
new Object[] {trackingId, routeSpecification.getDestination()});
}
logger.log(
Level.INFO,
"Changed destination for cargo {0} to {1}",
new Object[] {trackingId, routeSpecification.getDestination()});
}

@Override
public void changeDeadline(TrackingId trackingId, LocalDate newDeadline) {
Cargo cargo = cargoRepository.find(trackingId);
@Override
public void changeDeadline(TrackingId trackingId, LocalDate newDeadline) {
Cargo cargo = cargoRepository.find(trackingId);

RouteSpecification routeSpecification =
new RouteSpecification(
cargo.getOrigin(), cargo.getRouteSpecification().getDestination(), newDeadline);
cargo.specifyNewRoute(routeSpecification);
RouteSpecification routeSpecification =
new RouteSpecification(
cargo.getOrigin(),
cargo.getRouteSpecification().getDestination(),
newDeadline);
cargo.specifyNewRoute(routeSpecification);

cargoRepository.store(cargo);
cargoRepository.store(cargo);

logger.log(
Level.INFO,
"Changed deadline for cargo {0} to {1}",
new Object[] {trackingId, newDeadline});
}
logger.log(
Level.INFO,
"Changed deadline for cargo {0} to {1}",
new Object[] {trackingId, newDeadline});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,38 @@
@Stateless
public class DefaultCargoInspectionService implements CargoInspectionService {

@Inject private ApplicationEvents applicationEvents;
@Inject private CargoRepository cargoRepository;
@Inject private HandlingEventRepository handlingEventRepository;
@Inject private ApplicationEvents applicationEvents;
@Inject private CargoRepository cargoRepository;
@Inject private HandlingEventRepository handlingEventRepository;

@Inject @CargoInspected private Event<Cargo> cargoInspected;
@Inject @CargoInspected private Event<Cargo> cargoInspected;

@Inject private Logger logger;
@Inject private Logger logger;

@Override
public void inspectCargo(TrackingId trackingId) {
Cargo cargo = cargoRepository.find(trackingId);
@Override
public void inspectCargo(TrackingId trackingId) {
Cargo cargo = cargoRepository.find(trackingId);

if (cargo == null) {
logger.log(Level.WARNING, "Can't inspect non-existing cargo {0}", trackingId);
return;
}
if (cargo == null) {
logger.log(Level.WARNING, "Can't inspect non-existing cargo {0}", trackingId);
return;
}

HandlingHistory handlingHistory =
handlingEventRepository.lookupHandlingHistoryOfCargo(trackingId);
HandlingHistory handlingHistory =
handlingEventRepository.lookupHandlingHistoryOfCargo(trackingId);

cargo.deriveDeliveryProgress(handlingHistory);
cargo.deriveDeliveryProgress(handlingHistory);

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

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

cargoRepository.store(cargo);
cargoRepository.store(cargo);

cargoInspected.fire(cargo);
}
cargoInspected.fire(cargo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,40 @@
@Stateless
public class DefaultHandlingEventService implements HandlingEventService {

@Inject private ApplicationEvents applicationEvents;
@Inject private HandlingEventRepository handlingEventRepository;
@Inject private HandlingEventFactory handlingEventFactory;
@Inject private Logger logger;

@Override
public void registerHandlingEvent(
LocalDateTime completionTime,
TrackingId trackingId,
VoyageNumber voyageNumber,
UnLocode unLocode,
HandlingEvent.Type type)
throws CannotCreateHandlingEventException {
LocalDateTime registrationTime = LocalDateTime.now();

/*
* Using a factory to create a HandlingEvent (aggregate). This is where it is
* determined wether the incoming data, the attempt, actually is capable of
* representing a real handling event.
*/
HandlingEvent event =
handlingEventFactory.createHandlingEvent(
registrationTime, completionTime, trackingId, voyageNumber, unLocode, type);

/*
* Store the new handling event, which updates the persistent state of the
* handling event aggregate (but not the cargo aggregate - that happens
* asynchronously!)
*/
handlingEventRepository.store(event);

/* Publish an event stating that a cargo has been handled. */
applicationEvents.cargoWasHandled(event);

logger.info("Registered handling event");
}
@Inject private ApplicationEvents applicationEvents;
@Inject private HandlingEventRepository handlingEventRepository;
@Inject private HandlingEventFactory handlingEventFactory;
@Inject private Logger logger;

@Override
public void registerHandlingEvent(
LocalDateTime completionTime,
TrackingId trackingId,
VoyageNumber voyageNumber,
UnLocode unLocode,
HandlingEvent.Type type)
throws CannotCreateHandlingEventException {
LocalDateTime registrationTime = LocalDateTime.now();

/*
* Using a factory to create a HandlingEvent (aggregate). This is where it is
* determined wether the incoming data, the attempt, actually is capable of
* representing a real handling event.
*/
HandlingEvent event =
handlingEventFactory.createHandlingEvent(
registrationTime, completionTime, trackingId, voyageNumber, unLocode, type);

/*
* Store the new handling event, which updates the persistent state of the
* handling event aggregate (but not the cargo aggregate - that happens
* asynchronously!)
*/
handlingEventRepository.store(event);

/* Publish an event stating that a cargo has been handled. */
applicationEvents.cargoWasHandled(event);

logger.info("Registered handling event");
}
}
Loading

0 comments on commit 1d352f4

Please sign in to comment.