From a0641d1b4d154443548eb2129e49979a9e7badb5 Mon Sep 17 00:00:00 2001 From: "USERSAD\\evalenti" Date: Wed, 8 Nov 2023 11:22:44 +0100 Subject: [PATCH 1/9] Deploy WorkflowResource and refinements --- .../model/repository/BpmnBankConfigRepository.java | 2 +- .../model/resource/WorkflowResourceResource.java | 13 +++++++++++++ .../model/service/impl/BpmnBankConfigService.java | 4 +--- .../service/impl/WorkflowResourceServiceImpl.java | 6 +++--- .../impl/WorkflowResourceStorageServiceImpl.java | 1 - .../service/impl/BpmnBankConfigServiceImplTest.java | 6 +++--- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/repository/BpmnBankConfigRepository.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/repository/BpmnBankConfigRepository.java index ed29c101..2b20828f 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/repository/BpmnBankConfigRepository.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/repository/BpmnBankConfigRepository.java @@ -29,7 +29,7 @@ public Uni> findByAcquirerIdAndFunctionType(String acquirer return list("select b from BpmnBankConfig b where b.bpmnBankConfigPK.acquirerId = :acquirerId and b.functionType= :functionType", params); } - public Uni> findByTriadAndFunctionType(String acquirerId, String branchId, String terminalId, FunctionTypeEnum functionType) { + public Uni> findByConfigAndFunctionType(String acquirerId, String branchId, String terminalId, FunctionTypeEnum functionType) { Map params = new HashMap<>(); params.put("acquirerId", acquirerId); params.put("branchId", branchId); diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/resource/WorkflowResourceResource.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/resource/WorkflowResourceResource.java index 66221ff9..1f6a15b4 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/resource/WorkflowResourceResource.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/resource/WorkflowResourceResource.java @@ -3,8 +3,10 @@ import io.smallrye.common.annotation.NonBlocking; import io.smallrye.mutiny.Uni; import it.gov.pagopa.atmlayer.service.model.dto.WorkflowResourceCreationDto; +import it.gov.pagopa.atmlayer.service.model.entity.BpmnVersionPK; import it.gov.pagopa.atmlayer.service.model.entity.WorkflowResource; import it.gov.pagopa.atmlayer.service.model.mapper.WorkflowResourceMapper; +import it.gov.pagopa.atmlayer.service.model.model.BpmnDTO; import it.gov.pagopa.atmlayer.service.model.model.WorkflowResourceDTO; import it.gov.pagopa.atmlayer.service.model.service.WorkflowResourceService; import jakarta.enterprise.context.ApplicationScoped; @@ -13,6 +15,7 @@ import jakarta.ws.rs.Consumes; import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; import lombok.extern.slf4j.Slf4j; @@ -21,6 +24,7 @@ import java.io.IOException; import java.security.NoSuchAlgorithmException; +import java.util.UUID; @ApplicationScoped @Path("/workflow-resource") @@ -43,4 +47,13 @@ public Uni createWorkflowResource(@RequestBody(required = t return this.workflowResourceService.createWorkflowResource(workflowResource, workflowResourceCreationDto.getFile(), workflowResourceCreationDto.getFilename()) .onItem().transformToUni(bpmn -> Uni.createFrom().item(this.workflowResourceMapper.toDTO(bpmn))); } + + @POST + @Path("/deploy/{uuid}") + @Produces(MediaType.APPLICATION_JSON) + public Uni deployBPMN(@PathParam("uuid") UUID uuid) { + + return this.workflowResourceService.deploy(uuid) + .onItem().transformToUni(workflow -> Uni.createFrom().item(this.workflowResourceMapper.toDTO(workflow))); + } } diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnBankConfigService.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnBankConfigService.java index 71d8b675..92e05ed0 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnBankConfigService.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnBankConfigService.java @@ -14,8 +14,6 @@ import jakarta.inject.Inject; import jakarta.ws.rs.core.Response; -import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -43,7 +41,7 @@ public Uni deleteByAcquirerIdAndFunctionType(String acquirerId, FunctionTy } public Uni> findByConfigurationsAndFunction(String acquirerId, String branchId, String terminalId, FunctionTypeEnum functionTypeEnum) { - return this.bankConfigRepository.findByTriadAndFunctionType(acquirerId, branchId, terminalId, functionTypeEnum) + return this.bankConfigRepository.findByConfigAndFunctionType(acquirerId, branchId, terminalId, functionTypeEnum) .onItem().transformToUni(Unchecked.function(x -> { if (!x.isEmpty() && x.size() > 1) { throw new AtmLayerException("Multiple BPMN found for a single configuration.", Response.Status.INTERNAL_SERVER_ERROR, AppErrorCodeEnum.ATMLM_500); diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java index 53351e8b..b6d87753 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java @@ -135,15 +135,15 @@ public Uni deploy(UUID uuid) { .onItem() .transformToUni(Unchecked.function(x -> { if (!x) { - String errorMessage = "The referenced BPMN file can not be deployed"; + String errorMessage = "The referenced Workflow Resource file can not be deployed"; throw new AtmLayerException(errorMessage, Response.Status.BAD_REQUEST, AppErrorCodeEnum.BPMN_FILE_CANNOT_BE_DEPLOYED); } return this.setWorkflowResourceVersionStatus(uuid, StatusEnum.WAITING_DEPLOY); })) .onItem() - .transformToUni(bpmnWaiting -> { - ResourceFile resourceFile = bpmnWaiting.getResourceFile(); + .transformToUni(workflowWaiting -> { + ResourceFile resourceFile = workflowWaiting.getResourceFile(); if (Objects.isNull(resourceFile) || StringUtils.isBlank(resourceFile.getStorageKey())) { String errorMessage = String.format("No file associated to Workflow Resource or no storage key found: %s", uuid); log.error(errorMessage); diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceStorageServiceImpl.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceStorageServiceImpl.java index a66ac3e3..64c8396a 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceStorageServiceImpl.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceStorageServiceImpl.java @@ -89,7 +89,6 @@ public RestMulti download(String storageKey) { return this.objectStoreService.download(storageKey); } - //TODO: fix {$RESOURCE_TYPE} private String calculatePath(UUID uuid, ResourceTypeEnum resourceType) { Map valuesMap = new HashMap<>(); valuesMap.put("uuid", uuid.toString()); diff --git a/src/test/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnBankConfigServiceImplTest.java b/src/test/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnBankConfigServiceImplTest.java index 60449395..9921dd46 100644 --- a/src/test/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnBankConfigServiceImplTest.java +++ b/src/test/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnBankConfigServiceImplTest.java @@ -101,7 +101,7 @@ public void testFindByConfigurationsAndFunction() { List mockResult = Collections.singletonList(bpmnBankConfig); - when(bankConfigRepository.findByTriadAndFunctionType(acquirerId, branchId, terminalId, functionType)) + when(bankConfigRepository.findByConfigAndFunctionType(acquirerId, branchId, terminalId, functionType)) .thenReturn(Uni.createFrom().item(mockResult)); Uni> result = bankConfigService.findByConfigurationsAndFunction(acquirerId, branchId, terminalId, functionType); @@ -125,7 +125,7 @@ public void testFindByConfigurationsAndFunctionWithEmptyList() { String terminalId = "terminal1"; FunctionTypeEnum functionType = FunctionTypeEnum.MENU; - when(bankConfigRepository.findByTriadAndFunctionType(acquirerId, branchId, terminalId, functionType)) + when(bankConfigRepository.findByConfigAndFunctionType(acquirerId, branchId, terminalId, functionType)) .thenReturn(Uni.createFrom().item(Collections.emptyList())); Uni> result = bankConfigService.findByConfigurationsAndFunction(acquirerId, branchId, terminalId, functionType); @@ -147,7 +147,7 @@ public void testFindByConfigurationsAndFunctionWithMultipleResults() { BpmnBankConfig config2 = new BpmnBankConfig(); List mockResult = List.of(config1, config2); - when(bankConfigRepository.findByTriadAndFunctionType(acquirerId, branchId, terminalId, functionType)) + when(bankConfigRepository.findByConfigAndFunctionType(acquirerId, branchId, terminalId, functionType)) .thenReturn(Uni.createFrom().item(mockResult)); // Modifica il test per catturare l'eccezione AtmLayerException From 8e04459a48eab2e18d2271c7e267a3bc0d1c4399 Mon Sep 17 00:00:00 2001 From: "USERSAD\\evalenti" Date: Wed, 8 Nov 2023 12:12:56 +0100 Subject: [PATCH 2/9] Refactor WorkflowResourceEnum --- .../service/model/dto/ResourceCreationDto.java | 4 ++-- .../model/dto/WorkflowResourceCreationDto.java | 9 ++------- .../service/model/entity/ResourceEntity.java | 6 ++---- .../service/model/entity/ResourceFile.java | 4 ++-- .../service/model/entity/WorkflowResource.java | 10 ++-------- ...TypeEnum.java => WorkflowResourceTypeEnum.java} | 3 +-- .../service/model/mapper/BpmnVersionMapper.java | 6 +++--- .../service/model/mapper/ResourceEntityMapper.java | 3 +-- .../model/mapper/WorkflowResourceMapper.java | 2 -- .../service/model/model/ResourceEntityDTO.java | 8 ++------ .../service/model/model/ResourceFileDTO.java | 4 ++-- .../service/model/service/ObjectStoreService.java | 5 ++--- .../service/impl/BpmnFileStorageServiceImpl.java | 8 ++++---- .../model/service/impl/BpmnVersionServiceImpl.java | 4 ++-- .../service/impl/S3ObjectStoreServiceImpl.java | 4 ++-- .../service/impl/WorkflowResourceServiceImpl.java | 9 +++------ .../impl/WorkflowResourceStorageServiceImpl.java | 14 ++++++-------- .../service/model/utils/BpmnDtoMapper.java | 4 ---- .../atmlayer/service/model/utils/FileUtils.java | 12 +++++------- .../service/impl/BpmnVersionServiceImplTest.java | 12 +++++------- .../service/impl/ResourceFileServiceImplTest.java | 6 ++---- 21 files changed, 50 insertions(+), 87 deletions(-) rename src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/{ResourceTypeEnum.java => WorkflowResourceTypeEnum.java} (80%) diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/ResourceCreationDto.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/ResourceCreationDto.java index 1c91f0a9..b84b3235 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/ResourceCreationDto.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/ResourceCreationDto.java @@ -1,6 +1,6 @@ package it.gov.pagopa.atmlayer.service.model.dto; -import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum; +import it.gov.pagopa.atmlayer.service.model.enumeration.WorkflowResourceTypeEnum; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Pattern; import jakarta.ws.rs.FormParam; @@ -21,5 +21,5 @@ public class ResourceCreationDto { private String filename; @FormParam("resourceType") @NotNull(message = "resource type is required") - private ResourceTypeEnum resourceType; + private WorkflowResourceTypeEnum resourceType; } diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/WorkflowResourceCreationDto.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/WorkflowResourceCreationDto.java index 01c0482c..1c64533c 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/WorkflowResourceCreationDto.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/WorkflowResourceCreationDto.java @@ -1,7 +1,6 @@ package it.gov.pagopa.atmlayer.service.model.dto; -import it.gov.pagopa.atmlayer.service.model.enumeration.FunctionTypeEnum; -import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum; +import it.gov.pagopa.atmlayer.service.model.enumeration.WorkflowResourceTypeEnum; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Pattern; import jakarta.ws.rs.FormParam; @@ -25,11 +24,7 @@ public class WorkflowResourceCreationDto { @Pattern(regexp = "^[a-zA-Z0-9_-]+$", message = "deve essere della forma ${regexp} e non contenere l'estensione del file") private String filename; - @FormParam("functionType") - @NotNull(message = "function type is required") - private FunctionTypeEnum functionType; - @FormParam("resourceType") @NotNull(message = "resource type is required") - private ResourceTypeEnum resourceType; + private WorkflowResourceTypeEnum resourceType; } diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/ResourceEntity.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/ResourceEntity.java index 8a84c98a..b98784cd 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/ResourceEntity.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/ResourceEntity.java @@ -1,14 +1,12 @@ package it.gov.pagopa.atmlayer.service.model.entity; import io.quarkus.hibernate.reactive.panache.PanacheEntityBase; -import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum; -import jakarta.persistence.CascadeType; +import it.gov.pagopa.atmlayer.service.model.enumeration.WorkflowResourceTypeEnum; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; -import jakarta.persistence.OneToOne; import jakarta.persistence.Table; import lombok.Getter; import lombok.NoArgsConstructor; @@ -35,7 +33,7 @@ public class ResourceEntity extends PanacheEntityBase implements Serializable { @Column(name = "sha256", unique = true) private String sha256; @Column(name="resourceType") - ResourceTypeEnum resourceTypeEnum; + WorkflowResourceTypeEnum workflowResourceTypeEnum; @Column(name="file_name") String fileName; @CreationTimestamp diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/ResourceFile.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/ResourceFile.java index 186d47de..1dc651db 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/ResourceFile.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/ResourceFile.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import io.quarkus.hibernate.reactive.panache.PanacheEntityBase; -import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum; +import it.gov.pagopa.atmlayer.service.model.enumeration.WorkflowResourceTypeEnum; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; @@ -46,7 +46,7 @@ public class ResourceFile extends PanacheEntityBase implements Serializable { @Column(name = "resource_type") @Enumerated(EnumType.STRING) @NotNull - private ResourceTypeEnum resourceType; + private WorkflowResourceTypeEnum resourceType; @OneToOne(fetch = FetchType.LAZY) @JoinColumns({ diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/WorkflowResource.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/WorkflowResource.java index ca403929..fdb81bcd 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/WorkflowResource.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/WorkflowResource.java @@ -1,8 +1,7 @@ package it.gov.pagopa.atmlayer.service.model.entity; import io.quarkus.hibernate.reactive.panache.PanacheEntityBase; -import it.gov.pagopa.atmlayer.service.model.enumeration.FunctionTypeEnum; -import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum; +import it.gov.pagopa.atmlayer.service.model.enumeration.WorkflowResourceTypeEnum; import it.gov.pagopa.atmlayer.service.model.enumeration.StatusEnum; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; @@ -12,7 +11,6 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.OneToOne; -import jakarta.persistence.PrePersist; import jakarta.persistence.Table; import lombok.Getter; import lombok.NoArgsConstructor; @@ -45,13 +43,9 @@ public class WorkflowResource extends PanacheEntityBase implements Serializable @Column(name = "definition_key") private String definitionKey; - @Column(name = "function_type") - @Enumerated(EnumType.STRING) - private FunctionTypeEnum functionType; - @Column(name = "resource_type") @Enumerated(EnumType.STRING) - private ResourceTypeEnum resourceType; + private WorkflowResourceTypeEnum resourceType; @Column(name = "status") @Enumerated(EnumType.STRING) diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/ResourceTypeEnum.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/WorkflowResourceTypeEnum.java similarity index 80% rename from src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/ResourceTypeEnum.java rename to src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/WorkflowResourceTypeEnum.java index 6606a2be..4ccb11a9 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/ResourceTypeEnum.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/WorkflowResourceTypeEnum.java @@ -6,9 +6,8 @@ @AllArgsConstructor @Getter -public enum ResourceTypeEnum { +public enum WorkflowResourceTypeEnum { BPMN("bpmn","application/bpmn", "bpmn:process", "id"), - HTML("html","application/html", "NULL", "NULL"), DMN("dmn", "application/dmn", "decision", "id"); String extension; diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/mapper/BpmnVersionMapper.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/mapper/BpmnVersionMapper.java index c966f490..5dfb7356 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/mapper/BpmnVersionMapper.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/mapper/BpmnVersionMapper.java @@ -3,7 +3,7 @@ import it.gov.pagopa.atmlayer.service.model.dto.BpmnCreationDto; import it.gov.pagopa.atmlayer.service.model.dto.BpmnUpgradeDto; import it.gov.pagopa.atmlayer.service.model.entity.BpmnVersion; -import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum; +import it.gov.pagopa.atmlayer.service.model.enumeration.WorkflowResourceTypeEnum; import it.gov.pagopa.atmlayer.service.model.enumeration.StatusEnum; import it.gov.pagopa.atmlayer.service.model.model.BpmnDTO; import it.gov.pagopa.atmlayer.service.model.utils.BpmnUtils; @@ -27,7 +27,7 @@ public BpmnVersion toEntityCreation(BpmnCreationDto bpmnCreationDto) throws NoSu bpmnVersion.setFunctionType(bpmnCreationDto.getFunctionType()); bpmnVersion.setStatus(StatusEnum.CREATED); bpmnVersion.setSha256(BpmnUtils.calculateSha256(bpmnCreationDto.getFile())); - bpmnVersion.setDeployedFileName(bpmnCreationDto.getFilename().concat(".").concat(ResourceTypeEnum.BPMN.getExtension())); + bpmnVersion.setDeployedFileName(bpmnCreationDto.getFilename().concat(".").concat(WorkflowResourceTypeEnum.BPMN.getExtension())); bpmnVersion.setEnabled(true); return bpmnVersion; } @@ -47,7 +47,7 @@ public BpmnVersion toEntityUpgrade(BpmnUpgradeDto bpmnUpgradeDto, Long version, bpmnVersion.setFunctionType(bpmnUpgradeDto.getFunctionType()); bpmnVersion.setStatus(StatusEnum.CREATED); bpmnVersion.setSha256(BpmnUtils.calculateSha256(bpmnUpgradeDto.getFile())); - bpmnVersion.setDeployedFileName(bpmnUpgradeDto.getFilename().concat(".").concat(ResourceTypeEnum.BPMN.getExtension())); + bpmnVersion.setDeployedFileName(bpmnUpgradeDto.getFilename().concat(".").concat(WorkflowResourceTypeEnum.BPMN.getExtension())); bpmnVersion.setEnabled(true); bpmnVersion.setModelVersion(version); bpmnVersion.setDefinitionKey(definitionKey); diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/mapper/ResourceEntityMapper.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/mapper/ResourceEntityMapper.java index 12cd23fc..5f0f3c1b 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/mapper/ResourceEntityMapper.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/mapper/ResourceEntityMapper.java @@ -2,7 +2,6 @@ import it.gov.pagopa.atmlayer.service.model.dto.ResourceCreationDto; import it.gov.pagopa.atmlayer.service.model.entity.ResourceEntity; -import it.gov.pagopa.atmlayer.service.model.model.ResourceEntityDTO; import it.gov.pagopa.atmlayer.service.model.utils.BpmnUtils; import org.mapstruct.Mapper; @@ -14,7 +13,7 @@ public abstract class ResourceEntityMapper { public ResourceEntity toEntityCreation(ResourceCreationDto resourceCreationDto) throws NoSuchAlgorithmException, IOException { ResourceEntity resourceEntity = new ResourceEntity(); resourceEntity.setSha256(BpmnUtils.calculateSha256(resourceCreationDto.getFile())); - resourceEntity.setResourceTypeEnum(resourceCreationDto.getResourceType()); + resourceEntity.setWorkflowResourceTypeEnum(resourceCreationDto.getResourceType()); resourceEntity.setFileName(resourceCreationDto.getFilename()); return resourceEntity; } diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/mapper/WorkflowResourceMapper.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/mapper/WorkflowResourceMapper.java index 4be445bd..1327b7ea 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/mapper/WorkflowResourceMapper.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/mapper/WorkflowResourceMapper.java @@ -2,7 +2,6 @@ import it.gov.pagopa.atmlayer.service.model.dto.WorkflowResourceCreationDto; import it.gov.pagopa.atmlayer.service.model.entity.WorkflowResource; -import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum; import it.gov.pagopa.atmlayer.service.model.enumeration.StatusEnum; import it.gov.pagopa.atmlayer.service.model.model.WorkflowResourceDTO; import it.gov.pagopa.atmlayer.service.model.utils.BpmnUtils; @@ -21,7 +20,6 @@ public abstract class WorkflowResourceMapper { public WorkflowResource toEntityCreation(WorkflowResourceCreationDto workflowCreationDto) throws NoSuchAlgorithmException, IOException { WorkflowResource workflowResource = new WorkflowResource(); - workflowResource.setFunctionType(workflowCreationDto.getFunctionType()); workflowResource.setStatus(StatusEnum.CREATED); workflowResource.setSha256(BpmnUtils.calculateSha256(workflowCreationDto.getFile())); workflowResource.setDeployedFileName(workflowCreationDto.getFilename().concat(".").concat(workflowCreationDto.getResourceType().toString())); diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/model/ResourceEntityDTO.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/model/ResourceEntityDTO.java index 112d5b2f..fc77607d 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/model/ResourceEntityDTO.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/model/ResourceEntityDTO.java @@ -1,11 +1,7 @@ package it.gov.pagopa.atmlayer.service.model.model; -import it.gov.pagopa.atmlayer.service.model.entity.ResourceFile; -import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum; -import jakarta.persistence.CascadeType; +import it.gov.pagopa.atmlayer.service.model.enumeration.WorkflowResourceTypeEnum; import jakarta.persistence.Column; -import jakarta.persistence.Id; -import jakarta.persistence.OneToOne; import org.hibernate.annotations.CreationTimestamp; import org.hibernate.annotations.UpdateTimestamp; @@ -17,7 +13,7 @@ public class ResourceEntityDTO { private UUID resourceId; private String sha256; @Column(name="resourceType") - ResourceTypeEnum resourceTypeEnum; + WorkflowResourceTypeEnum workflowResourceTypeEnum; @CreationTimestamp @Column(name = "created_at") private Timestamp createdAt; diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/model/ResourceFileDTO.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/model/ResourceFileDTO.java index d0c2d3ab..fe2d371b 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/model/ResourceFileDTO.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/model/ResourceFileDTO.java @@ -1,6 +1,6 @@ package it.gov.pagopa.atmlayer.service.model.model; -import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum; +import it.gov.pagopa.atmlayer.service.model.enumeration.WorkflowResourceTypeEnum; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -20,7 +20,7 @@ @EqualsAndHashCode public class ResourceFileDTO { private UUID id; - private ResourceTypeEnum resourceType; + private WorkflowResourceTypeEnum resourceType; private String storageKey; private String fileName; private String extension; diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/ObjectStoreService.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/ObjectStoreService.java index 5328cb25..91477ed1 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/ObjectStoreService.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/ObjectStoreService.java @@ -1,10 +1,9 @@ package it.gov.pagopa.atmlayer.service.model.service; -import io.smallrye.mutiny.Multi; import io.smallrye.mutiny.Uni; import io.vertx.core.buffer.Buffer; import it.gov.pagopa.atmlayer.service.model.enumeration.ObjectStoreStrategyEnum; -import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum; +import it.gov.pagopa.atmlayer.service.model.enumeration.WorkflowResourceTypeEnum; import it.gov.pagopa.atmlayer.service.model.model.ObjectStorePutResponse; import org.jboss.resteasy.reactive.RestMulti; @@ -16,7 +15,7 @@ public interface ObjectStoreService { ObjectStoreStrategyEnum getType(); - Uni uploadFile(File file, String path, ResourceTypeEnum fileType, String filename); + Uni uploadFile(File file, String path, WorkflowResourceTypeEnum fileType, String filename); Uni generatePresignedUrl(String objectKey); diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnFileStorageServiceImpl.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnFileStorageServiceImpl.java index d484b4f5..1f554114 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnFileStorageServiceImpl.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnFileStorageServiceImpl.java @@ -8,7 +8,7 @@ import it.gov.pagopa.atmlayer.service.model.entity.BpmnVersion; import it.gov.pagopa.atmlayer.service.model.entity.ResourceFile; import it.gov.pagopa.atmlayer.service.model.enumeration.ObjectStoreStrategyEnum; -import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum; +import it.gov.pagopa.atmlayer.service.model.enumeration.WorkflowResourceTypeEnum; import it.gov.pagopa.atmlayer.service.model.model.BpmnIdDto; import it.gov.pagopa.atmlayer.service.model.model.ObjectStorePutResponse; import it.gov.pagopa.atmlayer.service.model.properties.ObjectStoreProperties; @@ -50,7 +50,7 @@ public BpmnFileStorageServiceImpl(ObjectStoreStrategy objectStoreStrategy, Objec public Uni writeResourceInfoToDatabase(BpmnVersion bpmn, ObjectStorePutResponse putObjectResponse, String filename) { ResourceFile entity = ResourceFile.builder() .fileName(filename) - .resourceType(ResourceTypeEnum.BPMN) + .resourceType(WorkflowResourceTypeEnum.BPMN) .bpmn(bpmn) .storageKey(putObjectResponse.getStorage_key()) .build(); @@ -61,10 +61,10 @@ public Uni writeResourceInfoToDatabase(BpmnVersion bpmn, ObjectSto public Uni uploadFile(BpmnVersion bpmnVersion, File file, String filename) { BpmnIdDto bpmnVersionPK = new BpmnIdDto(bpmnVersion.getBpmnId(), bpmnVersion.getModelVersion()); String path = calculatePath(bpmnVersionPK); - String completeName = filename.concat(".").concat(ResourceTypeEnum.BPMN.getExtension()); + String completeName = filename.concat(".").concat(WorkflowResourceTypeEnum.BPMN.getExtension()); log.info("Requesting to write file {} in Object Store at path {}", file.getName(), path); Context context = Vertx.currentContext(); - return objectStoreService.uploadFile(file, path, ResourceTypeEnum.BPMN, completeName) + return objectStoreService.uploadFile(file, path, WorkflowResourceTypeEnum.BPMN, completeName) .emitOn(command -> context.runOnContext(x -> command.run())) .onItem() .transformToUni(objectStorePutResponse -> this.writeResourceInfoToDatabase(bpmnVersion, objectStorePutResponse, filename)); diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnVersionServiceImpl.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnVersionServiceImpl.java index a19c300f..17b19838 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnVersionServiceImpl.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnVersionServiceImpl.java @@ -14,7 +14,7 @@ import it.gov.pagopa.atmlayer.service.model.entity.ResourceFile; import it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum; import it.gov.pagopa.atmlayer.service.model.enumeration.FunctionTypeEnum; -import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum; +import it.gov.pagopa.atmlayer.service.model.enumeration.WorkflowResourceTypeEnum; import it.gov.pagopa.atmlayer.service.model.enumeration.StatusEnum; import it.gov.pagopa.atmlayer.service.model.exception.AtmLayerException; import it.gov.pagopa.atmlayer.service.model.mapper.BpmnVersionMapper; @@ -61,7 +61,7 @@ public class BpmnVersionServiceImpl implements BpmnVersionService { @Inject BpmnVersionMapper bpmnVersionMapper; - final ResourceTypeEnum resourceType = ResourceTypeEnum.BPMN; + final WorkflowResourceTypeEnum resourceType = WorkflowResourceTypeEnum.BPMN; @Override public Uni> getAll() { diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/S3ObjectStoreServiceImpl.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/S3ObjectStoreServiceImpl.java index 74c48321..04c8d7b6 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/S3ObjectStoreServiceImpl.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/S3ObjectStoreServiceImpl.java @@ -5,7 +5,7 @@ import io.vertx.core.buffer.Buffer; import it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType; import it.gov.pagopa.atmlayer.service.model.enumeration.ObjectStoreStrategyEnum; -import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum; +import it.gov.pagopa.atmlayer.service.model.enumeration.WorkflowResourceTypeEnum; import it.gov.pagopa.atmlayer.service.model.exception.AtmLayerException; import it.gov.pagopa.atmlayer.service.model.model.ObjectStorePutResponse; import it.gov.pagopa.atmlayer.service.model.service.S3ObjectStoreService; @@ -90,7 +90,7 @@ public RestMulti download(String key) { } - public Uni uploadFile(File file, String path, ResourceTypeEnum fileType, String filename) { + public Uni uploadFile(File file, String path, WorkflowResourceTypeEnum fileType, String filename) { if (StringUtils.isBlank(filename)) { String errorMessage = String.format("S3 File Upload - invalid filename %s", filename); log.error(errorMessage); diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java index b6d87753..a2896c63 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java @@ -7,12 +7,10 @@ import it.gov.pagopa.atmlayer.service.model.client.ProcessClient; import it.gov.pagopa.atmlayer.service.model.dto.DeployResponseDto; import it.gov.pagopa.atmlayer.service.model.dto.DeployedProcessInfoDto; -import it.gov.pagopa.atmlayer.service.model.entity.BpmnVersion; -import it.gov.pagopa.atmlayer.service.model.entity.BpmnVersionPK; import it.gov.pagopa.atmlayer.service.model.entity.ResourceFile; import it.gov.pagopa.atmlayer.service.model.entity.WorkflowResource; import it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum; -import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum; +import it.gov.pagopa.atmlayer.service.model.enumeration.WorkflowResourceTypeEnum; import it.gov.pagopa.atmlayer.service.model.enumeration.StatusEnum; import it.gov.pagopa.atmlayer.service.model.exception.AtmLayerException; import it.gov.pagopa.atmlayer.service.model.repository.WorkflowResourceRepository; @@ -32,7 +30,6 @@ import java.util.UUID; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.ATMLM_500; -import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.BPMN_FILE_DOES_NOT_EXIST; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.BPMN_FILE_WITH_SAME_CAMUNDA_DEFINITION_KEY_ALREADY_EXISTS; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.DEPLOY_ERROR; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.OBJECT_STORE_SAVE_FILE_ERROR; @@ -54,7 +51,7 @@ public class WorkflowResourceServiceImpl implements WorkflowResourceService { @RestClient ProcessClient processClient; - final ResourceTypeEnum resourceType = ResourceTypeEnum.DMN; + WorkflowResourceTypeEnum resourceType; @Override @WithTransaction @@ -218,7 +215,7 @@ public Uni saveAndUpload(WorkflowResource workflowResource, Fi @Override public Uni createWorkflowResource(WorkflowResource workflowResource, File file, String filename) { - String definitionKey = extractIdValue(file, resourceType); + String definitionKey = extractIdValue(file, workflowResource.getResourceType()); workflowResource.setDefinitionKey(definitionKey); return findByDefinitionKey(definitionKey) .onItem().transformToUni(Unchecked.function(x -> { diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceStorageServiceImpl.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceStorageServiceImpl.java index 64c8396a..317ac7be 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceStorageServiceImpl.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceStorageServiceImpl.java @@ -5,12 +5,10 @@ import io.vertx.core.Context; import io.vertx.core.Vertx; import io.vertx.core.buffer.Buffer; -import it.gov.pagopa.atmlayer.service.model.entity.BpmnVersion; import it.gov.pagopa.atmlayer.service.model.entity.ResourceFile; import it.gov.pagopa.atmlayer.service.model.entity.WorkflowResource; import it.gov.pagopa.atmlayer.service.model.enumeration.ObjectStoreStrategyEnum; -import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum; -import it.gov.pagopa.atmlayer.service.model.model.BpmnIdDto; +import it.gov.pagopa.atmlayer.service.model.enumeration.WorkflowResourceTypeEnum; import it.gov.pagopa.atmlayer.service.model.model.ObjectStorePutResponse; import it.gov.pagopa.atmlayer.service.model.properties.ObjectStoreProperties; import it.gov.pagopa.atmlayer.service.model.service.ObjectStoreService; @@ -56,12 +54,12 @@ public WorkflowResourceStorageServiceImpl(ObjectStoreStrategy objectStoreStrateg @Override public Uni uploadFile(WorkflowResource workflowResource, File file, String filename) { UUID uuid = workflowResource.getWorkflowResourceId(); - ResourceTypeEnum resourceType = workflowResource.getResourceType(); + WorkflowResourceTypeEnum resourceType = workflowResource.getResourceType(); String path = calculatePath(uuid, resourceType); - String completeName = filename.concat(".").concat(ResourceTypeEnum.DMN.getExtension()); + String completeName = filename.concat(".").concat(resourceType.getExtension()); log.info("Requesting to write file {} in Object Store at path {}", file.getName(), path); Context context = Vertx.currentContext(); - return objectStoreService.uploadFile(file, path, ResourceTypeEnum.DMN, completeName) + return objectStoreService.uploadFile(file, path, resourceType, completeName) .emitOn(command -> context.runOnContext(x -> command.run())) .onItem() .transformToUni(objectStorePutResponse -> this.writeResourceInfoToDatabase(workflowResource, objectStorePutResponse, filename)); @@ -72,7 +70,7 @@ public Uni uploadFile(WorkflowResource workflowResource, File file public Uni writeResourceInfoToDatabase(WorkflowResource workflowResource, ObjectStorePutResponse putObjectResponse, String filename) { ResourceFile entity = ResourceFile.builder() .fileName(filename) - .resourceType(ResourceTypeEnum.DMN) + .resourceType(workflowResource.getResourceType()) .workflowResource(workflowResource) .storageKey(putObjectResponse.getStorage_key()) .build(); @@ -89,7 +87,7 @@ public RestMulti download(String storageKey) { return this.objectStoreService.download(storageKey); } - private String calculatePath(UUID uuid, ResourceTypeEnum resourceType) { + private String calculatePath(UUID uuid, WorkflowResourceTypeEnum resourceType) { Map valuesMap = new HashMap<>(); valuesMap.put("uuid", uuid.toString()); valuesMap.put("RESOURCE_TYPE", resourceType.toString()); diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/utils/BpmnDtoMapper.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/utils/BpmnDtoMapper.java index 576c4c42..68f7417d 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/utils/BpmnDtoMapper.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/utils/BpmnDtoMapper.java @@ -1,9 +1,5 @@ package it.gov.pagopa.atmlayer.service.model.utils; -import it.gov.pagopa.atmlayer.service.model.dto.BpmnCreationDto; -import it.gov.pagopa.atmlayer.service.model.entity.BpmnVersion; -import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum; -import it.gov.pagopa.atmlayer.service.model.enumeration.StatusEnum; import jakarta.enterprise.context.ApplicationScoped; import java.io.File; diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/utils/FileUtils.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/utils/FileUtils.java index a9e5f813..b4cebfd9 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/utils/FileUtils.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/utils/FileUtils.java @@ -1,7 +1,6 @@ package it.gov.pagopa.atmlayer.service.model.utils; -import it.gov.pagopa.atmlayer.service.model.enumeration.FileParsingUtilityValues; -import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum; +import it.gov.pagopa.atmlayer.service.model.enumeration.WorkflowResourceTypeEnum; import it.gov.pagopa.atmlayer.service.model.exception.AtmLayerException; import jakarta.enterprise.context.ApplicationScoped; import jakarta.ws.rs.core.Response; @@ -16,7 +15,6 @@ import java.io.File; import java.io.IOException; -import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.ATMLM_500; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.BPMN_FILE_DOES_NOT_HAVE_DEFINITION_KEY; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.MALFORMED_FILE; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.METHOD_NOT_ALLOWED; @@ -25,8 +23,8 @@ @Slf4j public class FileUtils { - public static String extractIdValue(File file, ResourceTypeEnum resourceTypeEnum) { - if (resourceTypeEnum == ResourceTypeEnum.HTML){ + public static String extractIdValue(File file, WorkflowResourceTypeEnum workflowResourceTypeEnum) { + if (workflowResourceTypeEnum == WorkflowResourceTypeEnum.HTML){ throw new AtmLayerException("extractIdValue() cannot be invoked on HTML file", Response.Status.BAD_REQUEST, METHOD_NOT_ALLOWED); } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); @@ -39,8 +37,8 @@ public static String extractIdValue(File file, ResourceTypeEnum resourceTypeEnum log.error(e.getMessage()); throw new AtmLayerException("Malformed File", Response.Status.BAD_REQUEST, MALFORMED_FILE); } - Element definitionsElement = (Element) document.getElementsByTagName(resourceTypeEnum.getTagName()).item(0); - String definitionKey = definitionsElement.getAttribute(resourceTypeEnum.getAttribute()); + Element definitionsElement = (Element) document.getElementsByTagName(workflowResourceTypeEnum.getTagName()).item(0); + String definitionKey = definitionsElement.getAttribute(workflowResourceTypeEnum.getAttribute()); if (definitionKey.isBlank()) { throw new AtmLayerException("Failed to find definition key in the BPMN file", Response.Status.NOT_ACCEPTABLE, BPMN_FILE_DOES_NOT_HAVE_DEFINITION_KEY); } diff --git a/src/test/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnVersionServiceImplTest.java b/src/test/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnVersionServiceImplTest.java index 4f854fc1..e9aee23b 100644 --- a/src/test/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnVersionServiceImplTest.java +++ b/src/test/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnVersionServiceImplTest.java @@ -13,20 +13,18 @@ import it.gov.pagopa.atmlayer.service.model.entity.ResourceFile; import it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType; import it.gov.pagopa.atmlayer.service.model.enumeration.FunctionTypeEnum; -import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum; +import it.gov.pagopa.atmlayer.service.model.enumeration.WorkflowResourceTypeEnum; import it.gov.pagopa.atmlayer.service.model.enumeration.StatusEnum; import it.gov.pagopa.atmlayer.service.model.exception.AtmLayerException; import it.gov.pagopa.atmlayer.service.model.mapper.BpmnVersionMapper; import it.gov.pagopa.atmlayer.service.model.model.BpmnDTO; import it.gov.pagopa.atmlayer.service.model.repository.BpmnVersionRepository; -import it.gov.pagopa.atmlayer.service.model.service.BpmnFileStorageService; import jakarta.ws.rs.core.Response; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.mockito.internal.matchers.InstanceOf; import software.amazon.awssdk.services.s3.model.ListObjectsResponse; import java.io.File; @@ -396,7 +394,7 @@ void testDeployOK() throws MalformedURLException { bpmnVersion.setStatus(StatusEnum.CREATED); ResourceFile resourceFile=new ResourceFile(); resourceFile.setId(UUID.randomUUID()); - resourceFile.setResourceType(ResourceTypeEnum.BPMN); + resourceFile.setResourceType(WorkflowResourceTypeEnum.BPMN); resourceFile.setStorageKey("storage key"); bpmnVersion.setResourceFile(resourceFile); BpmnVersion bpmnVersionUpdated=new BpmnVersion(); @@ -424,7 +422,7 @@ void testDeployNotDeployable() throws MalformedURLException { bpmnVersion.setStatus(StatusEnum.DEPLOYED); ResourceFile resourceFile=new ResourceFile(); resourceFile.setId(UUID.randomUUID()); - resourceFile.setResourceType(ResourceTypeEnum.BPMN); + resourceFile.setResourceType(WorkflowResourceTypeEnum.BPMN); resourceFile.setStorageKey("storage key"); bpmnVersion.setResourceFile(resourceFile); URL url=new URL("http://localhost:8081/test"); @@ -480,7 +478,7 @@ void testDeployURLGenerationFailure() throws MalformedURLException { bpmnVersion.setStatus(StatusEnum.CREATED); ResourceFile resourceFile=new ResourceFile(); resourceFile.setId(UUID.randomUUID()); - resourceFile.setResourceType(ResourceTypeEnum.BPMN); + resourceFile.setResourceType(WorkflowResourceTypeEnum.BPMN); resourceFile.setStorageKey("storage key"); bpmnVersion.setResourceFile(resourceFile); BpmnVersion bpmnVersionUpdated=new BpmnVersion(); @@ -514,7 +512,7 @@ void testDeployClientFailure() throws MalformedURLException { bpmnVersion.setStatus(StatusEnum.CREATED); ResourceFile resourceFile=new ResourceFile(); resourceFile.setId(UUID.randomUUID()); - resourceFile.setResourceType(ResourceTypeEnum.BPMN); + resourceFile.setResourceType(WorkflowResourceTypeEnum.BPMN); resourceFile.setStorageKey("storage key"); bpmnVersion.setResourceFile(resourceFile); URL url=new URL("http://localhost:8081/test"); diff --git a/src/test/java/it/gov/pagopa/atmlayer/service/model/service/impl/ResourceFileServiceImplTest.java b/src/test/java/it/gov/pagopa/atmlayer/service/model/service/impl/ResourceFileServiceImplTest.java index 5a8b1791..22d24886 100644 --- a/src/test/java/it/gov/pagopa/atmlayer/service/model/service/impl/ResourceFileServiceImplTest.java +++ b/src/test/java/it/gov/pagopa/atmlayer/service/model/service/impl/ResourceFileServiceImplTest.java @@ -1,11 +1,9 @@ package it.gov.pagopa.atmlayer.service.model.service.impl; -import io.quarkus.test.InjectMock; import io.smallrye.mutiny.Uni; import it.gov.pagopa.atmlayer.service.model.entity.ResourceFile; -import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum; +import it.gov.pagopa.atmlayer.service.model.enumeration.WorkflowResourceTypeEnum; import it.gov.pagopa.atmlayer.service.model.repository.ResourceFileRepository; -import it.gov.pagopa.atmlayer.service.model.service.ResourceFileService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; @@ -32,7 +30,7 @@ public void setUp() { public void testSaveResourceFile() { ResourceFile resourceFile = new ResourceFile(); resourceFile.setFileName("test.txt"); - resourceFile.setResourceType(ResourceTypeEnum.BPMN); + resourceFile.setResourceType(WorkflowResourceTypeEnum.BPMN); when(resourceFileRepository.persist(resourceFile)).thenReturn(Uni.createFrom().item(resourceFile)); From 3a135abab241067f7213a706406935c7d7dc3372 Mon Sep 17 00:00:00 2001 From: "USERSAD\\evalenti" Date: Wed, 8 Nov 2023 12:27:14 +0100 Subject: [PATCH 3/9] FileUtils refinements --- .../it/gov/pagopa/atmlayer/service/model/utils/FileUtils.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/utils/FileUtils.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/utils/FileUtils.java index b4cebfd9..cc48c44a 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/utils/FileUtils.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/utils/FileUtils.java @@ -24,9 +24,6 @@ public class FileUtils { public static String extractIdValue(File file, WorkflowResourceTypeEnum workflowResourceTypeEnum) { - if (workflowResourceTypeEnum == WorkflowResourceTypeEnum.HTML){ - throw new AtmLayerException("extractIdValue() cannot be invoked on HTML file", Response.Status.BAD_REQUEST, METHOD_NOT_ALLOWED); - } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = null; Document document = null; From 83719da16b54b38db58fa54aae008f09af8c8446 Mon Sep 17 00:00:00 2001 From: "USERSAD\\evalenti" Date: Wed, 8 Nov 2023 12:52:17 +0100 Subject: [PATCH 4/9] WorkflowResource Delete --- .../model/resource/WorkflowResourceResource.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/resource/WorkflowResourceResource.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/resource/WorkflowResourceResource.java index 1f6a15b4..e55dd508 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/resource/WorkflowResourceResource.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/resource/WorkflowResourceResource.java @@ -3,16 +3,15 @@ import io.smallrye.common.annotation.NonBlocking; import io.smallrye.mutiny.Uni; import it.gov.pagopa.atmlayer.service.model.dto.WorkflowResourceCreationDto; -import it.gov.pagopa.atmlayer.service.model.entity.BpmnVersionPK; import it.gov.pagopa.atmlayer.service.model.entity.WorkflowResource; import it.gov.pagopa.atmlayer.service.model.mapper.WorkflowResourceMapper; -import it.gov.pagopa.atmlayer.service.model.model.BpmnDTO; import it.gov.pagopa.atmlayer.service.model.model.WorkflowResourceDTO; import it.gov.pagopa.atmlayer.service.model.service.WorkflowResourceService; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import jakarta.validation.Valid; import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.DELETE; import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; @@ -56,4 +55,14 @@ public Uni deployBPMN(@PathParam("uuid") UUID uuid) { return this.workflowResourceService.deploy(uuid) .onItem().transformToUni(workflow -> Uni.createFrom().item(this.workflowResourceMapper.toDTO(workflow))); } + + @DELETE + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("/{uuid}") + public Uni deleteBpmn(@PathParam("uuid") UUID uuid) { + + return this.workflowResourceService.delete(uuid) + .onItem().ignore().andSwitchTo(Uni.createFrom().voidItem()); + } } From 312c080c2c0e4d356d8925e405356476b3bdfd32 Mon Sep 17 00:00:00 2001 From: "USERSAD\\evalenti" Date: Wed, 8 Nov 2023 16:04:49 +0100 Subject: [PATCH 5/9] refinements --- .../model/service/impl/WorkflowResourceServiceImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java index a2896c63..dc1d8d06 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java @@ -204,7 +204,7 @@ public Uni saveAndUpload(WorkflowResource workflowResource, Fi return this.workflowResourceStorageService.uploadFile(workflowResource, file, filename) .onFailure().recoverWithUni(failure -> { log.error(failure.getMessage()); - return Uni.createFrom().failure(new AtmLayerException("Failed to save Workflow Resource in Object Store. BPMN creation aborted", Response.Status.INTERNAL_SERVER_ERROR, OBJECT_STORE_SAVE_FILE_ERROR)); + return Uni.createFrom().failure(new AtmLayerException("Failed to save Workflow Resource in Object Store. Workflow Resource creation aborted", Response.Status.INTERNAL_SERVER_ERROR, OBJECT_STORE_SAVE_FILE_ERROR)); }) .onItem().transformToUni(putObjectResponse -> { log.info("Completed Workflow Resource Creation"); @@ -245,9 +245,9 @@ public Uni delete(UUID uuid) { if (x.isEmpty()) { throw new AtmLayerException(String.format("Workflow Resource with id %s does not exists", uuid), Response.Status.NOT_FOUND, WORKFLOW_FILE_DOES_NOT_EXIST); } - if (!StatusEnum.isDeletable(x.get().getStatus())) { + if (!StatusEnum.isEditable(x.get().getStatus())) { throw new AtmLayerException(String.format("Workflow Resource with id %s is in status %s and cannot be " + - "deleted. Only Workflow Resource files in status %s can be deleted", uuid.toString(), x.get().getStatus(), StatusEnum.getDeletableStatuses()), Response.Status.BAD_REQUEST, AppErrorCodeEnum.WORKFLOW_RESOURCE_CANNOT_BE_DELETED_FOR_STATUS); + "deleted. Only Workflow Resource files in status %s can be deleted", uuid.toString(), x.get().getStatus(), StatusEnum.getUpdatableAndDeletableStatuses()), Response.Status.BAD_REQUEST, AppErrorCodeEnum.WORKFLOW_RESOURCE_CANNOT_BE_DELETED_FOR_STATUS); } return Uni.createFrom().item(x.get()); })).onItem().transformToUni(y -> this.workflowResourceRepository.deleteById(uuid)); From fca90cced03bd1d11bc3c2a6a7aa9b0140812f36 Mon Sep 17 00:00:00 2001 From: "USERSAD\\evalenti" Date: Wed, 8 Nov 2023 17:27:00 +0100 Subject: [PATCH 6/9] WorkflowResource Delete --- .../model/enumeration/AppErrorCodeEnum.java | 4 +++- .../model/enumeration/AppErrorType.java | 3 ++- .../service/model/enumeration/StatusEnum.java | 6 +++--- .../resource/WorkflowResourceResource.java | 2 +- .../service/WorkflowResourceService.java | 2 ++ .../service/impl/BpmnVersionServiceImpl.java | 4 ++-- .../impl/WorkflowResourceServiceImpl.java | 19 +++++++++++++++++++ 7 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorCodeEnum.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorCodeEnum.java index b4dc5a89..4c48ca46 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorCodeEnum.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorCodeEnum.java @@ -13,6 +13,7 @@ import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.NOT_DEPLOYED_STATUS; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.NOT_EXISTING_REFERENCED_ENTITY; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.ID_NOT_FOUND; +import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.NOT_UPDATABLE; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.NOT_UPGRADABLE; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.NOT_VALID_FILE; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.NOT_VALID_REFERENCED_ENTITY; @@ -46,7 +47,8 @@ public enum AppErrorCodeEnum { WORKFLOW_RESOURCE_FILE_WITH_SAME_CONTENT_ALREADY_EXIST("ATMLM_4000021","A Workflow Resource file with the same content already exists", CONSTRAINT_VIOLATION), WORKFLOW_RESOURCE_FILE_WITH_SAME_CAMUNDA_DEFINITION_KEY_ALREADY_EXISTS("ATMLM_4000022","A Workflow Resource file with the same Camunda definition key already exists", CONSTRAINT_VIOLATION), WORKFLOW_FILE_DOES_NOT_EXIST("ATMLM_4000023", "The referenced Workflow Resource file does not exist", NOT_EXISTING_REFERENCED_ENTITY), - WORKFLOW_RESOURCE_CANNOT_BE_DELETED_FOR_STATUS("ATMLM_4000024", "The referenced Workflow Resource file can not be deleted in the actual state", NOT_DELETABLE); + WORKFLOW_RESOURCE_CANNOT_BE_DELETED_FOR_STATUS("ATMLM_4000024", "The referenced Workflow Resource file can not be deleted in the actual state", NOT_DELETABLE), + WORKFLOW_RESOURCE_CANNOT_BE_UPDATED_FOR_STATUS("ATMLM_4000025", "The referenced Workflow Resource file can not be updated in the actual state", NOT_UPDATABLE); diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorType.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorType.java index 93bb4fd8..71c61532 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorType.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorType.java @@ -18,5 +18,6 @@ public enum AppErrorType { NOT_VALID_FILE, INVALID_DEPLOY, ID_NOT_FOUND, - INVALID_ARGUMENT + INVALID_ARGUMENT, + NOT_UPDATABLE } \ No newline at end of file diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/StatusEnum.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/StatusEnum.java index abd38b8a..1fb0c1ac 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/StatusEnum.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/StatusEnum.java @@ -19,12 +19,12 @@ public enum StatusEnum { @JsonValue private String value; - public static Set getDeletableStatuses() { + public static Set getUpdatableAndDeletableStatuses() { return new HashSet<>(Arrays.asList(CREATED, DEPLOY_ERROR)); } - public static boolean isDeletable(StatusEnum status) { - return getDeletableStatuses().contains(status); + public static boolean isEditable(StatusEnum status) { + return getUpdatableAndDeletableStatuses().contains(status); } } diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/resource/WorkflowResourceResource.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/resource/WorkflowResourceResource.java index e55dd508..65802df0 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/resource/WorkflowResourceResource.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/resource/WorkflowResourceResource.java @@ -13,6 +13,7 @@ import jakarta.ws.rs.Consumes; import jakarta.ws.rs.DELETE; import jakarta.ws.rs.POST; +import jakarta.ws.rs.PUT; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; import jakarta.ws.rs.Produces; @@ -51,7 +52,6 @@ public Uni createWorkflowResource(@RequestBody(required = t @Path("/deploy/{uuid}") @Produces(MediaType.APPLICATION_JSON) public Uni deployBPMN(@PathParam("uuid") UUID uuid) { - return this.workflowResourceService.deploy(uuid) .onItem().transformToUni(workflow -> Uni.createFrom().item(this.workflowResourceMapper.toDTO(workflow))); } diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/WorkflowResourceService.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/WorkflowResourceService.java index f1ca64b7..40b17446 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/WorkflowResourceService.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/WorkflowResourceService.java @@ -24,4 +24,6 @@ public interface WorkflowResourceService { Uni createWorkflowResource(WorkflowResource workflowResource, File file, String filename); Uni delete(UUID uuid); + +// Uni update(UUID id, WorkflowResource workflowResource); } diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnVersionServiceImpl.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnVersionServiceImpl.java index 17b19838..aef7690b 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnVersionServiceImpl.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnVersionServiceImpl.java @@ -100,9 +100,9 @@ public Uni delete(BpmnVersionPK bpmnVersionPK) { if (x.isEmpty()) { throw new AtmLayerException(String.format("BPMN with id %s does not exists", bpmnVersionPK), Response.Status.NOT_FOUND, BPMN_FILE_DOES_NOT_EXIST); } - if (!StatusEnum.isDeletable(x.get().getStatus())) { + if (!StatusEnum.isEditable(x.get().getStatus())) { throw new AtmLayerException(String.format("BPMN with id %s is in status %s and cannot be " + - "deleted. Only BPMN files in status %s can be deleted", bpmnVersionPK.toString(), x.get().getStatus(), StatusEnum.getDeletableStatuses()), Response.Status.BAD_REQUEST, AppErrorCodeEnum.BPMN_CANNOT_BE_DELETED_FOR_STATUS); + "deleted. Only BPMN files in status %s can be deleted", bpmnVersionPK.toString(), x.get().getStatus(), StatusEnum.getUpdatableAndDeletableStatuses()), Response.Status.BAD_REQUEST, AppErrorCodeEnum.BPMN_CANNOT_BE_DELETED_FOR_STATUS); } return Uni.createFrom().item(x.get()); })).onItem().transformToUni(y -> this.bpmnVersionRepository.deleteById(bpmnVersionPK)); diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java index dc1d8d06..7a1a0e87 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java @@ -24,6 +24,7 @@ import org.eclipse.microprofile.rest.client.inject.RestClient; import java.io.File; +import java.sql.Timestamp; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -252,4 +253,22 @@ public Uni delete(UUID uuid) { return Uni.createFrom().item(x.get()); })).onItem().transformToUni(y -> this.workflowResourceRepository.deleteById(uuid)); } + +// @Override +// public Uni update(UUID id, WorkflowResource workflowResource) { +// log.info("Updating Workflow Resource with id {}", id.toString()); +// return this.findById(id) +// .onItem() +// .transformToUni(Unchecked.function((x -> { +// if (x.isEmpty()) { +// throw new AtmLayerException(String.format("Workflow Resource with id %s does not exists", id), Response.Status.NOT_FOUND, WORKFLOW_FILE_DOES_NOT_EXIST); +// } +// if (!StatusEnum.isEditable(x.get().getStatus())) { +// throw new AtmLayerException(String.format("Workflow Resource with id %s is in status %s and cannot be " + +// "deleted. Only Workflow Resource files in status %s can be deleted", id.toString(), x.get().getStatus(), StatusEnum.getUpdatableAndDeletableStatuses()), Response.Status.BAD_REQUEST, AppErrorCodeEnum.WORKFLOW_RESOURCE_CANNOT_BE_UPDATED_FOR_STATUS); +// } +// workflowResource.setWorkflowResourceId(id); +// return this.workflowResourceRepository.persist(workflowResource); +// }))); +// } } From 5de02c84b66580d76fb20e7a6a57881fa7337027 Mon Sep 17 00:00:00 2001 From: "USERSAD\\evalenti" Date: Wed, 8 Nov 2023 17:54:40 +0100 Subject: [PATCH 7/9] Refinements --- .../service/model/enumeration/AppErrorCodeEnum.java | 3 ++- .../model/service/impl/WorkflowResourceServiceImpl.java | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorCodeEnum.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorCodeEnum.java index 4c48ca46..405c3805 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorCodeEnum.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorCodeEnum.java @@ -48,7 +48,8 @@ public enum AppErrorCodeEnum { WORKFLOW_RESOURCE_FILE_WITH_SAME_CAMUNDA_DEFINITION_KEY_ALREADY_EXISTS("ATMLM_4000022","A Workflow Resource file with the same Camunda definition key already exists", CONSTRAINT_VIOLATION), WORKFLOW_FILE_DOES_NOT_EXIST("ATMLM_4000023", "The referenced Workflow Resource file does not exist", NOT_EXISTING_REFERENCED_ENTITY), WORKFLOW_RESOURCE_CANNOT_BE_DELETED_FOR_STATUS("ATMLM_4000024", "The referenced Workflow Resource file can not be deleted in the actual state", NOT_DELETABLE), - WORKFLOW_RESOURCE_CANNOT_BE_UPDATED_FOR_STATUS("ATMLM_4000025", "The referenced Workflow Resource file can not be updated in the actual state", NOT_UPDATABLE); + WORKFLOW_RESOURCE_CANNOT_BE_UPDATED_FOR_STATUS("ATMLM_4000025", "The referenced Workflow Resource file can not be updated in the actual state", NOT_UPDATABLE), + WORKFLOW_RESOURCE_FILE_CANNOT_BE_DEPLOYED("ATMLM_4000026", "The referenced Workflow Resource file can not be deployed", NOT_DEPLOYABLE_STATUS); diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java index 7a1a0e87..b4b2a4ec 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java @@ -24,7 +24,6 @@ import org.eclipse.microprofile.rest.client.inject.RestClient; import java.io.File; -import java.sql.Timestamp; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -35,6 +34,7 @@ import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.DEPLOY_ERROR; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.OBJECT_STORE_SAVE_FILE_ERROR; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.WORKFLOW_FILE_DOES_NOT_EXIST; +import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.WORKFLOW_RESOURCE_FILE_WITH_SAME_CAMUNDA_DEFINITION_KEY_ALREADY_EXISTS; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.WORKFLOW_RESOURCE_FILE_WITH_SAME_CONTENT_ALREADY_EXIST; import static it.gov.pagopa.atmlayer.service.model.utils.FileUtils.extractIdValue; @@ -135,7 +135,7 @@ public Uni deploy(UUID uuid) { if (!x) { String errorMessage = "The referenced Workflow Resource file can not be deployed"; throw new AtmLayerException(errorMessage, Response.Status.BAD_REQUEST, - AppErrorCodeEnum.BPMN_FILE_CANNOT_BE_DEPLOYED); + AppErrorCodeEnum.WORKFLOW_RESOURCE_FILE_CANNOT_BE_DEPLOYED); } return this.setWorkflowResourceVersionStatus(uuid, StatusEnum.WAITING_DEPLOY); })) @@ -221,7 +221,7 @@ public Uni createWorkflowResource(WorkflowResource workflowRes return findByDefinitionKey(definitionKey) .onItem().transformToUni(Unchecked.function(x -> { if (x.isPresent()) { - throw new AtmLayerException("A Workflow Resource with the same definitionKey already exists", Response.Status.BAD_REQUEST, BPMN_FILE_WITH_SAME_CAMUNDA_DEFINITION_KEY_ALREADY_EXISTS); + throw new AtmLayerException("A Workflow Resource with the same definitionKey already exists", Response.Status.BAD_REQUEST, WORKFLOW_RESOURCE_FILE_WITH_SAME_CAMUNDA_DEFINITION_KEY_ALREADY_EXISTS); } return saveAndUpload(workflowResource, file, filename) .onItem().transformToUni(workflow -> { From 4b40a04eebc92057f9e8305d4c40a60e41f5dfdf Mon Sep 17 00:00:00 2001 From: "Cocuzzoli, Andrea" Date: Wed, 8 Nov 2023 19:45:31 +0100 Subject: [PATCH 8/9] added modifications for workflow_resource base path on s3 --- .../service/model/properties/ObjectStoreProperties.java | 4 ++-- .../model/service/impl/WorkflowResourceServiceImpl.java | 5 ++--- .../service/impl/WorkflowResourceStorageServiceImpl.java | 2 +- src/main/resources/application-local.properties | 3 ++- src/main/resources/application.properties | 1 + src/test/resources/application.properties | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/properties/ObjectStoreProperties.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/properties/ObjectStoreProperties.java index 3d57068e..ee2897bc 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/properties/ObjectStoreProperties.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/properties/ObjectStoreProperties.java @@ -14,7 +14,7 @@ public interface ObjectStoreProperties { Bpmn bpmn(); - Dmn dmn(); + WorkflowResource workflowResource(); interface Bucket { String name(); @@ -33,7 +33,7 @@ interface Bpmn { String pathTemplate(); } - interface Dmn { + interface WorkflowResource { String pathTemplate(); } diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java index b4b2a4ec..00c1d2ca 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java @@ -10,8 +10,8 @@ import it.gov.pagopa.atmlayer.service.model.entity.ResourceFile; import it.gov.pagopa.atmlayer.service.model.entity.WorkflowResource; import it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum; -import it.gov.pagopa.atmlayer.service.model.enumeration.WorkflowResourceTypeEnum; import it.gov.pagopa.atmlayer.service.model.enumeration.StatusEnum; +import it.gov.pagopa.atmlayer.service.model.enumeration.WorkflowResourceTypeEnum; import it.gov.pagopa.atmlayer.service.model.exception.AtmLayerException; import it.gov.pagopa.atmlayer.service.model.repository.WorkflowResourceRepository; import it.gov.pagopa.atmlayer.service.model.service.WorkflowResourceService; @@ -30,7 +30,6 @@ import java.util.UUID; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.ATMLM_500; -import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.BPMN_FILE_WITH_SAME_CAMUNDA_DEFINITION_KEY_ALREADY_EXISTS; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.DEPLOY_ERROR; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.OBJECT_STORE_SAVE_FILE_ERROR; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.WORKFLOW_FILE_DOES_NOT_EXIST; @@ -209,7 +208,7 @@ public Uni saveAndUpload(WorkflowResource workflowResource, Fi }) .onItem().transformToUni(putObjectResponse -> { log.info("Completed Workflow Resource Creation"); - return Uni.createFrom().item(record); + return Uni.createFrom().item(record); }); }); } diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceStorageServiceImpl.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceStorageServiceImpl.java index 317ac7be..5a2d61ae 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceStorageServiceImpl.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceStorageServiceImpl.java @@ -92,7 +92,7 @@ private String calculatePath(UUID uuid, WorkflowResourceTypeEnum resourceType) { valuesMap.put("uuid", uuid.toString()); valuesMap.put("RESOURCE_TYPE", resourceType.toString()); StringSubstitutor stringSubstitutor = new StringSubstitutor(valuesMap); - Optional workflowResourcePathTemplateProps = Optional.ofNullable(objectStoreProperties.dmn().pathTemplate()); + Optional workflowResourcePathTemplateProps = Optional.ofNullable(objectStoreProperties.workflowResource().pathTemplate()); String pathTemplate = WORKFLOW_TEMPLATE_PATH_DEFAULT; if (workflowResourcePathTemplateProps.isPresent() && StringUtils.isNotBlank(workflowResourcePathTemplateProps.get())) { pathTemplate = workflowResourcePathTemplateProps.get(); diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index e6775fd5..0e85b487 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -1,5 +1,5 @@ quarkus.profile=local -quarkus.http.port=${SERVER_PORT:8080} +quarkus.http.port=${SERVER_PORT:8086} quarkus.datasource.db-kind=${MODEL_DB_TYPE:postgresql} quarkus.datasource.username=${MODEL_DB_USERNAME:postgres} quarkus.datasource.password=${MODEL_DB_PASSWORD:password} @@ -27,5 +27,6 @@ object-store.bucket.access-key=${OBJECT_STORE_ACCESS_KEY_ID:admin123} object-store.bucket.secret-key=${OBJECT_STORE_ACCESS_KEY_SECRET:admin123} object-store.bucket.endpoint-override=http://127.0.0.1:9999 object-store.bpmn.path-template=${MODEL_OBJECT_STORE_BPMN_TEMPLATE_PATH:BPMN/files/UUID/[uuid]/VERSION/[version]} +object-store.workflow-resource.path-template=${MODEL_OBJECT_STORE_WORKFLOW_RESOURCE_TEMPLATE_PATH:WORKFLOW_RESOURCE/[RESOURCE_TYPE]/files/UUID/[uuid]} quarkus.resteay-reactive.input-buffer-size=10000 diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index a2ed8ee3..f2598465 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -60,6 +60,7 @@ object-store.type=${MODEL_OBJECT_STORE_TYPE:AWS_S3} object-store.bucket.name=${MODEL_OBJECT_STORE_BUCKET_NAME:pagopa-dev-atm-layer-s3-model} object-store.bucket.region=${MODEL_OBJECT_STORE_REGION:eu-south-1} object-store.bpmn.path-template=${MODEL_OBJECT_STORE_BPMN_TEMPLATE_PATH:BPMN/files/UUID/[uuid]/VERSION/[version]} +object-store.workflow-resource.path-template=${MODEL_OBJECT_STORE_WORKFLOW_RESOURCE_TEMPLATE_PATH:WORKFLOW_RESOURCE/[RESOURCE_TYPE]/files/UUID/[uuid]} quarkus.rest-client.process-deploy.url=${MODEL_PROCESS_BASE_PATH:http://pagopa-dev-atm-layer-wf-process.pagopa.svc.cluster.local:8080} diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index 4bdd54c8..5c235618 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -2,5 +2,5 @@ quarkus.devservices.enabled=false object-store.type=${MODEL_OBJECT_STORE_TYPE:AWS_S3} object-store.bucket.name=${MODEL_OBJECT_STORE_BUCKET_NAME:pagopa-dev-atm-layer-s3-model} object-store.bpmn.path-template=${MODEL_OBJECT_STORE_BPMN_TEMPLATE_PATH:/BPMN/files/UUID/[uuid]/VERSION/[version]} -object-store.dmn.path-template=${MODEL_OBJECT_STORE_DMN_TEMPLATE_PATH:WORKFLOW_RESOURCE/files/[RESOURCE_TYPE]/[uuid]} +object-store.workflow-resource.path-template=${MODEL_OBJECT_STORE_WORKFLOW_RESOURCE_TEMPLATE_PATH:WORKFLOW_RESOURCE/[RESOURCE_TYPE]/files/UUID/[uuid]} object-store.bucket.region=${MODEL_OBJECT_STORE_REGION:eu-south-1} \ No newline at end of file From 794f69ffa96ccb794f4f6888b1427318aa1f149f Mon Sep 17 00:00:00 2001 From: "USERSAD\\evalenti" Date: Thu, 9 Nov 2023 16:12:26 +0100 Subject: [PATCH 9/9] Refinements --- .../service/model/entity/ResourceFile.java | 1 - .../model/mapper/WorkflowResourceMapper.java | 8 +++++ .../resource/WorkflowResourceResource.java | 35 ++++++++++++++++++- .../service/WorkflowResourceService.java | 3 ++ .../impl/WorkflowResourceServiceImpl.java | 6 ++++ 5 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/ResourceFile.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/ResourceFile.java index 1dc651db..bc6d4795 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/ResourceFile.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/ResourceFile.java @@ -45,7 +45,6 @@ public class ResourceFile extends PanacheEntityBase implements Serializable { @Column(name = "resource_type") @Enumerated(EnumType.STRING) - @NotNull private WorkflowResourceTypeEnum resourceType; @OneToOne(fetch = FetchType.LAZY) diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/mapper/WorkflowResourceMapper.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/mapper/WorkflowResourceMapper.java index 1327b7ea..2ead5618 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/mapper/WorkflowResourceMapper.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/mapper/WorkflowResourceMapper.java @@ -1,8 +1,10 @@ package it.gov.pagopa.atmlayer.service.model.mapper; import it.gov.pagopa.atmlayer.service.model.dto.WorkflowResourceCreationDto; +import it.gov.pagopa.atmlayer.service.model.entity.BpmnVersion; import it.gov.pagopa.atmlayer.service.model.entity.WorkflowResource; import it.gov.pagopa.atmlayer.service.model.enumeration.StatusEnum; +import it.gov.pagopa.atmlayer.service.model.model.BpmnDTO; import it.gov.pagopa.atmlayer.service.model.model.WorkflowResourceDTO; import it.gov.pagopa.atmlayer.service.model.utils.BpmnUtils; import org.mapstruct.Mapper; @@ -10,6 +12,8 @@ import java.io.IOException; import java.security.NoSuchAlgorithmException; +import java.util.List; +import java.util.stream.Collectors; @Mapper(componentModel = "cdi") public abstract class WorkflowResourceMapper { @@ -29,6 +33,10 @@ public WorkflowResource toEntityCreation(WorkflowResourceCreationDto workflowCre public abstract WorkflowResourceDTO toDTO(WorkflowResource workflowResource); + public List toDTOList(List list){ + return list.stream().map(this::toDTO).collect(Collectors.toList()); + } + // @Mapping(ignore = true, target = "enabled") // @Mapping(target = "resourceFile.dmn",ignore = true) // public abstract WorkflowResource toEntity(WorkflowResourceDTO workflowResourceDTO); diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/resource/WorkflowResourceResource.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/resource/WorkflowResourceResource.java index 65802df0..ed314094 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/resource/WorkflowResourceResource.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/resource/WorkflowResourceResource.java @@ -2,8 +2,10 @@ import io.smallrye.common.annotation.NonBlocking; import io.smallrye.mutiny.Uni; +import io.smallrye.mutiny.unchecked.Unchecked; import it.gov.pagopa.atmlayer.service.model.dto.WorkflowResourceCreationDto; import it.gov.pagopa.atmlayer.service.model.entity.WorkflowResource; +import it.gov.pagopa.atmlayer.service.model.exception.AtmLayerException; import it.gov.pagopa.atmlayer.service.model.mapper.WorkflowResourceMapper; import it.gov.pagopa.atmlayer.service.model.model.WorkflowResourceDTO; import it.gov.pagopa.atmlayer.service.model.service.WorkflowResourceService; @@ -12,20 +14,24 @@ import jakarta.validation.Valid; import jakarta.ws.rs.Consumes; import jakarta.ws.rs.DELETE; +import jakarta.ws.rs.GET; import jakarta.ws.rs.POST; -import jakarta.ws.rs.PUT; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; import lombok.extern.slf4j.Slf4j; import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody; import org.eclipse.microprofile.openapi.annotations.tags.Tag; import java.io.IOException; import java.security.NoSuchAlgorithmException; +import java.util.List; import java.util.UUID; +import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.WORKFLOW_FILE_DOES_NOT_EXIST; + @ApplicationScoped @Path("/workflow-resource") @Tag(name = "Workflow Resource", description = "Workflow Resource Operations") @@ -38,6 +44,33 @@ public class WorkflowResourceResource { @Inject WorkflowResourceMapper workflowResourceMapper; + @GET + @Produces(MediaType.APPLICATION_JSON) + public Uni> getAllBpmn(){ + return this.workflowResourceService.getAll() + .onItem() + .transform(Unchecked.function(list -> { + if (list.isEmpty()) { + log.info("No Workflow Resource files saved in database"); + } + return workflowResourceMapper.toDTOList(list); + })); + } + + @GET + @Path("/{uuid}") + @Produces(MediaType.APPLICATION_JSON) + public Uni getById(@PathParam("uuid") UUID id) { + return this.workflowResourceService.findById(id) + .onItem() + .transform(Unchecked.function(x -> { + if (x.isEmpty()) { + throw new AtmLayerException(Response.Status.NOT_FOUND, WORKFLOW_FILE_DOES_NOT_EXIST); + } + return workflowResourceMapper.toDTO(x.get()); + })); + } + @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/WorkflowResourceService.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/WorkflowResourceService.java index 40b17446..8c8b5a26 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/WorkflowResourceService.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/WorkflowResourceService.java @@ -4,6 +4,7 @@ import it.gov.pagopa.atmlayer.service.model.entity.WorkflowResource; import java.io.File; +import java.util.List; import java.util.Optional; import java.util.UUID; @@ -25,5 +26,7 @@ public interface WorkflowResourceService { Uni delete(UUID uuid); + Uni> getAll(); + // Uni update(UUID id, WorkflowResource workflowResource); } diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java index 00c1d2ca..7a98eabb 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/WorkflowResourceServiceImpl.java @@ -24,6 +24,7 @@ import org.eclipse.microprofile.rest.client.inject.RestClient; import java.io.File; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -253,6 +254,11 @@ public Uni delete(UUID uuid) { })).onItem().transformToUni(y -> this.workflowResourceRepository.deleteById(uuid)); } + @Override + public Uni> getAll() { + return this.workflowResourceRepository.findAll().list(); + } + // @Override // public Uni update(UUID id, WorkflowResource workflowResource) { // log.info("Updating Workflow Resource with id {}", id.toString());