diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md new file mode 100644 index 0000000..4285a5a --- /dev/null +++ b/DEVELOPMENT.md @@ -0,0 +1,113 @@ + + +# Development for Sitipe Service + +This project uses Java 17 and Quarkus to build and run the application. The project is split into multi modules. +The app module will use Quarkus to expose the services as REST XML and JSON Endpoints. The service module contains all +the logic to retrieve data from a Sitipe database. This module uses no Quarkus dependencies, but mainly standard java. This way the service module can also be used in +other environment as Java library, for instance a Spring project. + +## Building the application + +You can use Maven to build the application and see if all tests are working using: + +```shell script +./mvnw clean verify +``` + +This should normally be enough to also run the application, but there were cases that we need to build using: + +```shell script +./mvnw clean install +``` + +This to make the local modules available for the app module to run the application. + +## Running the application locally in dev mode + +You can run your application in dev mode that enables live coding using: + +```shell script +./mvnw package io.quarkus:quarkus-maven-plugin::dev +``` + +### Application depends on a running KeyCloak instance for dev mode + +A KeyCloak instance needs to be running on port 8089 by default in dev mode. If a custom KeyCloak instance is used see +[Security](README.md#security) for more details. + +There is a preconfigured Demo KeyCloak instance available for CoMPAS in the +[CoMPAS Deployment Repository](https://github.com/com-pas/compas-deployment). This repository can be cloned and +used to execute the following commands to create a local Docker Image with the CoMPAS Demo configuration. + +```shell +cd /compas/keycloak +docker build -t compas_keycloak . +``` + +A Docker Image `compas_keycloak` is created that can be started using the following command + +```shell +docker run --rm --name compas_keycloak \ + -p 8089:8080 + -d compas_keycloak:latest +``` + +There are now 3 users available to be used, `scl-data-editor`, `scl-data-reader`, `scd-reader`. See +[CoMPAS Deployment Repository](https://github.com/com-pas/compas-deployment) for more information about the users. + +## Testing the application + +The application is tested with unit and integration tests, but you can also manually test the application using for +instance Postman. And there is also a way to test this service with the CoMPAS OpenSCD Frontend application. + +### Postman + +To manually test the application there is a Postman collection in the directory `postman` that can be imported +and used to execute REST XML and JSON Calls. + +To make the call work we also need to import an environment and authorisation collection. These files can be found +in [CoMPAS Deployment Repository](https://github.com/com-pas/compas-deployment) in the directory `postman` +(`auth.collection.json` and `local.environment.json`). + +In the authorisation collection there are called for the 3 users known within the Demo KeyCloak instance. +If one of these calls are executed there is a variable `bearer` filled. + +Now one of the Sitipe Service calls can be executed, the variable `bearer` is added to the header of the request. +After the call is executed the result should be shown in Postman. + +### CoMPAS OpenSCD Frontend application + +To test the Sitipe Service with the CoMPAS OpenSCD application just run the application in dev mode, including the +KeyCloak instance. For further instruction how to start the CoMPAS OpenSCD application and use this locally see +the file `DEVELOPMENT.md` in [CoMPAS OpenSCD application](https://github.com/com-pas/compas-open-scd). + +## Docker Images + +### Creating a Docker image with native executable + +The releases created in the repository will create a docker image with a native executable. If you're running a Linux +system it's possible to create and run the executable locally. You can create a Docker image with native executable +using: + +```shell script +./mvnw package -Pnative-image +``` + +You can then execute your native executable with: `./app/target/app-local-SNAPSHOT-runner` + +### Creating a Docker image with JVM executable + +There is also a profile to create a Docker Image which runs the application using a JVM. You can create a Docker Image +with JVM executable using: + +```shell script +./mvnw package -Pjvm-image +``` + +The JVM Image can also (temporary) be created by the release action if there are problems creating or running the +native executable. \ No newline at end of file diff --git a/README.md b/README.md index 8360e31..bed9c9e 100644 --- a/README.md +++ b/README.md @@ -10,17 +10,40 @@ SPDX-License-Identifier: Apache-2.0 [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/5925/badge)](https://bestpractices.coreinfrastructure.org/projects/5925) [![Slack](https://raw.githubusercontent.com/com-pas/compas-architecture/master/public/LFEnergy-slack.svg)](http://lfenergy.slack.com/) -# CoMPAS Sitipe Service +# CoMPAS Sitipe-service +The CoMPAS Sitipe-Service Allows users to integrate Siemens Sitipe within the CoMPAS environment. -### Local Development +## Development + +Information about how to run and develop for this project check [Development](./DEVELOPMENT.md). + +## Environment Variables + +|Environment Variable | Default | Example | +|--|--|--| +| JWT_VERIFY_KEY | http://localhost:8089/auth/realms/compas/protocol/openid-connect/certs | http://localhost:8089/auth/realms/compas/protocol/openid-connect/certs | +| JWT_VERIFY_ISSUER | http://localhost/auth/realms/compas | http://localhost/auth/realms/compas | +| JWT_VERIFY_CLIENT | sitipe-service | sitipe-service | +| JWT_GROUPS_PATH | resource_access/sitipe-service/roles | resource_access/sitipe-service/roles | +| SITIPE_FRAMEWORK_ID | - | cf1 | +| SITIPE_VERSION | 1.00 | 1.00 | +| SITIPE_MSSQL_URL | _ | jdbc:sqlserver://localhost:1433;databaseName=DB_2019_IC1;ssl-mode=disabled;trustServerCertificate=true;encrypt=false;integratedSecurity=false; +| SITIPE_MSSQL_USER | sa | sa | +| SITIPE_MSSQL_PASSWORD | - | bigStrongPwd123! | + +## Security + +To use most of the endpoints the users needs to be authenticated using JWT in the authorization header. There are [4 environment variables](#environment-variables) that can be set in the container to configure the validation/processing of the JWT. + +## Local Development You can start the mssql database by running one of the following commands: -#### Mac M1 +### Mac M1 ``` docker-compose --env-file docker/.env -f docker/docker-compose-m1.yml up -d --build ``` -#### AMD64 +### AMD64 ``` docker-compose --env-file docker/.env -f docker/docker-compose-amd64.yml up -d --build ``` diff --git a/app/pom.xml b/app/pom.xml index be8b18d..e267a73 100644 --- a/app/pom.xml +++ b/app/pom.xml @@ -145,6 +145,15 @@ SPDX-License-Identifier: Apache-2.0 openpojo test + + io.quarkus + quarkus-jdbc-h2 + 3.0.0.Alpha5 + + + io.quarkus + quarkus-flyway + diff --git a/app/src/main/docker/Dockerfile.native b/app/src/main/docker/Dockerfile.native index 0bcd45a..3b91abf 100644 --- a/app/src/main/docker/Dockerfile.native +++ b/app/src/main/docker/Dockerfile.native @@ -19,7 +19,11 @@ WORKDIR /work/ RUN chown 1001 /work \ && chmod "g+rwX" /work \ && chown 1001:root /work -COPY --chown=1001:root target/quarkus-app/*-runner /work/application +COPY --chown=1001:root target/*-runner /work/application + +RUN mkdir -p /data/temp \ + && chown -R 1001 /data \ + && chmod -R "g+rwX" /data EXPOSE 8080 USER 1001 diff --git a/app/src/main/java/org/lfenergy/compas/sitipe/rest/v1/CompasSitipeResource.java b/app/src/main/java/org/lfenergy/compas/sitipe/rest/v1/BayTypicalResource.java similarity index 53% rename from app/src/main/java/org/lfenergy/compas/sitipe/rest/v1/CompasSitipeResource.java rename to app/src/main/java/org/lfenergy/compas/sitipe/rest/v1/BayTypicalResource.java index ae6754d..a22cb17 100644 --- a/app/src/main/java/org/lfenergy/compas/sitipe/rest/v1/CompasSitipeResource.java +++ b/app/src/main/java/org/lfenergy/compas/sitipe/rest/v1/BayTypicalResource.java @@ -4,9 +4,9 @@ package org.lfenergy.compas.sitipe.rest.v1; +import io.quarkus.security.Authenticated; import io.smallrye.common.annotation.Blocking; import io.smallrye.mutiny.Uni; -import org.lfenergy.compas.sitipe.data.entity.BayTypical; import org.lfenergy.compas.sitipe.rest.v1.model.BayTypicalResponse; import org.lfenergy.compas.sitipe.service.BayTypicalService; @@ -19,14 +19,15 @@ import javax.ws.rs.core.MediaType; import java.util.stream.Collectors; -// @Authenticated +@Authenticated @RequestScoped -@Path("/sitipe/v1") -public class CompasSitipeResource { +@Path("/v1/baytypicals") +public class BayTypicalResource { + private final BayTypicalService bayTypicalService; @Inject - public CompasSitipeResource(final BayTypicalService bayTypicalService) { + public BayTypicalResource(final BayTypicalService bayTypicalService) { this.bayTypicalService = bayTypicalService; } @@ -34,26 +35,14 @@ public CompasSitipeResource(final BayTypicalService bayTypicalService) { @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) @Blocking - public Uni getHelloWorld() { + public Uni getAssignedBayTypicals() { var response = new BayTypicalResponse(); response.setBayTypicals( - this.bayTypicalService.getBayTypicals() + this.bayTypicalService.getAssignedBayTypicals() .stream() - .map(bt -> new BayTypicalResponse.BayTypical( - bt.getId(), - bt.getAccessId(), - bt.getName(), - bt.getVersion(), - bt.getDescription(), - bt.getReleased(), - bt.getLockedBy(), - bt.getLockedOn(), - bt.getModifiedOn(), - bt.getSmrFile(), - bt.getContentVersion(), - bt.getReferenceAccessId() - )).collect(Collectors.toList()) + .map(BayTypicalResponse.BayTypicalItem::new) + .collect(Collectors.toList()) ); return Uni.createFrom().item(response); diff --git a/app/src/main/java/org/lfenergy/compas/sitipe/rest/v1/model/BayTypicalResponse.java b/app/src/main/java/org/lfenergy/compas/sitipe/rest/v1/model/BayTypicalResponse.java index e21fc75..2442bed 100644 --- a/app/src/main/java/org/lfenergy/compas/sitipe/rest/v1/model/BayTypicalResponse.java +++ b/app/src/main/java/org/lfenergy/compas/sitipe/rest/v1/model/BayTypicalResponse.java @@ -1,9 +1,12 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + package org.lfenergy.compas.sitipe.rest.v1.model; import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.lfenergy.compas.sitipe.data.entity.BayTypical; -import javax.persistence.Column; -import javax.persistence.Id; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; @@ -19,23 +22,23 @@ public class BayTypicalResponse { @Schema(description = "List of found BayTypicals in the database.") @XmlElement(name = "BayTypical", namespace = SITIPE_SERVICE_V1_NS_URI) - private List bayTypicals; + private List bayTypicals; - public void setBayTypicals(final List bayTypicals) { + public void setBayTypicals(final List bayTypicals) { this.bayTypicals = bayTypicals; } - public List getBayTypicals() { + public List getBayTypicals() { return bayTypicals; } @Schema(description = "BayTypical found in the database.") @XmlAccessorType(XmlAccessType.FIELD) - public static class BayTypical { + public static class BayTypicalItem { @Schema(description = "Id of the BayTypical.", example = "1") @XmlElement(name = "Id", namespace = SITIPE_SERVICE_V1_NS_URI) - private int id; + private Integer id; @Schema(description = "Access Id of the BayTypical.", example = "c50b3276-81f6-4bc3-82ab-b8adef829136") @XmlElement(name = "AccessId", namespace = SITIPE_SERVICE_V1_NS_URI) @@ -49,7 +52,7 @@ public static class BayTypical { @XmlElement(name = "Version", namespace = SITIPE_SERVICE_V1_NS_URI) private String version; - @Schema(description = "Description of the BayTypical.", example = "") + @Schema(description = "Description of the BayTypical.") @XmlElement(name = "Description", namespace = SITIPE_SERVICE_V1_NS_URI) private String description; @@ -81,38 +84,27 @@ public static class BayTypical { @XmlElement(name = "ReferenceAccessId", namespace = SITIPE_SERVICE_V1_NS_URI) private String referenceAccessId; - public BayTypical( - final int id, - final String accessId, - final String name, - final String version, - final String description, - final int released, - final String lockedBy, - final Long lockedOn, - final Long modifiedOn, - final String smrFile, - final String contentVersion, - final String referenceAccessId + public BayTypicalItem( + final BayTypical bt ) { - this.id = id; - this.accessId = accessId; - this.name = name; - this.version = version; - this.description = description; - this.released = released; - this.lockedBy = lockedBy; - this.lockedOn = lockedOn; - this.modifiedOn = modifiedOn; - this.smrFile = smrFile; - this.contentVersion = contentVersion; - this.referenceAccessId = referenceAccessId; - } - public int getId() { + this.id = bt.getId(); + this.accessId = bt.getAccessId(); + this.name = bt.getName(); + this.version = bt.getVersion(); + this.description = bt.getDescription(); + this.released = bt.getReleased(); + this.lockedBy = bt.getLockedBy(); + this.lockedOn = bt.getLockedOn(); + this.modifiedOn = bt.getModifiedOn(); + this.smrFile = bt.getSmrFile(); + this.contentVersion = bt.getContentVersion(); + this.referenceAccessId = bt.getReferenceAccessId(); + } + public Integer getId() { return id; } - public void setId(int id) { + public void setId(Integer id) { this.id = id; } diff --git a/app/src/main/java/org/lfenergy/compas/sitipe/rest/v2/BayTypicalResource.java b/app/src/main/java/org/lfenergy/compas/sitipe/rest/v2/BayTypicalResource.java new file mode 100644 index 0000000..22bd1b2 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/sitipe/rest/v2/BayTypicalResource.java @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.rest.v2; + +import io.quarkus.security.Authenticated; +import io.smallrye.common.annotation.Blocking; +import io.smallrye.mutiny.Uni; +import org.lfenergy.compas.sitipe.data.entity.BayTypical; +import org.lfenergy.compas.sitipe.service.BayTypicalService; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Consumes; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import java.util.List; + +@Authenticated +@RequestScoped +@Path("/v2/baytypicals") +public class BayTypicalResource { + + private final BayTypicalService bayTypicalService; + + @Inject + public BayTypicalResource(final BayTypicalService bayTypicalService) { + this.bayTypicalService = bayTypicalService; + } + + @GET + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Blocking + public Uni> getAssignedBayTypicals() { + return Uni.createFrom().item(this.bayTypicalService.getAssignedBayTypicals()); + } + +} diff --git a/app/src/main/java/org/lfenergy/compas/sitipe/rest/v2/CompasSitipeResource.java b/app/src/main/java/org/lfenergy/compas/sitipe/rest/v2/CompasSitipeResource.java deleted file mode 100644 index b9bc70b..0000000 --- a/app/src/main/java/org/lfenergy/compas/sitipe/rest/v2/CompasSitipeResource.java +++ /dev/null @@ -1,33 +0,0 @@ -// SPDX-FileCopyrightText: 2023 Alliander N.V. -// -// SPDX-License-Identifier: Apache-2.0 - -package org.lfenergy.compas.sitipe.rest.v2; - -import io.smallrye.mutiny.Uni; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Consumes; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -// @Authenticated -@RequestScoped -@Path("/sitipe/v2") -public class CompasSitipeResource { - - @Inject - public CompasSitipeResource() { - } - - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Uni getHelloWorld() { - return Uni.createFrom().item("Hello World!"); - } - -} diff --git a/app/src/main/resources/application-dev.properties b/app/src/main/resources/application-dev.properties new file mode 100644 index 0000000..8f7b4a6 --- /dev/null +++ b/app/src/main/resources/application-dev.properties @@ -0,0 +1,6 @@ +# SPDX-FileCopyrightText: 2023 Alliander N.V. +# +# SPDX-License-Identifier: Apache-2.0 + +quarkus.http.cors = true +quarkus.http.cors.origins = http://localhost:8081 \ No newline at end of file diff --git a/app/src/main/resources/application-prod.properties b/app/src/main/resources/application-prod.properties deleted file mode 100644 index 73f079e..0000000 --- a/app/src/main/resources/application-prod.properties +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-FileCopyrightText: 2023 Alliander N.V. -# -# SPDX-License-Identifier: Apache-2.0 - - -# quarkus.datasource.jdbc.url = jdbc:postgresql://${MSSQL_HOST:localhost}:${MSSQL_PORT:5432}/${MSSQL_DB:compas} \ No newline at end of file diff --git a/app/src/main/resources/application.properties b/app/src/main/resources/application.properties index e4cbabd..3ae2193 100644 --- a/app/src/main/resources/application.properties +++ b/app/src/main/resources/application.properties @@ -2,8 +2,8 @@ # # SPDX-License-Identifier: Apache-2.0 -compas.sitipe.framework-id=cf3 -sitipe.version=1.00 +compas.sitipe.framework-id=${SITIPE_FRAMEWORK_ID:cf3} +sitipe.version=${SITIPE_VERSION:1.00} quarkus.http.cors = false quarkus.http.root-path = /compas-sitipe-service @@ -26,21 +26,34 @@ quarkus.index-dependency.sitipe-service.artifact-id = service quarkus.index-dependency.sitipe-repository.group-id = org.lfenergy.compas.sitipe quarkus.index-dependency.sitipe-repository.artifact-id = repository + +# Smallrye JWT Properties (Microprofile) +smallrye.jwt.verify.key.location = ${JWT_VERIFY_KEY:http://localhost:8089/auth/realms/compas/protocol/openid-connect/certs} +mp.jwt.verify.issuer = ${JWT_VERIFY_ISSUER:http://localhost/auth/realms/compas} +mp.jwt.verify.audiences = ${JWT_VERIFY_CLIENT_ID:sitipe-service} +smallrye.jwt.path.groups = ${JWT_GROUPS_PATH:resource_access/sitipe-service/roles} + quarkus.http.auth.permission.deny-default.paths=/* -quarkus.http.auth.permission.deny-default.policy=permit +quarkus.http.auth.permission.deny-default.policy=deny quarkus.http.auth.permission.allow-quarkus-services.paths=/compas-sitipe-service/q/health/live,/compas-sitipe-service/q/health/ready,/compas-sitipe-service/q/openapi quarkus.http.auth.permission.allow-quarkus-services.policy=permit +quarkus.http.auth.permission.common.paths=/compas-sitipe-service/v1/*,/compas-sitipe-service/v2/* +quarkus.http.auth.permission.common.policy=authenticated + +quarkus.http.auth.permission.BAY_TYPICALS.paths=/compas-sitipe-service/v1/baytypicals,/compas-sitipe-service/v2/baytypicals +quarkus.http.auth.permission.BAY_TYPICALS.policy=authenticated +quarkus.http.auth.permission.BAY_TYPICALS.methods=GET + quarkus.datasource.db-kind=mssql quarkus.datasource.username=sa quarkus.datasource.password=bigStrongPwd123! -quarkus.datasource.jdbc.url=jdbc:sqlserver://localhost:1433;databaseName=DB_2019_IC2;ssl-mode=disabled;trustServerCertificate=true;encrypt=false;integratedSecurity=false; +quarkus.datasource.jdbc.url=${SITIPE_MSSQL_URL:jdbc:sqlserver://localhost:1433;databaseName=DB_2019_IC2;ssl-mode=disabled;trustServerCertificate=true;encrypt=false;integratedSecurity=false;} quarkus.datasource.jdbc.max-size=16 #quarkus.hibernate-orm.dialect=org.hibernate.dialect.SQLServer2012Dialect - quarkus.hibernate-orm.physical-naming-strategy=org.lfenergy.compas.sitipe.data.table.SitipeFrameworkIdNamingStrategy diff --git a/app/src/test/java/org/lfenergy/compas/sitipe/BaseIntegrationTest.java b/app/src/test/java/org/lfenergy/compas/sitipe/BaseIntegrationTest.java new file mode 100644 index 0000000..654ddac --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/sitipe/BaseIntegrationTest.java @@ -0,0 +1,21 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe; + +import org.junit.jupiter.api.AfterEach; +import org.lfenergy.compas.sitipe.helper.DatabaseCleaner; + +import javax.inject.Inject; + +public class BaseIntegrationTest { + + @Inject() + DatabaseCleaner databaseCleaner; + + @AfterEach() + public void tearDown() { + databaseCleaner.cleanUp(); + } +} diff --git a/app/src/test/java/org/lfenergy/compas/sitipe/helper/DatabaseCleaner.java b/app/src/test/java/org/lfenergy/compas/sitipe/helper/DatabaseCleaner.java new file mode 100644 index 0000000..2573590 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/sitipe/helper/DatabaseCleaner.java @@ -0,0 +1,28 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.helper; + +import org.lfenergy.compas.sitipe.data.repository.BayTypicalRepository; +import org.lfenergy.compas.sitipe.data.repository.SystemVersionRepository; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.transaction.Transactional; + +@ApplicationScoped +public class DatabaseCleaner { + + @Inject + SystemVersionRepository systemVersionRepository; + + @Inject + BayTypicalRepository bayTypicalRepository; + + @Transactional + public void cleanUp() { + bayTypicalRepository.deleteAll(); + systemVersionRepository.deleteAll(); + } +} diff --git a/app/src/test/java/org/lfenergy/compas/sitipe/helper/SystemVersionHelper.java b/app/src/test/java/org/lfenergy/compas/sitipe/helper/SystemVersionHelper.java new file mode 100644 index 0000000..2e9752a --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/sitipe/helper/SystemVersionHelper.java @@ -0,0 +1,97 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.helper; + +import org.lfenergy.compas.sitipe.SitipeProperties; +import org.lfenergy.compas.sitipe.data.entity.BayTypical; +import org.lfenergy.compas.sitipe.data.entity.SystemVersion; +import org.lfenergy.compas.sitipe.data.repository.BayTypicalRepository; +import org.lfenergy.compas.sitipe.data.repository.SystemVersionRepository; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.transaction.Transactional; +import java.util.*; + +import static java.util.Arrays.asList; + +@ApplicationScoped +@Transactional +public class SystemVersionHelper { + + private final SystemVersionRepository systemVersionRepository; + private final BayTypicalRepository bayTypicalRepository; + + private final SitipeProperties sitipeProperties; + @Inject + public SystemVersionHelper( + final SystemVersionRepository systemVersionRepository, + final BayTypicalRepository bayTypicalRepository, + final SitipeProperties sitipeProperties + ) { + this.systemVersionRepository = systemVersionRepository; + this.bayTypicalRepository = bayTypicalRepository; + + this.sitipeProperties = sitipeProperties; + } + + public SystemVersion createAndStoreSystemVersion(final Long id, final String version) { + final SystemVersion systemVersion = new SystemVersion(); + + systemVersion.setId(id); + systemVersion.setVersion(version); + + systemVersion.setComment("TEST"); + systemVersion.setDescription("TEST"); + + systemVersion.setAccessId(UUID.randomUUID().toString()); + + systemVersion.setReferenceAccessId(UUID.randomUUID().toString()); + + systemVersion.setLockedBy(""); + systemVersion.setLockedOn(0L); + systemVersion.setModifiedOn(0L); + + systemVersionRepository.persistAndFlush(systemVersion); + + return systemVersion; + } + + public SystemVersion assignBayTypicalToSystemVersion(final Long systemVersionId, final BayTypical bayTypical) { + final List assignedBayTypicals = new ArrayList<>(); + assignedBayTypicals.add(bayTypical.getAccessId().toString()); + final SystemVersion systemVersion = systemVersionRepository.findById(systemVersionId); + + Optional + .ofNullable(systemVersion.getAssignedBayTypicals()) + .ifPresent((a) -> assignedBayTypicals.addAll(asList(a.split(",")))); + + systemVersion.setAssignedBayTypicals( + String.join( + ",", + assignedBayTypicals + ) + ); + + + systemVersionRepository.persistAndFlush(systemVersion); + + return systemVersion; + } + + public BayTypical createAndStoreBayTypical(Integer id) { + final BayTypical bayTypical = new BayTypical(); + + bayTypical.setId(id); + bayTypical.setAccessId(UUID.randomUUID().toString()); + bayTypical.setContentVersion("1.0"); + bayTypical.setVersion(sitipeProperties.version()); + bayTypical.setDescription("TEST"); + + bayTypicalRepository.persistAndFlush(bayTypical); + + return bayTypical; + } +} diff --git a/app/src/test/java/org/lfenergy/compas/sitipe/rest/v1/BayTypicalResourceTest.java b/app/src/test/java/org/lfenergy/compas/sitipe/rest/v1/BayTypicalResourceTest.java new file mode 100644 index 0000000..75bf756 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/sitipe/rest/v1/BayTypicalResourceTest.java @@ -0,0 +1,99 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.rest.v1; + +import io.quarkus.test.common.http.TestHTTPEndpoint; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.security.TestSecurity; +import io.restassured.path.xml.XmlPath; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.sitipe.BaseIntegrationTest; +import org.lfenergy.compas.sitipe.SitipeProperties; +import org.lfenergy.compas.sitipe.data.entity.BayTypical; +import org.lfenergy.compas.sitipe.data.entity.SystemVersion; +import org.lfenergy.compas.sitipe.helper.SystemVersionHelper; + +import javax.inject.Inject; + +import static io.restassured.RestAssured.given; +import static java.util.Arrays.asList; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@QuarkusTest +@TestHTTPEndpoint(BayTypicalResource.class) +class BayTypicalResourceTest extends BaseIntegrationTest { + + @Inject() + SitipeProperties sitipeProperties; + + @Inject() + SystemVersionHelper systemVersionHelper; + + @Test + @TestSecurity(user = "test-user", roles = {"USER"}) + void itShouldListBayTypicalsForVersion() { + final SystemVersion systemVersion = systemVersionHelper.createAndStoreSystemVersion(1L, sitipeProperties.version()); + final BayTypical bayTypical1 = systemVersionHelper.createAndStoreBayTypical(1); + final BayTypical bayTypical2 = systemVersionHelper.createAndStoreBayTypical(2); + + final SystemVersion systemVersion2 = systemVersionHelper.createAndStoreSystemVersion(2L, "2.00"); + final BayTypical bayTypicalForVersion2 = systemVersionHelper.createAndStoreBayTypical(3); + + systemVersionHelper.assignBayTypicalToSystemVersion(systemVersion.getId(), bayTypical1); + systemVersionHelper.assignBayTypicalToSystemVersion(systemVersion.getId(), bayTypical2); + + systemVersionHelper.assignBayTypicalToSystemVersion(systemVersion2.getId(), bayTypicalForVersion2); + + var response = given() + .when().get("/") + .then() + .statusCode(200) + .extract() + .response(); + + XmlPath xmlPath = response.xmlPath(); + assertEquals(2, xmlPath.getList("BayTypicalResponse.BayTypical").size()); + assertTrue( + asList(bayTypical2.getId(), bayTypical1.getId()) + .contains(xmlPath.getInt("BayTypicalResponse.BayTypical[0].Id")) + ); + assertTrue( + asList(bayTypical2.getId(), bayTypical1.getId()) + .contains(xmlPath.getInt("BayTypicalResponse.BayTypical[1].Id")) + ); + } + + @Test + @TestSecurity(user = "test-user", roles = {"USER"}) + void itShouldReturnEmptyListWhenVersionNotFound() { + var response = given() + .when().get("/") + .then() + .statusCode(200) + .extract() + .response(); + + XmlPath xmlPath = response.xmlPath(); + assertEquals(0, xmlPath.getList("BayTypicalResponse.BayTypical").size()); + } + + @Test + @TestSecurity(user = "test-user", roles = {"USER"}) + void itShouldReturnEmptyListWhenNoBayTypicalsAreFound() { + final SystemVersion systemVersion = systemVersionHelper.createAndStoreSystemVersion(1L, sitipeProperties.version()); + + var response = given() + .when().get("/") + .then() + .statusCode(200) + .extract() + .response(); + + XmlPath xmlPath = response.xmlPath(); + assertEquals(0, xmlPath.getList("BayTypicalResponse.BayTypical").size()); + } + +} diff --git a/app/src/test/java/org/lfenergy/compas/sitipe/rest/v2/BayTypicalResourceTest.java b/app/src/test/java/org/lfenergy/compas/sitipe/rest/v2/BayTypicalResourceTest.java new file mode 100644 index 0000000..b4e9121 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/sitipe/rest/v2/BayTypicalResourceTest.java @@ -0,0 +1,106 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.rest.v2; + +import io.quarkus.test.common.http.TestHTTPEndpoint; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.security.TestSecurity; +import io.restassured.path.json.JsonPath; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.sitipe.BaseIntegrationTest; +import org.lfenergy.compas.sitipe.SitipeProperties; +import org.lfenergy.compas.sitipe.data.entity.BayTypical; +import org.lfenergy.compas.sitipe.data.entity.SystemVersion; +import org.lfenergy.compas.sitipe.helper.SystemVersionHelper; + +import javax.inject.Inject; +import java.util.ArrayList; +import java.util.LinkedHashMap; + +import static io.restassured.RestAssured.given; +import static java.util.Arrays.asList; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@QuarkusTest +@TestHTTPEndpoint(BayTypicalResource.class) +class BayTypicalResourceTest extends BaseIntegrationTest { + + @Inject() + SitipeProperties sitipeProperties; + + @Inject() + SystemVersionHelper systemVersionHelper; + + @Test + @TestSecurity(user = "test-user", roles = {"USER"}) + void itShouldListBayTypicalsForVersion() { + final SystemVersion systemVersion = systemVersionHelper.createAndStoreSystemVersion(1L, sitipeProperties.version()); + final BayTypical bayTypical1 = systemVersionHelper.createAndStoreBayTypical(1); + final BayTypical bayTypical2 = systemVersionHelper.createAndStoreBayTypical(2); + + final SystemVersion systemVersion2 = systemVersionHelper.createAndStoreSystemVersion(2L, "2.00"); + final BayTypical bayTypicalForVersion2 = systemVersionHelper.createAndStoreBayTypical(3); + + systemVersionHelper.assignBayTypicalToSystemVersion(systemVersion.getId(), bayTypical1); + systemVersionHelper.assignBayTypicalToSystemVersion(systemVersion.getId(), bayTypical2); + + systemVersionHelper.assignBayTypicalToSystemVersion(systemVersion2.getId(), bayTypicalForVersion2); + + var response = given() + .when().get("/") + .then() + .statusCode(200) + .extract() + .response(); + + JsonPath jsonPath = response.jsonPath(); + + ArrayList> res = jsonPath.get(); + assertEquals(2, res.size()); + + assertTrue( + asList(bayTypical1.getId(), bayTypical2.getId()) + .contains((Integer)res.get(0).get("id")) + ); + + assertTrue( + asList(bayTypical1.getId(), bayTypical2.getId()) + .contains((Integer)res.get(1).get("id")) + ); + } + + + @Test + @TestSecurity(user = "test-user", roles = {"USER"}) + void itShouldReturnEmptyListWhenVersionNotFound() { + var response = given() + .when().get("/") + .then() + .statusCode( 200) + .extract() + .response(); + + JsonPath jsonPath = response.jsonPath(); + assertEquals(0, jsonPath.>get().size()); + } + + @Test + @TestSecurity(user = "test-user", roles = {"USER"}) + void itShouldReturnEmptyListWhenNoBayTypicalsAreFound() { + final SystemVersion systemVersion = systemVersionHelper.createAndStoreSystemVersion(1L, sitipeProperties.version()); + + var response = given() + .when().get("/") + .then() + .statusCode(200) + .extract() + .response(); + + JsonPath jsonPath = response.jsonPath(); + assertEquals(0, jsonPath.>get().size()); + } + +} diff --git a/app/src/test/resources/application.properties b/app/src/test/resources/application.properties new file mode 100644 index 0000000..f24b267 --- /dev/null +++ b/app/src/test/resources/application.properties @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2023 Alliander N.V. +# +# SPDX-License-Identifier: Apache-2.0 + +quarkus.datasource.jdbc.url=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1 +quarkus.datasource.username=admin +quarkus.hibernate-orm.database.generation=drop-and-create +quarkus.flyway.migrate-at-start=true + +quarkus.datasource.db-kind=h2 + +quarkus.datasource.jdbc.max-size=16 + +compas.sitipe.framework-id=FRAMEWORK_ID diff --git a/docker/docker-compose-amd64.yml b/docker/docker-compose-amd64.yml index d165ad8..ee8773f 100644 --- a/docker/docker-compose-amd64.yml +++ b/docker/docker-compose-amd64.yml @@ -14,4 +14,4 @@ services: ACCEPT_EULA: 1 MSSQL_SA_PASSWORD: ${DB_PASSWORD} ports: - - "1434:1433" + - "1433:1433" diff --git a/docker/docker-compose-m1.yml b/docker/docker-compose-m1.yml index 9c57dfc..3e198c2 100644 --- a/docker/docker-compose-m1.yml +++ b/docker/docker-compose-m1.yml @@ -14,4 +14,4 @@ services: ACCEPT_EULA: 1 MSSQL_SA_PASSWORD: ${DB_PASSWORD} ports: - - "1434:1433" + - "1433:1433" diff --git a/postman/sitipe.postman_collection.json b/postman/sitipe.postman_collection.json new file mode 100644 index 0000000..1341e35 --- /dev/null +++ b/postman/sitipe.postman_collection.json @@ -0,0 +1,92 @@ +{ + "info": { + "_postman_id": "2e507905-52bd-4eee-8c5f-557a07987b19", + "name": "CoMPAS Sitipe Service", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "v1", + "item": [ + { + "name": "Get BayTypicals", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{sitpeServiceBaseUrl}}/v1/baytypicals", + "host": [ + "{{sitpeServiceBaseUrl}}" + ], + "path": [ + "v1", + "baytypicals" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "v2", + "item": [ + { + "name": "Get Bay Typicals", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{sitpeServiceBaseUrl}}/v2/baytypicals", + "host": [ + "{{sitpeServiceBaseUrl}}" + ], + "path": [ + "v2", + "baytypicals" + ] + } + }, + "response": [] + } + ] + } + ], + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJuM0F5VTh3LXNON3NDdWRFS1NrblBuUXZsbHMyZ2pELWtwcGNUUGI1cVI4In0.eyJleHAiOjE2NzkwNTUyNzksImlhdCI6MTY3OTA1NDk3OSwianRpIjoiYjFkYjQ3MDYtMzE5OC00YWM0LWEyMzQtMjJhYThjY2VkYzE4IiwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdC9hdXRoL3JlYWxtcy9jb21wYXMiLCJhdWQiOlsib3BlbnNjZCIsInNjbC1hdXRvLWFsaWdubWVudCIsInNjbC1kYXRhLXNlcnZpY2UiLCJjaW0tbWFwcGluZyIsInNjbC12YWxpZGF0b3IiLCJzaXRpcGUtc2VydmljZSIsImFjY291bnQiXSwic3ViIjoiZGVlZDQ4MzItODUzMS00M2VlLThiZjItMjBiYzUzNGZlZTQ1IiwidHlwIjoiQmVhcmVyIiwiYXpwIjoib3BlbnNjZCIsInNlc3Npb25fc3RhdGUiOiJhYjMzOTY1My1mODg0LTQ4M2QtYjRlYi0zZGM0NmQyYmQzMTUiLCJhY3IiOiIxIiwiYWxsb3dlZC1vcmlnaW5zIjpbImh0dHA6Ly9sb2NhbGhvc3QiXSwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbImRlZmF1bHQtcm9sZXMtY29tcGFzIiwib2ZmbGluZV9hY2Nlc3MiLCJ1bWFfYXV0aG9yaXphdGlvbiJdfSwicmVzb3VyY2VfYWNjZXNzIjp7InNjbC1hdXRvLWFsaWdubWVudCI6eyJyb2xlcyI6WyJVU0VSIl19LCJzY2wtZGF0YS1zZXJ2aWNlIjp7InJvbGVzIjpbIlNTRF9SRUFEIiwiU1REX1JFQUQiLCJJSURfUkVBRCIsIkNJRF9SRUFEIiwiU0VEX1JFQUQiLCJJQ0RfUkVBRCIsIlNDRF9SRUFEIiwiSVNEX1JFQUQiXX0sImNpbS1tYXBwaW5nIjp7InJvbGVzIjpbIlVTRVIiXX0sInNjbC12YWxpZGF0b3IiOnsicm9sZXMiOlsiVVNFUiJdfSwic2l0aXBlLXNlcnZpY2UiOnsicm9sZXMiOlsiVVNFUiJdfSwiYWNjb3VudCI6eyJyb2xlcyI6WyJtYW5hZ2UtYWNjb3VudCIsIm1hbmFnZS1hY2NvdW50LWxpbmtzIiwidmlldy1wcm9maWxlIl19LCJvcGVuc2NkIjp7InJvbGVzIjpbIlVTRVIiXX19LCJzY29wZSI6ImVtYWlsIHByb2ZpbGUiLCJzaWQiOiJhYjMzOTY1My1mODg0LTQ4M2QtYjRlYi0zZGM0NmQyYmQzMTUiLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwibmFtZSI6Ik1ycyBSZWFkZXIiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJzY2wtZGF0YS1yZWFkZXIiLCJnaXZlbl9uYW1lIjoiTXJzIiwiZmFtaWx5X25hbWUiOiJSZWFkZXIifQ.IAHpbM6TN8zPoqrw-HvNIpJWtS1KCuzWh426rYC289pMsU5snhtEphKfB7Kj2Pq9c2LDjxF0j2o0lJKUc8j37Y-i1G3te1ryU9d2lbBXS5Kzzpj-WNzuRVzSR6TnAc0EWu0enmMXX9gbiCeU927U16KsvF99T4vW7TcYwMz5_hgJURp0ijHDtembhbbZO6yPBTqmxWg5Wij5_Eg3X6BXnqCFo32XpxY7V-3YFOEbS3ta67u6xth9NEk4uUzSNNjBCLwqp0cV4gZR3i8Pfosrem7_KaIfw7YOT8Eq49PC88nSg6Ie-XCO4H4mPGQ6wJXwbM-FY47GF_tmugHDsFH1vw", + "type": "string" + } + ] + }, + "event": [ + { + "listen": "prerequest", + "script": { + "type": "text/javascript", + "exec": [ + "" + ] + } + }, + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ], + "variable": [ + { + "key": "sitpeServiceBaseUrl", + "value": "http://localhost:8080/compas-sitipe-service", + "type": "default" + } + ] +} \ No newline at end of file diff --git a/postman/sitipe.postman_collection.json.license b/postman/sitipe.postman_collection.json.license new file mode 100644 index 0000000..324d95d --- /dev/null +++ b/postman/sitipe.postman_collection.json.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2023 Alliander N.V. + +SPDX-License-Identifier: Apache-2.0 \ No newline at end of file diff --git a/repository/src/main/java/org/lfenergy/compas/sitipe/data/entity/BayTypical.java b/repository/src/main/java/org/lfenergy/compas/sitipe/data/entity/BayTypical.java index a8d85f7..836856c 100644 --- a/repository/src/main/java/org/lfenergy/compas/sitipe/data/entity/BayTypical.java +++ b/repository/src/main/java/org/lfenergy/compas/sitipe/data/entity/BayTypical.java @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + package org.lfenergy.compas.sitipe.data.entity; import javax.persistence.Column; @@ -10,9 +14,10 @@ public class BayTypical { @Id() - private int id; + @Column(columnDefinition = "BIGINT") + private Integer id; - @Column(name = "accessId", columnDefinition = "uniqueIdentifier") + @Column(name = "accessId", columnDefinition = "UUID") private String accessId; @Column(name = "name", columnDefinition = "nvarchar") @@ -42,14 +47,14 @@ public class BayTypical { @Column(name = "contentVersion", columnDefinition = "nvarchar") private String contentVersion; - @Column(name = "referenceAccessId", columnDefinition = "uniqueidentifier") + @Column(name = "referenceAccessId", columnDefinition = "UUID") private String referenceAccessId; - public int getId() { + public Integer getId() { return id; } - public void setId(int id) { + public void setId(Integer id) { this.id = id; } diff --git a/repository/src/main/java/org/lfenergy/compas/sitipe/data/entity/SystemVersion.java b/repository/src/main/java/org/lfenergy/compas/sitipe/data/entity/SystemVersion.java index ebe3ba1..01bb479 100644 --- a/repository/src/main/java/org/lfenergy/compas/sitipe/data/entity/SystemVersion.java +++ b/repository/src/main/java/org/lfenergy/compas/sitipe/data/entity/SystemVersion.java @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + package org.lfenergy.compas.sitipe.data.entity; import javax.persistence.Column; @@ -10,9 +14,9 @@ public class SystemVersion { @Id() - private int id; + private Long id; - @Column(name = "accessId", columnDefinition = "uniqueIdentifier") + @Column(name = "accessId", columnDefinition = "UUID") private String accessId; @Column(name = "version", columnDefinition = "nvarchar") @@ -39,14 +43,14 @@ public class SystemVersion { @Column(name = "contentVersion", columnDefinition = "nvarchar") private String contentVersion; - @Column(name = "referenceAccessId", columnDefinition = "uniqueidentifier") + @Column(name = "referenceAccessId", columnDefinition = "UUID") private String referenceAccessId; - public int getId() { + public Long getId() { return id; } - public void setId(int id) { + public void setId(Long id) { this.id = id; } diff --git a/repository/src/main/java/org/lfenergy/compas/sitipe/data/repository/BayTypicalRepository.java b/repository/src/main/java/org/lfenergy/compas/sitipe/data/repository/BayTypicalRepository.java index 91a4961..4c64a7b 100644 --- a/repository/src/main/java/org/lfenergy/compas/sitipe/data/repository/BayTypicalRepository.java +++ b/repository/src/main/java/org/lfenergy/compas/sitipe/data/repository/BayTypicalRepository.java @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + package org.lfenergy.compas.sitipe.data.repository; import io.quarkus.hibernate.orm.panache.PanacheRepository; @@ -5,7 +9,6 @@ import javax.enterprise.context.ApplicationScoped; import java.util.List; -import java.util.Map; @ApplicationScoped public class BayTypicalRepository implements PanacheRepository { diff --git a/repository/src/main/java/org/lfenergy/compas/sitipe/data/repository/SystemVersionRepository.java b/repository/src/main/java/org/lfenergy/compas/sitipe/data/repository/SystemVersionRepository.java index 7ab7207..4c53ed0 100644 --- a/repository/src/main/java/org/lfenergy/compas/sitipe/data/repository/SystemVersionRepository.java +++ b/repository/src/main/java/org/lfenergy/compas/sitipe/data/repository/SystemVersionRepository.java @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + package org.lfenergy.compas.sitipe.data.repository; import io.quarkus.hibernate.orm.panache.PanacheRepository; diff --git a/repository/src/main/java/org/lfenergy/compas/sitipe/data/table/SitipeFrameworkIdNamingStrategy.java b/repository/src/main/java/org/lfenergy/compas/sitipe/data/table/SitipeFrameworkIdNamingStrategy.java index 7aaf056..285d3b2 100644 --- a/repository/src/main/java/org/lfenergy/compas/sitipe/data/table/SitipeFrameworkIdNamingStrategy.java +++ b/repository/src/main/java/org/lfenergy/compas/sitipe/data/table/SitipeFrameworkIdNamingStrategy.java @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + package org.lfenergy.compas.sitipe.data.table; import org.eclipse.microprofile.config.ConfigProvider; @@ -5,8 +9,6 @@ import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; - - public class SitipeFrameworkIdNamingStrategy extends PhysicalNamingStrategyStandardImpl { private final String prefix; diff --git a/service/src/main/java/org/lfenergy/compas/sitipe/SitipeProperties.java b/service/src/main/java/org/lfenergy/compas/sitipe/SitipeProperties.java index 326de56..fcacf17 100644 --- a/service/src/main/java/org/lfenergy/compas/sitipe/SitipeProperties.java +++ b/service/src/main/java/org/lfenergy/compas/sitipe/SitipeProperties.java @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + package org.lfenergy.compas.sitipe; import io.smallrye.config.ConfigMapping; diff --git a/service/src/main/java/org/lfenergy/compas/sitipe/service/BayTypicalService.java b/service/src/main/java/org/lfenergy/compas/sitipe/service/BayTypicalService.java index 51d8663..3a6aed1 100644 --- a/service/src/main/java/org/lfenergy/compas/sitipe/service/BayTypicalService.java +++ b/service/src/main/java/org/lfenergy/compas/sitipe/service/BayTypicalService.java @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + package org.lfenergy.compas.sitipe.service; import org.lfenergy.compas.sitipe.SitipeProperties; @@ -29,7 +33,7 @@ public BayTypicalService(final SystemVersionRepository systemVersionRepository, this.sitipeProperties = sitipeProperties; } - public List getBayTypicals() { + public List getAssignedBayTypicals() { return this.systemVersionRepository.findByVersion(sitipeProperties.version()) .stream() .flatMap(systemVersion -> systemVersion.getAssignedBayTypicals() != null ? Arrays.stream(systemVersion.getAssignedBayTypicals().split(",")) : Stream.empty()) diff --git a/service/src/test/java/org/lfenergy/compas/sitipe/service/BayTypicalServiceTest.java b/service/src/test/java/org/lfenergy/compas/sitipe/service/BayTypicalServiceTest.java index 4bb4b67..95a51cc 100644 --- a/service/src/test/java/org/lfenergy/compas/sitipe/service/BayTypicalServiceTest.java +++ b/service/src/test/java/org/lfenergy/compas/sitipe/service/BayTypicalServiceTest.java @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + package org.lfenergy.compas.sitipe.service; import org.junit.jupiter.api.BeforeEach; @@ -53,7 +57,7 @@ public void itShouldReturnBayTypicals() { when(bayTypicalRepository.findByAccessId("A")).thenReturn(Collections.singletonList(bayTypical1)); when(bayTypicalRepository.findByAccessId("B")).thenReturn(Collections.singletonList(bayTypical2)); - var res = sut.getBayTypicals(); + var res = sut.getAssignedBayTypicals(); assertEquals(2, res.size()); assertTrue(res.containsAll(asList(bayTypical1, bayTypical2))); @@ -75,7 +79,7 @@ public void itShouldReturnMultipleBayTypicals() { when(bayTypicalRepository.findByAccessId("A")).thenReturn(asList(bayTypical1, bayTypical2)); when(bayTypicalRepository.findByAccessId("B")).thenReturn(asList(bayTypical3, bayTypical4)); - var res = sut.getBayTypicals(); + var res = sut.getAssignedBayTypicals(); assertEquals(4, res.size()); assertTrue(res.containsAll(asList(bayTypical1, bayTypical2, bayTypical3, bayTypical4))); @@ -88,7 +92,7 @@ public void itShouldReturnEmptyListWhenVersionIsNotFound() { when(systemVersionRepository.findByVersion(version)).thenReturn(emptyList()); when(properties.version()).thenReturn(version); - var res = sut.getBayTypicals(); + var res = sut.getAssignedBayTypicals(); assertEquals(0, res.size()); } @@ -104,7 +108,7 @@ public void itShouldReturnEmptyListWhenNoAssignedBayTypicals() { when(properties.version()).thenReturn(version); when(bayTypicalRepository.findByAccessId(any())).thenReturn(emptyList()); - var res = sut.getBayTypicals(); + var res = sut.getAssignedBayTypicals(); assertEquals(0, res.size()); } @@ -118,7 +122,7 @@ public void itShouldReturnEmptyListWhenAssignedBayTypicalsIsNull() { when(systemVersionRepository.findByVersion(version)).thenReturn(singletonList(systemVersion)); when(properties.version()).thenReturn(version); - var res = sut.getBayTypicals(); + var res = sut.getAssignedBayTypicals(); assertEquals(0, res.size()); }