From cb976bcccf1cd880e95fb83e57386ca8193f0283 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Tue, 7 Jun 2022 12:04:38 +0200 Subject: [PATCH] Prepare for JPA rewrite Signed-off-by: Niels Thykier --- .dockerignore | 1 + .editorconfig | 17 ++ .github/workflows/docker_publish.yml | 27 +-- .github/workflows/microservices.yml | 93 +++++--- .gitignore | 3 +- DCSA-Information-Model | 2 +- Dockerfile | 14 +- docker-compose.yml | 6 + lombok.config | 2 + pom.xml | 139 ++++++++--- run-in-container.sh | 2 +- .../uisupport/config/ApplicationConfig.java | 13 - .../controller/CarrierController.java | 52 ---- .../controller/FacilityController.java | 52 ---- .../NegotiationCycleController.java | 54 ----- .../PortWithTimezoneController.java | 51 ---- .../TimestampDefinitionController.java | 54 ----- .../controller/TimestampExportController.java | 223 ------------------ .../controller/TransportCallController.java | 59 ----- .../controller/UITimestampInfoController.java | 51 ---- .../controller/VesselController.java | 64 ----- .../uisupport/model/DataExportDefinition.java | 163 ------------- .../dcsa/uisupport/model/ExcelGenerator.java | 199 ---------------- .../dcsa/uisupport/model/PendingEvent.java | 39 --- .../dcsa/uisupport/model/PortTimezone.java | 18 -- .../uisupport/model/PortWithTimezone.java | 41 ---- .../model/TransportCallWithTimestampsTO.java | 24 -- .../dcsa/uisupport/model/UITimestampInfo.java | 46 ---- .../dcsa/uisupport/model/UnmappedEvent.java | 20 -- .../model/enums/EventDeliveryStatus.java | 7 - .../NegotiationCycleRepository.java | 7 - .../PortWithTimezoneRepository.java | 7 - ...TransportCallWithTimestampsRepository.java | 7 - .../repository/UITimestampInfoRepository.java | 14 -- .../service/NegotiationCycleService.java | 7 - .../service/PortWithTimezoneService.java | 8 - .../TransportCallWithTimestampsTOService.java | 8 - .../service/UISupportEventService.java | 11 - .../service/UITimestampInfoService.java | 9 - .../impl/NegotiationCycleServiceImpl.java | 20 -- .../impl/PortWithTimezoneServiceImpl.java | 20 -- ...nsportCallWithTimestampsTOServiceImpl.java | 20 -- .../impl/UISupportEventServiceImpl.java | 36 --- .../impl/UITimestampInfoServiceImpl.java | 23 -- src/main/resources/application.yaml | 73 ------ .../org/dcsa/uisupport/ApplicationTests.java | 11 - ui-support-integration-tests/pom.xml | 104 ++++++++ .../java/org/dcsa/uisupport/itests/Main.java | 47 ++++ .../config/IntegrationTestsProperties.java | 36 +++ .../config/RestAssuredConfigurator.java | 13 + .../uisupport/itests/v1/HealthCheckIT.java | 29 +++ .../resources/integration-tests.properties | 2 + .../main/resources/simplelogger.properties | 3 + ui-support-persistence/pom.xml | 36 +++ ui-support-service/pom.xml | 96 ++++++++ .../java/org/dcsa/uisupport/Application.java | 5 +- .../configuration/JacksonConfiguration.java | 25 ++ .../src/main/resources/application.yml | 90 +++++++ ui-support-transfer-obj/pom.xml | 32 +++ 59 files changed, 730 insertions(+), 1605 deletions(-) create mode 100644 .dockerignore create mode 100644 .editorconfig create mode 100644 lombok.config delete mode 100644 src/main/java/org/dcsa/uisupport/config/ApplicationConfig.java delete mode 100644 src/main/java/org/dcsa/uisupport/controller/CarrierController.java delete mode 100644 src/main/java/org/dcsa/uisupport/controller/FacilityController.java delete mode 100644 src/main/java/org/dcsa/uisupport/controller/NegotiationCycleController.java delete mode 100644 src/main/java/org/dcsa/uisupport/controller/PortWithTimezoneController.java delete mode 100644 src/main/java/org/dcsa/uisupport/controller/TimestampDefinitionController.java delete mode 100644 src/main/java/org/dcsa/uisupport/controller/TimestampExportController.java delete mode 100644 src/main/java/org/dcsa/uisupport/controller/TransportCallController.java delete mode 100644 src/main/java/org/dcsa/uisupport/controller/UITimestampInfoController.java delete mode 100644 src/main/java/org/dcsa/uisupport/controller/VesselController.java delete mode 100644 src/main/java/org/dcsa/uisupport/model/DataExportDefinition.java delete mode 100644 src/main/java/org/dcsa/uisupport/model/ExcelGenerator.java delete mode 100644 src/main/java/org/dcsa/uisupport/model/PendingEvent.java delete mode 100644 src/main/java/org/dcsa/uisupport/model/PortTimezone.java delete mode 100644 src/main/java/org/dcsa/uisupport/model/PortWithTimezone.java delete mode 100644 src/main/java/org/dcsa/uisupport/model/TransportCallWithTimestampsTO.java delete mode 100644 src/main/java/org/dcsa/uisupport/model/UITimestampInfo.java delete mode 100644 src/main/java/org/dcsa/uisupport/model/UnmappedEvent.java delete mode 100644 src/main/java/org/dcsa/uisupport/model/enums/EventDeliveryStatus.java delete mode 100644 src/main/java/org/dcsa/uisupport/repository/NegotiationCycleRepository.java delete mode 100644 src/main/java/org/dcsa/uisupport/repository/PortWithTimezoneRepository.java delete mode 100644 src/main/java/org/dcsa/uisupport/repository/TransportCallWithTimestampsRepository.java delete mode 100644 src/main/java/org/dcsa/uisupport/repository/UITimestampInfoRepository.java delete mode 100644 src/main/java/org/dcsa/uisupport/service/NegotiationCycleService.java delete mode 100644 src/main/java/org/dcsa/uisupport/service/PortWithTimezoneService.java delete mode 100644 src/main/java/org/dcsa/uisupport/service/TransportCallWithTimestampsTOService.java delete mode 100644 src/main/java/org/dcsa/uisupport/service/UISupportEventService.java delete mode 100644 src/main/java/org/dcsa/uisupport/service/UITimestampInfoService.java delete mode 100644 src/main/java/org/dcsa/uisupport/service/impl/NegotiationCycleServiceImpl.java delete mode 100644 src/main/java/org/dcsa/uisupport/service/impl/PortWithTimezoneServiceImpl.java delete mode 100644 src/main/java/org/dcsa/uisupport/service/impl/TransportCallWithTimestampsTOServiceImpl.java delete mode 100644 src/main/java/org/dcsa/uisupport/service/impl/UISupportEventServiceImpl.java delete mode 100644 src/main/java/org/dcsa/uisupport/service/impl/UITimestampInfoServiceImpl.java delete mode 100644 src/main/resources/application.yaml delete mode 100644 src/test/java/org/dcsa/uisupport/ApplicationTests.java create mode 100644 ui-support-integration-tests/pom.xml create mode 100644 ui-support-integration-tests/src/main/java/org/dcsa/uisupport/itests/Main.java create mode 100644 ui-support-integration-tests/src/main/java/org/dcsa/uisupport/itests/config/IntegrationTestsProperties.java create mode 100644 ui-support-integration-tests/src/main/java/org/dcsa/uisupport/itests/config/RestAssuredConfigurator.java create mode 100644 ui-support-integration-tests/src/main/java/org/dcsa/uisupport/itests/v1/HealthCheckIT.java create mode 100644 ui-support-integration-tests/src/main/resources/integration-tests.properties create mode 100644 ui-support-integration-tests/src/main/resources/simplelogger.properties create mode 100644 ui-support-persistence/pom.xml create mode 100644 ui-support-service/pom.xml rename {src => ui-support-service/src}/main/java/org/dcsa/uisupport/Application.java (63%) create mode 100644 ui-support-service/src/main/java/org/dcsa/uisupport/configuration/JacksonConfiguration.java create mode 100644 ui-support-service/src/main/resources/application.yml create mode 100644 ui-support-transfer-obj/pom.xml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f3c96ff --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +**/*-sources.jar diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..cba52cf --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +# https://editorconfig.org/ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.{bat,cmd}] +end_of_line = crlf + +[pom.xml] +indent_style = tab +indent_size = 2 diff --git a/.github/workflows/docker_publish.yml b/.github/workflows/docker_publish.yml index e85746e..13ff5cd 100644 --- a/.github/workflows/docker_publish.yml +++ b/.github/workflows/docker_publish.yml @@ -6,10 +6,9 @@ name: Docker # documentation. on: - push: - branches: - - master - - live-* + create: + tags: + - v* env: # Use docker.io for Docker Hub if empty @@ -17,7 +16,6 @@ env: # github.repository as / IMAGE_NAME: ${{ github.repository }} - jobs: build: @@ -27,14 +25,16 @@ jobs: packages: write steps: - - name: Branch name - run: |- - tag_name=$(echo "${GITHUB_REF}" | sed 's/.*\///g; s/master/latest/') - echo DOCKER_TAG_NAME=${tag_name} - echo DOCKER_TAG_NAME=${tag_name} >> $GITHUB_ENV - - name: Checkout repository uses: actions/checkout@v2 + submodules: recursive + + - name: Set up Java JDK + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: 17 + cache: 'maven' - name: maven-settings-xml-action uses: whelk-io/maven-settings-xml-action@v12 @@ -45,8 +45,6 @@ jobs: - name: maven build run: mvn -B package --file pom.xml - - name: print context - run: echo "$GITHUB_CONTEXT" # Build and push Docker image # https://github.com/marketplace/actions/docker-build-push-action @@ -58,5 +56,4 @@ jobs: githubOrg: dcsaorg username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - tags: ${{ env.DOCKER_TAG_NAME }} - addLatest: ${{ false }} + addLatest: ${{ true }} diff --git a/.github/workflows/microservices.yml b/.github/workflows/microservices.yml index 9632a90..72cfa5a 100644 --- a/.github/workflows/microservices.yml +++ b/.github/workflows/microservices.yml @@ -1,36 +1,69 @@ -name: Microservices CI +name: DCSA-UI-Support MASTER CI -on: [push] +on: + push: + branches: + - master + pull_request: + branches: + - master jobs: build: runs-on: ubuntu-latest steps: - - name: Fetch backend - uses: actions/checkout@v2 - with: - path: DCSA-UI-Support - submodules: recursive - - name: Set up Java JDK - uses: actions/setup-java@v1 - with: - java-version: 11 - - name: Cache local Maven repository - uses: actions/cache@v2 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven- - - name: maven-settings-xml-action - uses: whelk-io/maven-settings-xml-action@v12 - with: - repositories: '[{ "id": "github", "name": "DCSA Backend repo", "url": "https://maven.pkg.github.com/dcsaorg/DCSA-Core", "releases": { "enabled": "true" }, "snapshots": { "enabled": "true" } }]' - servers: '[{ "id": "github", "username": "${{ secrets.DCSA_USER }}", "password": "${{ secrets.DCSA_PACKAGES_PAT }}" }]' - - - name: Build API - run: cd DCSA-UI-Support && mvn package -DskipTests -X #Need to skip the tests as they depend on a running DB - - - name: Run the UI Support microservice plus database - run: cd DCSA-UI-Support && docker-compose -f docker-compose.yml up -d -V - \ No newline at end of file + - uses: actions/checkout@v2 + with: + path: DCSA-UI-Support + submodules: recursive + + - name: Set up Java JDK + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: 17 + cache: 'maven' + + - name: maven-settings-xml-action + uses: whelk-io/maven-settings-xml-action@v12 + with: + repositories: '[{ "id": "github", "name": "DCSA Backend repo", "url": "https://maven.pkg.github.com/dcsaorg/DCSA-Core", "releases": { "enabled": "true" }, "snapshots": { "enabled": "true" } }]' + servers: '[{ "id": "github", "username": "${{ secrets.DCSA_USER }}", "password": "${{ secrets.DCSA_PACKAGES_PAT }}" }]' + + - name: Build UI-Support + run: cd DCSA-UI-Support && mvn clean -U -B package -Ddcsa.artifacttype=-SNAPSHOT + + - name: Build and run the microservices + run: cd DCSA-UI-Support && docker-compose -f docker-compose.yml up -d -V --build + + - name: Fetch Backend Status + run: | + sleep 10 + status=$(curl -s http://localhost:9091/v1/actuator/health | jq -r '.status') + retries=12 + + while [[ "$status" != "UP" ]] && [[ $retries -gt 0 ]]; do + echo "Status is '$status' - waiting 5 secs ($retries retries left)" + sleep 5 + retries=$((retries - 1)) + status=$(curl -s http://localhost:9091/v1/actuator/health | jq -r '.status') + done + + echo "Final status is '$status'" + if [[ "$status" != "UP" ]]; then + curl -v http://localhost:9091/v1/actuator/health + docker ps + docker logs dcsa-ui-support_dcsa-ui-support_1 + fi + + echo "::set-output name=STATUS::$status" + id: healthcheck + + - name: Confirm microservice status + if: ${{ steps.healthcheck.outputs.STATUS == 'UP' }} + run: | + echo "The DCSA-UI-Support service is UP." + + - name: Run Integration Tests + run: | + cd DCSA-UI-Support && java -jar ui-support-integration-tests/target/dcsa-ui-support-integration-tests-with-dependencies.jar diff --git a/.gitignore b/.gitignore index d4dfde6..6af701e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.flattened-pom.xml HELP.md target/ !.mvn/wrapper/maven-wrapper.jar @@ -28,4 +29,4 @@ target/ build/ ### VS Code ### -.vscode/ \ No newline at end of file +.vscode/ diff --git a/DCSA-Information-Model b/DCSA-Information-Model index 5b774d9..7843679 160000 --- a/DCSA-Information-Model +++ b/DCSA-Information-Model @@ -1 +1 @@ -Subproject commit 5b774d91ff863efb85cc3ed520fab1af716d7597 +Subproject commit 7843679d54fe593ca9590e590b89d8237fed31d1 diff --git a/Dockerfile b/Dockerfile index 95f7f8b..4f8da9c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,9 @@ -FROM debian:buster +FROM eclipse-temurin:17-jre-alpine -RUN apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get -y upgrade \ - && DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ - openjdk-11-jre-headless \ - && rm -rf /var/lib/apt/lists/* - -EXPOSE 9090 +EXPOSE 9091 ENV db_hostname dcsa_db COPY run-in-container.sh /run.sh RUN chmod +x /run.sh -COPY src/main/resources/application.yaml . -COPY target/dcsa_ui_support-*.jar . +COPY ui-support-service/src/main/resources/application.yml . +COPY ui-support-service/target/dcsa-ui-support-service.jar . CMD ["/run.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index aa2d009..d900dec 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,6 +5,12 @@ services: . ports: - 9091:9091 + environment: + - "db_hostname=dcsa-test-db" + - "SPRING_PROFILES_ACTIVE=${SPRING_PROFILES_ACTIVE:-nosecurity}" + - "SPRING_DATASOURCE_PASSWORD=9c072fe8-c59c-11ea-b8d1-7b6577e9f3f5" + - "ROOT_LOG_LEVEL=${ROOT_LOG_LEVEL:-INFO}" + - "DCSA_LOG_LEVEL=${DCSA_LOG_LEVEL:-INFO}" logging: options: max-file: '10' diff --git a/lombok.config b/lombok.config new file mode 100644 index 0000000..5540e1f --- /dev/null +++ b/lombok.config @@ -0,0 +1,2 @@ +# This is the top of the project +config.stopBubbling = true diff --git a/pom.xml b/pom.xml index 3b2e6b4..350959f 100644 --- a/pom.xml +++ b/pom.xml @@ -3,59 +3,116 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.springframework.boot - spring-boot-starter-parent - 2.4.2 + org.dcsa + dcsa-bom + 1.1-SNAPSHOT - org.dcsa - dcsa_ui_support - 0.0.1-SNAPSHOT - jar DCSA-UI-Support - Demo project for Spring Boot + org.dcsa.uisupport + dcsa-ui-support-parent + ${revision}${sha1}${changelist} + pom + Just In Time Port Call Optimization - 11 - 0.8.23 - 0.0.48 - + + 0.0.2 + + -SNAPSHOT + + + 0.0.61 -SNAPSHOT + ${dcsa.events.version}${dcsa.event.tag}${dcsa.artifacttype} + + + + + 0.8.33 + ${dcsa.core.version}${dcsa.core.tag}${dcsa.artifacttype} + + + + 0.1.0 + + -SNAPSHOT + ${dcsa.shared-kernel.version}${dcsa.shared-kernel.tag}${dcsa.shared-kernel.artifacttype} + + + ui-support-transfer-obj + ui-support-persistence + ui-support-service + ui-support-integration-tests + + - org.dcsa - dcsa_core - ${dcsa.version}${dcsa.core.tag}${dcsa.artifacttype} - - - org.dcsa - dcsa_event_core - ${dcsa.events.version}${dcsa.event.tag}${dcsa.artifacttype} - - - org.apache.poi - poi-ooxml - 5.0.0 + org.projectlombok + lombok - - - - org.springframework.boot - spring-boot-maven-plugin - - - + + + + + commons-logging + commons-logging + 1.2 + + + org.dcsa.uisupport + dcsa-ui-support-transfer-obj + ${project.version} + + + org.dcsa.uisupport + dcsa-ui-support-persistence + ${project.version} + + + org.apache.poi + poi-ooxml + 5.0.0 + + + org.dcsa.shared-kernel + dcsa-shared-kernel-parent + ${shared-kernel.version} + pom + import + + + + + central + Maven Central + https://repo1.maven.org/maven2 + + true + + + false + + + github - GitHub dcsaorg Apache Maven Packages + GitHub DCSA Backend https://maven.pkg.github.com/dcsaorg/DCSA-Core + + true + + + true + always + @@ -63,8 +120,20 @@ github GitHub OWNER Apache Maven Packages - https://maven.pkg.github.com/dcsaorg/DCSA-UI-Support + https://maven.pkg.github.com/dcsaorg/DCSA-OVS + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + diff --git a/run-in-container.sh b/run-in-container.sh index 07464a6..ba204e8 100644 --- a/run-in-container.sh +++ b/run-in-container.sh @@ -1,6 +1,6 @@ #!/bin/sh -echo "spring.config.import=/application.yaml" >> dcsa-spring-boot.properties +echo "spring.config.import=/application.yml" >> dcsa-spring-boot.properties if [ -f "/config/dcsa-config.yaml" ]; then echo "Add /config/dcsa-config.yaml to dcsa-spring-boot.properties" diff --git a/src/main/java/org/dcsa/uisupport/config/ApplicationConfig.java b/src/main/java/org/dcsa/uisupport/config/ApplicationConfig.java deleted file mode 100644 index 9c03903..0000000 --- a/src/main/java/org/dcsa/uisupport/config/ApplicationConfig.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.dcsa.uisupport.config; - -import org.dcsa.core.repository.ExtendedRepositoryImpl; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories; - -@Configuration -@ComponentScan("org.dcsa") -@EnableR2dbcRepositories( - basePackages = {"org.dcsa"}, - repositoryBaseClass = ExtendedRepositoryImpl.class) -public class ApplicationConfig {} diff --git a/src/main/java/org/dcsa/uisupport/controller/CarrierController.java b/src/main/java/org/dcsa/uisupport/controller/CarrierController.java deleted file mode 100644 index 5999ae1..0000000 --- a/src/main/java/org/dcsa/uisupport/controller/CarrierController.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.dcsa.uisupport.controller; - -import lombok.RequiredArgsConstructor; -import org.dcsa.core.controller.ExtendedBaseController; -import org.dcsa.core.events.model.Carrier; -import org.dcsa.core.events.service.CarrierService; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; -import reactor.core.publisher.Mono; - -import javax.validation.Valid; -import java.util.UUID; - -@RestController -@RequestMapping( - value = "unofficial/carriers", - produces = {MediaType.APPLICATION_JSON_VALUE}) -@RequiredArgsConstructor -public class CarrierController extends ExtendedBaseController { - - private final CarrierService carrierService; - - @Override - public CarrierService getService() { - return carrierService; - } - - @PostMapping - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono create(@Valid @RequestBody Carrier carrier) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - @PutMapping(path = "{carrierID}") - public Mono update(@PathVariable UUID carrierID, @Valid @RequestBody Carrier carrier) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - @DeleteMapping - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono delete(@RequestBody Carrier carrier) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - @DeleteMapping(path = "{carrierID}") - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono deleteById(@PathVariable UUID carrierID) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } -} diff --git a/src/main/java/org/dcsa/uisupport/controller/FacilityController.java b/src/main/java/org/dcsa/uisupport/controller/FacilityController.java deleted file mode 100644 index d4197dd..0000000 --- a/src/main/java/org/dcsa/uisupport/controller/FacilityController.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.dcsa.uisupport.controller; - -import lombok.RequiredArgsConstructor; -import org.dcsa.core.controller.ExtendedBaseController; -import org.dcsa.core.events.model.Facility; -import org.dcsa.core.events.service.FacilityService; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; -import reactor.core.publisher.Mono; - -import javax.validation.Valid; -import java.util.UUID; - -@RestController -@RequestMapping( - value = "unofficial/terminals", - produces = {MediaType.APPLICATION_JSON_VALUE}) -@RequiredArgsConstructor -public class FacilityController extends ExtendedBaseController { - - private final FacilityService facilityService; - - @Override - public FacilityService getService() { - return facilityService; - } - - @PostMapping - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono create(@Valid @RequestBody Facility facility) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - @PutMapping(path = "{facilityID}") - public Mono update(@PathVariable UUID facilityID, @Valid @RequestBody Facility facility) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - @DeleteMapping - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono delete(@RequestBody Facility facility) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - @DeleteMapping(path = "{facilityID}") - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono deleteById(@PathVariable UUID facilityID) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } -} diff --git a/src/main/java/org/dcsa/uisupport/controller/NegotiationCycleController.java b/src/main/java/org/dcsa/uisupport/controller/NegotiationCycleController.java deleted file mode 100644 index 8c1fbd8..0000000 --- a/src/main/java/org/dcsa/uisupport/controller/NegotiationCycleController.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.dcsa.uisupport.controller; - -import lombok.RequiredArgsConstructor; -import org.dcsa.core.controller.ExtendedBaseController; -import org.dcsa.core.events.model.NegotiationCycle; -import org.dcsa.uisupport.service.NegotiationCycleService; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; -import reactor.core.publisher.Mono; - -import javax.validation.Valid; - -@RestController -@RequestMapping( - value = "unofficial/negotiation-cycles", - produces = {MediaType.APPLICATION_JSON_VALUE}) -@RequiredArgsConstructor -public class NegotiationCycleController extends ExtendedBaseController { - - private final NegotiationCycleService negotiationCycleService; - - @Override - public NegotiationCycleService getService() { - return negotiationCycleService; - } - - @PostMapping - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono create(@Valid @RequestBody NegotiationCycle negotiationCycle) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - @PutMapping(path = "{cycle_key}") - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono update(@PathVariable String cycle_key, @Valid @RequestBody NegotiationCycle negotiationCycle) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - @DeleteMapping - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono delete(@RequestBody NegotiationCycle negotiationCycle) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - @DeleteMapping(path = "{cycle_key}") - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono deleteById(@PathVariable String cycle_key) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - -} diff --git a/src/main/java/org/dcsa/uisupport/controller/PortWithTimezoneController.java b/src/main/java/org/dcsa/uisupport/controller/PortWithTimezoneController.java deleted file mode 100644 index 98ee266..0000000 --- a/src/main/java/org/dcsa/uisupport/controller/PortWithTimezoneController.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.dcsa.uisupport.controller; - -import lombok.RequiredArgsConstructor; -import org.dcsa.core.controller.ExtendedBaseController; -import org.dcsa.uisupport.model.PortWithTimezone; -import org.dcsa.uisupport.service.PortWithTimezoneService; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; -import reactor.core.publisher.Mono; - -import javax.validation.Valid; - -@RestController -@RequestMapping( - value = "unofficial/ports", - produces = {MediaType.APPLICATION_JSON_VALUE}) -@RequiredArgsConstructor -public class PortWithTimezoneController extends ExtendedBaseController { - - private final PortWithTimezoneService portWithTimezoneService; - - @Override - public PortWithTimezoneService getService() { - return portWithTimezoneService; - } - - @PostMapping - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono create(@Valid @RequestBody PortWithTimezone port) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - @PutMapping(path = "{unLocationCode}") - public Mono update(@PathVariable String unLocationCode, @Valid @RequestBody PortWithTimezone port) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - @DeleteMapping - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono delete(@RequestBody PortWithTimezone port) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - @DeleteMapping(path = "{unLocationCode}") - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono deleteById(@PathVariable String unLocationCode) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } -} diff --git a/src/main/java/org/dcsa/uisupport/controller/TimestampDefinitionController.java b/src/main/java/org/dcsa/uisupport/controller/TimestampDefinitionController.java deleted file mode 100644 index af8403f..0000000 --- a/src/main/java/org/dcsa/uisupport/controller/TimestampDefinitionController.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.dcsa.uisupport.controller; - -import lombok.RequiredArgsConstructor; -import org.dcsa.core.controller.ExtendedBaseController; -import org.dcsa.core.events.model.TimestampDefinition; -import org.dcsa.core.events.service.TimestampDefinitionService; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; -import reactor.core.publisher.Mono; - -import javax.validation.Valid; - -@RestController -@RequestMapping( - value = "unofficial/timestamp-definitions", - produces = {MediaType.APPLICATION_JSON_VALUE}) -@RequiredArgsConstructor -public class TimestampDefinitionController extends ExtendedBaseController { - - private final TimestampDefinitionService timestampDefinitionService; - - @Override - public TimestampDefinitionService getService() { - return timestampDefinitionService; - } - - @PostMapping - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono create(@Valid @RequestBody TimestampDefinition timestampDefinition) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - @PutMapping(path = "{id}") - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono update(@PathVariable String id, @Valid @RequestBody TimestampDefinition timestampDefinition) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - @DeleteMapping - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono delete(@RequestBody TimestampDefinition timestampDefinition) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - @DeleteMapping(path = "{id}") - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono deleteById(@PathVariable String id) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - -} diff --git a/src/main/java/org/dcsa/uisupport/controller/TimestampExportController.java b/src/main/java/org/dcsa/uisupport/controller/TimestampExportController.java deleted file mode 100644 index e2f1b57..0000000 --- a/src/main/java/org/dcsa/uisupport/controller/TimestampExportController.java +++ /dev/null @@ -1,223 +0,0 @@ -package org.dcsa.uisupport.controller; - -import lombok.RequiredArgsConstructor; -import org.apache.poi.ss.usermodel.DataConsolidateFunction; -import org.dcsa.core.events.model.Event; -import org.dcsa.core.events.model.OperationsEvent; -import org.dcsa.core.events.model.TimestampDefinition; -import org.dcsa.core.events.model.Vessel; -import org.dcsa.core.events.model.enums.DCSAResponsibleAgencyCode; -import org.dcsa.core.events.model.enums.FacilityTypeCode; -import org.dcsa.core.events.model.transferobjects.LocationTO; -import org.dcsa.core.events.model.transferobjects.PartyTO; -import org.dcsa.core.events.model.transferobjects.TransportCallTO; -import org.dcsa.core.events.service.TimestampDefinitionService; -import org.dcsa.core.events.util.ExtendedGenericEventRequest; -import org.dcsa.core.extendedrequest.ExtendedParameters; -import org.dcsa.core.extendedrequest.ExtendedRequest; -import org.dcsa.uisupport.model.DataExportDefinition; -import org.dcsa.uisupport.model.ExcelGenerator; -import org.dcsa.uisupport.model.PortWithTimezone; -import org.dcsa.uisupport.model.UITimestampInfo; -import org.dcsa.uisupport.service.PortWithTimezoneService; -import org.dcsa.uisupport.service.UISupportEventService; -import org.dcsa.uisupport.service.UITimestampInfoService; -import org.springframework.data.r2dbc.dialect.R2dbcDialect; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import reactor.core.publisher.Mono; -import reactor.util.function.Tuple2; -import reactor.util.function.Tuple3; - -import java.time.*; -import java.util.*; -import java.util.function.Function; -import java.util.stream.Collectors; - -@RestController -@RequestMapping(value = "unofficial/export-timestamps") -@RequiredArgsConstructor -public class TimestampExportController { - - private final static ZoneOffset UTC = ZoneOffset.UTC; - - private final ExcelGenerator excelGenerator; - private final TimestampDefinitionService timestampDefinitionService; - private final PortWithTimezoneService portWithTimezoneService; - private final UISupportEventService uiSupportEventService; - private final UITimestampInfoService uiTimestampInfoService; - private final ExtendedParameters extendedParameters; - private final R2dbcDialect r2dbcDialect; - - private final static Set> OPERATIONS_EVENT_TYPE = Set.of(OperationsEvent.class); - private final DataExportDefinition> dataExportDefinition = DataExportDefinition.>builder() - .column("Publisher SMDG code", Tuple2::getT1, oe -> mapPublisher(oe, p -> - Objects.requireNonNullElseGet(p.getIdentifyingCodes(), Collections::emptyList).stream() - .filter(idc -> idc.getDCSAResponsibleAgencyCode() == DCSAResponsibleAgencyCode.SMDG) - .map(PartyTO.IdentifyingCode::getPartyCode) - .collect(Collectors.joining(",")))) - .column("Publisher Role", Tuple3::getT1, OperationsEvent::getPublisherRole) - .column("Publisher Name", Tuple3::getT1, OperationsEvent::getPublisher, PartyTO::getPartyName) - .column("Vessel Name", Tuple3::getT1, OperationsEvent::getTransportCall, TransportCallTO::getVessel, Vessel::getVesselName) - .column("Vessel IMO", Tuple3::getT1, OperationsEvent::getTransportCall, TransportCallTO::getVessel, v -> Integer.parseInt(v.getVesselIMONumber())) - .column("Vessel location lat", Tuple3::getT1, OperationsEvent::getVesselPosition, LocationTO::getLatitude) - .column("Vessel location long", Tuple3::getT1, OperationsEvent::getVesselPosition, LocationTO::getLongitude) - //.column("Rotation From", oe -> "N/A (data not available)") - //.column("Rotation To", oe -> "N/A (data not available)") - //.column("Direction", oe -> "N/A (data not available)") - .column("Carrier Import Voyage Number", Tuple3::getT1, OperationsEvent::getTransportCall, TransportCallTO::getImportVoyageNumber) - .column("Carrier Export Voyage Number", Tuple3::getT1, OperationsEvent::getTransportCall, TransportCallTO::getExportVoyageNumber) - .column("Transport Mode", Tuple3::getT1, OperationsEvent::getTransportCall, TransportCallTO::getModeOfTransport) - .column("Facility Location", Tuple3::getT1, OperationsEvent::getTransportCall, TransportCallTO::getUNLocationCode) - .column("Terminal Code", Tuple3::getT1, OperationsEvent::getTransportCall, TransportCallTO::getFacilityCode) - .column("Facility type code", Tuple3::getT1, OperationsEvent::getFacilityTypeCode) - .column("Port Call Service type code", Tuple3::getT1, (oe) -> mapOrDefault(oe, OperationsEvent::getPortCallServiceTypeCode, "")) - .column("Event Classifier code", Tuple3::getT1, OperationsEvent::getEventClassifierCode) - /* Only for *-PBP related timestamps*/ - .column("PBP Location", Tuple3::getT1, oe -> isPBPTimestamp(oe) - ? mapEventLocation(oe, LocationTO::getLocationName) - : "N/A (wrong timestamp type)") - /* Only for *-Berth related timestamps*/ - .column("Berth Location", Tuple3::getT1, oe -> isBerthRelatedTimestamp(oe) - ? mapEventLocation(oe, LocationTO::getLocationName) - : "N/A (wrong timestamp type)") - .column("Event Message", Tuple3::getT2, TimestampDefinition::getTimestampTypeName) - .column("Event Timestamp (port local TZ)", tuple -> asLocalDateTime(tuple.getT1().getEventDateTime(), tuple.getT3())) - .column("Event created date time (port local TZ)", tuple -> asLocalDateTime(tuple.getT1().getEventCreatedDateTime(), tuple.getT3())) - .column("Port (UN Location Code)", Tuple3::getT1, OperationsEvent::getTransportCall, this::getUnLocationCode) - .column("Port Timezone", Tuple3::getT3) - //.column("Response time", oe -> "N/A") - //.column("Port call duration", oe -> "N/A") - .column("Delay Reason Code", Tuple3::getT1, OperationsEvent::getDelayReasonCode) - .column("Negotiation Sequence ID", TimestampExportController::computeNegotiationSequenceID) - .column("Remark", Tuple3::getT1, OperationsEvent::getRemark) - .pivotChart((dataExportDefinition, pivotTable) -> { - pivotTable.addRowLabel(dataExportDefinition.getColumnIndexOf("Vessel Name")); - pivotTable.addRowLabel(dataExportDefinition.getColumnIndexOf("Negotiation Sequence ID")); - pivotTable.addReportFilter(dataExportDefinition.getColumnIndexOf("Facility Location")); - pivotTable.addReportFilter(dataExportDefinition.getColumnIndexOf("Facility type code")); - pivotTable.addReportFilter(dataExportDefinition.getColumnIndexOf("Port Call Service type code")); - pivotTable.addColLabel(dataExportDefinition.getColumnIndexOf("Event Classifier code")); - pivotTable.addColumnLabel( - DataConsolidateFunction.COUNT, - dataExportDefinition.getColumnIndexOf("Event Timestamp (port local TZ)"), - "Number of timestamps for a given negotiation cycle per Vessel" - ); - }) - .build(); - - private boolean isBerthRelatedTimestamp(OperationsEvent oe) { - return oe.getFacilityTypeCode() == FacilityTypeCode.BRTH; - } - - private String getUnLocationCode(TransportCallTO transportCallTO) { - String unLocode = transportCallTO.getUNLocationCode(); - if (unLocode == null && transportCallTO.getLocation() != null) { - unLocode = transportCallTO.getLocation().getUnLocationCode(); - } - return unLocode; - } - - private LocalDateTime asLocalDateTime(OffsetDateTime dateTime, ZoneId timeZone) { - Instant instant = dateTime.toInstant(); - ZoneOffset offset = timeZone.getRules().getOffset(instant); - return instant.atOffset(offset).toLocalDateTime(); - } - - private boolean isPBPTimestamp(OperationsEvent oe) { - return oe.getFacilityTypeCode() == FacilityTypeCode.PBPL; - } - - private Object mapOrDefault(T t, Function mapper, Object defaultValue) { - Object res = mapper.apply(t); - if (res == null) { - return defaultValue; - } - return res; - } - - private Object mapEventLocation(OperationsEvent oe, Function mapper) { - LocationTO location = oe.getEventLocation(); - if (location != null) { - return mapper.apply(location); - } - return null; - } - - private Object mapPublisher(OperationsEvent oe, Function mapper) { - PartyTO publisher = oe.getPublisher(); - if (publisher != null) { - return mapper.apply(publisher); - } - return null; - } - - private static Object computeNegotiationSequenceID(Tuple2 tuple) { - OperationsEvent operationsEvent = tuple.getT1(); - TimestampDefinition timestampDefinition = tuple.getT2(); - StringBuilder builder = new StringBuilder(); - if (operationsEvent.getTransportCall() != null) { - builder.append(operationsEvent.getTransportCall().getTransportCallID()); - } else { - builder.append("NO_TC-").append(operationsEvent.getEventID()); - } - return builder.append('-').append(timestampDefinition.getNegotiationCycle()).toString(); - } - - @GetMapping - public Mono> findAll() { - ExtendedGenericEventRequest genericEventRequest = new ExtendedGenericEventRequest(extendedParameters, r2dbcDialect, OPERATIONS_EVENT_TYPE); - genericEventRequest.parseParameter( - Map.of("eventType", List.of("OPERATIONS"), - "limit", List.of("1000000"), - "sort", List.of("eventCreatedDateTime:ASC") - ) - ); - ExtendedRequest portWithTimezoneExtendedRequest = new ExtendedRequest<>(extendedParameters, r2dbcDialect, PortWithTimezone.class); - portWithTimezoneExtendedRequest.parseParameter(Map.of("limit", List.of("1000000"))); - return excelGenerator.generateExcel( - "timestamps", - dataExportDefinition, - uiSupportEventService.countAllExtended(genericEventRequest), - timestampDefinitionService.findAll() - .collectMap(TimestampDefinition::getId, Function.identity()) - .flatMap(timestampDefinitions -> - Mono.zip(uiTimestampInfoService.findAll() - .collectMap(UITimestampInfo::getEventID, info -> timestampDefinitions.get(info.getTimestampDefinition())), - portWithTimezoneService.findAllExtended(portWithTimezoneExtendedRequest) - .collectMap(PortWithTimezone::getUnLocationCode, - portWithTimezone -> { - String timezone = portWithTimezone.getTimezone(); - if (timezone == null) { - return UTC; - } - try { - return ZoneId.of(timezone); - } catch (DateTimeException e) { - return UTC; - } - } - ) - )).flatMapMany(tuple -> { - Map eventID2TimestampDefinitions = tuple.getT1(); - Map unLocode2TZ = tuple.getT2(); - return uiSupportEventService.findAllExtended(genericEventRequest).cast(OperationsEvent.class) - .concatMap(oe -> { - TimestampDefinition timestampDefinition = eventID2TimestampDefinitions.get(oe.getEventID()); - TransportCallTO transportCallTO = oe.getTransportCall(); - String unLocode = transportCallTO.getUNLocationCode(); - if (unLocode == null && transportCallTO.getLocation() != null) { - unLocode = transportCallTO.getLocation().getUnLocationCode(); - } - return Mono.zip( - Mono.just(oe), - Mono.justOrEmpty(timestampDefinition), - Mono.just(unLocode2TZ.getOrDefault(unLocode, UTC)) - ); - }); - }) - ); - } -} diff --git a/src/main/java/org/dcsa/uisupport/controller/TransportCallController.java b/src/main/java/org/dcsa/uisupport/controller/TransportCallController.java deleted file mode 100644 index d309b1a..0000000 --- a/src/main/java/org/dcsa/uisupport/controller/TransportCallController.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.dcsa.uisupport.controller; - -import lombok.RequiredArgsConstructor; -import org.dcsa.core.controller.ExtendedBaseController; -import org.dcsa.core.events.model.transferobjects.TransportCallTO; -import org.dcsa.core.events.service.TransportCallTOService; -import org.dcsa.core.util.MappingUtils; -import org.dcsa.uisupport.model.TransportCallWithTimestampsTO; -import org.dcsa.uisupport.service.TransportCallWithTimestampsTOService; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; -import reactor.core.publisher.Mono; - -@RestController -@RequestMapping( - value = "unofficial/transport-calls", - produces = {MediaType.APPLICATION_JSON_VALUE}) -@RequiredArgsConstructor -public class TransportCallController - extends ExtendedBaseController { - - private final TransportCallWithTimestampsTOService transportCallWithTimestampsTOService; - private final TransportCallTOService transportCallTOService; - - @Override - public TransportCallWithTimestampsTOService getService() { - return transportCallWithTimestampsTOService; - } - - @PostMapping - @ResponseStatus(HttpStatus.CREATED) - public Mono create(@RequestBody TransportCallWithTimestampsTO transportCallTO) { - return transportCallTOService.create(transportCallTO) - .map(tc -> MappingUtils.instanceFrom(tc, TransportCallWithTimestampsTO::new, TransportCallTO.class)); - } - - @Override - @PutMapping(path = "{transportCallID}") - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono update( - @PathVariable String transportCallID, @RequestBody TransportCallWithTimestampsTO transportCallTO) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - @Override - @DeleteMapping - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono delete(@RequestBody TransportCallWithTimestampsTO transportCallTO) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - @DeleteMapping(path = "{transportCallID}") - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono deleteById(@PathVariable String transportCallID) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } -} diff --git a/src/main/java/org/dcsa/uisupport/controller/UITimestampInfoController.java b/src/main/java/org/dcsa/uisupport/controller/UITimestampInfoController.java deleted file mode 100644 index 996c895..0000000 --- a/src/main/java/org/dcsa/uisupport/controller/UITimestampInfoController.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.dcsa.uisupport.controller; - -import lombok.RequiredArgsConstructor; -import org.dcsa.core.controller.ExtendedBaseController; -import org.dcsa.uisupport.model.UITimestampInfo; -import org.dcsa.uisupport.service.UITimestampInfoService; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; -import reactor.core.publisher.Mono; - -import javax.validation.Valid; -import java.util.UUID; - -@RestController -@RequestMapping( - value = "unofficial/timestamp-info", - produces = {MediaType.APPLICATION_JSON_VALUE}) -@RequiredArgsConstructor -public class UITimestampInfoController extends ExtendedBaseController { - private final UITimestampInfoService UITimestampInfoService; - - @Override - public UITimestampInfoService getService() { - return UITimestampInfoService; - } - - @PostMapping - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono create(@Valid @RequestBody UITimestampInfo UITimestampInfo) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - @PutMapping(path = "{eventID}") - public Mono update(@PathVariable UUID eventID, @Valid @RequestBody UITimestampInfo UITimestampInfo) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - @DeleteMapping - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono delete(@RequestBody UITimestampInfo UITimestampInfo) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - @DeleteMapping(path = "{eventID}") - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono deleteById(@PathVariable UUID eventID) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } -} diff --git a/src/main/java/org/dcsa/uisupport/controller/VesselController.java b/src/main/java/org/dcsa/uisupport/controller/VesselController.java deleted file mode 100644 index ebf0975..0000000 --- a/src/main/java/org/dcsa/uisupport/controller/VesselController.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.dcsa.uisupport.controller; - -import lombok.RequiredArgsConstructor; -import org.dcsa.core.controller.ExtendedBaseController; -import org.dcsa.core.events.model.Vessel; -import org.dcsa.core.events.service.VesselService; -import org.dcsa.core.exception.CreateException; -import org.dcsa.core.validator.ValidVesselIMONumber; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; -import reactor.core.publisher.Mono; - -import javax.validation.Valid; -import java.util.UUID; - -@RestController -@RequestMapping( - value = "unofficial/vessels", - produces = {MediaType.APPLICATION_JSON_VALUE}) -@RequiredArgsConstructor -public class VesselController extends ExtendedBaseController { - - private final VesselService vesselService; - - @Override - public VesselService getService() { - return vesselService; - } - - @PostMapping - @ResponseStatus(HttpStatus.CREATED) - public Mono create(@Valid @RequestBody Vessel vessel) { - // Override subclass as we *want* an ID (default is that the ID must be absent) - if (vessel.getVesselIMONumber() == null) { - throw new CreateException("Missing vessel IMO number"); - } - return vesselService.create(vessel); - } - - @PutMapping(path = "{id}") - @ResponseStatus(HttpStatus.OK) - public Mono update( - @PathVariable UUID id, @Valid @RequestBody Vessel vessel) { - if (!id.equals(vesselService.getIdOfEntity(vessel))) { - return updateMonoError(); - } - return vesselService.update(vessel); - } - - @Override - @DeleteMapping - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono delete(@RequestBody Vessel vessel) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } - - @DeleteMapping(path = "{id}") - @ResponseStatus(HttpStatus.FORBIDDEN) - public Mono deleteById(@PathVariable UUID id) { - return Mono.error(new ResponseStatusException(HttpStatus.FORBIDDEN)); - } -} diff --git a/src/main/java/org/dcsa/uisupport/model/DataExportDefinition.java b/src/main/java/org/dcsa/uisupport/model/DataExportDefinition.java deleted file mode 100644 index 6526f9b..0000000 --- a/src/main/java/org/dcsa/uisupport/model/DataExportDefinition.java +++ /dev/null @@ -1,163 +0,0 @@ -package org.dcsa.uisupport.model; - -import lombok.AccessLevel; -import lombok.Data; -import lombok.RequiredArgsConstructor; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.CellStyle; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.xssf.streaming.SXSSFCell; -import org.apache.poi.xssf.streaming.SXSSFRow; -import org.apache.poi.xssf.usermodel.XSSFPivotTable; - -import java.time.LocalDateTime; -import java.util.*; -import java.util.function.BiConsumer; -import java.util.function.Function; - -@RequiredArgsConstructor(access = AccessLevel.PACKAGE) -public class DataExportDefinition { - - private final Map> columnDefinitions; - private final BiConsumer, XSSFPivotTable> pivotTableGenerator; - - public int getColumnCount() { - return columnDefinitions.size(); - } - - public boolean includePivotChart() { - return pivotTableGenerator != null; - } - - public void setupPivotChart(XSSFPivotTable pivotTable) { - if (pivotTableGenerator == null) { - throw new IllegalStateException("setupPivotChart MUST NOT be called with includePivotChart() returns false"); - } - pivotTableGenerator.accept(this, pivotTable); - } - - public int getColumnIndexOf(String column) { - ColumnDefinition columnDefinition = columnDefinitions.get(column); - if (columnDefinition == null) { - throw new IllegalStateException("Unknown Column " + column); - } - return columnDefinition.getColumnIndex(); - } - - public void insertColumnNames(Row headerRow) { - int i = 0; - for (String columnName : columnDefinitions.keySet()) { - int columnIndex = i++; - Cell cell = headerRow.createCell(columnIndex); - cell.setCellValue(columnName); - } - } - - public void writeEntityIntoRow(T entity, Row valueRow, CellStyle dateCellStyle) { - int i = 0; - for (ColumnDefinition columnDefinition : columnDefinitions.values()) { - Object value = columnDefinition.valueExtractor.apply(entity); - Cell cell = valueRow.createCell(i++); - if (value == null) { - cell.setBlank(); - } else if (value instanceof Boolean) { - cell.setCellValue((Boolean) value); - } else if (value instanceof Number) { - cell.setCellValue(((Number) value).doubleValue()); - } else if (value instanceof LocalDateTime) { - cell.setCellValue((LocalDateTime) value); - cell.setCellStyle(dateCellStyle); - } else { - cell.setCellValue(value.toString()); - } - } - } - - public static Builder builder() { - return new Builder<>(); - } - - public static DataExportDefinition of(LinkedHashMap> mapperFunctions) { - return of(mapperFunctions, null); - } - - public static DataExportDefinition of(LinkedHashMap> mapperFunctions, BiConsumer, XSSFPivotTable> pivotTableGenerator) { - LinkedHashMap> columnDefinitions = new LinkedHashMap<>(); - int columnIndex = 0; - for (Map.Entry> entry : mapperFunctions.entrySet()) { - String key = entry.getKey(); - ColumnDefinition columnDefinition = ColumnDefinition.of(columnIndex++, entry.getValue()); - if (columnDefinitions.putIfAbsent(key, columnDefinition) != null) { - throw new IllegalArgumentException("Key " + key + " is not unique"); - } - } - return new DataExportDefinition<>( - Collections.unmodifiableMap(columnDefinitions), - pivotTableGenerator - ); - } - - @Data(staticConstructor = "of") - private static class ColumnDefinition { - final int columnIndex; - final Function valueExtractor; - } - - public static class Builder { - private final LinkedHashMap> columnDefinitions = new LinkedHashMap<>(); - private BiConsumer, XSSFPivotTable> pivotTableGenerator; - - private Builder() {} - - public Builder column(String columnName, Function valueExtractor) { - ColumnDefinition columnDefinition = ColumnDefinition.of(columnDefinitions.size(), valueExtractor); - if (columnDefinitions.putIfAbsent(columnName, columnDefinition) != null) { - throw new IllegalArgumentException("Column " + columnName + " is not unique"); - } - return this; - } - - public Builder column(String columnName, Function mapping, Function valueExtractor) { - return column(columnName, combine(mapping, valueExtractor)); - } - - public Builder column(String columnName, Function mappingA, Function mappingB, Function valueExtractor) { - return column(columnName, combine(mappingA, mappingB, valueExtractor)); - } - - public Builder column(String columnName, Function mappingA, Function mappingB, Function mappingC, Function valueExtractor) { - return column(columnName, combine(mappingA, mappingB, mappingC, valueExtractor)); - } - - public Builder pivotChart(BiConsumer, XSSFPivotTable> pivotTableGenerator) { - this.pivotTableGenerator = pivotTableGenerator; - return this; - } - - public DataExportDefinition build() { - if (columnDefinitions.isEmpty()) { - throw new IllegalStateException("No columns to export"); - } - return new DataExportDefinition<>( - Collections.unmodifiableMap(new LinkedHashMap<>(columnDefinitions)), - pivotTableGenerator - ); - } - } - - private static Function combine(Function first, Function second) { - return (a -> { - B b = first.apply(a); - return b != null ? second.apply(b) : null; - }); - } - - private static Function combine(Function first, Function second, Function third) { - return combine(combine(first, second), third); - } - - private static Function combine(Function first, Function second, Function third, Function fourth) { - return combine(combine(first, second, third), fourth); - } - -} diff --git a/src/main/java/org/dcsa/uisupport/model/ExcelGenerator.java b/src/main/java/org/dcsa/uisupport/model/ExcelGenerator.java deleted file mode 100644 index 9f34db1..0000000 --- a/src/main/java/org/dcsa/uisupport/model/ExcelGenerator.java +++ /dev/null @@ -1,199 +0,0 @@ -package org.dcsa.uisupport.model; - -import lombok.RequiredArgsConstructor; -import lombok.SneakyThrows; -import org.apache.poi.ss.usermodel.*; -import org.apache.poi.ss.util.AreaReference; -import org.apache.poi.ss.util.CellRangeAddress; -import org.apache.poi.ss.util.CellReference; -import org.apache.poi.xssf.streaming.SXSSFRow; -import org.apache.poi.xssf.streaming.SXSSFSheet; -import org.apache.poi.xssf.streaming.SXSSFWorkbook; -import org.apache.poi.xssf.usermodel.XSSFPivotTable; -import org.apache.poi.xssf.usermodel.XSSFSheet; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.springframework.http.*; -import org.springframework.stereotype.Component; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.*; - -@Component -public class ExcelGenerator { - - private static final int BUFFER_ROW = 100; - - private static final MediaType EXCEL_MEDIA_TYPE = MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); - - public Mono> generateExcel(String basename, DataExportDefinition dataExportDefinition, Mono rowCount, Flux dataFlux) { - ExcelGeneratorState state = ExcelGeneratorState.of(dataExportDefinition); - return rowCount.doOnNext(state::initialize) - .thenMany(dataFlux.buffer(BUFFER_ROW)) - .doOnNext(state::processData) - // Abuse count to collapse the flux into a non-empty mono, - // so we can use doOnNext/map from there. - .count() - .doOnNext(ignored -> state.dataFinished()) - .map(ignored -> { - byte[] data = state.toByteArray(); - HttpHeaders responseHeaders = new HttpHeaders(); - String name = basename + ".xlsx"; - responseHeaders.setContentType(EXCEL_MEDIA_TYPE); - responseHeaders.setContentDisposition( - ContentDisposition.builder("attachment").filename(name).build() - ); - return new ResponseEntity<>(data, responseHeaders, HttpStatus.OK); - }).doFinally(ignored -> state.close()); - } - - @RequiredArgsConstructor(staticName = "of") - private static class ExcelGeneratorState { - private final DataExportDefinition dataExportDefinition; - - private Workbook workbook; - private int rowNum = 0; - private boolean initialized = false; - private boolean finished = false; - private Sheet dataSheet; - private CellStyle dataRowStyle; - private CellStyle dateCellStyle; - private XSSFPivotTable pivotTable; - - public void initialize(int pivotRowCount) { - if (dataExportDefinition.includePivotChart() && pivotRowCount > 0) { - workbook = new XSSFWorkbook(); - } else { - // We need a few extra rows in the access window because we also operate on the header row along - // with the first batch. - workbook = new SXSSFWorkbook(null, BUFFER_ROW + 5, false); - } - - CreationHelper createHelper = workbook.getCreationHelper(); - Font defaultFont = workbook.createFont(); - defaultFont.setBold(false); - Font boldfaceFont = workbook.createFont(); - boldfaceFont.setBold(true); - CellStyle headerStyle = workbook.createCellStyle(); - headerStyle.setFont(boldfaceFont); - - dateCellStyle = workbook.createCellStyle(); - dateCellStyle.setDataFormat(createHelper.createDataFormat().getFormat("yyyy-mmm-dd hh:mm")); - - if (rowNum > 0) { - throw new IllegalStateException("createHeaderRow must be called at most once and before any row is created"); - } - - dataSheet = workbook.createSheet("data"); - Row headerRow = dataSheet.createRow(rowNum++); - dataExportDefinition.insertColumnNames(headerRow); - headerRow.setRowStyle(headerStyle); - - if (dataExportDefinition.includePivotChart() && pivotRowCount > 0) { - assert workbook instanceof XSSFWorkbook; - XSSFSheet pivotChartSheet = (XSSFSheet)workbook.createSheet("pivot"); - CellReference topLeft = new CellReference("data", - headerRow.getRowNum(), - headerRow.getFirstCellNum(), - false, - false - ); - CellReference bottomRight = new CellReference("data", - pivotRowCount, - headerRow.getLastCellNum() - 1, - false, - false - ); - AreaReference areaReference = new AreaReference(topLeft, bottomRight, workbook.getSpreadsheetVersion()); - CellReference pivotTopLeft = new CellReference(0, 0); - pivotTable = pivotChartSheet.createPivotTable(areaReference, pivotTopLeft); - } - - dataRowStyle = workbook.createCellStyle(); - dataRowStyle.setFont(defaultFont); - dataSheet.createFreezePane(0, 1); - if (dataSheet instanceof SXSSFSheet) { - ((SXSSFSheet)dataSheet).trackAllColumnsForAutoSizing(); - } - initialized = true; - } - - - public void processData(List rows) { - boolean first = rowNum == 0; - if (finished) { - throw new IllegalStateException("Already finished!"); - } - if (first && !initialized) { - initialize(-1); - } - for (T t : rows) { - Row row = dataSheet.createRow(rowNum++); - dataExportDefinition.writeEntityIntoRow(t, row, dateCellStyle); - row.setRowStyle(dataRowStyle); - } - if (first && dataSheet instanceof SXSSFSheet) { - // For SXSSFSheet's, we do auto-resizing after the first row batch to keep the advantage of streaming - SXSSFSheet sxssfSheet = (SXSSFSheet)dataSheet; - // The auto-sizing of column is expensive because it involves going over all values in the sheet. - // Since we can generate very large sheets, we are interested in a "cheap" solution. We cheat and - // use the first batch of rows to "guessimate" the size of the column. This enables us to use POI's - // built-in resizing feature while avoiding to go through the sheet again. - resizeColumn(); - sxssfSheet.untrackAllColumnsForAutoSizing(); - } - } - - private void resizeColumn() { - final int size = dataExportDefinition.getColumnCount(); - for (int i = 0; i < size ; i++) { - dataSheet.autoSizeColumn(i); - } - } - - public void dataFinished() { - ensureDataIsFinished(); - if (dataSheet instanceof XSSFSheet) { - // For XSSFSheet's, we can do the resize of all columns at the end - resizeColumn(); - } - if (pivotTable != null && rowNum > 0) { - dataExportDefinition.setupPivotChart(pivotTable); - } - } - - private void ensureDataIsFinished() { - if (!finished) { - finished = true; - if (!initialized) { - // Special-case: If there were no matching results (i.e. the Flux was empty), - // then we still have to generate an Excel file. However, we have to remember - // to generate the header row (etc.) - initialize(-1); - } - dataSheet.setAutoFilter(new CellRangeAddress(0, rowNum - 1, 0, dataExportDefinition.getColumnCount() - 1)); - } - } - - @SneakyThrows(IOException.class) - public byte[] toByteArray() { - ByteArrayOutputStream bout = new ByteArrayOutputStream(); - - ensureDataIsFinished(); - workbook.write(bout); - return bout.toByteArray(); - } - - @SneakyThrows(IOException.class) - public void close() { - if (workbook != null) { - workbook.close(); - if (workbook instanceof SXSSFWorkbook) { - ((SXSSFWorkbook)workbook).dispose(); - } - } - } - } -} diff --git a/src/main/java/org/dcsa/uisupport/model/PendingEvent.java b/src/main/java/org/dcsa/uisupport/model/PendingEvent.java deleted file mode 100644 index 5c882b5..0000000 --- a/src/main/java/org/dcsa/uisupport/model/PendingEvent.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.dcsa.uisupport.model; - -import com.fasterxml.jackson.annotation.JsonFormat; -import lombok.Data; -import org.springframework.data.annotation.Id; -import org.springframework.data.relational.core.mapping.Column; - -import java.time.OffsetDateTime; -import java.util.UUID; - -@Data -public class PendingEvent { - @Id - @Column("delivery_id") - private UUID deliveryId; - - @Column("subscription_id") - private UUID subscriptionId; - - @Column("event_id") - private UUID eventId; - - @Column("payload") - private String payload; - - @Column("enqueued_at_date_time") - @JsonFormat(shape = JsonFormat.Shape.STRING) - private OffsetDateTime equeuedAtDateTime; - - @Column("last_attempt_date_time") - @JsonFormat(shape = JsonFormat.Shape.STRING) - private OffsetDateTime lastAttemptDateTime; - - @Column("last_error_message") - private String lastErrorMessage; - - @Column("retry_count") - private int retryCount; -} diff --git a/src/main/java/org/dcsa/uisupport/model/PortTimezone.java b/src/main/java/org/dcsa/uisupport/model/PortTimezone.java deleted file mode 100644 index ccf4aa6..0000000 --- a/src/main/java/org/dcsa/uisupport/model/PortTimezone.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.dcsa.uisupport.model; - -import lombok.Data; -import org.springframework.data.annotation.Id; -import org.springframework.data.relational.core.mapping.Column; -import org.springframework.data.relational.core.mapping.Table; - -@Data -@Table("port_timezone") -public class PortTimezone { - - @Id - @Column("un_location_code") - private String unLocationCode; - - @Column("iana_timezone") - private String ianaTimezone; -} diff --git a/src/main/java/org/dcsa/uisupport/model/PortWithTimezone.java b/src/main/java/org/dcsa/uisupport/model/PortWithTimezone.java deleted file mode 100644 index d9cc911..0000000 --- a/src/main/java/org/dcsa/uisupport/model/PortWithTimezone.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.dcsa.uisupport.model; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import lombok.Data; -import org.dcsa.core.model.ForeignKey; -import org.springframework.data.annotation.Id; -import org.springframework.data.annotation.Transient; -import org.springframework.data.relational.core.mapping.Column; -import org.springframework.data.relational.core.mapping.Table; -import org.springframework.data.relational.core.sql.Join; - -@Data -@Table("un_location") -public class PortWithTimezone { - - @Id - @Column("un_location_code") - private String unLocationCode; - - @Column("un_location_name") - private String unLocationName; - - @Column("location_code") - private String locationCode; - - @Column("country_code") - private String countryCode; - - public String getTimezone() { - if (portTimezone == null) { - return null; - } - return portTimezone.getIanaTimezone(); - } - - @JsonIgnore - @Transient - @ForeignKey(fromFieldName = "unLocationCode", foreignFieldName = "unLocationCode", joinType = Join.JoinType.LEFT_OUTER_JOIN) - private PortTimezone portTimezone; - -} diff --git a/src/main/java/org/dcsa/uisupport/model/TransportCallWithTimestampsTO.java b/src/main/java/org/dcsa/uisupport/model/TransportCallWithTimestampsTO.java deleted file mode 100644 index 2d722dc..0000000 --- a/src/main/java/org/dcsa/uisupport/model/TransportCallWithTimestampsTO.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.dcsa.uisupport.model; - -import lombok.Data; -import lombok.EqualsAndHashCode; -import org.dcsa.core.events.model.transferobjects.TransportCallTO; -import org.springframework.data.relational.core.mapping.Column; -import org.springframework.data.relational.core.mapping.Table; - -import java.time.OffsetDateTime; - -@Data -@EqualsAndHashCode(callSuper = true) -@Table("transport_call_with_timestamps") -public class TransportCallWithTimestampsTO extends TransportCallTO { - - @Column("latest_event_created_date_time") - private OffsetDateTime latestEventCreatedDateTime; - - @Column("eta_berth_date_time") - private OffsetDateTime etaBerthDateTime; - - @Column("atd_berth_date_time") - private OffsetDateTime atdBerthDateTime; -} diff --git a/src/main/java/org/dcsa/uisupport/model/UITimestampInfo.java b/src/main/java/org/dcsa/uisupport/model/UITimestampInfo.java deleted file mode 100644 index 85048fb..0000000 --- a/src/main/java/org/dcsa/uisupport/model/UITimestampInfo.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.dcsa.uisupport.model; - -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.Data; -import org.dcsa.uisupport.model.enums.EventDeliveryStatus; -import org.springframework.data.annotation.Id; -import org.springframework.data.relational.core.mapping.Column; -import org.springframework.data.relational.core.mapping.Table; - -import java.time.OffsetDateTime; -import java.util.UUID; - -@Table("ui_timestamp_info") -@Data -public class UITimestampInfo { - - @Id - @Column("event_id") - private UUID eventID; - - @Column("timestamp_definition") - private String timestampDefinition; - - @Column("event_delivery_status") - private EventDeliveryStatus eventDeliveryStatus; - - @Column("enqueued_at_date_time") - @JsonFormat(shape = JsonFormat.Shape.STRING) - private OffsetDateTime enqueuedAtDateTime; - - @JsonInclude(JsonInclude.Include.NON_NULL) - @Column("last_attempt_date_time") - @JsonFormat(shape = JsonFormat.Shape.STRING) - private OffsetDateTime lastAttemptDateTime; - - @JsonInclude(JsonInclude.Include.NON_NULL) - @Column("last_error_message") - private String lastErrorMessage; - - @Column("retry_count") - private int retryCount; - - @Column("transport_call_id") - private String transportCallID; -} diff --git a/src/main/java/org/dcsa/uisupport/model/UnmappedEvent.java b/src/main/java/org/dcsa/uisupport/model/UnmappedEvent.java deleted file mode 100644 index 222f28f..0000000 --- a/src/main/java/org/dcsa/uisupport/model/UnmappedEvent.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.dcsa.uisupport.model; - -import com.fasterxml.jackson.annotation.JsonFormat; -import lombok.Data; -import org.springframework.data.annotation.Id; -import org.springframework.data.relational.core.mapping.Column; - -import java.time.OffsetDateTime; -import java.util.UUID; - -@Data -public class UnmappedEvent { - @Id - @Column("event_id") - private UUID eventId; - - @Column("enqueued_at_date_time") - @JsonFormat(shape = JsonFormat.Shape.STRING) - private OffsetDateTime equeuedAtDateTime; -} diff --git a/src/main/java/org/dcsa/uisupport/model/enums/EventDeliveryStatus.java b/src/main/java/org/dcsa/uisupport/model/enums/EventDeliveryStatus.java deleted file mode 100644 index d08fee0..0000000 --- a/src/main/java/org/dcsa/uisupport/model/enums/EventDeliveryStatus.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.dcsa.uisupport.model.enums; - -public enum EventDeliveryStatus { - PENDING_DELIVERY, - ATTEMPTED_DELIVERY, - DELIVERY_FINISHED, -} diff --git a/src/main/java/org/dcsa/uisupport/repository/NegotiationCycleRepository.java b/src/main/java/org/dcsa/uisupport/repository/NegotiationCycleRepository.java deleted file mode 100644 index 53059fe..0000000 --- a/src/main/java/org/dcsa/uisupport/repository/NegotiationCycleRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.dcsa.uisupport.repository; - -import org.dcsa.core.events.model.NegotiationCycle; -import org.dcsa.core.repository.ExtendedRepository; - -public interface NegotiationCycleRepository extends ExtendedRepository { -} diff --git a/src/main/java/org/dcsa/uisupport/repository/PortWithTimezoneRepository.java b/src/main/java/org/dcsa/uisupport/repository/PortWithTimezoneRepository.java deleted file mode 100644 index 76ee929..0000000 --- a/src/main/java/org/dcsa/uisupport/repository/PortWithTimezoneRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.dcsa.uisupport.repository; - -import org.dcsa.core.repository.ExtendedRepository; -import org.dcsa.uisupport.model.PortWithTimezone; - -public interface PortWithTimezoneRepository extends ExtendedRepository { -} diff --git a/src/main/java/org/dcsa/uisupport/repository/TransportCallWithTimestampsRepository.java b/src/main/java/org/dcsa/uisupport/repository/TransportCallWithTimestampsRepository.java deleted file mode 100644 index 66bd241..0000000 --- a/src/main/java/org/dcsa/uisupport/repository/TransportCallWithTimestampsRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.dcsa.uisupport.repository; - -import org.dcsa.core.events.repository.AbstractTransportCallTORepository; -import org.dcsa.uisupport.model.TransportCallWithTimestampsTO; - -public interface TransportCallWithTimestampsRepository extends AbstractTransportCallTORepository { -} diff --git a/src/main/java/org/dcsa/uisupport/repository/UITimestampInfoRepository.java b/src/main/java/org/dcsa/uisupport/repository/UITimestampInfoRepository.java deleted file mode 100644 index 480a971..0000000 --- a/src/main/java/org/dcsa/uisupport/repository/UITimestampInfoRepository.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.dcsa.uisupport.repository; - -import org.dcsa.core.repository.ExtendedRepository; -import org.dcsa.uisupport.model.UITimestampInfo; -import org.dcsa.uisupport.model.PendingEvent; -import org.dcsa.uisupport.model.UnmappedEvent; -import org.springframework.data.r2dbc.repository.Query; -import reactor.core.publisher.Mono; - -import java.util.UUID; - -public interface UITimestampInfoRepository extends ExtendedRepository { - -} diff --git a/src/main/java/org/dcsa/uisupport/service/NegotiationCycleService.java b/src/main/java/org/dcsa/uisupport/service/NegotiationCycleService.java deleted file mode 100644 index c6fd9d9..0000000 --- a/src/main/java/org/dcsa/uisupport/service/NegotiationCycleService.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.dcsa.uisupport.service; - -import org.dcsa.core.events.model.NegotiationCycle; -import org.dcsa.core.service.ExtendedBaseService; - -public interface NegotiationCycleService extends ExtendedBaseService { -} diff --git a/src/main/java/org/dcsa/uisupport/service/PortWithTimezoneService.java b/src/main/java/org/dcsa/uisupport/service/PortWithTimezoneService.java deleted file mode 100644 index 5199870..0000000 --- a/src/main/java/org/dcsa/uisupport/service/PortWithTimezoneService.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.dcsa.uisupport.service; - -import org.dcsa.core.service.ExtendedBaseService; -import org.dcsa.uisupport.model.PortWithTimezone; - -public interface PortWithTimezoneService extends ExtendedBaseService { - -} \ No newline at end of file diff --git a/src/main/java/org/dcsa/uisupport/service/TransportCallWithTimestampsTOService.java b/src/main/java/org/dcsa/uisupport/service/TransportCallWithTimestampsTOService.java deleted file mode 100644 index f6e2e55..0000000 --- a/src/main/java/org/dcsa/uisupport/service/TransportCallWithTimestampsTOService.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.dcsa.uisupport.service; - -import org.dcsa.core.events.service.AbstractTransportCallTOService; -import org.dcsa.uisupport.model.TransportCallWithTimestampsTO; - -public interface TransportCallWithTimestampsTOService extends AbstractTransportCallTOService { - -} diff --git a/src/main/java/org/dcsa/uisupport/service/UISupportEventService.java b/src/main/java/org/dcsa/uisupport/service/UISupportEventService.java deleted file mode 100644 index 10cc65f..0000000 --- a/src/main/java/org/dcsa/uisupport/service/UISupportEventService.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.dcsa.uisupport.service; - -import org.dcsa.core.events.model.Event; -import org.dcsa.core.events.service.GenericEventService; -import org.dcsa.core.extendedrequest.ExtendedRequest; -import reactor.core.publisher.Mono; - -public interface UISupportEventService extends GenericEventService { - - Mono countAllExtended(ExtendedRequest extendedRequest); -} \ No newline at end of file diff --git a/src/main/java/org/dcsa/uisupport/service/UITimestampInfoService.java b/src/main/java/org/dcsa/uisupport/service/UITimestampInfoService.java deleted file mode 100644 index 5bf4a53..0000000 --- a/src/main/java/org/dcsa/uisupport/service/UITimestampInfoService.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.dcsa.uisupport.service; - -import org.dcsa.core.service.ExtendedBaseService; -import org.dcsa.uisupport.model.UITimestampInfo; - -import java.util.UUID; - -public interface UITimestampInfoService extends ExtendedBaseService { -} diff --git a/src/main/java/org/dcsa/uisupport/service/impl/NegotiationCycleServiceImpl.java b/src/main/java/org/dcsa/uisupport/service/impl/NegotiationCycleServiceImpl.java deleted file mode 100644 index db5062d..0000000 --- a/src/main/java/org/dcsa/uisupport/service/impl/NegotiationCycleServiceImpl.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.dcsa.uisupport.service.impl; - -import lombok.RequiredArgsConstructor; -import org.dcsa.core.events.model.NegotiationCycle; -import org.dcsa.core.service.impl.ExtendedBaseServiceImpl; -import org.dcsa.uisupport.repository.NegotiationCycleRepository; -import org.dcsa.uisupport.service.NegotiationCycleService; -import org.springframework.stereotype.Service; - -@RequiredArgsConstructor -@Service -public class NegotiationCycleServiceImpl extends ExtendedBaseServiceImpl implements NegotiationCycleService{ - - private final NegotiationCycleRepository negotiationCycleRepository; - - @Override - public NegotiationCycleRepository getRepository() { - return negotiationCycleRepository; - } -} diff --git a/src/main/java/org/dcsa/uisupport/service/impl/PortWithTimezoneServiceImpl.java b/src/main/java/org/dcsa/uisupport/service/impl/PortWithTimezoneServiceImpl.java deleted file mode 100644 index ea9f5ff..0000000 --- a/src/main/java/org/dcsa/uisupport/service/impl/PortWithTimezoneServiceImpl.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.dcsa.uisupport.service.impl; - -import lombok.RequiredArgsConstructor; -import org.dcsa.core.service.impl.ExtendedBaseServiceImpl; -import org.dcsa.uisupport.model.PortWithTimezone; -import org.dcsa.uisupport.repository.PortWithTimezoneRepository; -import org.dcsa.uisupport.service.PortWithTimezoneService; -import org.springframework.stereotype.Service; - -@RequiredArgsConstructor -@Service -public class PortWithTimezoneServiceImpl extends ExtendedBaseServiceImpl implements PortWithTimezoneService { - - private final PortWithTimezoneRepository portWithTimezoneRepository; - - @Override - public PortWithTimezoneRepository getRepository() { - return portWithTimezoneRepository; - } -} diff --git a/src/main/java/org/dcsa/uisupport/service/impl/TransportCallWithTimestampsTOServiceImpl.java b/src/main/java/org/dcsa/uisupport/service/impl/TransportCallWithTimestampsTOServiceImpl.java deleted file mode 100644 index 57d70e8..0000000 --- a/src/main/java/org/dcsa/uisupport/service/impl/TransportCallWithTimestampsTOServiceImpl.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.dcsa.uisupport.service.impl; - -import lombok.RequiredArgsConstructor; -import org.dcsa.core.events.service.impl.AbstractTransportCallTOServiceImpl; -import org.dcsa.uisupport.model.TransportCallWithTimestampsTO; -import org.dcsa.uisupport.repository.TransportCallWithTimestampsRepository; -import org.dcsa.uisupport.service.TransportCallWithTimestampsTOService; -import org.springframework.stereotype.Service; - -@RequiredArgsConstructor -@Service -public class TransportCallWithTimestampsTOServiceImpl extends AbstractTransportCallTOServiceImpl implements TransportCallWithTimestampsTOService { - - private final TransportCallWithTimestampsRepository transportCallWithTimestampsRepository; - - @Override - public TransportCallWithTimestampsRepository getRepository() { - return transportCallWithTimestampsRepository; - } -} diff --git a/src/main/java/org/dcsa/uisupport/service/impl/UISupportEventServiceImpl.java b/src/main/java/org/dcsa/uisupport/service/impl/UISupportEventServiceImpl.java deleted file mode 100644 index ad68733..0000000 --- a/src/main/java/org/dcsa/uisupport/service/impl/UISupportEventServiceImpl.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.dcsa.uisupport.service.impl; - -import org.dcsa.core.events.model.Event; -import org.dcsa.core.events.model.enums.EventType; -import org.dcsa.core.events.repository.EventRepository; -import org.dcsa.core.events.repository.PendingEventRepository; -import org.dcsa.core.events.service.EquipmentEventService; -import org.dcsa.core.events.service.OperationsEventService; -import org.dcsa.core.events.service.ShipmentEventService; -import org.dcsa.core.events.service.TransportEventService; -import org.dcsa.core.events.service.impl.GenericEventServiceImpl; -import org.dcsa.core.extendedrequest.ExtendedRequest; -import org.dcsa.uisupport.service.UISupportEventService; -import org.springframework.stereotype.Service; -import reactor.core.publisher.Mono; - -import java.util.Set; - -@Service -public class UISupportEventServiceImpl extends GenericEventServiceImpl implements UISupportEventService { - - private final Set SUPPORTED_EVENT_TYPES = Set.of(EventType.OPERATIONS); - - public UISupportEventServiceImpl(TransportEventService transportEventService, EquipmentEventService equipmentEventService, ShipmentEventService shipmentEventService, OperationsEventService operationsEventService, EventRepository eventRepository, PendingEventRepository pendingEventRepository) { - super(shipmentEventService, transportEventService, equipmentEventService,operationsEventService, eventRepository, pendingEventRepository); - } - - public Mono countAllExtended(ExtendedRequest extendedRequest) { - return getRepository().countAllExtended(extendedRequest); - } - - - protected Set getSupportedEvents() { - return SUPPORTED_EVENT_TYPES; - } -} diff --git a/src/main/java/org/dcsa/uisupport/service/impl/UITimestampInfoServiceImpl.java b/src/main/java/org/dcsa/uisupport/service/impl/UITimestampInfoServiceImpl.java deleted file mode 100644 index 8581c5b..0000000 --- a/src/main/java/org/dcsa/uisupport/service/impl/UITimestampInfoServiceImpl.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.dcsa.uisupport.service.impl; - -import lombok.RequiredArgsConstructor; -import org.dcsa.core.service.impl.ExtendedBaseServiceImpl; -import org.dcsa.uisupport.model.UITimestampInfo; -import org.dcsa.uisupport.repository.UITimestampInfoRepository; -import org.dcsa.uisupport.service.UITimestampInfoService; -import org.springframework.stereotype.Service; - -import java.util.UUID; - -@RequiredArgsConstructor -@Service -public class UITimestampInfoServiceImpl extends ExtendedBaseServiceImpl - implements UITimestampInfoService { - private final UITimestampInfoRepository UITimestampInfoRepository; - - @Override - public UITimestampInfoRepository getRepository() { - return UITimestampInfoRepository; - } - -} diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml deleted file mode 100644 index e5b42d0..0000000 --- a/src/main/resources/application.yaml +++ /dev/null @@ -1,73 +0,0 @@ - -# Possibility to change the separator between the sortable field and the direction (ASC or DESC). Default value is : (colon) - can be changed to e.g. | by writing -#sort: -# direction: -# separator: \| - -# Pagination settings -pagination: - # # encryptionKey needs to be one of the following sizes: 128, 192 or 256 bits - in the example below it is 128 bit (= 16 bytes) - # encryptionKey: xyz123wersdgf354 - # config: - # # Change name of cursor parameter name - # cursorName: - # # Change name of pageSize parameter name - # pageSizeName: - # # Change name of current-page header name - # currentPageName: - # # Change name of next-page header name - # nextPageName: - # # Change name of previous-page header name - # previousPageName: - # # Change name of first-page header name - # firstPageName: - # # Possibility to change the default pagination size. If not specified all results will be returned as default - defaultPageSize: 20 - -spring: - profiles: - active: dev - application: - name: DCSA-Backend - r2dbc: - url: r2dbc:postgresql://${db_hostname} - name: dcsa_openapi - properties: - schema: dcsa_im_v3_0 - username: dcsa_db_owner - password: 9c072fe8-c59c-11ea-b8d1-7b6577e9f3f5 - initialization-mode: always - security: - oauth2: - resourceserver: - jwt: - issuer-uri: https://dcsa.eu.auth0.com/ - webflux: - base-path: ${dcsa.url.prefix:}/v1 - -auth0: - audience: localhost - enabled: true - -server: - port: 9091 - error: - include-binding-errors: on_param - include-message: always - -management: - endpoint: - health: - probes: - enabled: true - endpoints: - web: - exposure: - include: health - -logging: - level: - root: INFO - org: - springframework: - r2dbc: INFO diff --git a/src/test/java/org/dcsa/uisupport/ApplicationTests.java b/src/test/java/org/dcsa/uisupport/ApplicationTests.java deleted file mode 100644 index 2705a06..0000000 --- a/src/test/java/org/dcsa/uisupport/ApplicationTests.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.dcsa.uisupport; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest(properties = {"db_hostname=0.0.0.0:5432/dcsa_openapi"}) -class ApplicationTests { - - @Test - void contextLoads() {} -} diff --git a/ui-support-integration-tests/pom.xml b/ui-support-integration-tests/pom.xml new file mode 100644 index 0000000..ec84013 --- /dev/null +++ b/ui-support-integration-tests/pom.xml @@ -0,0 +1,104 @@ + + 4.0.0 + + + org.dcsa.uisupport + dcsa-ui-support-parent + ${revision}${sha1}${changelist} + + + DCSA UI Support - Integration Tests + dcsa-ui-support-integration-tests + ${revision}${sha1}${changelist} + jar + + DCSA UI Support - Integration Tests + + + + org.junit.jupiter + junit-jupiter + + + org.junit.platform + junit-platform-launcher + + + org.slf4j + slf4j-simple + + + commons-logging + commons-logging + + + io.rest-assured + rest-assured + + + io.rest-assured + json-path + + + io.rest-assured + rest-assured-all + + + io.rest-assured + json-schema-validator + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + package + + single + + + + + org.dcsa.uisupport.itests.Main + + + + jar-with-dependencies + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-resources + package + + copy + + + + + org.dcsa.uisupport + dcsa-ui-support-integration-tests + ${project.version} + jar-with-dependencies + ${project.build.directory} + dcsa-ui-support-integration-tests-with-dependencies.jar + + + + + + + + + + diff --git a/ui-support-integration-tests/src/main/java/org/dcsa/uisupport/itests/Main.java b/ui-support-integration-tests/src/main/java/org/dcsa/uisupport/itests/Main.java new file mode 100644 index 0000000..864f9ea --- /dev/null +++ b/ui-support-integration-tests/src/main/java/org/dcsa/uisupport/itests/Main.java @@ -0,0 +1,47 @@ +package org.dcsa.uisupport.itests; + +import org.junit.platform.engine.discovery.ClassNameFilter; +import org.junit.platform.engine.discovery.DiscoverySelectors; +import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder; +import org.junit.platform.launcher.core.LauncherFactory; +import org.junit.platform.launcher.listeners.SummaryGeneratingListener; +import org.junit.platform.launcher.listeners.TestExecutionSummary; +import org.junit.platform.launcher.listeners.discovery.LauncherDiscoveryListeners; + +import java.io.PrintWriter; + +public class Main { + + public static void main(String[] args) { + System.out.println("Running integration tests.."); + + var summary = runTests(); + if (summary.getContainersFailedCount() > 0 || summary.getTestsFailedCount() > 0) { + summary.printFailuresTo(new PrintWriter(System.out)); + System.exit(1); + } + System.exit(0); + } + + private static TestExecutionSummary runTests() { + var listener = new SummaryGeneratingListener(); + + var launcher = LauncherFactory.create(); + launcher.registerLauncherDiscoveryListeners( + LauncherDiscoveryListeners.logging(), + LauncherDiscoveryListeners.abortOnFailure() + ); + + var testplan = launcher.discover( + LauncherDiscoveryRequestBuilder.request() + .selectors(DiscoverySelectors.selectPackage(Main.class.getPackageName())) + .filters(ClassNameFilter.includeClassNamePatterns(".*(Test|IT)")) + .build() + ); + launcher.registerTestExecutionListeners(listener); + launcher.execute(testplan); + + listener.getSummary().printTo(new PrintWriter(System.out)); + return listener.getSummary(); + } +} diff --git a/ui-support-integration-tests/src/main/java/org/dcsa/uisupport/itests/config/IntegrationTestsProperties.java b/ui-support-integration-tests/src/main/java/org/dcsa/uisupport/itests/config/IntegrationTestsProperties.java new file mode 100644 index 0000000..f082b87 --- /dev/null +++ b/ui-support-integration-tests/src/main/java/org/dcsa/uisupport/itests/config/IntegrationTestsProperties.java @@ -0,0 +1,36 @@ +package org.dcsa.uisupport.itests.config; + +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import lombok.Synchronized; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +@RequiredArgsConstructor +public class IntegrationTestsProperties { + private static IntegrationTestsProperties instance; + private final Properties properties; + + @Synchronized + @SneakyThrows(IOException.class) + public static IntegrationTestsProperties getInstance() { + if (instance == null) { + Properties properties = new Properties(); + try (InputStream is = ClassLoader.getSystemResourceAsStream("integration-tests.properties")) { + properties.load(is); + instance = new IntegrationTestsProperties(properties); + } + } + return instance; + } + + public String getBaseUri() { + return properties.getProperty("base_uri"); + } + + public int getPort() { + return Integer.parseInt(properties.getProperty("port")); + } +} diff --git a/ui-support-integration-tests/src/main/java/org/dcsa/uisupport/itests/config/RestAssuredConfigurator.java b/ui-support-integration-tests/src/main/java/org/dcsa/uisupport/itests/config/RestAssuredConfigurator.java new file mode 100644 index 0000000..9f38cf5 --- /dev/null +++ b/ui-support-integration-tests/src/main/java/org/dcsa/uisupport/itests/config/RestAssuredConfigurator.java @@ -0,0 +1,13 @@ +package org.dcsa.uisupport.itests.config; + +import io.restassured.RestAssured; +import lombok.experimental.UtilityClass; + +@UtilityClass +public class RestAssuredConfigurator { + public void initialize() { + var properties = IntegrationTestsProperties.getInstance(); + RestAssured.baseURI = properties.getBaseUri(); + RestAssured.port = properties.getPort(); + } +} diff --git a/ui-support-integration-tests/src/main/java/org/dcsa/uisupport/itests/v1/HealthCheckIT.java b/ui-support-integration-tests/src/main/java/org/dcsa/uisupport/itests/v1/HealthCheckIT.java new file mode 100644 index 0000000..68df12c --- /dev/null +++ b/ui-support-integration-tests/src/main/java/org/dcsa/uisupport/itests/v1/HealthCheckIT.java @@ -0,0 +1,29 @@ +package org.dcsa.uisupport.itests.v1; + +import io.restassured.http.ContentType; +import org.dcsa.uisupport.itests.config.RestAssuredConfigurator; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.equalTo; + +public class HealthCheckIT { + @BeforeAll + public static void initializeRestAssured() { + RestAssuredConfigurator.initialize(); + } + + @Test + public void testHealth() { + given() + .contentType("application/json") + .get("/v1/actuator/health") + .then() + .assertThat() + .statusCode(200) + .contentType(ContentType.JSON) + .body("status", equalTo("UP")) + ; + } +} diff --git a/ui-support-integration-tests/src/main/resources/integration-tests.properties b/ui-support-integration-tests/src/main/resources/integration-tests.properties new file mode 100644 index 0000000..3913e16 --- /dev/null +++ b/ui-support-integration-tests/src/main/resources/integration-tests.properties @@ -0,0 +1,2 @@ +base_uri=http://localhost +port=9091 diff --git a/ui-support-integration-tests/src/main/resources/simplelogger.properties b/ui-support-integration-tests/src/main/resources/simplelogger.properties new file mode 100644 index 0000000..c52ebc4 --- /dev/null +++ b/ui-support-integration-tests/src/main/resources/simplelogger.properties @@ -0,0 +1,3 @@ +# Default log level for all instances of SimpleLogger. +# Must be one of ("trace", "debug", "info", "warn", "error" or "off"). If not specified, defaults to "info". +org.slf4j.simpleLogger.defaultLogLevel=debug diff --git a/ui-support-persistence/pom.xml b/ui-support-persistence/pom.xml new file mode 100644 index 0000000..6ba7497 --- /dev/null +++ b/ui-support-persistence/pom.xml @@ -0,0 +1,36 @@ + + 4.0.0 + + + org.dcsa.uisupport + dcsa-ui-support-parent + ${revision}${sha1}${changelist} + + + DCSA UI Support - Database Persistence + dcsa-ui-support-persistence + ${revision}${sha1}${changelist} + jar + + DCSA UI Support - Database Persistence + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + javax.validation + validation-api + + + org.postgresql + postgresql + + + org.dcsa.shared-kernel + dcsa-shared-kernel-domain + + + + diff --git a/ui-support-service/pom.xml b/ui-support-service/pom.xml new file mode 100644 index 0000000..78c021f --- /dev/null +++ b/ui-support-service/pom.xml @@ -0,0 +1,96 @@ + + 4.0.0 + + + org.dcsa.uisupport + dcsa-ui-support-parent + ${revision}${sha1}${changelist} + + + DCSA UI Support - Service + dcsa-ui-support-service + ${revision}${sha1}${changelist} + jar + + DCSA UI Support - Service + + + + org.dcsa.uisupport + dcsa-ui-support-transfer-obj + + + org.dcsa.uisupport + dcsa-ui-support-persistence + + + org.mapstruct + mapstruct + + + org.springframework + spring-context + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-validation + + + org.springframework.boot + spring-boot-starter-actuator + + + org.dcsa.shared-kernel + dcsa-shared-kernel-all + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + false + + dev + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-resources + package + + copy + + + + + org.dcsa.uisupport + dcsa-ui-support-service + ${project.version} + ${project.build.directory} + dcsa-ui-support-service.jar + + + + + + + + + + diff --git a/src/main/java/org/dcsa/uisupport/Application.java b/ui-support-service/src/main/java/org/dcsa/uisupport/Application.java similarity index 63% rename from src/main/java/org/dcsa/uisupport/Application.java rename to ui-support-service/src/main/java/org/dcsa/uisupport/Application.java index af63d81..885ec38 100644 --- a/src/main/java/org/dcsa/uisupport/Application.java +++ b/ui-support-service/src/main/java/org/dcsa/uisupport/Application.java @@ -2,10 +2,13 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.ComponentScan; +@ComponentScan("org.dcsa") +@EntityScan("org.dcsa") @SpringBootApplication public class Application { - public static void main(String[] args) { SpringApplication.run(Application.class, args); } diff --git a/ui-support-service/src/main/java/org/dcsa/uisupport/configuration/JacksonConfiguration.java b/ui-support-service/src/main/java/org/dcsa/uisupport/configuration/JacksonConfiguration.java new file mode 100644 index 0000000..f935622 --- /dev/null +++ b/ui-support-service/src/main/java/org/dcsa/uisupport/configuration/JacksonConfiguration.java @@ -0,0 +1,25 @@ +package org.dcsa.uisupport.configuration; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.text.SimpleDateFormat; + +@Configuration +public class JacksonConfiguration { + @Bean + public ObjectMapper defaultObjectMapper() { + return new ObjectMapper() + .enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .enable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES) + .setSerializationInclusion(JsonInclude.Include.NON_NULL) + .setSerializationInclusion(JsonInclude.Include.NON_EMPTY) + .setDateFormat(new SimpleDateFormat("yyyy-MM-dd")) + .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) + .findAndRegisterModules(); + } +} diff --git a/ui-support-service/src/main/resources/application.yml b/ui-support-service/src/main/resources/application.yml new file mode 100644 index 0000000..e2cb698 --- /dev/null +++ b/ui-support-service/src/main/resources/application.yml @@ -0,0 +1,90 @@ + +dcsa: + specification: + # This is not an official DCSA standard + version: unofficial-API + +spring: + application: + name: DCSA-UI-Support + datasource: + driver-class-name: org.postgresql.Driver + url: jdbc:postgresql://${db_hostname}/dcsa_openapi + username: dcsa_db_owner + jpa: + database-platform: org.hibernate.dialect.PostgreSQL10Dialect + hibernate.ddl-auto: validate + hikari: + schema: dcsa_im_v3_0 + security: + oauth2: + resourceserver: + jwt: + issuer-uri: https://dcsa.eu.auth0.com/ + profiles: + active: nosecurity + group: + dev: nosecurity, logsql, localdb + test: nosecurity, logsql, localdb + prod: default + +server: + # UI Support runs on 9091 by default because it is needed in parallel with JIT + # (which uses 9090) + port: 9091 + servlet.context-path: /v1 + error: + include-binding-errors: on_param + include-message: always + +management: + endpoints: + web: + exposure: + include: "health" + +logging: + level: + root: ${ROOT_LOG_LEVEL:INFO} + org: + springframework: ${SPRING_LOG_LEVEL:INFO} + dcsa: ${DCSA_LOG_LEVEL:INFO} + +--- +# A profile for disabling security +spring: + config: + activate: + on-profile: nosecurity + + autoconfigure: + exclude: + - org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration + - org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration + - org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration + +--- +# A profile for connecting to a local database +spring: + config: + activate: + on-profile: localdb + + datasource: + driver-class-name: org.postgresql.Driver + url: jdbc:postgresql://${db_hostname:localhost}/dcsa_openapi + username: dcsa_db_owner + password: 9c072fe8-c59c-11ea-b8d1-7b6577e9f3f5 + +--- +# A profile for logging the sql generated by jpa +spring: + config: + activate: + on-profile: logsql + +logging: + level: + org: + hibernate: + SQL: DEBUG diff --git a/ui-support-transfer-obj/pom.xml b/ui-support-transfer-obj/pom.xml new file mode 100644 index 0000000..ea66fcc --- /dev/null +++ b/ui-support-transfer-obj/pom.xml @@ -0,0 +1,32 @@ + + 4.0.0 + + + org.dcsa.uisupport + dcsa-ui-support-parent + ${revision}${sha1}${changelist} + + + DCSA UI Support - Transfer Objects + dcsa-ui-support-transfer-obj + ${revision}${sha1}${changelist} + jar + + DCSA UI Support - Transfer Objects + + + + javax.validation + validation-api + + + com.fasterxml.jackson.core + jackson-annotations + + + org.dcsa.shared-kernel + dcsa-shared-kernel-infrastructure + + + +