diff --git a/app/src/main/java/org/lfenergy/compas/sitipe/rest/v1/BayTypicalResource.java b/app/src/main/java/org/lfenergy/compas/sitipe/rest/v1/BayTypicalResource.java index a22cb17..4ad5d67 100644 --- a/app/src/main/java/org/lfenergy/compas/sitipe/rest/v1/BayTypicalResource.java +++ b/app/src/main/java/org/lfenergy/compas/sitipe/rest/v1/BayTypicalResource.java @@ -48,5 +48,4 @@ public Uni getAssignedBayTypicals() { 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 2442bed..9f7e82b 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 @@ -5,7 +5,7 @@ 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 org.lfenergy.compas.sitipe.dto.BayTypicalDTO; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -38,164 +38,116 @@ public static class BayTypicalItem { @Schema(description = "Id of the BayTypical.", example = "1") @XmlElement(name = "Id", namespace = SITIPE_SERVICE_V1_NS_URI) - private Integer id; + private final Integer id; @Schema(description = "Access Id of the BayTypical.", example = "c50b3276-81f6-4bc3-82ab-b8adef829136") @XmlElement(name = "AccessId", namespace = SITIPE_SERVICE_V1_NS_URI) - private String accessId; + private final String accessId; @Schema(description = "Name of the BayTypical.", example = "BT1") @XmlElement(name = "Name", namespace = SITIPE_SERVICE_V1_NS_URI) - private String name; + private final String name; @Schema(description = "Version of the BayTypical.", example = "1") @XmlElement(name = "Version", namespace = SITIPE_SERVICE_V1_NS_URI) - private String version; + private final String version; @Schema(description = "Description of the BayTypical.") @XmlElement(name = "Description", namespace = SITIPE_SERVICE_V1_NS_URI) - private String description; + private final String description; @Schema(description = "Released flag of the BayTypical.", example = "1") @XmlElement(name = "Released", namespace = SITIPE_SERVICE_V1_NS_URI) - private int released; + private final int released; @Schema(description = "Flag if the BayTypical is locked by someone.", example = "1") @XmlElement(name = "LockedBy", namespace = SITIPE_SERVICE_V1_NS_URI) - private String lockedBy; + private final String lockedBy; @Schema(description = "Timestamp of when the BayTypical is locked.", example = "18129347234") @XmlElement(name = "LockedOn", namespace = SITIPE_SERVICE_V1_NS_URI) - private Long lockedOn; + private final Long lockedOn; @Schema(description = "Timestamp of when the BayTypical is modified.", example = "18129347234") @XmlElement(name = "ModifiedOn", namespace = SITIPE_SERVICE_V1_NS_URI) - private Long modifiedOn; + private final Long modifiedOn; @Schema(description = "Name of the SMR File of the BayTypical.", example = "SMR_1_BT_Foo - Amsterdam.smr") @XmlElement(name = "SmrFile", namespace = SITIPE_SERVICE_V1_NS_URI) - private String smrFile; + private final String smrFile; @Schema(description = "Content Version of the BayTypical.", example = "2.0") @XmlElement(name = "ContentVersion", namespace = SITIPE_SERVICE_V1_NS_URI) - private String contentVersion; + private final String contentVersion; @Schema(description = "Reference Access Id of the BayTypical.", example = "d7b0ad3a-c0ae-4b8b-8321-71eaf8970ed7") @XmlElement(name = "ReferenceAccessId", namespace = SITIPE_SERVICE_V1_NS_URI) - private String referenceAccessId; + private final String referenceAccessId; public BayTypicalItem( - final BayTypical bt + final BayTypicalDTO dto ) { - 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(); + this.id = dto.getId(); + this.accessId = dto.getAccessId(); + this.name = dto.getName(); + this.version = dto.getVersion(); + this.description = dto.getDescription(); + this.released = dto.getReleased(); + this.lockedBy = dto.getLockedBy(); + this.lockedOn = dto.getLockedOn(); + this.modifiedOn = dto.getModifiedOn(); + this.smrFile = dto.getSmrFile(); + this.contentVersion = dto.getContentVersion(); + this.referenceAccessId = dto.getReferenceAccessId(); } public Integer getId() { return id; } - public void setId(Integer id) { - this.id = id; - } - public String getAccessId() { return accessId; } - public void setAccessId(String accessId) { - this.accessId = accessId; - } - public String getName() { return name; } - public void setName(String name) { - this.name = name; - } - public String getVersion() { return version; } - public void setVersion(String version) { - this.version = version; - } - public String getDescription() { return description; } - public void setDescription(String description) { - this.description = description; - } - public int getReleased() { return released; } - public void setReleased(int released) { - this.released = released; - } - public String getLockedBy() { return lockedBy; } - public void setLockedBy(String lockedBy) { - this.lockedBy = lockedBy; - } - public Long getLockedOn() { return lockedOn; } - public void setLockedOn(Long lockedOn) { - this.lockedOn = lockedOn; - } - public Long getModifiedOn() { return modifiedOn; } - public void setModifiedOn(Long modifiedOn) { - this.modifiedOn = modifiedOn; - } - public String getSmrFile() { return smrFile; } - public void setSmrFile(String smrFile) { - this.smrFile = smrFile; - } - public String getContentVersion() { return contentVersion; } - public void setContentVersion(String contentVersion) { - this.contentVersion = contentVersion; - } - public String getReferenceAccessId() { return referenceAccessId; } - public void setReferenceAccessId(String referenceAccessId) { - this.referenceAccessId = referenceAccessId; - } - } diff --git a/app/src/main/java/org/lfenergy/compas/sitipe/rest/v2/BTComponentResource.java b/app/src/main/java/org/lfenergy/compas/sitipe/rest/v2/BTComponentResource.java new file mode 100644 index 0000000..b06b6e8 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/sitipe/rest/v2/BTComponentResource.java @@ -0,0 +1,57 @@ +// 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.dto.ImportedComponentDTO; +import org.lfenergy.compas.sitipe.service.ImportedComponentService; +import org.lfenergy.compas.sitipe.dto.ImportedDataDTO; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import java.util.List; + +@Authenticated +@RequestScoped +@Path("/v2/btcomponents") +public class BTComponentResource { + + private final ImportedComponentService importedComponentService; + + @Inject + public BTComponentResource( + final ImportedComponentService importedComponentService + ) { + this.importedComponentService = importedComponentService; + } + + @GET + @Path("/{accessId}/imported") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Blocking + public Uni> getImportedComponents( + @PathParam("accessId") final String accessId + ) { + return Uni.createFrom().item(this.importedComponentService.getByAccessId(accessId)); + } + + @GET + @Path("/imported/{id}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Blocking + public Uni getImportedComponentData( + @PathParam("id") final Integer id + ) { + final ImportedDataDTO data = this.importedComponentService.getImportedComponentData(id); + + return Uni.createFrom().item(data); + } +} 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 index 22bd1b2..fbef764 100644 --- 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 @@ -7,15 +7,14 @@ 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.dto.BTComponentDTO; +import org.lfenergy.compas.sitipe.service.BTComponentService; +import org.lfenergy.compas.sitipe.dto.BayTypicalDTO; 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.*; import javax.ws.rs.core.MediaType; import java.util.List; @@ -25,18 +24,30 @@ public class BayTypicalResource { private final BayTypicalService bayTypicalService; + private final BTComponentService btComponentService; @Inject - public BayTypicalResource(final BayTypicalService bayTypicalService) { + public BayTypicalResource(final BayTypicalService bayTypicalService, final BTComponentService btComponentService) { this.bayTypicalService = bayTypicalService; + this.btComponentService = btComponentService; } @GET @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Blocking - public Uni> getAssignedBayTypicals() { + public Uni> getAssignedBayTypicals() { return Uni.createFrom().item(this.bayTypicalService.getAssignedBayTypicals()); } + @GET + @Path("/{accessId}/components") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Blocking + public Uni> getBayTypicalComponentsByAccessId( + @PathParam("accessId") final String accessId + ) { + return Uni.createFrom().item(this.btComponentService.getBTComponentsByBayTypicalAccessId(accessId)); + } } diff --git a/app/src/main/resources/application-dev.properties b/app/src/main/resources/application-dev.properties index 8f7b4a6..1ffa0e9 100644 --- a/app/src/main/resources/application-dev.properties +++ b/app/src/main/resources/application-dev.properties @@ -3,4 +3,4 @@ # SPDX-License-Identifier: Apache-2.0 quarkus.http.cors = true -quarkus.http.cors.origins = http://localhost:8081 \ No newline at end of file +quarkus.http.cors.origins = http://localhost:8081, http://localhost:8080 \ No newline at end of file diff --git a/app/src/main/resources/application.properties b/app/src/main/resources/application.properties index 3ae2193..d6cc94b 100644 --- a/app/src/main/resources/application.properties +++ b/app/src/main/resources/application.properties @@ -34,7 +34,7 @@ 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=deny +quarkus.http.auth.permission.deny-default.policy=permit 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 @@ -54,6 +54,5 @@ quarkus.datasource.jdbc.url=${SITIPE_MSSQL_URL:jdbc:sqlserver://localhost:1433;d 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/helper/CompressionUtils.java b/app/src/test/java/org/lfenergy/compas/sitipe/helper/CompressionUtils.java new file mode 100644 index 0000000..0cd16ed --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/sitipe/helper/CompressionUtils.java @@ -0,0 +1,23 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.helper; + +import javax.enterprise.context.ApplicationScoped; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.zip.DeflaterOutputStream; + +@ApplicationScoped +public class CompressionUtils { + + public byte[] compress(byte[] bArray) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (DeflaterOutputStream dos = new DeflaterOutputStream(baos)) { + dos.write(bArray); + } + return baos.toByteArray(); + } + +} 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 index 2573590..cd6fe76 100644 --- a/app/src/test/java/org/lfenergy/compas/sitipe/helper/DatabaseCleaner.java +++ b/app/src/test/java/org/lfenergy/compas/sitipe/helper/DatabaseCleaner.java @@ -4,7 +4,9 @@ package org.lfenergy.compas.sitipe.helper; +import org.lfenergy.compas.sitipe.data.repository.BTComponentRepository; import org.lfenergy.compas.sitipe.data.repository.BayTypicalRepository; +import org.lfenergy.compas.sitipe.data.repository.ImportedComponentRepository; import org.lfenergy.compas.sitipe.data.repository.SystemVersionRepository; import javax.enterprise.context.ApplicationScoped; @@ -20,9 +22,17 @@ public class DatabaseCleaner { @Inject BayTypicalRepository bayTypicalRepository; + @Inject + BTComponentRepository btComponentRepository; + + @Inject + ImportedComponentRepository importedComponentRepository; + @Transactional public void cleanUp() { bayTypicalRepository.deleteAll(); systemVersionRepository.deleteAll(); + btComponentRepository.deleteAll(); + importedComponentRepository.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 index 2e9752a..8247c13 100644 --- a/app/src/test/java/org/lfenergy/compas/sitipe/helper/SystemVersionHelper.java +++ b/app/src/test/java/org/lfenergy/compas/sitipe/helper/SystemVersionHelper.java @@ -5,14 +5,19 @@ package org.lfenergy.compas.sitipe.helper; import org.lfenergy.compas.sitipe.SitipeProperties; +import org.lfenergy.compas.sitipe.data.entity.BTComponent; import org.lfenergy.compas.sitipe.data.entity.BayTypical; +import org.lfenergy.compas.sitipe.data.entity.ImportedComponent; import org.lfenergy.compas.sitipe.data.entity.SystemVersion; +import org.lfenergy.compas.sitipe.data.repository.BTComponentRepository; import org.lfenergy.compas.sitipe.data.repository.BayTypicalRepository; +import org.lfenergy.compas.sitipe.data.repository.ImportedComponentRepository; import org.lfenergy.compas.sitipe.data.repository.SystemVersionRepository; import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; import javax.transaction.Transactional; +import java.io.IOException; import java.util.*; import static java.util.Arrays.asList; @@ -24,17 +29,30 @@ public class SystemVersionHelper { private final SystemVersionRepository systemVersionRepository; private final BayTypicalRepository bayTypicalRepository; + private final BTComponentRepository btComponentRepository; + + private final ImportedComponentRepository importedComponentRepository; + private final SitipeProperties sitipeProperties; + + private final CompressionUtils compressionUtils; @Inject public SystemVersionHelper( final SystemVersionRepository systemVersionRepository, final BayTypicalRepository bayTypicalRepository, - final SitipeProperties sitipeProperties + final BTComponentRepository btComponentRepository, + final ImportedComponentRepository importedComponentRepository, + final SitipeProperties sitipeProperties, + final CompressionUtils compressionUtils ) { this.systemVersionRepository = systemVersionRepository; this.bayTypicalRepository = bayTypicalRepository; + this.btComponentRepository = btComponentRepository; + this.importedComponentRepository = importedComponentRepository; this.sitipeProperties = sitipeProperties; + + this.compressionUtils = compressionUtils; } public SystemVersion createAndStoreSystemVersion(final Long id, final String version) { @@ -61,7 +79,7 @@ public SystemVersion createAndStoreSystemVersion(final Long id, final String ver public SystemVersion assignBayTypicalToSystemVersion(final Long systemVersionId, final BayTypical bayTypical) { final List assignedBayTypicals = new ArrayList<>(); - assignedBayTypicals.add(bayTypical.getAccessId().toString()); + assignedBayTypicals.add(bayTypical.getAccessId()); final SystemVersion systemVersion = systemVersionRepository.findById(systemVersionId); Optional @@ -81,7 +99,7 @@ public SystemVersion assignBayTypicalToSystemVersion(final Long systemVersionId, return systemVersion; } - public BayTypical createAndStoreBayTypical(Integer id) { + public BayTypical createAndStoreBayTypical(final Integer id) { final BayTypical bayTypical = new BayTypical(); bayTypical.setId(id); @@ -94,4 +112,46 @@ public BayTypical createAndStoreBayTypical(Integer id) { return bayTypical; } + + public BTComponent createAndStoreBTComponent(final Integer id, final BayTypical bayTypical, final String toolName) { + final BTComponent btComponent = new BTComponent(); + + btComponent.setId(id); + + btComponent.setTypicalAccessId(bayTypical.getAccessId()); + btComponent.setToolName(toolName); + btComponent.setIniVersion(1); + btComponent.setToolVersion("1.00"); + btComponent.setLanguage("NL"); + btComponent.setName("BT Component For Test"); + btComponent.setHasIecInformation(1); + btComponent.setImportedOn(0L); + btComponent.setReferenceAccessId(UUID.randomUUID().toString()); + btComponent.setComponentGuid(UUID.randomUUID().toString()); + + btComponentRepository.persistAndFlush(btComponent); + + return btComponent; + } + + public ImportedComponent createAndStoreImportedComponent(final Integer id, final String componentAccessId, final String type) throws IOException { + final ImportedComponent importedComponent = new ImportedComponent(); + + importedComponent.setId(id); + importedComponent.setComponentAccessId(componentAccessId); + importedComponent.setContentVersion("1.00"); + importedComponent.setType(type); + + final String data = "TEST DATA"; + + byte[] input = data.getBytes(); + + byte[] compressedInput = this.compressionUtils.compress(input); + + importedComponent.setData(compressedInput); + + importedComponentRepository.persistAndFlush(importedComponent); + + return importedComponent; + } } diff --git a/app/src/test/java/org/lfenergy/compas/sitipe/rest/v1/model/BayTypicalResponseTest.java b/app/src/test/java/org/lfenergy/compas/sitipe/rest/v1/model/BayTypicalResponseTest.java new file mode 100644 index 0000000..ea31c1c --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/sitipe/rest/v1/model/BayTypicalResponseTest.java @@ -0,0 +1,58 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.rest.v1.model; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.lfenergy.compas.sitipe.data.entity.BayTypical; +import org.lfenergy.compas.sitipe.dto.BayTypicalDTO; +import org.mockito.junit.jupiter.MockitoExtension; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.UUID; + +import static org.codehaus.groovy.runtime.InvokerHelper.asList; + +@ExtendWith(MockitoExtension.class) +class BayTypicalResponseTest { + + @Test + void itShouldMapProperties() { + final BayTypical entity = new BayTypical(); + + entity.setId(1); + entity.setAccessId(UUID.randomUUID().toString()); + entity.setName("NAME"); + entity.setSmrFile("SMR FILE"); + entity.setReleased(1); + entity.setModifiedOn(2L); + entity.setLockedOn(3L); + entity.setLockedBy("LOCKED BY"); + entity.setVersion("1.00"); + entity.setReferenceAccessId(UUID.randomUUID().toString()); + entity.setContentVersion("2.00"); + + final BayTypicalDTO bayTypical = new BayTypicalDTO(entity); + final BayTypicalResponse result = new BayTypicalResponse(); + + result.setBayTypicals(asList(new BayTypicalResponse.BayTypicalItem(bayTypical))); + + assertEquals(1, result.getBayTypicals().size()); + + assertEquals(entity.getId(), result.getBayTypicals().get(0).getId()); + assertEquals(entity.getName(), result.getBayTypicals().get(0).getName()); + assertEquals(entity.getAccessId(), result.getBayTypicals().get(0).getAccessId()); + assertEquals(entity.getContentVersion(), result.getBayTypicals().get(0).getContentVersion()); + assertEquals(entity.getReleased(), result.getBayTypicals().get(0).getReleased()); + assertEquals(entity.getSmrFile(), result.getBayTypicals().get(0).getSmrFile()); + assertEquals(entity.getModifiedOn(), result.getBayTypicals().get(0).getModifiedOn()); + assertEquals(entity.getLockedOn(), result.getBayTypicals().get(0).getLockedOn()); + assertEquals(entity.getReferenceAccessId(), result.getBayTypicals().get(0).getReferenceAccessId()); + assertEquals(entity.getVersion(), result.getBayTypicals().get(0).getVersion()); + assertEquals(entity.getDescription(), result.getBayTypicals().get(0).getDescription()); + assertEquals(entity.getLockedBy(), result.getBayTypicals().get(0).getLockedBy()); + } + +} \ No newline at end of file diff --git a/app/src/test/java/org/lfenergy/compas/sitipe/rest/v2/BTComponentResourceTest.java b/app/src/test/java/org/lfenergy/compas/sitipe/rest/v2/BTComponentResourceTest.java new file mode 100644 index 0000000..b1d890f --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/sitipe/rest/v2/BTComponentResourceTest.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.data.entity.ImportedComponent; +import org.lfenergy.compas.sitipe.helper.SystemVersionHelper; + +import javax.inject.Inject; + + +import java.io.IOException; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.UUID; + +import static io.restassured.RestAssured.given; +import static org.junit.jupiter.api.Assertions.*; + +@QuarkusTest +@TestHTTPEndpoint(BTComponentResource.class) +class BTComponentResourceTest extends BaseIntegrationTest { + + @Inject() + SystemVersionHelper systemVersionHelper; + + @Test + @TestSecurity(user = "test-user", roles = {"USER"}) + void itShouldListImportedComponentsForAccessId() throws IOException { + final String accessId = UUID.randomUUID().toString(); + final ImportedComponent importedComponent1 = systemVersionHelper.createAndStoreImportedComponent(1, accessId, "IID"); + final ImportedComponent importedComponent2 = systemVersionHelper.createAndStoreImportedComponent(2, accessId, "IED"); + + var response = given() + .when().get("/{accessId}/imported", accessId) + .then() + .statusCode(200) + .extract() + .response(); + + JsonPath jsonPath = response.jsonPath(); + + ArrayList> res = jsonPath.get(); + assertEquals(1, res.size()); + assertEquals(importedComponent1.getId(), ((ArrayList>)jsonPath.get()).get(0).get("id")); + } + + @Test + @TestSecurity(user = "test-user", roles = {"USER"}) + void itShouldReturnEmptyListWhenNoBTComponentFound() { + final String accessId = UUID.randomUUID().toString(); + + var response = given() + .when().get("/{accessId}/imported", accessId) + .then() + .statusCode(200) + .extract() + .response(); + + JsonPath jsonPath = response.jsonPath(); + + ArrayList> res = jsonPath.get(); + assertEquals(0, res.size()); + } + + @Test + @TestSecurity(user = "test-user", roles = {"USER"}) + void itShouldReturnImportedComponentData() throws IOException { + final String accessId = UUID.randomUUID().toString(); + final ImportedComponent importedComponent1 = systemVersionHelper.createAndStoreImportedComponent(1, accessId, "IID"); + + var response = given() + .when().get("/imported/{id}", importedComponent1.getId()) + .then() + .statusCode(200) + .extract() + .response(); + + JsonPath jsonPath = response.jsonPath(); + + LinkedHashMap res = jsonPath.get(); + assertEquals("TEST DATA", res.get("data")); + } + + @Test + @TestSecurity(user = "test-user", roles = {"USER"}) + void itShouldThrowErrorWhenImportedComponentNotFound() { + var response = given() + .when().get("/imported/{id}", 10) + .then() + .statusCode(500) + .extract() + .response(); + + JsonPath jsonPath = response.jsonPath(); + + assertEquals("CORE-9999", ((LinkedHashMap)((ArrayList)((LinkedHashMap)jsonPath.get()).get("errorMessages")).get(0)).get("code")); + } +} 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 index b4e9121..9ace0fb 100644 --- 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 @@ -8,16 +8,24 @@ import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.security.TestSecurity; import io.restassured.path.json.JsonPath; +import io.smallrye.common.annotation.Blocking; +import io.smallrye.mutiny.Uni; 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.BTComponent; import org.lfenergy.compas.sitipe.data.entity.BayTypical; import org.lfenergy.compas.sitipe.data.entity.SystemVersion; +import org.lfenergy.compas.sitipe.dto.BTComponentDTO; import org.lfenergy.compas.sitipe.helper.SystemVersionHelper; import javax.inject.Inject; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; import java.util.ArrayList; import java.util.LinkedHashMap; +import java.util.List; +import java.util.UUID; import static io.restassured.RestAssured.given; import static java.util.Arrays.asList; @@ -50,11 +58,11 @@ void itShouldListBayTypicalsForVersion() { systemVersionHelper.assignBayTypicalToSystemVersion(systemVersion2.getId(), bayTypicalForVersion2); var response = given() - .when().get("/") - .then() - .statusCode(200) - .extract() - .response(); + .when().get("/") + .then() + .statusCode(200) + .extract() + .response(); JsonPath jsonPath = response.jsonPath(); @@ -77,11 +85,11 @@ void itShouldListBayTypicalsForVersion() { @TestSecurity(user = "test-user", roles = {"USER"}) void itShouldReturnEmptyListWhenVersionNotFound() { var response = given() - .when().get("/") - .then() - .statusCode( 200) - .extract() - .response(); + .when().get("/") + .then() + .statusCode( 200) + .extract() + .response(); JsonPath jsonPath = response.jsonPath(); assertEquals(0, jsonPath.>get().size()); @@ -93,14 +101,67 @@ void itShouldReturnEmptyListWhenNoBayTypicalsAreFound() { final SystemVersion systemVersion = systemVersionHelper.createAndStoreSystemVersion(1L, sitipeProperties.version()); var response = given() - .when().get("/") - .then() - .statusCode(200) - .extract() - .response(); + .when().get("/") + .then() + .statusCode(200) + .extract() + .response(); + + JsonPath jsonPath = response.jsonPath(); + assertEquals(0, jsonPath.>get().size()); + } + + @Test + @TestSecurity(user = "test-user", roles = {"USER"}) + void itShouldReturnBTComponentsForDigsiForBayTypicals() { + final BayTypical bayTypical = systemVersionHelper.createAndStoreBayTypical(1); + + final BTComponent btComponent1 = systemVersionHelper.createAndStoreBTComponent(2, bayTypical, "DIGSI 5"); + final BTComponent btComponent2 = systemVersionHelper.createAndStoreBTComponent(3, bayTypical, "DIGSI 6"); + + var response = given() + .when().get("/{accessId}/components", bayTypical.getAccessId()) + .then() + .statusCode(200) + .extract() + .response(); + + JsonPath jsonPath = response.jsonPath(); + assertEquals(1, jsonPath.>get().size()); + assertEquals(btComponent1.getId(), ((ArrayList>)jsonPath.get()).get(0).get("id")); + } + @Test + @TestSecurity(user = "test-user", roles = {"USER"}) + void itShouldReturnEmptyListForBTComponentsWhenNoBayTypicalFound() { + var response = given() + .when().get("/{accessId}/components", UUID.randomUUID().toString()) + .then() + .statusCode(200) + .extract() + .response(); + + JsonPath jsonPath = response.jsonPath(); + assertEquals(0, jsonPath.>get().size()); + } + + @Test + @TestSecurity(user = "test-user", roles = {"USER"}) + void itShouldReturnEmptyListForBTComponentsWhenNoComponentsFoundFound() { + final BayTypical bayTypical = systemVersionHelper.createAndStoreBayTypical(1); + + final BTComponent btComponent1 = systemVersionHelper.createAndStoreBTComponent(2, bayTypical, "DIGSI 6"); + final BTComponent btComponent2 = systemVersionHelper.createAndStoreBTComponent(3, bayTypical, "DIGSI 6"); + + var response = given() + .when().get("/{accessId}/components", UUID.randomUUID().toString()) + .then() + .statusCode(200) + .extract() + .response(); JsonPath jsonPath = response.jsonPath(); assertEquals(0, jsonPath.>get().size()); } } + diff --git a/docker/docker-compose-m1.yml b/docker/docker-compose-m1.yml index 3e198c2..1d297d6 100644 --- a/docker/docker-compose-m1.yml +++ b/docker/docker-compose-m1.yml @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2021 Alliander N.V. +# SPDX-FileCopyrightText: 2023 Alliander N.V. # # SPDX-License-Identifier: Apache-2.0 diff --git a/postman/sitipe.postman_collection.json b/postman/sitipe.postman_collection.json index 1341e35..b3931d8 100644 --- a/postman/sitipe.postman_collection.json +++ b/postman/sitipe.postman_collection.json @@ -32,22 +32,109 @@ "name": "v2", "item": [ { - "name": "Get Bay Typicals", - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "{{sitpeServiceBaseUrl}}/v2/baytypicals", - "host": [ - "{{sitpeServiceBaseUrl}}" - ], - "path": [ - "v2", - "baytypicals" - ] + "name": "BayTypicals", + "item": [ + { + "name": "Get Bay Typicals", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{sitpeServiceBaseUrl}}/v2/baytypicals", + "host": [ + "{{sitpeServiceBaseUrl}}" + ], + "path": [ + "v2", + "baytypicals" + ] + } + }, + "response": [] + }, + { + "name": "Get BT Components For Bay Typical", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{sitpeServiceBaseUrl}}/v2/baytypicals/:accessId/components", + "host": [ + "{{sitpeServiceBaseUrl}}" + ], + "path": [ + "v2", + "baytypicals", + ":accessId", + "components" + ], + "variable": [ + { + "key": "accessId", + "value": "3BD3CA17-8136-4F72-A381-9C047FF1F3A8" + } + ] + } + }, + "response": [] } - }, - "response": [] + ] + }, + { + "name": "BT Components", + "item": [ + { + "name": "Get Imported BT Components", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{sitpeServiceBaseUrl}}/v2/btcomponents/:accessId/imported", + "host": [ + "{{sitpeServiceBaseUrl}}" + ], + "path": [ + "v2", + "btcomponents", + ":accessId" + ], + "variable": [ + { + "key": "accessId", + "value": "641862E1-FB2B-4159-9F07-2E9F85665F7C" + } + ] + } + }, + "response": [] + }, + { + "name": "Get SCL Data For BT Component", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{sitpeServiceBaseUrl}}/v2/btcomponents/imported/:id", + "host": [ + "{{sitpeServiceBaseUrl}}" + ], + "path": [ + "v2", + "btcomponents", + "imported", + ":id" + ], + "variable": [ + { + "key": "id", + "value": "1" + } + ] + } + }, + "response": [] + } + ] } ] } @@ -57,7 +144,7 @@ "bearer": [ { "key": "token", - "value": "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJuM0F5VTh3LXNON3NDdWRFS1NrblBuUXZsbHMyZ2pELWtwcGNUUGI1cVI4In0.eyJleHAiOjE2NzkwNTUyNzksImlhdCI6MTY3OTA1NDk3OSwianRpIjoiYjFkYjQ3MDYtMzE5OC00YWM0LWEyMzQtMjJhYThjY2VkYzE4IiwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdC9hdXRoL3JlYWxtcy9jb21wYXMiLCJhdWQiOlsib3BlbnNjZCIsInNjbC1hdXRvLWFsaWdubWVudCIsInNjbC1kYXRhLXNlcnZpY2UiLCJjaW0tbWFwcGluZyIsInNjbC12YWxpZGF0b3IiLCJzaXRpcGUtc2VydmljZSIsImFjY291bnQiXSwic3ViIjoiZGVlZDQ4MzItODUzMS00M2VlLThiZjItMjBiYzUzNGZlZTQ1IiwidHlwIjoiQmVhcmVyIiwiYXpwIjoib3BlbnNjZCIsInNlc3Npb25fc3RhdGUiOiJhYjMzOTY1My1mODg0LTQ4M2QtYjRlYi0zZGM0NmQyYmQzMTUiLCJhY3IiOiIxIiwiYWxsb3dlZC1vcmlnaW5zIjpbImh0dHA6Ly9sb2NhbGhvc3QiXSwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbImRlZmF1bHQtcm9sZXMtY29tcGFzIiwib2ZmbGluZV9hY2Nlc3MiLCJ1bWFfYXV0aG9yaXphdGlvbiJdfSwicmVzb3VyY2VfYWNjZXNzIjp7InNjbC1hdXRvLWFsaWdubWVudCI6eyJyb2xlcyI6WyJVU0VSIl19LCJzY2wtZGF0YS1zZXJ2aWNlIjp7InJvbGVzIjpbIlNTRF9SRUFEIiwiU1REX1JFQUQiLCJJSURfUkVBRCIsIkNJRF9SRUFEIiwiU0VEX1JFQUQiLCJJQ0RfUkVBRCIsIlNDRF9SRUFEIiwiSVNEX1JFQUQiXX0sImNpbS1tYXBwaW5nIjp7InJvbGVzIjpbIlVTRVIiXX0sInNjbC12YWxpZGF0b3IiOnsicm9sZXMiOlsiVVNFUiJdfSwic2l0aXBlLXNlcnZpY2UiOnsicm9sZXMiOlsiVVNFUiJdfSwiYWNjb3VudCI6eyJyb2xlcyI6WyJtYW5hZ2UtYWNjb3VudCIsIm1hbmFnZS1hY2NvdW50LWxpbmtzIiwidmlldy1wcm9maWxlIl19LCJvcGVuc2NkIjp7InJvbGVzIjpbIlVTRVIiXX19LCJzY29wZSI6ImVtYWlsIHByb2ZpbGUiLCJzaWQiOiJhYjMzOTY1My1mODg0LTQ4M2QtYjRlYi0zZGM0NmQyYmQzMTUiLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwibmFtZSI6Ik1ycyBSZWFkZXIiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJzY2wtZGF0YS1yZWFkZXIiLCJnaXZlbl9uYW1lIjoiTXJzIiwiZmFtaWx5X25hbWUiOiJSZWFkZXIifQ.IAHpbM6TN8zPoqrw-HvNIpJWtS1KCuzWh426rYC289pMsU5snhtEphKfB7Kj2Pq9c2LDjxF0j2o0lJKUc8j37Y-i1G3te1ryU9d2lbBXS5Kzzpj-WNzuRVzSR6TnAc0EWu0enmMXX9gbiCeU927U16KsvF99T4vW7TcYwMz5_hgJURp0ijHDtembhbbZO6yPBTqmxWg5Wij5_Eg3X6BXnqCFo32XpxY7V-3YFOEbS3ta67u6xth9NEk4uUzSNNjBCLwqp0cV4gZR3i8Pfosrem7_KaIfw7YOT8Eq49PC88nSg6Ie-XCO4H4mPGQ6wJXwbM-FY47GF_tmugHDsFH1vw", + "value": "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJuM0F5VTh3LXNON3NDdWRFS1NrblBuUXZsbHMyZ2pELWtwcGNUUGI1cVI4In0.eyJleHAiOjE2ODAwODY2MTksImlhdCI6MTY4MDA4NjMxOSwianRpIjoiNWJmMmI1NzktZTc0Yy00OTFmLWE4YzItMjkyZjBiODUxOWQyIiwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdC9hdXRoL3JlYWxtcy9jb21wYXMiLCJhdWQiOlsib3BlbnNjZCIsInNjbC1hdXRvLWFsaWdubWVudCIsInNjbC1kYXRhLXNlcnZpY2UiLCJjaW0tbWFwcGluZyIsInNjbC12YWxpZGF0b3IiLCJzaXRpcGUtc2VydmljZSIsImFjY291bnQiXSwic3ViIjoiZGVlZDQ4MzItODUzMS00M2VlLThiZjItMjBiYzUzNGZlZTQ1IiwidHlwIjoiQmVhcmVyIiwiYXpwIjoib3BlbnNjZCIsInNlc3Npb25fc3RhdGUiOiJmNzY5OGNkOC1mM2M4LTQ2MjgtOWU4MS0yNmYxNTkxZjk5ZjIiLCJhY3IiOiIxIiwiYWxsb3dlZC1vcmlnaW5zIjpbImh0dHA6Ly9sb2NhbGhvc3QiXSwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbImRlZmF1bHQtcm9sZXMtY29tcGFzIiwib2ZmbGluZV9hY2Nlc3MiLCJ1bWFfYXV0aG9yaXphdGlvbiJdfSwicmVzb3VyY2VfYWNjZXNzIjp7InNjbC1hdXRvLWFsaWdubWVudCI6eyJyb2xlcyI6WyJVU0VSIl19LCJzY2wtZGF0YS1zZXJ2aWNlIjp7InJvbGVzIjpbIlNTRF9SRUFEIiwiU1REX1JFQUQiLCJJSURfUkVBRCIsIkNJRF9SRUFEIiwiU0VEX1JFQUQiLCJJQ0RfUkVBRCIsIlNDRF9SRUFEIiwiSVNEX1JFQUQiXX0sImNpbS1tYXBwaW5nIjp7InJvbGVzIjpbIlVTRVIiXX0sInNjbC12YWxpZGF0b3IiOnsicm9sZXMiOlsiVVNFUiJdfSwic2l0aXBlLXNlcnZpY2UiOnsicm9sZXMiOlsiVVNFUiJdfSwiYWNjb3VudCI6eyJyb2xlcyI6WyJtYW5hZ2UtYWNjb3VudCIsIm1hbmFnZS1hY2NvdW50LWxpbmtzIiwidmlldy1wcm9maWxlIl19LCJvcGVuc2NkIjp7InJvbGVzIjpbIlVTRVIiXX19LCJzY29wZSI6ImVtYWlsIHByb2ZpbGUiLCJzaWQiOiJmNzY5OGNkOC1mM2M4LTQ2MjgtOWU4MS0yNmYxNTkxZjk5ZjIiLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwibmFtZSI6Ik1ycyBSZWFkZXIiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJzY2wtZGF0YS1yZWFkZXIiLCJnaXZlbl9uYW1lIjoiTXJzIiwiZmFtaWx5X25hbWUiOiJSZWFkZXIifQ.Ysjo-sUZQeiCIAXWBeu0XhNgG5JCxJYGPXHwh3-tGzHOjhtjwajSeS1iJUBgsPkD5--z05ZRV-mn7JHcQ4_hhBDqK_8xK7VP5J0sWdcPvCGdLG0XukbuwNvFdHd2ozHugJS4uS_EzOBtMp2MX3lKnnM3mcZYFB1EjpoudcSCCsT3ec1xo63E1Q2JedG6tqFEGzk1NzMtV9ldr5jlVyrj8VIdzFTQJ9gohBab6rRW-eRpoIu4TpJxrt_G9ezhc154Q6ooIByxCIm5cSwR3kTTZG3JHseaO90qsbApK2DJa_o-FSv_nK1KDnRPlSvY6ML8tCv8rpY-j71Ekyqee2oMZw", "type": "string" } ] @@ -89,4 +176,4 @@ "type": "default" } ] -} \ No newline at end of file +} diff --git a/repository/pom.xml b/repository/pom.xml index 6c30340..6a65ced 100644 --- a/repository/pom.xml +++ b/repository/pom.xml @@ -67,6 +67,11 @@ SPDX-License-Identifier: Apache-2.0 io.quarkus quarkus-hibernate-orm-panache + + com.openpojo + openpojo + test + diff --git a/repository/src/main/java/org/lfenergy/compas/sitipe/data/entity/BTComponent.java b/repository/src/main/java/org/lfenergy/compas/sitipe/data/entity/BTComponent.java new file mode 100644 index 0000000..1bd9f9d --- /dev/null +++ b/repository/src/main/java/org/lfenergy/compas/sitipe/data/entity/BTComponent.java @@ -0,0 +1,148 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.data.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "BTComponents_") +public class BTComponent { + + @Id() + @Column(columnDefinition = "BIGINT") + private Integer id; + + @Column(name = "name") + private String name; + + @Column(name = "typicalAccessId", columnDefinition = "UUID") + private String typicalAccessId; + + @Column(name = "importedOn") + private Long importedOn; + + @Column(name = "toolName") + private String toolName; + + @Column(name = "toolVersion") + private String toolVersion; + + @Column(name = "hasIecInformation", columnDefinition = "bit") + private int hasIecInformation; + + @Column(name = "componentGuid", columnDefinition = "UUID") + private String componentGuid; + + @Column(name = "accessId", columnDefinition = "UUID") + private String accessId; + + @Column(name = "language") + private String language; + + @Column(name = "IniVersion") + private int iniVersion; + + @Column(name = "referenceAccessId", columnDefinition = "UUID") + private String referenceAccessId; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getTypicalAccessId() { + return typicalAccessId; + } + + public void setTypicalAccessId(String typicalAccessId) { + this.typicalAccessId = typicalAccessId; + } + + public Long getImportedOn() { + return importedOn; + } + + public void setImportedOn(Long importedOn) { + this.importedOn = importedOn; + } + + public String getToolName() { + return toolName; + } + + public void setToolName(String toolName) { + this.toolName = toolName; + } + + public String getToolVersion() { + return toolVersion; + } + + public void setToolVersion(String toolVersion) { + this.toolVersion = toolVersion; + } + + public int getHasIecInformation() { + return hasIecInformation; + } + + public void setHasIecInformation(int hasIecInformation) { + this.hasIecInformation = hasIecInformation; + } + + public String getComponentGuid() { + return componentGuid; + } + + public void setComponentGuid(String componentGuid) { + this.componentGuid = componentGuid; + } + + public String getAccessId() { + return accessId; + } + + public void setAccessId(String accessId) { + this.accessId = accessId; + } + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + + public int getIniVersion() { + return iniVersion; + } + + public void setIniVersion(int iniVersion) { + this.iniVersion = iniVersion; + } + + public String getReferenceAccessId() { + return referenceAccessId; + } + + public void setReferenceAccessId(String referenceAccessId) { + this.referenceAccessId = referenceAccessId; + } +} diff --git a/repository/src/main/java/org/lfenergy/compas/sitipe/data/entity/ImportedComponent.java b/repository/src/main/java/org/lfenergy/compas/sitipe/data/entity/ImportedComponent.java new file mode 100644 index 0000000..4a7e3e9 --- /dev/null +++ b/repository/src/main/java/org/lfenergy/compas/sitipe/data/entity/ImportedComponent.java @@ -0,0 +1,80 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.data.entity; + +import javax.persistence.*; + +@Entity +@Table(name = "Imported_") +public class ImportedComponent { + + @Id() + private Integer id; + + @Column(name = "type") + private String type; + + @Column(name = "data") + @Basic(fetch = FetchType.LAZY) + @Lob + private byte[] data; + + @Column(name = "contentVersion") + private String contentVersion; + + @Column(name = "componentAccessId", columnDefinition = "UUID") + private String componentAccessId; + + @Column(name = "accessId", columnDefinition = "UUID") + private String accessId; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public byte[] getData() { + return data; + } + + public void setData(byte[] data) { + this.data = data; + } + + public String getContentVersion() { + return contentVersion; + } + + public void setContentVersion(String contentVersion) { + this.contentVersion = contentVersion; + } + + public String getComponentAccessId() { + return componentAccessId; + } + + public void setComponentAccessId(String componentAccessId) { + this.componentAccessId = componentAccessId; + } + + public String getAccessId() { + return accessId; + } + + public void setAccessId(String accessId) { + this.accessId = accessId; + } +} diff --git a/repository/src/main/java/org/lfenergy/compas/sitipe/data/repository/BTComponentRepository.java b/repository/src/main/java/org/lfenergy/compas/sitipe/data/repository/BTComponentRepository.java new file mode 100644 index 0000000..8fb42d7 --- /dev/null +++ b/repository/src/main/java/org/lfenergy/compas/sitipe/data/repository/BTComponentRepository.java @@ -0,0 +1,19 @@ +// 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; +import org.lfenergy.compas.sitipe.data.entity.BTComponent; + +import javax.enterprise.context.ApplicationScoped; +import java.util.List; + +@ApplicationScoped +public class BTComponentRepository implements PanacheRepository { + + public List findBayTypicalComponentsByTypicalAccessId(final String accessId) { + return this.list("typicalAccessId = ?1 AND toolName = ?2", accessId, "DIGSI 5"); + } +} 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 4c64a7b..9add0d9 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 @@ -17,7 +17,4 @@ public List findByAccessId(final String accessId) { return this.list("accessId", accessId); } - - - } diff --git a/repository/src/main/java/org/lfenergy/compas/sitipe/data/repository/ImportedComponentRepository.java b/repository/src/main/java/org/lfenergy/compas/sitipe/data/repository/ImportedComponentRepository.java new file mode 100644 index 0000000..d290b1b --- /dev/null +++ b/repository/src/main/java/org/lfenergy/compas/sitipe/data/repository/ImportedComponentRepository.java @@ -0,0 +1,24 @@ +// 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.PanacheRepositoryBase; +import org.lfenergy.compas.sitipe.data.entity.ImportedComponent; + +import javax.enterprise.context.ApplicationScoped; +import javax.persistence.LockModeType; +import java.util.List; + +@ApplicationScoped +public class ImportedComponentRepository implements PanacheRepositoryBase { + + public List getByAccessId(final String accessId) { + return this.list("componentAccessId = ?1 AND type = ?2", accessId, "IID"); + } + + public ImportedComponent getById(final Integer id) { + return this.findById(id, LockModeType.NONE); + } +} 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 4c53ed0..9faf5ee 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 @@ -8,18 +8,11 @@ import org.lfenergy.compas.sitipe.data.entity.SystemVersion; import javax.enterprise.context.ApplicationScoped; -import javax.sql.DataSource; import java.util.List; @ApplicationScoped public class SystemVersionRepository implements PanacheRepository { - private final DataSource dataSource; - - public SystemVersionRepository(DataSource dataSource) { - this.dataSource = dataSource; - } - public List findByVersion(final String version) { return this.list("version", version); } diff --git a/repository/src/test/java/org/lfenergy/compas/sitipe/data/entity/BTComponentTest.java b/repository/src/test/java/org/lfenergy/compas/sitipe/data/entity/BTComponentTest.java new file mode 100644 index 0000000..773360b --- /dev/null +++ b/repository/src/test/java/org/lfenergy/compas/sitipe/data/entity/BTComponentTest.java @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.data.entity; + +class BTComponentTest extends BaseEntityTest { + + @Override + protected Class getClassToBeTested() { + return BTComponent.class; + } + +} \ No newline at end of file diff --git a/repository/src/test/java/org/lfenergy/compas/sitipe/data/entity/BaseEntityTest.java b/repository/src/test/java/org/lfenergy/compas/sitipe/data/entity/BaseEntityTest.java new file mode 100644 index 0000000..c27d510 --- /dev/null +++ b/repository/src/test/java/org/lfenergy/compas/sitipe/data/entity/BaseEntityTest.java @@ -0,0 +1,34 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.data.entity; + +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; +import org.junit.jupiter.api.Test; + +abstract class BaseEntityTest { + + @Test + void validateSettersAndGetters() { + var personPojo = PojoClassFactory.getPojoClass(getClassToBeTested()); + var validator = ValidatorBuilder.create() + // Let's make sure that we have a getter and a setter for every field defined. + .with(new GetterMustExistRule()) + .with(new SetterMustExistRule()) + // Let's also validate that they are behaving as expected + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + + // Start the Test + validator.validate(personPojo); + } + + protected abstract Class getClassToBeTested(); +} diff --git a/repository/src/test/java/org/lfenergy/compas/sitipe/data/entity/BayTypicalTest.java b/repository/src/test/java/org/lfenergy/compas/sitipe/data/entity/BayTypicalTest.java new file mode 100644 index 0000000..d11e5ef --- /dev/null +++ b/repository/src/test/java/org/lfenergy/compas/sitipe/data/entity/BayTypicalTest.java @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.data.entity; + +class BayTypicalTest extends BaseEntityTest { + + @Override + protected Class getClassToBeTested() { + return BayTypical.class; + } + +} \ No newline at end of file diff --git a/repository/src/test/java/org/lfenergy/compas/sitipe/data/entity/ImportedComponentTest.java b/repository/src/test/java/org/lfenergy/compas/sitipe/data/entity/ImportedComponentTest.java new file mode 100644 index 0000000..e9629ce --- /dev/null +++ b/repository/src/test/java/org/lfenergy/compas/sitipe/data/entity/ImportedComponentTest.java @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.data.entity; + +class ImportedComponentTest extends BaseEntityTest { + + @Override + protected Class getClassToBeTested() { + return ImportedComponent.class; + } + +} \ No newline at end of file diff --git a/repository/src/test/java/org/lfenergy/compas/sitipe/data/entity/SystemVersionTest.java b/repository/src/test/java/org/lfenergy/compas/sitipe/data/entity/SystemVersionTest.java new file mode 100644 index 0000000..14a7057 --- /dev/null +++ b/repository/src/test/java/org/lfenergy/compas/sitipe/data/entity/SystemVersionTest.java @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.data.entity; + +class SystemVersionTest extends BaseEntityTest { + + @Override + protected Class getClassToBeTested() { + return SystemVersion.class; + } + +} \ No newline at end of file diff --git a/repository/src/test/java/org/lfenergy/compas/sitipe/data/repository/BTComponentRepositoryTest.java b/repository/src/test/java/org/lfenergy/compas/sitipe/data/repository/BTComponentRepositoryTest.java new file mode 100644 index 0000000..6c716eb --- /dev/null +++ b/repository/src/test/java/org/lfenergy/compas/sitipe/data/repository/BTComponentRepositoryTest.java @@ -0,0 +1,51 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.data.repository; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.lfenergy.compas.sitipe.data.entity.BTComponent; +import org.lfenergy.compas.sitipe.data.entity.BayTypical; +import org.mockito.ArgumentCaptor; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; +import java.util.UUID; + +import static java.util.Collections.emptyList; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; + +@ExtendWith(MockitoExtension.class) +class BTComponentRepositoryTest { + + private BTComponentRepository sut; + + @BeforeEach + public void setUp() { + sut = spy(BTComponentRepository.class); + } + + @Test + void itShouldGetBTComponents() { + final ArgumentCaptor causeArgumentCaptor = ArgumentCaptor.forClass(String.class); + final ArgumentCaptor typeArgumentCaptor = ArgumentCaptor.forClass(String.class); + final ArgumentCaptor toolNameArgumentCaptor = ArgumentCaptor.forClass(String.class); + + doReturn(emptyList()).when(sut).list(causeArgumentCaptor.capture(), typeArgumentCaptor.capture(), toolNameArgumentCaptor.capture()); + + final String accessId = UUID.randomUUID().toString(); + + final List result = sut.findBayTypicalComponentsByTypicalAccessId(accessId); + + assertEquals("DIGSI 5", toolNameArgumentCaptor.getValue()); + + assertEquals("typicalAccessId = ?1 AND toolName = ?2", causeArgumentCaptor.getValue()); + assertEquals(accessId, typeArgumentCaptor.getValue()); + assertEquals(0, result.size()); + } +} \ No newline at end of file diff --git a/repository/src/test/java/org/lfenergy/compas/sitipe/data/repository/BayTypicalRepositoryTest.java b/repository/src/test/java/org/lfenergy/compas/sitipe/data/repository/BayTypicalRepositoryTest.java new file mode 100644 index 0000000..716d8ef --- /dev/null +++ b/repository/src/test/java/org/lfenergy/compas/sitipe/data/repository/BayTypicalRepositoryTest.java @@ -0,0 +1,46 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.data.repository; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.lfenergy.compas.sitipe.data.entity.BayTypical; +import org.mockito.ArgumentCaptor; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; +import java.util.UUID; + +import static java.util.Collections.emptyList; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +@ExtendWith(MockitoExtension.class) +class BayTypicalRepositoryTest { + + private BayTypicalRepository sut; + + @BeforeEach + public void setUp() { + sut = spy(BayTypicalRepository.class); + } + + @Test + void itShouldGetBayTypicals() { + final ArgumentCaptor causeArgumentCaptor = ArgumentCaptor.forClass(String.class); + final ArgumentCaptor typeArgumentCaptor = ArgumentCaptor.forClass(String.class); + + doReturn(emptyList()).when(sut).list(causeArgumentCaptor.capture(), typeArgumentCaptor.capture()); + + final String accessId = UUID.randomUUID().toString(); + + final List result = sut.findByAccessId(accessId); + + assertEquals("accessId", causeArgumentCaptor.getValue()); + assertEquals(accessId, typeArgumentCaptor.getValue()); + assertEquals(0, result.size()); + } +} \ No newline at end of file diff --git a/repository/src/test/java/org/lfenergy/compas/sitipe/data/repository/ImportedComponentRepositoryTest.java b/repository/src/test/java/org/lfenergy/compas/sitipe/data/repository/ImportedComponentRepositoryTest.java new file mode 100644 index 0000000..7a11b25 --- /dev/null +++ b/repository/src/test/java/org/lfenergy/compas/sitipe/data/repository/ImportedComponentRepositoryTest.java @@ -0,0 +1,69 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.data.repository; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.lfenergy.compas.sitipe.data.entity.BayTypical; +import org.lfenergy.compas.sitipe.data.entity.ImportedComponent; +import org.mockito.ArgumentCaptor; +import org.mockito.junit.jupiter.MockitoExtension; + +import javax.persistence.LockModeType; +import java.util.List; +import java.util.UUID; + +import static java.util.Collections.emptyList; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; + +@ExtendWith(MockitoExtension.class) +class ImportedComponentRepositoryTest { + + private ImportedComponentRepository sut; + + @BeforeEach + public void setUp() { + sut = spy(ImportedComponentRepository.class); + } + + @Test + void itShouldGetImportedComponents() { + final ArgumentCaptor causeArgumentCaptor = ArgumentCaptor.forClass(String.class); + final ArgumentCaptor typeArgumentCaptor = ArgumentCaptor.forClass(String.class); + final ArgumentCaptor iidArgumentCaptor = ArgumentCaptor.forClass(String.class); + + doReturn(emptyList()).when(sut).list(causeArgumentCaptor.capture(), typeArgumentCaptor.capture(), iidArgumentCaptor.capture()); + + final String accessId = UUID.randomUUID().toString(); + + final List result = sut.getByAccessId(accessId); + + assertEquals("IID", iidArgumentCaptor.getValue()); + assertEquals("componentAccessId = ?1 AND type = ?2", causeArgumentCaptor.getValue()); + assertEquals(accessId, typeArgumentCaptor.getValue()); + assertEquals(0, result.size()); + } + + @Test + void itShouldGetById() { + final ArgumentCaptor idArgumentCaptor = ArgumentCaptor.forClass(Integer.class); + final ArgumentCaptor lockModeTypeArgumentCaptor = ArgumentCaptor.forClass(LockModeType.class); + + final ImportedComponent importedComponent = new ImportedComponent(); + + doReturn(importedComponent).when(sut).findById(idArgumentCaptor.capture(), lockModeTypeArgumentCaptor.capture()); + + final Integer id = 1; + + final ImportedComponent result = sut.getById(id); + + assertEquals(importedComponent, result); + assertEquals(id, idArgumentCaptor.getValue()); + assertEquals(LockModeType.NONE, lockModeTypeArgumentCaptor.getValue()); + } +} diff --git a/repository/src/test/java/org/lfenergy/compas/sitipe/data/table/SitipeFrameworkIdNamingStrategyTest.java b/repository/src/test/java/org/lfenergy/compas/sitipe/data/table/SitipeFrameworkIdNamingStrategyTest.java new file mode 100644 index 0000000..d0fc769 --- /dev/null +++ b/repository/src/test/java/org/lfenergy/compas/sitipe/data/table/SitipeFrameworkIdNamingStrategyTest.java @@ -0,0 +1,66 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.data.table; + +import io.smallrye.config.ConfigValuePropertiesConfigSource; +import io.smallrye.config.SmallRyeConfig; +import io.smallrye.config.SmallRyeConfigBuilder; +import org.eclipse.microprofile.config.ConfigProvider; +import org.eclipse.microprofile.config.spi.ConfigProviderResolver; +import org.hibernate.boot.model.naming.Identifier; +import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class SitipeFrameworkIdNamingStrategyTest { + + private SitipeFrameworkIdNamingStrategy sut; + + private final String frameworkId = "123"; + + @BeforeEach + void setUp() { + final Map configMap = new HashMap<>(); + configMap.put("compas.sitipe.framework-id", frameworkId); + + SmallRyeConfig config = new SmallRyeConfigBuilder() + .withSources(new ConfigValuePropertiesConfigSource(configMap, "CONFIG", 0)) + .build(); + ConfigProviderResolver.instance().registerConfig(config, Thread.currentThread().getContextClassLoader()); + + sut = new SitipeFrameworkIdNamingStrategy(); + } + + @AfterEach + void tearDown() { + ConfigProviderResolver.instance().releaseConfig(ConfigProvider.getConfig()); + } + + @Test + void itShouldSetCorrectNamingWhenHasFrameworkId() { + final String tableName = "TABLE"; + + final Identifier identifier = mock(Identifier.class); + final JdbcEnvironment environment = mock(JdbcEnvironment.class); + + when(identifier.getText()).thenReturn(tableName); + + final Identifier result = sut.toPhysicalTableName(identifier, environment); + + assertEquals("123__TABLE", result.getText()); + } + +} \ No newline at end of file diff --git a/service/pom.xml b/service/pom.xml index ca1ff6b..ac02bb9 100644 --- a/service/pom.xml +++ b/service/pom.xml @@ -49,6 +49,12 @@ SPDX-License-Identifier: Apache-2.0 junit-jupiter-engine test + + javax.ws.rs + javax.ws.rs-api + 2.1.1 + compile + diff --git a/service/src/main/java/org/lfenergy/compas/sitipe/dto/BTComponentDTO.java b/service/src/main/java/org/lfenergy/compas/sitipe/dto/BTComponentDTO.java new file mode 100644 index 0000000..fa63773 --- /dev/null +++ b/service/src/main/java/org/lfenergy/compas/sitipe/dto/BTComponentDTO.java @@ -0,0 +1,89 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.dto; + +import org.lfenergy.compas.sitipe.data.entity.BTComponent; + +public class BTComponentDTO { + + private final Integer id; + private final String name; + private final String typicalAccessId; + private final Long importedOn; + private final String toolName; + private final String toolVersion; + private final int hasIecInformation; + private final String componentGuid; + private final String accessId; + private final String language; + private final int iniVersion; + private final String referenceAccessId; + + public BTComponentDTO( + final BTComponent entity + ) { + this.id = entity.getId(); + this.name = entity.getName(); + this.typicalAccessId = entity.getTypicalAccessId(); + this.importedOn = entity.getImportedOn(); + this.toolName = entity.getToolName(); + this.toolVersion = entity.getToolVersion(); + this.hasIecInformation = entity.getHasIecInformation(); + this.componentGuid = entity.getComponentGuid(); + this.accessId = entity.getAccessId(); + this.language = entity.getLanguage(); + this.iniVersion = entity.getIniVersion(); + this.referenceAccessId = entity.getReferenceAccessId(); + } + + public Integer getId() { + return id; + } + + public String getName() { + return name; + } + + public String getTypicalAccessId() { + return typicalAccessId; + } + + public Long getImportedOn() { + return importedOn; + } + + public String getToolName() { + return toolName; + } + + public String getToolVersion() { + return toolVersion; + } + + public int getHasIecInformation() { + return hasIecInformation; + } + + public String getComponentGuid() { + return componentGuid; + } + + public String getAccessId() { + return accessId; + } + + public String getLanguage() { + return language; + } + + public int getIniVersion() { + return iniVersion; + } + + public String getReferenceAccessId() { + return referenceAccessId; + } + +} diff --git a/service/src/main/java/org/lfenergy/compas/sitipe/dto/BayTypicalDTO.java b/service/src/main/java/org/lfenergy/compas/sitipe/dto/BayTypicalDTO.java new file mode 100644 index 0000000..ec19ea1 --- /dev/null +++ b/service/src/main/java/org/lfenergy/compas/sitipe/dto/BayTypicalDTO.java @@ -0,0 +1,98 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.dto; + +import org.lfenergy.compas.sitipe.data.entity.BayTypical; + +public class BayTypicalDTO { + + private final Integer id; + private final String accessId; + + private final String description; + + private final String contentVersion; + + private final String lockedBy; + + private final Long lockedOn; + + private final Long modifiedOn; + + private final String name; + + private final String referenceAccessId; + + private final String smrFile; + + private final String version; + + private final int released; + + public BayTypicalDTO( + final BayTypical entity + ) { + this.id = entity.getId(); + this.accessId = entity.getAccessId(); + this.description = entity.getDescription(); + this.contentVersion = entity.getContentVersion(); + this.lockedBy = entity.getLockedBy(); + this.lockedOn = entity.getLockedOn(); + this.modifiedOn = entity.getModifiedOn(); + this.name = entity.getName(); + this.referenceAccessId = entity.getReferenceAccessId(); + this.smrFile = entity.getSmrFile(); + this.version = entity.getVersion(); + this.released = entity.getReleased(); + } + + public Integer getId() { + return id; + } + + public String getAccessId() { + return accessId; + } + + public String getDescription() { + return description; + } + + public String getContentVersion() { + return contentVersion; + } + + public String getLockedBy() { + return lockedBy; + } + + public Long getLockedOn() { + return lockedOn; + } + + public Long getModifiedOn() { + return modifiedOn; + } + + public String getName() { + return name; + } + + public String getReferenceAccessId() { + return referenceAccessId; + } + + public String getSmrFile() { + return smrFile; + } + + public String getVersion() { + return version; + } + + public int getReleased() { + return released; + } +} diff --git a/service/src/main/java/org/lfenergy/compas/sitipe/dto/ImportedComponentDTO.java b/service/src/main/java/org/lfenergy/compas/sitipe/dto/ImportedComponentDTO.java new file mode 100644 index 0000000..b2a83c4 --- /dev/null +++ b/service/src/main/java/org/lfenergy/compas/sitipe/dto/ImportedComponentDTO.java @@ -0,0 +1,45 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.dto; + +import org.lfenergy.compas.sitipe.data.entity.ImportedComponent; + +public class ImportedComponentDTO { + + private final Integer id; + private final String type; + private final String contentVersion; + private final String componentAccessId; + private final String accessId; + + public ImportedComponentDTO(final ImportedComponent entity) { + this.id = entity.getId(); + this.type = entity.getType(); + this.contentVersion = entity.getContentVersion(); + this.componentAccessId = entity.getComponentAccessId(); + this.accessId = entity.getAccessId(); + } + + public Integer getId() { + return id; + } + + public String getType() { + return type; + } + + public String getContentVersion() { + return contentVersion; + } + + public String getComponentAccessId() { + return componentAccessId; + } + + public String getAccessId() { + return accessId; + } +} + diff --git a/service/src/main/java/org/lfenergy/compas/sitipe/dto/ImportedDataDTO.java b/service/src/main/java/org/lfenergy/compas/sitipe/dto/ImportedDataDTO.java new file mode 100644 index 0000000..3998b15 --- /dev/null +++ b/service/src/main/java/org/lfenergy/compas/sitipe/dto/ImportedDataDTO.java @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.dto; + +public class ImportedDataDTO { + + private final String data; + + public ImportedDataDTO(final String data) { + this.data = data; + } + + public String getData() { + return this.data; + } +} diff --git a/service/src/main/java/org/lfenergy/compas/sitipe/service/BTComponentService.java b/service/src/main/java/org/lfenergy/compas/sitipe/service/BTComponentService.java new file mode 100644 index 0000000..fb1fad9 --- /dev/null +++ b/service/src/main/java/org/lfenergy/compas/sitipe/service/BTComponentService.java @@ -0,0 +1,33 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.service; + +import org.lfenergy.compas.sitipe.data.repository.BTComponentRepository; +import org.lfenergy.compas.sitipe.dto.BTComponentDTO; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import java.util.List; + +@ApplicationScoped +public class BTComponentService { + + private final BTComponentRepository btComponentRepository; + + @Inject + public BTComponentService( + final BTComponentRepository btComponentRepository + ) { + this.btComponentRepository = btComponentRepository; + } + + public List getBTComponentsByBayTypicalAccessId(final String accessId) { + return btComponentRepository.findBayTypicalComponentsByTypicalAccessId(accessId) + .stream() + .map(BTComponentDTO::new) + .toList(); + } + +} 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 3a6aed1..5d2763e 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 @@ -5,9 +5,9 @@ package org.lfenergy.compas.sitipe.service; import org.lfenergy.compas.sitipe.SitipeProperties; -import org.lfenergy.compas.sitipe.data.entity.BayTypical; import org.lfenergy.compas.sitipe.data.repository.BayTypicalRepository; import org.lfenergy.compas.sitipe.data.repository.SystemVersionRepository; +import org.lfenergy.compas.sitipe.dto.BayTypicalDTO; import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; @@ -33,11 +33,12 @@ public BayTypicalService(final SystemVersionRepository systemVersionRepository, this.sitipeProperties = sitipeProperties; } - public List getAssignedBayTypicals() { + public List getAssignedBayTypicals() { return this.systemVersionRepository.findByVersion(sitipeProperties.version()) .stream() .flatMap(systemVersion -> systemVersion.getAssignedBayTypicals() != null ? Arrays.stream(systemVersion.getAssignedBayTypicals().split(",")) : Stream.empty()) .flatMap(accessId -> bayTypicalRepository.findByAccessId(accessId).stream()) + .map(BayTypicalDTO::new) .collect(Collectors.toList()); } } diff --git a/service/src/main/java/org/lfenergy/compas/sitipe/service/ImportedComponentService.java b/service/src/main/java/org/lfenergy/compas/sitipe/service/ImportedComponentService.java new file mode 100644 index 0000000..69ff166 --- /dev/null +++ b/service/src/main/java/org/lfenergy/compas/sitipe/service/ImportedComponentService.java @@ -0,0 +1,80 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.service; + +import org.lfenergy.compas.sitipe.data.entity.ImportedComponent; +import org.lfenergy.compas.sitipe.data.repository.ImportedComponentRepository; +import org.lfenergy.compas.sitipe.dto.ImportedComponentDTO; +import org.lfenergy.compas.sitipe.dto.ImportedDataDTO; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.transaction.Transactional; +import javax.ws.rs.InternalServerErrorException; +import javax.ws.rs.NotFoundException; +import java.io.*; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.List; +import java.util.zip.Inflater; +import java.util.zip.InflaterInputStream; +import java.util.zip.ZipInputStream; + +@ApplicationScoped +public class ImportedComponentService { + + private final ImportedComponentRepository importedComponentRepository; + + @Inject + public ImportedComponentService( + final ImportedComponentRepository importedComponentRepository + ) { + this.importedComponentRepository = importedComponentRepository; + } + + public List getByAccessId(final String accessId) { + return importedComponentRepository.getByAccessId(accessId) + .stream() + .map(ImportedComponentDTO::new) + .toList(); + } + + public ImportedDataDTO getImportedComponentData(final Integer id) { + final ImportedComponent importedComponent = this.getEntity(id); + + if (importedComponent == null) { + throw new NotFoundException("Imported BT Component not found"); + } + + final ByteArrayInputStream bais = new ByteArrayInputStream(importedComponent.getData()); + final InflaterInputStream iis = new InflaterInputStream(bais); + + StringBuilder result = new StringBuilder(); + byte[] buffer = new byte[5]; + + int rlen = -1; + + try { + while ((rlen = iis.read(buffer)) != -1) { + result.append(new String(Arrays.copyOf(buffer, rlen), StandardCharsets.ISO_8859_1)); + } + } catch (IOException e) { + throw new InternalServerErrorException(e); + } + + return new ImportedDataDTO( + new String(result.toString().getBytes(), StandardCharsets.UTF_8) + .replaceAll("[^\\x00-\\x7F]", "") + ); + + + } + + @Transactional + private ImportedComponent getEntity(final Integer id) { + return importedComponentRepository.getById(id); + } +} diff --git a/service/src/test/java/org/lfenergy/compas/sitipe/dto/BTComponentDTOTest.java b/service/src/test/java/org/lfenergy/compas/sitipe/dto/BTComponentDTOTest.java new file mode 100644 index 0000000..971dcea --- /dev/null +++ b/service/src/test/java/org/lfenergy/compas/sitipe/dto/BTComponentDTOTest.java @@ -0,0 +1,51 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.dto; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.lfenergy.compas.sitipe.data.entity.BTComponent; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.*; + +@ExtendWith(MockitoExtension.class) +class BTComponentDTOTest { + + @Test + void itShouldMapProperties() { + final BTComponent entity = new BTComponent(); + + entity.setId(1); + entity.setImportedOn(1L); + entity.setReferenceAccessId(UUID.randomUUID().toString()); + entity.setLanguage("NL"); + entity.setName("NAME"); + entity.setToolVersion("1.00"); + entity.setIniVersion(2); + entity.setToolName("TOOL NAME"); + entity.setHasIecInformation(1); + entity.setTypicalAccessId(UUID.randomUUID().toString()); + entity.setComponentGuid(UUID.randomUUID().toString()); + entity.setAccessId(UUID.randomUUID().toString()); + + final BTComponentDTO result = new BTComponentDTO(entity); + + assertEquals(entity.getId(), result.getId()); + assertEquals(entity.getImportedOn(), result.getImportedOn()); + assertEquals(entity.getReferenceAccessId(), result.getReferenceAccessId()); + assertEquals(entity.getLanguage(), result.getLanguage()); + assertEquals(entity.getName(), result.getName()); + assertEquals(entity.getToolVersion(), result.getToolVersion()); + assertEquals(entity.getToolName(), result.getToolName()); + assertEquals(entity.getIniVersion(), result.getIniVersion()); + assertEquals(entity.getTypicalAccessId(), result.getTypicalAccessId()); + assertEquals(entity.getComponentGuid(), result.getComponentGuid()); + assertEquals(entity.getHasIecInformation(), result.getHasIecInformation()); + assertEquals(entity.getAccessId(), result.getAccessId()); + } +} \ No newline at end of file diff --git a/service/src/test/java/org/lfenergy/compas/sitipe/dto/BayTypicalDTOTest.java b/service/src/test/java/org/lfenergy/compas/sitipe/dto/BayTypicalDTOTest.java new file mode 100644 index 0000000..716cb5b --- /dev/null +++ b/service/src/test/java/org/lfenergy/compas/sitipe/dto/BayTypicalDTOTest.java @@ -0,0 +1,50 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.dto; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.lfenergy.compas.sitipe.data.entity.BayTypical; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.*; + +@ExtendWith(MockitoExtension.class) +class BayTypicalDTOTest { + + @Test + void itShouldMapProperties() { + final BayTypical entity = new BayTypical(); + entity.setId(1); + entity.setDescription("DESCRIPTION"); + entity.setVersion("1.00"); + entity.setContentVersion("2.00"); + entity.setAccessId(UUID.randomUUID().toString()); + entity.setLockedBy("LOCKED BY"); + entity.setLockedOn(1L); + entity.setModifiedOn(2L); + entity.setReferenceAccessId(UUID.randomUUID().toString()); + entity.setSmrFile("SMR FILE"); + entity.setReleased(1); + entity.setName("NAME"); + + final BayTypicalDTO result = new BayTypicalDTO(entity); + + assertEquals(entity.getId(), result.getId()); + assertEquals(entity.getDescription(), result.getDescription()); + assertEquals(entity.getVersion(), result.getVersion()); + assertEquals(entity.getContentVersion(), result.getContentVersion()); + assertEquals(entity.getAccessId(), result.getAccessId()); + assertEquals(entity.getLockedBy(), result.getLockedBy()); + assertEquals(entity.getLockedOn(), result.getLockedOn()); + assertEquals(entity.getModifiedOn(), result.getModifiedOn()); + assertEquals(entity.getReferenceAccessId(), result.getReferenceAccessId()); + assertEquals(entity.getSmrFile(), result.getSmrFile()); + assertEquals(entity.getReleased(), result.getReleased()); + assertEquals(entity.getName(), result.getName()); + } +} \ No newline at end of file diff --git a/service/src/test/java/org/lfenergy/compas/sitipe/dto/ImportedComponentDTOTest.java b/service/src/test/java/org/lfenergy/compas/sitipe/dto/ImportedComponentDTOTest.java new file mode 100644 index 0000000..7b3275b --- /dev/null +++ b/service/src/test/java/org/lfenergy/compas/sitipe/dto/ImportedComponentDTOTest.java @@ -0,0 +1,36 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.dto; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.lfenergy.compas.sitipe.data.entity.ImportedComponent; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.*; + +@ExtendWith(MockitoExtension.class) +class ImportedComponentDTOTest { + + @Test + void itShouldMapProperties() { + final ImportedComponent entity = new ImportedComponent(); + entity.setId(1); + entity.setType("TYPE"); + entity.setContentVersion("CONTENT VERSION"); + entity.setAccessId(UUID.randomUUID().toString()); + entity.setComponentAccessId(UUID.randomUUID().toString()); + + final ImportedComponentDTO result = new ImportedComponentDTO(entity); + + assertEquals(entity.getId(), result.getId()); + assertEquals(entity.getType(), result.getType()); + assertEquals(entity.getContentVersion(), result.getContentVersion()); + assertEquals(entity.getAccessId(), result.getAccessId()); + assertEquals(entity.getComponentAccessId(), result.getComponentAccessId()); + } +} \ No newline at end of file diff --git a/service/src/test/java/org/lfenergy/compas/sitipe/service/BTComponentServiceTest.java b/service/src/test/java/org/lfenergy/compas/sitipe/service/BTComponentServiceTest.java new file mode 100644 index 0000000..8c304ca --- /dev/null +++ b/service/src/test/java/org/lfenergy/compas/sitipe/service/BTComponentServiceTest.java @@ -0,0 +1,69 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.service; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.lfenergy.compas.sitipe.data.entity.BTComponent; +import org.lfenergy.compas.sitipe.data.repository.BTComponentRepository; +import org.lfenergy.compas.sitipe.dto.BTComponentDTO; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; +import java.util.UUID; + +import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class BTComponentServiceTest { + + @Mock + private BTComponentRepository btComponentRepository; + + private BTComponentService sut; + + @BeforeEach + void setUp() { + sut = new BTComponentService(btComponentRepository); + } + + @Test + void itShouldReturnListOfBTComponents() { + final BTComponent btComponent1 = new BTComponent(); + btComponent1.setId(1); + + final BTComponent btComponent2 = new BTComponent(); + btComponent2.setId(2); + + final String accessId = UUID.randomUUID().toString(); + + when(btComponentRepository.findBayTypicalComponentsByTypicalAccessId(accessId)) + .thenReturn(asList(btComponent1, btComponent2)); + + final List result = sut.getBTComponentsByBayTypicalAccessId(accessId); + + assertEquals(2, result.size()); + assertTrue(asList(btComponent1.getId(), btComponent2.getId()).contains(result.get(0).getId())); + assertTrue(asList(btComponent1.getId(), btComponent2.getId()).contains(result.get(1).getId())); + } + + @Test + void itShouldReturnEmptyListWhenNoBTComponentsFound() { + final String accessId = UUID.randomUUID().toString(); + + when(btComponentRepository.findBayTypicalComponentsByTypicalAccessId(accessId)) + .thenReturn(emptyList()); + + final List result = sut.getBTComponentsByBayTypicalAccessId(accessId); + + assertEquals(0, result.size()); + } +} \ No newline at end of file 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 95a51cc..db3aa9a 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 @@ -21,7 +21,6 @@ import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -60,7 +59,6 @@ public void itShouldReturnBayTypicals() { var res = sut.getAssignedBayTypicals(); assertEquals(2, res.size()); - assertTrue(res.containsAll(asList(bayTypical1, bayTypical2))); } @Test @@ -82,7 +80,6 @@ public void itShouldReturnMultipleBayTypicals() { var res = sut.getAssignedBayTypicals(); assertEquals(4, res.size()); - assertTrue(res.containsAll(asList(bayTypical1, bayTypical2, bayTypical3, bayTypical4))); } @Test diff --git a/service/src/test/java/org/lfenergy/compas/sitipe/service/ImportedComponentServiceTest.java b/service/src/test/java/org/lfenergy/compas/sitipe/service/ImportedComponentServiceTest.java new file mode 100644 index 0000000..e51dd5f --- /dev/null +++ b/service/src/test/java/org/lfenergy/compas/sitipe/service/ImportedComponentServiceTest.java @@ -0,0 +1,104 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.sitipe.service; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.lfenergy.compas.sitipe.data.entity.ImportedComponent; +import org.lfenergy.compas.sitipe.data.repository.ImportedComponentRepository; +import org.lfenergy.compas.sitipe.dto.ImportedComponentDTO; +import org.lfenergy.compas.sitipe.dto.ImportedDataDTO; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.UUID; +import java.util.zip.DeflaterOutputStream; + +import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class ImportedComponentServiceTest { + + + @Mock + private ImportedComponentRepository importedComponentRepository; + + private ImportedComponentService sut; + + @BeforeEach + void setUp() { + sut = new ImportedComponentService(importedComponentRepository); + } + + @Test + void itShouldReturnListOfImportedComponents() { + final ImportedComponent importedComponent1 = new ImportedComponent(); + importedComponent1.setId(1); + final ImportedComponent importedComponent2 = new ImportedComponent(); + importedComponent2.setId(2); + + final String accessId = UUID.randomUUID().toString(); + + when(importedComponentRepository.getByAccessId(accessId)) + .thenReturn(asList(importedComponent1, importedComponent2)); + + final List result = sut.getByAccessId(accessId); + + assertEquals(2, result.size()); + assertTrue(asList(importedComponent1.getId(), importedComponent2.getId()).contains(result.get(0).getId())); + assertTrue(asList(importedComponent1.getId(), importedComponent2.getId()).contains(result.get(1).getId())); + } + + @Test + void itShouldReturnEmptyListWhenNoImportedComponentsFound() { + final String accessId = UUID.randomUUID().toString(); + + when(importedComponentRepository.getByAccessId(accessId)) + .thenReturn(emptyList()); + + final List result = sut.getByAccessId(accessId); + + assertEquals(0, result.size()); + } + + @Test + void itShouldGetById() throws IOException { + final Integer id = 1; + final String data = "TEST DATA"; + ImportedComponent importedComponent = new ImportedComponent(); + importedComponent.setId(id); + importedComponent.setData(compress(data.getBytes(StandardCharsets.UTF_8))); + + when(importedComponentRepository.getById(id)) + .thenReturn(importedComponent); + + ImportedDataDTO result = sut.getImportedComponentData(id); + + assertEquals(data, result.getData()); + } + + @Test + void itShouldThrowErrorWhenImportedComponentNotFound() { + when(importedComponentRepository.getById(any())).thenReturn(null); + assertThrows(RuntimeException.class, () -> sut.getImportedComponentData(1)); + } + + private byte[] compress(byte[] bArray) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (DeflaterOutputStream dos = new DeflaterOutputStream(baos)) { + dos.write(bArray); + } + return baos.toByteArray(); + } +} \ No newline at end of file