From 8de91d4d57e0741fe8870f6884ef73928320cb38 Mon Sep 17 00:00:00 2001 From: Pascal Wilbrink Date: Tue, 4 Apr 2023 10:47:38 +0200 Subject: [PATCH 1/9] Added BT Component Endpoints + Imported BT Component Endpoint Signed-off-by: Pascal Wilbrink --- .../rest/v1/model/BayTypicalResponse.java | 100 ++++-------- .../sitipe/rest/v2/BTComponentResource.java | 52 +++++++ .../sitipe/rest/v2/BayTypicalResource.java | 28 ++-- .../main/resources/application-dev.properties | 2 +- app/src/main/resources/application.properties | 21 +-- .../sitipe/helper/CompressionUtils.java | 23 +++ .../compas/sitipe/helper/DatabaseCleaner.java | 10 ++ .../sitipe/helper/SystemVersionHelper.java | 72 ++++++++- .../rest/v1/model/BayTypicalResponseTest.java | 54 +++++++ .../rest/v2/BTComponentResourceTest.java | 104 +++++++++++++ .../rest/v2/BayTypicalResourceTest.java | 88 +++++++++-- postman/sitipe.postman_collection.json | 119 +++++++++++++-- .../sitipe/data/entity/BTComponent.java | 144 ++++++++++++++++++ .../sitipe/data/entity/ImportedComponent.java | 76 +++++++++ .../repository/BTComponentRepository.java | 15 ++ .../ImportedComponentRepository.java | 21 +++ .../repository/SystemVersionRepository.java | 6 - service/pom.xml | 6 + .../compas/sitipe/dto/BTComponentDTO.java | 88 +++++++++++ .../compas/sitipe/dto/BayTypicalDTO.java | 94 ++++++++++++ .../sitipe/dto/ImportedComponentDTO.java | 42 +++++ .../compas/sitipe/dto/ImportedDataDTO.java | 14 ++ .../sitipe/service/BTComponentService.java | 30 ++++ .../sitipe/service/BayTypicalService.java | 5 +- .../service/ImportedComponentService.java | 69 +++++++++ .../compas/sitipe/dto/BTComponentDTOTest.java | 47 ++++++ .../compas/sitipe/dto/BayTypicalDTOTest.java | 46 ++++++ .../sitipe/dto/ImportedComponentDTOTest.java | 32 ++++ .../service/BTComponentServiceTest.java | 67 ++++++++ .../sitipe/service/BayTypicalServiceTest.java | 3 - .../service/ImportedComponentServiceTest.java | 102 +++++++++++++ 31 files changed, 1441 insertions(+), 139 deletions(-) create mode 100644 app/src/main/java/org/lfenergy/compas/sitipe/rest/v2/BTComponentResource.java create mode 100644 app/src/test/java/org/lfenergy/compas/sitipe/helper/CompressionUtils.java create mode 100644 app/src/test/java/org/lfenergy/compas/sitipe/rest/v1/model/BayTypicalResponseTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/sitipe/rest/v2/BTComponentResourceTest.java create mode 100644 repository/src/main/java/org/lfenergy/compas/sitipe/data/entity/BTComponent.java create mode 100644 repository/src/main/java/org/lfenergy/compas/sitipe/data/entity/ImportedComponent.java create mode 100644 repository/src/main/java/org/lfenergy/compas/sitipe/data/repository/BTComponentRepository.java create mode 100644 repository/src/main/java/org/lfenergy/compas/sitipe/data/repository/ImportedComponentRepository.java create mode 100644 service/src/main/java/org/lfenergy/compas/sitipe/dto/BTComponentDTO.java create mode 100644 service/src/main/java/org/lfenergy/compas/sitipe/dto/BayTypicalDTO.java create mode 100644 service/src/main/java/org/lfenergy/compas/sitipe/dto/ImportedComponentDTO.java create mode 100644 service/src/main/java/org/lfenergy/compas/sitipe/dto/ImportedDataDTO.java create mode 100644 service/src/main/java/org/lfenergy/compas/sitipe/service/BTComponentService.java create mode 100644 service/src/main/java/org/lfenergy/compas/sitipe/service/ImportedComponentService.java create mode 100644 service/src/test/java/org/lfenergy/compas/sitipe/dto/BTComponentDTOTest.java create mode 100644 service/src/test/java/org/lfenergy/compas/sitipe/dto/BayTypicalDTOTest.java create mode 100644 service/src/test/java/org/lfenergy/compas/sitipe/dto/ImportedComponentDTOTest.java create mode 100644 service/src/test/java/org/lfenergy/compas/sitipe/service/BTComponentServiceTest.java create mode 100644 service/src/test/java/org/lfenergy/compas/sitipe/service/ImportedComponentServiceTest.java 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..ec2c030 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/sitipe/rest/v2/BTComponentResource.java @@ -0,0 +1,52 @@ +package org.lfenergy.compas.sitipe.rest.v2; + +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..0afc4da 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 @@ -4,39 +4,49 @@ 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.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; -@Authenticated +//@Authenticated @RequestScoped @Path("/v2/baytypicals") 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..5780752 100644 --- a/app/src/main/resources/application.properties +++ b/app/src/main/resources/application.properties @@ -5,10 +5,12 @@ compas.sitipe.framework-id=${SITIPE_FRAMEWORK_ID:cf3} sitipe.version=${SITIPE_VERSION:1.00} -quarkus.http.cors = false +quarkus.http.cors = true +quarkus.http.cors.origins = http://localhost:8081 quarkus.http.root-path = /compas-sitipe-service quarkus.http.limits.max-body-size = 150M quarkus.websocket.max-frame-size = 157286400 +quarkus.http.port = 1221 quarkus.log.level = INFO quarkus.log.category."org.lfenergy.compas.sitipe".level = INFO @@ -34,17 +36,17 @@ 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 +# 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.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.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 @@ -54,6 +56,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..8e1ebbf --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/sitipe/helper/CompressionUtils.java @@ -0,0 +1,23 @@ +package org.lfenergy.compas.sitipe.helper; + +import javax.enterprise.context.ApplicationScoped; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import java.util.zip.DeflaterOutputStream; +import java.util.zip.InflaterOutputStream; + +@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..87ddd0c 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,15 +5,27 @@ 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.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.nio.charset.StandardCharsets; import java.util.*; +import java.util.zip.Inflater; +import java.util.zip.InflaterInputStream; +import java.util.zip.InflaterOutputStream; import static java.util.Arrays.asList; @@ -24,17 +36,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 +86,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 +106,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 +119,45 @@ 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()); + + 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..80b91d3 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/sitipe/rest/v1/model/BayTypicalResponseTest.java @@ -0,0 +1,54 @@ +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 + public 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..93a36ec --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/sitipe/rest/v2/BTComponentResourceTest.java @@ -0,0 +1,104 @@ +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.BTComponent; +import org.lfenergy.compas.sitipe.data.entity.BayTypical; +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..acc0fdd 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,64 @@ 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 + public 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 + public 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 + public 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/postman/sitipe.postman_collection.json b/postman/sitipe.postman_collection.json index 1341e35..8a87279 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", + "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" } ] 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..e11454e --- /dev/null +++ b/repository/src/main/java/org/lfenergy/compas/sitipe/data/entity/BTComponent.java @@ -0,0 +1,144 @@ +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..a564345 --- /dev/null +++ b/repository/src/main/java/org/lfenergy/compas/sitipe/data/entity/ImportedComponent.java @@ -0,0 +1,76 @@ +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..f5478e3 --- /dev/null +++ b/repository/src/main/java/org/lfenergy/compas/sitipe/data/repository/BTComponentRepository.java @@ -0,0 +1,15 @@ +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/ImportedComponentRepository.java b/repository/src/main/java/org/lfenergy/compas/sitipe/data/repository/ImportedComponentRepository.java new file mode 100644 index 0000000..a990cdc --- /dev/null +++ b/repository/src/main/java/org/lfenergy/compas/sitipe/data/repository/ImportedComponentRepository.java @@ -0,0 +1,21 @@ +package org.lfenergy.compas.sitipe.data.repository; + +import io.quarkus.hibernate.orm.panache.PanacheRepository; +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 = 'IID'", accessId); + } + + 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..e61ef50 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 @@ -14,12 +14,6 @@ @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/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..45f3fdd --- /dev/null +++ b/service/src/main/java/org/lfenergy/compas/sitipe/dto/BTComponentDTO.java @@ -0,0 +1,88 @@ +package org.lfenergy.compas.sitipe.dto; + +import org.lfenergy.compas.sitipe.data.entity.BTComponent; + +import javax.persistence.Column; +import javax.persistence.Id; + +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..b78d7f0 --- /dev/null +++ b/service/src/main/java/org/lfenergy/compas/sitipe/dto/BayTypicalDTO.java @@ -0,0 +1,94 @@ +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..401c55d --- /dev/null +++ b/service/src/main/java/org/lfenergy/compas/sitipe/dto/ImportedComponentDTO.java @@ -0,0 +1,42 @@ +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..b774de9 --- /dev/null +++ b/service/src/main/java/org/lfenergy/compas/sitipe/dto/ImportedDataDTO.java @@ -0,0 +1,14 @@ +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..e25e3b2 --- /dev/null +++ b/service/src/main/java/org/lfenergy/compas/sitipe/service/BTComponentService.java @@ -0,0 +1,30 @@ +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; +import java.util.stream.Collectors; + +@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) + .collect(Collectors.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..c94ec06 --- /dev/null +++ b/service/src/main/java/org/lfenergy/compas/sitipe/service/ImportedComponentService.java @@ -0,0 +1,69 @@ +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.ByteArrayInputStream; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import java.util.zip.InflaterInputStream; + +@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) + .collect(Collectors.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))); + } + } catch (IOException e) { + throw new InternalServerErrorException(e); + } + + return new ImportedDataDTO(result.toString()); + } + + @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..99f9f47 --- /dev/null +++ b/service/src/test/java/org/lfenergy/compas/sitipe/dto/BTComponentDTOTest.java @@ -0,0 +1,47 @@ +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 + public 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..91d42f9 --- /dev/null +++ b/service/src/test/java/org/lfenergy/compas/sitipe/dto/BayTypicalDTOTest.java @@ -0,0 +1,46 @@ +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 + public 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..7c033d1 --- /dev/null +++ b/service/src/test/java/org/lfenergy/compas/sitipe/dto/ImportedComponentDTOTest.java @@ -0,0 +1,32 @@ +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 + public 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..6df0d89 --- /dev/null +++ b/service/src/test/java/org/lfenergy/compas/sitipe/service/BTComponentServiceTest.java @@ -0,0 +1,67 @@ +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 + public void setUp() { + sut = new BTComponentService(btComponentRepository); + } + + @Test + public 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 + public 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..b857af0 --- /dev/null +++ b/service/src/test/java/org/lfenergy/compas/sitipe/service/ImportedComponentServiceTest.java @@ -0,0 +1,102 @@ +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 javax.ws.rs.NotFoundException; +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 + public void setUp() { + sut = new ImportedComponentService(importedComponentRepository); + } + + @Test + public 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 + public 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 + public 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 + public 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 From a5981b132b4250feebffd95c9e62452bd09f4f32 Mon Sep 17 00:00:00 2001 From: Pascal Wilbrink Date: Mon, 17 Apr 2023 10:03:21 +0200 Subject: [PATCH 2/9] re-added Authorization headers. Added test for NamingStrategy Signed-off-by: Pascal Wilbrink --- .../sitipe/rest/v1/BayTypicalResource.java | 1 - .../sitipe/rest/v2/BTComponentResource.java | 3 +- .../sitipe/rest/v2/BayTypicalResource.java | 3 +- .../sitipe/helper/SystemVersionHelper.java | 1 + docker/docker-compose-m1.yml | 2 +- .../SitipeFrameworkIdNamingStrategyTest.java | 63 +++++++++++++++++++ 6 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 repository/src/test/java/org/lfenergy/compas/sitipe/data/table/SitipeFrameworkIdNamingStrategyTest.java 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/v2/BTComponentResource.java b/app/src/main/java/org/lfenergy/compas/sitipe/rest/v2/BTComponentResource.java index ec2c030..28449c2 100644 --- 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 @@ -1,5 +1,6 @@ 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; @@ -12,7 +13,7 @@ import javax.ws.rs.core.MediaType; import java.util.List; -//@Authenticated +@Authenticated @RequestScoped @Path("/v2/btcomponents") public class BTComponentResource { 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 0afc4da..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 @@ -4,6 +4,7 @@ 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.BTComponentDTO; @@ -17,7 +18,7 @@ import javax.ws.rs.core.MediaType; import java.util.List; -//@Authenticated +@Authenticated @RequestScoped @Path("/v2/baytypicals") public class BayTypicalResource { 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 87ddd0c..7ccd560 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 @@ -134,6 +134,7 @@ public BTComponent createAndStoreBTComponent(final Integer id, final BayTypical btComponent.setHasIecInformation(1); btComponent.setImportedOn(0L); btComponent.setReferenceAccessId(UUID.randomUUID().toString()); + btComponent.setComponentGuid(UUID.randomUUID().toString()); btComponentRepository.persistAndFlush(btComponent); 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/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..facddec --- /dev/null +++ b/repository/src/test/java/org/lfenergy/compas/sitipe/data/table/SitipeFrameworkIdNamingStrategyTest.java @@ -0,0 +1,63 @@ +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.eclipse.microprofile.config.spi.ConfigSource; +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 + public 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 + public void tearDown() { + ConfigProviderResolver.instance().releaseConfig(ConfigProvider.getConfig()); + } + + @Test + public 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 From b126359e6d15d857e4f757832c75d4274eeb0eb6 Mon Sep 17 00:00:00 2001 From: Pascal Wilbrink Date: Mon, 17 Apr 2023 10:09:08 +0200 Subject: [PATCH 3/9] re-added Authorization headers. Added Mock user for test Signed-off-by: Pascal Wilbrink --- .../lfenergy/compas/sitipe/rest/v2/BayTypicalResourceTest.java | 3 +++ 1 file changed, 3 insertions(+) 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 acc0fdd..5e8f221 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 @@ -112,6 +112,7 @@ void itShouldReturnEmptyListWhenNoBayTypicalsAreFound() { } @Test + @TestSecurity(user = "test-user", roles = {"USER"}) public void itShouldReturnBTComponentsForDigsiForBayTypicals() { final BayTypical bayTypical = systemVersionHelper.createAndStoreBayTypical(1); @@ -130,6 +131,7 @@ public void itShouldReturnBTComponentsForDigsiForBayTypicals() { assertEquals(btComponent1.getId(), ((ArrayList>)jsonPath.get()).get(0).get("id")); } @Test + @TestSecurity(user = "test-user", roles = {"USER"}) public void itShouldReturnEmptyListForBTComponentsWhenNoBayTypicalFound() { var response = given() .when().get("/{accessId}/components", UUID.randomUUID().toString()) @@ -143,6 +145,7 @@ public void itShouldReturnEmptyListForBTComponentsWhenNoBayTypicalFound() { } @Test + @TestSecurity(user = "test-user", roles = {"USER"}) public void itShouldReturnEmptyListForBTComponentsWhenNoComponentsFoundFound() { final BayTypical bayTypical = systemVersionHelper.createAndStoreBayTypical(1); From 99916a2a929d6aa03c6db30021cceecf4dfcc576 Mon Sep 17 00:00:00 2001 From: Pascal Wilbrink Date: Mon, 17 Apr 2023 10:31:12 +0200 Subject: [PATCH 4/9] Added SPDX headers. Added Mock user for test Signed-off-by: Pascal Wilbrink --- .../compas/sitipe/rest/v2/BTComponentResource.java | 4 ++++ .../lfenergy/compas/sitipe/helper/CompressionUtils.java | 8 ++++---- .../compas/sitipe/helper/SystemVersionHelper.java | 7 ------- .../sitipe/rest/v1/model/BayTypicalResponseTest.java | 4 ++++ .../compas/sitipe/rest/v2/BTComponentResourceTest.java | 6 ++++-- .../lfenergy/compas/sitipe/data/entity/BTComponent.java | 4 ++++ .../compas/sitipe/data/entity/ImportedComponent.java | 6 +++++- .../sitipe/data/repository/BTComponentRepository.java | 4 ++++ .../data/repository/ImportedComponentRepository.java | 5 ++++- .../org/lfenergy/compas/sitipe/dto/BTComponentDTO.java | 4 ++++ .../org/lfenergy/compas/sitipe/dto/BayTypicalDTO.java | 4 ++++ .../lfenergy/compas/sitipe/dto/ImportedComponentDTO.java | 5 ++++- .../org/lfenergy/compas/sitipe/dto/ImportedDataDTO.java | 4 ++++ .../compas/sitipe/service/BTComponentService.java | 4 ++++ .../compas/sitipe/service/ImportedComponentService.java | 4 ++++ .../lfenergy/compas/sitipe/dto/BTComponentDTOTest.java | 4 ++++ .../org/lfenergy/compas/sitipe/dto/BayTypicalDTOTest.java | 4 ++++ .../compas/sitipe/dto/ImportedComponentDTOTest.java | 4 ++++ .../compas/sitipe/service/BTComponentServiceTest.java | 4 ++++ .../sitipe/service/ImportedComponentServiceTest.java | 5 ++++- 20 files changed, 77 insertions(+), 17 deletions(-) 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 index 28449c2..b06b6e8 100644 --- 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 @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + package org.lfenergy.compas.sitipe.rest.v2; import io.quarkus.security.Authenticated; 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 index 8e1ebbf..0cd16ed 100644 --- a/app/src/test/java/org/lfenergy/compas/sitipe/helper/CompressionUtils.java +++ b/app/src/test/java/org/lfenergy/compas/sitipe/helper/CompressionUtils.java @@ -1,13 +1,13 @@ +// 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.io.OutputStream; -import java.nio.charset.StandardCharsets; -import java.util.Base64; import java.util.zip.DeflaterOutputStream; -import java.util.zip.InflaterOutputStream; @ApplicationScoped public class CompressionUtils { 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 7ccd560..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 @@ -17,15 +17,8 @@ import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; import javax.transaction.Transactional; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.ObjectOutputStream; -import java.nio.charset.StandardCharsets; import java.util.*; -import java.util.zip.Inflater; -import java.util.zip.InflaterInputStream; -import java.util.zip.InflaterOutputStream; import static java.util.Arrays.asList; 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 index 80b91d3..491edf8 100644 --- 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 @@ -1,3 +1,7 @@ +// 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; 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 index 93a36ec..b1d890f 100644 --- 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 @@ -1,3 +1,7 @@ +// 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; @@ -6,8 +10,6 @@ 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.BTComponent; -import org.lfenergy.compas.sitipe.data.entity.BayTypical; import org.lfenergy.compas.sitipe.data.entity.ImportedComponent; import org.lfenergy.compas.sitipe.helper.SystemVersionHelper; 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 index e11454e..1bd9f9d 100644 --- 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 @@ -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; 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 index a564345..4a7e3e9 100644 --- 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 @@ -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.*; @@ -13,7 +17,7 @@ public class ImportedComponent { private String type; @Column(name = "data") - // @Basic(fetch = FetchType.LAZY) + @Basic(fetch = FetchType.LAZY) @Lob private byte[] data; 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 index f5478e3..8fb42d7 100644 --- 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 @@ -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/repository/ImportedComponentRepository.java b/repository/src/main/java/org/lfenergy/compas/sitipe/data/repository/ImportedComponentRepository.java index a990cdc..9bc2825 100644 --- 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 @@ -1,6 +1,9 @@ +// 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 io.quarkus.hibernate.orm.panache.PanacheRepositoryBase; import org.lfenergy.compas.sitipe.data.entity.ImportedComponent; 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 index 45f3fdd..d5074cc 100644 --- a/service/src/main/java/org/lfenergy/compas/sitipe/dto/BTComponentDTO.java +++ b/service/src/main/java/org/lfenergy/compas/sitipe/dto/BTComponentDTO.java @@ -1,3 +1,7 @@ +// 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; 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 index b78d7f0..ec19ea1 100644 --- a/service/src/main/java/org/lfenergy/compas/sitipe/dto/BayTypicalDTO.java +++ b/service/src/main/java/org/lfenergy/compas/sitipe/dto/BayTypicalDTO.java @@ -1,3 +1,7 @@ +// 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; 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 index 401c55d..b2a83c4 100644 --- a/service/src/main/java/org/lfenergy/compas/sitipe/dto/ImportedComponentDTO.java +++ b/service/src/main/java/org/lfenergy/compas/sitipe/dto/ImportedComponentDTO.java @@ -1,8 +1,11 @@ +// 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; 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 index b774de9..3998b15 100644 --- a/service/src/main/java/org/lfenergy/compas/sitipe/dto/ImportedDataDTO.java +++ b/service/src/main/java/org/lfenergy/compas/sitipe/dto/ImportedDataDTO.java @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + package org.lfenergy.compas.sitipe.dto; public class ImportedDataDTO { 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 index e25e3b2..8d58ff9 100644 --- a/service/src/main/java/org/lfenergy/compas/sitipe/service/BTComponentService.java +++ b/service/src/main/java/org/lfenergy/compas/sitipe/service/BTComponentService.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.data.repository.BTComponentRepository; 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 index c94ec06..44e10a7 100644 --- a/service/src/main/java/org/lfenergy/compas/sitipe/service/ImportedComponentService.java +++ b/service/src/main/java/org/lfenergy/compas/sitipe/service/ImportedComponentService.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.data.entity.ImportedComponent; 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 index 99f9f47..1536587 100644 --- a/service/src/test/java/org/lfenergy/compas/sitipe/dto/BTComponentDTOTest.java +++ b/service/src/test/java/org/lfenergy/compas/sitipe/dto/BTComponentDTOTest.java @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + package org.lfenergy.compas.sitipe.dto; import org.junit.jupiter.api.Test; 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 index 91d42f9..674b0b0 100644 --- a/service/src/test/java/org/lfenergy/compas/sitipe/dto/BayTypicalDTOTest.java +++ b/service/src/test/java/org/lfenergy/compas/sitipe/dto/BayTypicalDTOTest.java @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + package org.lfenergy.compas.sitipe.dto; import org.junit.jupiter.api.Test; 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 index 7c033d1..695bde6 100644 --- a/service/src/test/java/org/lfenergy/compas/sitipe/dto/ImportedComponentDTOTest.java +++ b/service/src/test/java/org/lfenergy/compas/sitipe/dto/ImportedComponentDTOTest.java @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + package org.lfenergy.compas.sitipe.dto; import org.junit.jupiter.api.Test; 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 index 6df0d89..04d3aa2 100644 --- a/service/src/test/java/org/lfenergy/compas/sitipe/service/BTComponentServiceTest.java +++ b/service/src/test/java/org/lfenergy/compas/sitipe/service/BTComponentServiceTest.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; 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 index b857af0..ecb6c49 100644 --- a/service/src/test/java/org/lfenergy/compas/sitipe/service/ImportedComponentServiceTest.java +++ b/service/src/test/java/org/lfenergy/compas/sitipe/service/ImportedComponentServiceTest.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; @@ -10,7 +14,6 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import javax.ws.rs.NotFoundException; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; From f4da177f5e9b959105675b420a5a004fe054b41e Mon Sep 17 00:00:00 2001 From: Pascal Wilbrink Date: Mon, 17 Apr 2023 10:49:16 +0200 Subject: [PATCH 5/9] Added SPDX headers. Sonarcloud fix Signed-off-by: Pascal Wilbrink --- .../compas/sitipe/rest/v2/BayTypicalResourceTest.java | 6 +++--- .../data/repository/SystemVersionRepository.java | 1 - .../table/SitipeFrameworkIdNamingStrategyTest.java | 11 +++++++---- .../lfenergy/compas/sitipe/dto/BTComponentDTO.java | 3 --- .../compas/sitipe/service/BTComponentService.java | 2 +- .../sitipe/service/ImportedComponentService.java | 2 +- .../compas/sitipe/dto/BTComponentDTOTest.java | 2 +- .../lfenergy/compas/sitipe/dto/BayTypicalDTOTest.java | 2 +- .../compas/sitipe/dto/ImportedComponentDTOTest.java | 2 +- .../compas/sitipe/service/BTComponentServiceTest.java | 8 +++----- .../sitipe/service/ImportedComponentServiceTest.java | 10 +++++----- 11 files changed, 23 insertions(+), 26 deletions(-) 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 5e8f221..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 @@ -113,7 +113,7 @@ void itShouldReturnEmptyListWhenNoBayTypicalsAreFound() { @Test @TestSecurity(user = "test-user", roles = {"USER"}) - public void itShouldReturnBTComponentsForDigsiForBayTypicals() { + void itShouldReturnBTComponentsForDigsiForBayTypicals() { final BayTypical bayTypical = systemVersionHelper.createAndStoreBayTypical(1); final BTComponent btComponent1 = systemVersionHelper.createAndStoreBTComponent(2, bayTypical, "DIGSI 5"); @@ -132,7 +132,7 @@ public void itShouldReturnBTComponentsForDigsiForBayTypicals() { } @Test @TestSecurity(user = "test-user", roles = {"USER"}) - public void itShouldReturnEmptyListForBTComponentsWhenNoBayTypicalFound() { + void itShouldReturnEmptyListForBTComponentsWhenNoBayTypicalFound() { var response = given() .when().get("/{accessId}/components", UUID.randomUUID().toString()) .then() @@ -146,7 +146,7 @@ public void itShouldReturnEmptyListForBTComponentsWhenNoBayTypicalFound() { @Test @TestSecurity(user = "test-user", roles = {"USER"}) - public void itShouldReturnEmptyListForBTComponentsWhenNoComponentsFoundFound() { + void itShouldReturnEmptyListForBTComponentsWhenNoComponentsFoundFound() { final BayTypical bayTypical = systemVersionHelper.createAndStoreBayTypical(1); final BTComponent btComponent1 = systemVersionHelper.createAndStoreBTComponent(2, bayTypical, "DIGSI 6"); 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 e61ef50..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,7 +8,6 @@ import org.lfenergy.compas.sitipe.data.entity.SystemVersion; import javax.enterprise.context.ApplicationScoped; -import javax.sql.DataSource; import java.util.List; @ApplicationScoped 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 index facddec..d0fc769 100644 --- 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 @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + package org.lfenergy.compas.sitipe.data.table; import io.smallrye.config.ConfigValuePropertiesConfigSource; @@ -5,7 +9,6 @@ import io.smallrye.config.SmallRyeConfigBuilder; import org.eclipse.microprofile.config.ConfigProvider; import org.eclipse.microprofile.config.spi.ConfigProviderResolver; -import org.eclipse.microprofile.config.spi.ConfigSource; import org.hibernate.boot.model.naming.Identifier; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.junit.jupiter.api.AfterEach; @@ -29,7 +32,7 @@ class SitipeFrameworkIdNamingStrategyTest { private final String frameworkId = "123"; @BeforeEach - public void setUp() { + void setUp() { final Map configMap = new HashMap<>(); configMap.put("compas.sitipe.framework-id", frameworkId); @@ -42,12 +45,12 @@ public void setUp() { } @AfterEach - public void tearDown() { + void tearDown() { ConfigProviderResolver.instance().releaseConfig(ConfigProvider.getConfig()); } @Test - public void itShouldSetCorrectNamingWhenHasFrameworkId() { + void itShouldSetCorrectNamingWhenHasFrameworkId() { final String tableName = "TABLE"; final Identifier identifier = mock(Identifier.class); 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 index d5074cc..fa63773 100644 --- a/service/src/main/java/org/lfenergy/compas/sitipe/dto/BTComponentDTO.java +++ b/service/src/main/java/org/lfenergy/compas/sitipe/dto/BTComponentDTO.java @@ -6,9 +6,6 @@ import org.lfenergy.compas.sitipe.data.entity.BTComponent; -import javax.persistence.Column; -import javax.persistence.Id; - public class BTComponentDTO { private final Integer id; 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 index 8d58ff9..63d9fcb 100644 --- a/service/src/main/java/org/lfenergy/compas/sitipe/service/BTComponentService.java +++ b/service/src/main/java/org/lfenergy/compas/sitipe/service/BTComponentService.java @@ -28,7 +28,7 @@ public List getBTComponentsByBayTypicalAccessId(final String acc return btComponentRepository.findBayTypicalComponentsByTypicalAccessId(accessId) .stream() .map(BTComponentDTO::new) - .collect(Collectors.toList()); + .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 index 44e10a7..f6f4990 100644 --- a/service/src/main/java/org/lfenergy/compas/sitipe/service/ImportedComponentService.java +++ b/service/src/main/java/org/lfenergy/compas/sitipe/service/ImportedComponentService.java @@ -37,7 +37,7 @@ public List getByAccessId(final String accessId) { return importedComponentRepository.getByAccessId(accessId) .stream() .map(ImportedComponentDTO::new) - .collect(Collectors.toList()); + .toList(); } public ImportedDataDTO getImportedComponentData(final Integer 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 index 1536587..971dcea 100644 --- a/service/src/test/java/org/lfenergy/compas/sitipe/dto/BTComponentDTOTest.java +++ b/service/src/test/java/org/lfenergy/compas/sitipe/dto/BTComponentDTOTest.java @@ -17,7 +17,7 @@ class BTComponentDTOTest { @Test - public void itShouldMapProperties() { + void itShouldMapProperties() { final BTComponent entity = new BTComponent(); entity.setId(1); 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 index 674b0b0..716cb5b 100644 --- a/service/src/test/java/org/lfenergy/compas/sitipe/dto/BayTypicalDTOTest.java +++ b/service/src/test/java/org/lfenergy/compas/sitipe/dto/BayTypicalDTOTest.java @@ -17,7 +17,7 @@ class BayTypicalDTOTest { @Test - public void itShouldMapProperties() { + void itShouldMapProperties() { final BayTypical entity = new BayTypical(); entity.setId(1); entity.setDescription("DESCRIPTION"); 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 index 695bde6..7b3275b 100644 --- a/service/src/test/java/org/lfenergy/compas/sitipe/dto/ImportedComponentDTOTest.java +++ b/service/src/test/java/org/lfenergy/compas/sitipe/dto/ImportedComponentDTOTest.java @@ -17,7 +17,7 @@ class ImportedComponentDTOTest { @Test - public void itShouldMapProperties() { + void itShouldMapProperties() { final ImportedComponent entity = new ImportedComponent(); entity.setId(1); entity.setType("TYPE"); 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 index 04d3aa2..8c304ca 100644 --- a/service/src/test/java/org/lfenergy/compas/sitipe/service/BTComponentServiceTest.java +++ b/service/src/test/java/org/lfenergy/compas/sitipe/service/BTComponentServiceTest.java @@ -30,15 +30,13 @@ class BTComponentServiceTest { private BTComponentService sut; - - @BeforeEach - public void setUp() { + void setUp() { sut = new BTComponentService(btComponentRepository); } @Test - public void itShouldReturnListOfBTComponents() { + void itShouldReturnListOfBTComponents() { final BTComponent btComponent1 = new BTComponent(); btComponent1.setId(1); @@ -58,7 +56,7 @@ public void itShouldReturnListOfBTComponents() { } @Test - public void itShouldReturnEmptyListWhenNoBTComponentsFound() { + void itShouldReturnEmptyListWhenNoBTComponentsFound() { final String accessId = UUID.randomUUID().toString(); when(btComponentRepository.findBayTypicalComponentsByTypicalAccessId(accessId)) 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 index ecb6c49..e841529 100644 --- a/service/src/test/java/org/lfenergy/compas/sitipe/service/ImportedComponentServiceTest.java +++ b/service/src/test/java/org/lfenergy/compas/sitipe/service/ImportedComponentServiceTest.java @@ -38,12 +38,12 @@ class ImportedComponentServiceTest { private ImportedComponentService sut; @BeforeEach - public void setUp() { + void setUp() { sut = new ImportedComponentService(importedComponentRepository); } @Test - public void itShouldReturnListOfImportedComponents() { + void itShouldReturnListOfImportedComponents() { final ImportedComponent importedComponent1 = new ImportedComponent(); importedComponent1.setId(1); final ImportedComponent importedComponent2 = new ImportedComponent(); @@ -62,7 +62,7 @@ public void itShouldReturnListOfImportedComponents() { } @Test - public void itShouldReturnEmptyListWhenNoImportedComponentsFound() { + void itShouldReturnEmptyListWhenNoImportedComponentsFound() { final String accessId = UUID.randomUUID().toString(); when(importedComponentRepository.getByAccessId(accessId)) @@ -74,7 +74,7 @@ public void itShouldReturnEmptyListWhenNoImportedComponentsFound() { } @Test - public void itShouldGetById() throws IOException { + void itShouldGetById() throws IOException { final Integer id = 1; final String data = "TEST DATA"; ImportedComponent importedComponent = new ImportedComponent(); @@ -90,7 +90,7 @@ public void itShouldGetById() throws IOException { } @Test - public void itShouldThrowErrorWhenImportedComponentNotFound() { + void itShouldThrowErrorWhenImportedComponentNotFound() { when(importedComponentRepository.getById(any())).thenReturn(null); assertThrows(RuntimeException.class, () -> sut.getImportedComponentData(1)); } From bd0881caeb869fb5d8468c6cb6158eb6ad2feb55 Mon Sep 17 00:00:00 2001 From: Pascal Wilbrink Date: Mon, 17 Apr 2023 12:04:46 +0200 Subject: [PATCH 6/9] Added unit tests for repository Signed-off-by: Pascal Wilbrink --- .../rest/v1/model/BayTypicalResponseTest.java | 2 +- repository/pom.xml | 5 ++ .../data/repository/BayTypicalRepository.java | 3 - .../ImportedComponentRepository.java | 2 +- .../sitipe/data/entity/BTComponentTest.java | 14 ++++ .../sitipe/data/entity/BaseEntityTest.java | 34 +++++++++ .../sitipe/data/entity/BayTypicalTest.java | 14 ++++ .../data/entity/ImportedComponentTest.java | 14 ++++ .../sitipe/data/entity/SystemVersionTest.java | 14 ++++ .../repository/BTComponentRepositoryTest.java | 51 ++++++++++++++ .../repository/BayTypicalRepositoryTest.java | 46 +++++++++++++ .../ImportedComponentRepositoryTest.java | 69 +++++++++++++++++++ .../sitipe/service/BTComponentService.java | 1 - .../service/ImportedComponentService.java | 1 - .../service/ImportedComponentServiceTest.java | 1 - 15 files changed, 263 insertions(+), 8 deletions(-) create mode 100644 repository/src/test/java/org/lfenergy/compas/sitipe/data/entity/BTComponentTest.java create mode 100644 repository/src/test/java/org/lfenergy/compas/sitipe/data/entity/BaseEntityTest.java create mode 100644 repository/src/test/java/org/lfenergy/compas/sitipe/data/entity/BayTypicalTest.java create mode 100644 repository/src/test/java/org/lfenergy/compas/sitipe/data/entity/ImportedComponentTest.java create mode 100644 repository/src/test/java/org/lfenergy/compas/sitipe/data/entity/SystemVersionTest.java create mode 100644 repository/src/test/java/org/lfenergy/compas/sitipe/data/repository/BTComponentRepositoryTest.java create mode 100644 repository/src/test/java/org/lfenergy/compas/sitipe/data/repository/BayTypicalRepositoryTest.java create mode 100644 repository/src/test/java/org/lfenergy/compas/sitipe/data/repository/ImportedComponentRepositoryTest.java 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 index 491edf8..ea31c1c 100644 --- 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 @@ -19,7 +19,7 @@ class BayTypicalResponseTest { @Test - public void itShouldMapProperties() { + void itShouldMapProperties() { final BayTypical entity = new BayTypical(); entity.setId(1); 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/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 index 9bc2825..d290b1b 100644 --- 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 @@ -15,7 +15,7 @@ public class ImportedComponentRepository implements PanacheRepositoryBase { public List getByAccessId(final String accessId) { - return this.list("componentAccessId = ?1 AND type = 'IID'", accessId); + return this.list("componentAccessId = ?1 AND type = ?2", accessId, "IID"); } public ImportedComponent getById(final Integer id) { 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/service/src/main/java/org/lfenergy/compas/sitipe/service/BTComponentService.java b/service/src/main/java/org/lfenergy/compas/sitipe/service/BTComponentService.java index 63d9fcb..fb1fad9 100644 --- a/service/src/main/java/org/lfenergy/compas/sitipe/service/BTComponentService.java +++ b/service/src/main/java/org/lfenergy/compas/sitipe/service/BTComponentService.java @@ -10,7 +10,6 @@ import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; import java.util.List; -import java.util.stream.Collectors; @ApplicationScoped public class BTComponentService { 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 index f6f4990..2fb79d8 100644 --- a/service/src/main/java/org/lfenergy/compas/sitipe/service/ImportedComponentService.java +++ b/service/src/main/java/org/lfenergy/compas/sitipe/service/ImportedComponentService.java @@ -18,7 +18,6 @@ import java.io.IOException; import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; import java.util.zip.InflaterInputStream; @ApplicationScoped 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 index e841529..e51dd5f 100644 --- a/service/src/test/java/org/lfenergy/compas/sitipe/service/ImportedComponentServiceTest.java +++ b/service/src/test/java/org/lfenergy/compas/sitipe/service/ImportedComponentServiceTest.java @@ -27,7 +27,6 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; - @ExtendWith(MockitoExtension.class) class ImportedComponentServiceTest { From 1eee238dece9fe345ae7cf76b6d84b96b97b8d3e Mon Sep 17 00:00:00 2001 From: Pascal Wilbrink Date: Mon, 24 Apr 2023 09:43:18 +0200 Subject: [PATCH 7/9] Fixed character encoding for special characters (for example the degree sign) Signed-off-by: Pascal Wilbrink --- .../sitipe/rest/v2/BTComponentResource.java | 2 +- .../sitipe/rest/v2/BayTypicalResource.java | 2 +- .../sitipe/service/ImportedComponentService.java | 16 ++++++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) 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 index b06b6e8..bab8abb 100644 --- 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 @@ -17,7 +17,7 @@ import javax.ws.rs.core.MediaType; import java.util.List; -@Authenticated +//@Authenticated @RequestScoped @Path("/v2/btcomponents") public class BTComponentResource { 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 fbef764..29e7711 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 @@ -18,7 +18,7 @@ import javax.ws.rs.core.MediaType; import java.util.List; -@Authenticated +//@Authenticated @RequestScoped @Path("/v2/baytypicals") public class BayTypicalResource { 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 index 2fb79d8..69ff166 100644 --- a/service/src/main/java/org/lfenergy/compas/sitipe/service/ImportedComponentService.java +++ b/service/src/main/java/org/lfenergy/compas/sitipe/service/ImportedComponentService.java @@ -14,11 +14,14 @@ import javax.transaction.Transactional; import javax.ws.rs.InternalServerErrorException; import javax.ws.rs.NotFoundException; -import java.io.ByteArrayInputStream; -import java.io.IOException; +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 { @@ -56,13 +59,18 @@ public ImportedDataDTO getImportedComponentData(final Integer id) { try { while ((rlen = iis.read(buffer)) != -1) { - result.append(new String(Arrays.copyOf(buffer, rlen))); + result.append(new String(Arrays.copyOf(buffer, rlen), StandardCharsets.ISO_8859_1)); } } catch (IOException e) { throw new InternalServerErrorException(e); } - return new ImportedDataDTO(result.toString()); + return new ImportedDataDTO( + new String(result.toString().getBytes(), StandardCharsets.UTF_8) + .replaceAll("[^\\x00-\\x7F]", "") + ); + + } @Transactional From 2a935d97bf4f8329888064b36a73dc9231846683 Mon Sep 17 00:00:00 2001 From: Pascal Wilbrink Date: Mon, 1 May 2023 10:16:43 +0200 Subject: [PATCH 8/9] re-added authentication filters Signed-off-by: Pascal Wilbrink --- .../sitipe/rest/v2/BTComponentResource.java | 2 +- .../sitipe/rest/v2/BayTypicalResource.java | 2 +- app/src/main/resources/application.properties | 18 ++++++++---------- 3 files changed, 10 insertions(+), 12 deletions(-) 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 index bab8abb..b06b6e8 100644 --- 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 @@ -17,7 +17,7 @@ import javax.ws.rs.core.MediaType; import java.util.List; -//@Authenticated +@Authenticated @RequestScoped @Path("/v2/btcomponents") public class BTComponentResource { 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 29e7711..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 @@ -18,7 +18,7 @@ import javax.ws.rs.core.MediaType; import java.util.List; -//@Authenticated +@Authenticated @RequestScoped @Path("/v2/baytypicals") public class BayTypicalResource { diff --git a/app/src/main/resources/application.properties b/app/src/main/resources/application.properties index 5780752..d6cc94b 100644 --- a/app/src/main/resources/application.properties +++ b/app/src/main/resources/application.properties @@ -5,12 +5,10 @@ compas.sitipe.framework-id=${SITIPE_FRAMEWORK_ID:cf3} sitipe.version=${SITIPE_VERSION:1.00} -quarkus.http.cors = true -quarkus.http.cors.origins = http://localhost:8081 +quarkus.http.cors = false quarkus.http.root-path = /compas-sitipe-service quarkus.http.limits.max-body-size = 150M quarkus.websocket.max-frame-size = 157286400 -quarkus.http.port = 1221 quarkus.log.level = INFO quarkus.log.category."org.lfenergy.compas.sitipe".level = INFO @@ -38,15 +36,15 @@ smallrye.jwt.path.groups = ${JWT_GROUPS_PATH:resource_access/sitipe-serv quarkus.http.auth.permission.deny-default.paths=/* 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 +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.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.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 From 0548672c2407460b919660572d1f535dc43605ce Mon Sep 17 00:00:00 2001 From: Pascal Wilbrink Date: Tue, 9 May 2023 13:20:05 +0200 Subject: [PATCH 9/9] Update sitipe.postman_collection.json Added /imported to the url Signed-off-by: Pascal Wilbrink --- postman/sitipe.postman_collection.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/postman/sitipe.postman_collection.json b/postman/sitipe.postman_collection.json index 8a87279..b3931d8 100644 --- a/postman/sitipe.postman_collection.json +++ b/postman/sitipe.postman_collection.json @@ -89,7 +89,7 @@ "method": "GET", "header": [], "url": { - "raw": "{{sitpeServiceBaseUrl}}/v2/btcomponents/:accessId", + "raw": "{{sitpeServiceBaseUrl}}/v2/btcomponents/:accessId/imported", "host": [ "{{sitpeServiceBaseUrl}}" ], @@ -176,4 +176,4 @@ "type": "default" } ] -} \ No newline at end of file +}