Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rest frontend #102

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 61 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,65 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED</argLine>
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED
</argLine>
</configuration>
<version>3.2.5</version>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<workingDirectory>src/main/resources/frontend/</workingDirectory>
</configuration>
<executions>
<execution>
<id>npm install (initialize)</id>
<goals>
<goal>exec</goal>
</goals>
<phase>initialize</phase>
<configuration>
<executable>npm</executable>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
</execution>

<execution>
<id>npm run build (compile)</id>
<goals>
<goal>exec</goal>
</goals>
<phase>compile</phase>
<configuration>
<executable>npm</executable>
<arguments>
<argument>run</argument>
<argument>build</argument>
</arguments>
</configuration>
</execution>

<execution>
<id>npm run clean (clean)</id>
<goals>
<goal>exec</goal>
</goals>
<phase>clean</phase>
<configuration>
<executable>npm</executable>
<arguments>
<argument>run</argument>
<argument>clean</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down Expand Up @@ -226,11 +281,11 @@
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
</dependency>
<!-- <dependency>--> <!-- Used to generate OpenAPI docs -->
<!-- <groupId>org.springdoc</groupId>-->
<!-- <artifactId>springdoc-openapi-webmvc-core</artifactId>-->
<!-- <version>1.6.12</version>-->
<!-- </dependency>-->
<!-- <dependency>--> <!-- Used to generate OpenAPI docs -->
<!-- <groupId>org.springdoc</groupId>-->
<!-- <artifactId>springdoc-openapi-webmvc-core</artifactId>-->
<!-- <version>1.6.12</version>-->
<!-- </dependency>-->
</dependencies>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,32 +76,32 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {
voyageRepository.store(HELSINKI_TO_HONGKONG);
voyageRepository.store(DALLAS_TO_HELSINKI_ALT);

RouteSpecification routeSpecification = new RouteSpecification(HONGKONG, HELSINKI, toDate("2009-03-15"));
RouteSpecification routeSpecification = new RouteSpecification(HONGKONG, HELSINKI, toDate("2024-03-15"));
TrackingId trackingId = new TrackingId("ABC123");
Cargo abc123 = new Cargo(trackingId, routeSpecification);

Itinerary itinerary = new Itinerary(List.of(
new Leg(HONGKONG_TO_NEW_YORK, HONGKONG, NEWYORK, toDate("2009-03-02"), toDate("2009-03-05")),
new Leg(NEW_YORK_TO_DALLAS, NEWYORK, DALLAS, toDate("2009-03-06"), toDate("2009-03-08")),
new Leg(DALLAS_TO_HELSINKI, DALLAS, HELSINKI, toDate("2009-03-09"), toDate("2009-03-12"))
new Leg(HONGKONG_TO_NEW_YORK, HONGKONG, NEWYORK, toDate("2024-03-02"), toDate("2024-03-05")),
new Leg(NEW_YORK_TO_DALLAS, NEWYORK, DALLAS, toDate("2024-03-06"), toDate("2024-03-08")),
new Leg(DALLAS_TO_HELSINKI, DALLAS, HELSINKI, toDate("2024-03-09"), toDate("2024-03-12"))
));
abc123.assignToRoute(itinerary);

cargoRepository.store(abc123);

try {
HandlingEvent event1 = handlingEventFactory.createHandlingEvent(
Instant.now(), toDate("2009-03-01"), trackingId, null, HONGKONG.unLocode(), HandlingEvent.Type.RECEIVE
Instant.now(), toDate("2024-03-01"), trackingId, null, HONGKONG.unLocode(), HandlingEvent.Type.RECEIVE
);
handlingEventRepository.store(event1);

HandlingEvent event2 = handlingEventFactory.createHandlingEvent(
Instant.now(), toDate("2009-03-02"), trackingId, HONGKONG_TO_NEW_YORK.voyageNumber(), HONGKONG.unLocode(), HandlingEvent.Type.LOAD
Instant.now(), toDate("2024-03-02"), trackingId, HONGKONG_TO_NEW_YORK.voyageNumber(), HONGKONG.unLocode(), HandlingEvent.Type.LOAD
);
handlingEventRepository.store(event2);

HandlingEvent event3 = handlingEventFactory.createHandlingEvent(
Instant.now(), toDate("2009-03-05"), trackingId, HONGKONG_TO_NEW_YORK.voyageNumber(), NEWYORK.unLocode(), HandlingEvent.Type.UNLOAD
Instant.now(), toDate("2024-03-05"), trackingId, HONGKONG_TO_NEW_YORK.voyageNumber(), NEWYORK.unLocode(), HandlingEvent.Type.UNLOAD
);
handlingEventRepository.store(event3);
} catch (CannotCreateHandlingEventException e) {
Expand All @@ -115,37 +115,37 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {

// Cargo JKL567

RouteSpecification routeSpecification1 = new RouteSpecification(HANGZHOU, STOCKHOLM, toDate("2009-03-18"));
RouteSpecification routeSpecification1 = new RouteSpecification(HANGZHOU, STOCKHOLM, toDate("2024-03-18"));
TrackingId trackingId1 = new TrackingId("JKL567");
Cargo jkl567 = new Cargo(trackingId1, routeSpecification1);

Itinerary itinerary1 = new Itinerary(List.of(
new Leg(HONGKONG_TO_NEW_YORK, HANGZHOU, NEWYORK, toDate("2009-03-03"), toDate("2009-03-05")),
new Leg(NEW_YORK_TO_DALLAS, NEWYORK, DALLAS, toDate("2009-03-06"), toDate("2009-03-08")),
new Leg(DALLAS_TO_HELSINKI, DALLAS, STOCKHOLM, toDate("2009-03-09"), toDate("2009-03-11"))
new Leg(HONGKONG_TO_NEW_YORK, HANGZHOU, NEWYORK, toDate("2024-03-03"), toDate("2024-03-05")),
new Leg(NEW_YORK_TO_DALLAS, NEWYORK, DALLAS, toDate("2024-03-06"), toDate("2024-03-08")),
new Leg(DALLAS_TO_HELSINKI, DALLAS, STOCKHOLM, toDate("2024-03-09"), toDate("2024-03-11"))
));
jkl567.assignToRoute(itinerary1);

cargoRepository.store(jkl567);

try {
HandlingEvent event1 = handlingEventFactory.createHandlingEvent(
Instant.now(), toDate("2009-03-01"), trackingId1, null, HANGZHOU.unLocode(), HandlingEvent.Type.RECEIVE
Instant.now(), toDate("2024-03-01"), trackingId1, null, HANGZHOU.unLocode(), HandlingEvent.Type.RECEIVE
);
handlingEventRepository.store(event1);

HandlingEvent event2 = handlingEventFactory.createHandlingEvent(
Instant.now(), toDate("2009-03-03"), trackingId1, HONGKONG_TO_NEW_YORK.voyageNumber(), HANGZHOU.unLocode(), HandlingEvent.Type.LOAD
Instant.now(), toDate("2024-03-03"), trackingId1, HONGKONG_TO_NEW_YORK.voyageNumber(), HANGZHOU.unLocode(), HandlingEvent.Type.LOAD
);
handlingEventRepository.store(event2);

HandlingEvent event3 = handlingEventFactory.createHandlingEvent(
Instant.now(), toDate("2009-03-05"), trackingId1, HONGKONG_TO_NEW_YORK.voyageNumber(), NEWYORK.unLocode(), HandlingEvent.Type.UNLOAD
Instant.now(), toDate("2024-03-05"), trackingId1, HONGKONG_TO_NEW_YORK.voyageNumber(), NEWYORK.unLocode(), HandlingEvent.Type.UNLOAD
);
handlingEventRepository.store(event3);

HandlingEvent event4 = handlingEventFactory.createHandlingEvent(
Instant.now(), toDate("2009-03-06"), trackingId1, HONGKONG_TO_NEW_YORK.voyageNumber(), NEWYORK.unLocode(), HandlingEvent.Type.LOAD
Instant.now(), toDate("2024-03-06"), trackingId1, HONGKONG_TO_NEW_YORK.voyageNumber(), NEWYORK.unLocode(), HandlingEvent.Type.LOAD
);
handlingEventRepository.store(event4);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package se.citerus.dddsample.infrastructure.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HomeController {

@RequestMapping(value = {"/", "/cargo/**", "/admin/**"})
public String index() {
return "/";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public CargoTrackingController cargoTrackingController(MessageSource messageSour
}

@Bean
public CargoTrackingRestService cargoTrackingRestService(CargoRepository cargoRepository, HandlingEventRepository handlingEventRepository, MessageSource messageSource) {
return new CargoTrackingRestService(cargoRepository, handlingEventRepository, messageSource);
public CargoTrackingRestService cargoTrackingRestService(CargoRepository cargoRepository, BookingServiceFacade bookingServiceFacade, HandlingEventRepository handlingEventRepository, MessageSource messageSource) {
return new CargoTrackingRestService(cargoRepository, bookingServiceFacade, handlingEventRepository, messageSource);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ public String getUnLocode() {
public String getName() {
return name;
}


@Override
public String toString() {
return name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package se.citerus.dddsample.interfaces.tracking.ws;

public class CargoLegDTO {
public final String voyageNumber;
public final String from;
public final String to;
public final String loadTime;
public final String unloadTime;

public CargoLegDTO(final String voyageNumber, final String from, final String to, String loadTime, String unloadTime) {
this.voyageNumber = voyageNumber;
this.from = from;
this.to = to;
this.loadTime = loadTime;
this.unloadTime = unloadTime;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package se.citerus.dddsample.interfaces.tracking.ws;

import java.util.Date;

public class CargoRegistrationDTO {
public String origin;
public String destination;
public String arrivalDeadline;

public CargoRegistrationDTO(String origin, String destination, String arrivalDeadline) {
this.origin = origin;
this.destination = destination;
this.arrivalDeadline = arrivalDeadline;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package se.citerus.dddsample.interfaces.tracking.ws;

import se.citerus.dddsample.interfaces.booking.facade.dto.LegDTO;
import se.citerus.dddsample.interfaces.booking.facade.dto.LocationDTO;

import java.util.List;

/**
Expand All @@ -10,19 +13,23 @@ public class CargoTrackingDTO {

public final String trackingId;
public final String statusText;
public final String destination;
public final LocationDTO origin;
public final LocationDTO destination;
public final String eta;
public final String nextExpectedActivity;
public final boolean isMisdirected;
public final List<CargoLegDTO> itinerary;
public final List<HandlingEventDTO> handlingEvents;

public CargoTrackingDTO(String trackingId, String statusText, String destination, String eta, String nextExpectedActivity, boolean isMisdirected, List<HandlingEventDTO> handlingEvents) {
public CargoTrackingDTO(String trackingId, String statusText, LocationDTO origin, LocationDTO destination, String eta, String nextExpectedActivity, boolean isMisdirected, List<CargoLegDTO> legDTOS, List<HandlingEventDTO> handlingEvents) {
this.trackingId = trackingId;
this.statusText = statusText;
this.origin = origin;
this.destination = destination;
this.eta = eta;
this.nextExpectedActivity = nextExpectedActivity;
this.isMisdirected = isMisdirected;
this.itinerary = legDTOS;
this.handlingEvents = handlingEvents;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
import se.citerus.dddsample.domain.model.cargo.Cargo;
import se.citerus.dddsample.domain.model.cargo.Delivery;
import se.citerus.dddsample.domain.model.cargo.HandlingActivity;
import se.citerus.dddsample.domain.model.cargo.Leg;
import se.citerus.dddsample.domain.model.handling.HandlingEvent;
import se.citerus.dddsample.domain.model.location.Location;
import se.citerus.dddsample.interfaces.booking.facade.dto.CargoRoutingDTO;
import se.citerus.dddsample.interfaces.booking.facade.dto.LegDTO;
import se.citerus.dddsample.interfaces.booking.facade.dto.LocationDTO;
import se.citerus.dddsample.interfaces.booking.facade.internal.assembler.CargoRoutingDTOAssembler;

import java.text.SimpleDateFormat;
import java.time.Instant;
Expand All @@ -25,14 +31,32 @@ public static CargoTrackingDTO convert(Cargo cargo, List<HandlingEvent> handling
return new CargoTrackingDTO(
convertTrackingId(cargo),
convertStatusText(cargo, messageSource, locale),
convertOrigin(cargo),
convertDestination(cargo),
convertEta(cargo),
convertNextExpectedActivity(cargo),
convertIsMisdirected(cargo),
convertLegs(cargo),
handlingEventDTOs);
}

private static List<CargoLegDTO> convertLegs(Cargo cargo) {
return cargo.itinerary().legs().stream()
.map(CargoTrackingDTOConverter::convertLeg)
.collect(Collectors.toList());
}

private static CargoLegDTO convertLeg(Leg leg) {
return new CargoLegDTO(
leg.voyage().voyageNumber().idString(),
leg.loadLocation().unLocode().idString(),
leg.unloadLocation().unLocode().idString(),
leg.loadTime().toString(),
leg.unloadTime().toString());
}

private static List<HandlingEventDTO> convertHandlingEvents(List<HandlingEvent> handlingEvents, Cargo cargo, MessageSource messageSource, Locale locale) {

return handlingEvents.stream().map(he -> new HandlingEventDTO(
convertLocation(he),
convertTime(he),
Expand Down Expand Up @@ -121,13 +145,19 @@ protected static String convertStatusText(Cargo cargo, MessageSource messageSour
return messageSource.getMessage(code, args, "[Unknown status]", locale);
}

private static String convertDestination(Cargo cargo) {
return cargo.routeSpecification().destination().name();
private static LocationDTO convertOrigin(Cargo cargo) {
Location loc = cargo.routeSpecification().origin();
return new LocationDTO(loc.unlocode, loc.name);
}

private static LocationDTO convertDestination(Cargo cargo) {
Location loc = cargo.routeSpecification().destination();
return new LocationDTO(loc.unlocode, loc.name);
}

private static String convertEta(Cargo cargo) {
Instant date = cargo.delivery().estimatedTimeOfArrival();
return date == null ? "Unknown" : formatter.format(date);
return date == null ? "Unknown" : date.toString();
}

protected static String convertNextExpectedActivity(Cargo cargo) {
Expand Down
Loading
Loading