diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/client/ProcessClient.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/client/ProcessClient.java new file mode 100644 index 00000000..8201e7c3 --- /dev/null +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/client/ProcessClient.java @@ -0,0 +1,20 @@ +package it.gov.pagopa.atmlayer.service.model.client; + +import io.smallrye.mutiny.Uni; +import it.gov.pagopa.atmlayer.service.model.dto.DeployResponseDto; +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.FormParam; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; + +@RegisterRestClient(configKey = "process-deploy") +public interface ProcessClient { + @POST + @Path("/api/v1/processes/deploy") + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + @Produces(MediaType.APPLICATION_JSON) + Uni deploy(@FormParam("url") String url); +} diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/constraint/BankKeyConstraint.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/constraint/BankKeyConstraint.java index 0738573e..0d82a2ab 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/constraint/BankKeyConstraint.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/constraint/BankKeyConstraint.java @@ -1,31 +1,31 @@ -package it.gov.pagopa.atmlayer.service.model.constraint; - -import it.gov.pagopa.atmlayer.service.model.validators.BankKeyValidator; -import jakarta.validation.Constraint; -import jakarta.validation.Payload; -import jakarta.validation.constraintvalidation.SupportedValidationTarget; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static jakarta.validation.constraintvalidation.ValidationTarget.ANNOTATED_ELEMENT; -import static java.lang.annotation.ElementType.ANNOTATION_TYPE; -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.PARAMETER; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -@Retention(RUNTIME) -@Constraint(validatedBy = BankKeyValidator.class) -@Target({ElementType.TYPE_USE, FIELD, METHOD, PARAMETER, ANNOTATION_TYPE}) -@SupportedValidationTarget(ANNOTATED_ELEMENT) -@Documented -public @interface BankKeyConstraint { - String message() default "{the BankKey is invalid}"; - - Class[] groups() default {}; - - Class[] payload() default {}; -} +//package it.gov.pagopa.atmlayer.service.model.constraint; +// +//import it.gov.pagopa.atmlayer.service.model.validators.BankKeyValidator; +//import jakarta.validation.Constraint; +//import jakarta.validation.Payload; +//import jakarta.validation.constraintvalidation.SupportedValidationTarget; +// +//import java.lang.annotation.Documented; +//import java.lang.annotation.ElementType; +//import java.lang.annotation.Retention; +//import java.lang.annotation.Target; +// +//import static jakarta.validation.constraintvalidation.ValidationTarget.ANNOTATED_ELEMENT; +//import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +//import static java.lang.annotation.ElementType.FIELD; +//import static java.lang.annotation.ElementType.METHOD; +//import static java.lang.annotation.ElementType.PARAMETER; +//import static java.lang.annotation.RetentionPolicy.RUNTIME; +// +//@Retention(RUNTIME) +//@Constraint(validatedBy = BankKeyValidator.class) +//@Target({ElementType.TYPE_USE, FIELD, METHOD, PARAMETER, ANNOTATION_TYPE}) +//@SupportedValidationTarget(ANNOTATED_ELEMENT) +//@Documented +//public @interface BankKeyConstraint { +// String message() default "{the BankKey is invalid}"; +// +// Class[] groups() default {}; +// +// Class[] payload() default {}; +//} diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/BpmnAssociationDto.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/BpmnAssociationDto.java index e9eb0c5e..cbbef5ad 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/BpmnAssociationDto.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/BpmnAssociationDto.java @@ -1,15 +1,24 @@ package it.gov.pagopa.atmlayer.service.model.dto; -import it.gov.pagopa.atmlayer.service.model.constraint.BankKeyConstraint; -import jakarta.validation.Valid; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; import java.util.List; +import java.util.UUID; @Data @NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter public class BpmnAssociationDto { - private List<@BankKeyConstraint @Valid BankKeyDto> bankKeyDtoList; + private UUID defaultTemplateId; + + private Long defaultTemplateVersion; + + private List branchesConfigs; } diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/BpmnCreationDto.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/BpmnCreationDto.java index 8ad263cb..97020ab2 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/BpmnCreationDto.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/BpmnCreationDto.java @@ -1,6 +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.FunctionTypeEnum; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Pattern; import jakarta.ws.rs.FormParam; @@ -26,5 +26,5 @@ public class BpmnCreationDto { @FormParam("functionType") @NotNull(message = "function type is required") - private functionTypeEnum functionType; + private FunctionTypeEnum functionType; } diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/BranchConfigs.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/BranchConfigs.java new file mode 100644 index 00000000..831bab39 --- /dev/null +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/BranchConfigs.java @@ -0,0 +1,19 @@ +package it.gov.pagopa.atmlayer.service.model.dto; + +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +import java.util.List; +import java.util.UUID; + +@Data +public class BranchConfigs { + //TODO: Validatore custom + private String branchId; + + private UUID branchDefaultTemplateId; + + private Long branchDefaultTemplateVersion; + + private List terminals; +} diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/DeployResponseDto.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/DeployResponseDto.java new file mode 100644 index 00000000..7d847ec9 --- /dev/null +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/DeployResponseDto.java @@ -0,0 +1,27 @@ +package it.gov.pagopa.atmlayer.service.model.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.util.List; +import java.util.Map; +import java.util.UUID; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class DeployResponseDto { + private List links; + private UUID id; + private String name; + private String source; + private String deploymentTime; + private String tenantId; + private Map deployedProcessDefinitions; + private String deployedCaseDefinitions; + private String deployedDecisionDefinitions; + private String deployedDecisionRequirementsDefinitions; +} diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/DeployedProcessInfoDto.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/DeployedProcessInfoDto.java new file mode 100644 index 00000000..60bd7f0e --- /dev/null +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/DeployedProcessInfoDto.java @@ -0,0 +1,29 @@ +package it.gov.pagopa.atmlayer.service.model.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.util.UUID; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class DeployedProcessInfoDto { + private String id; + private String key; + private String category; + private String description; + private String name; + private Integer version; + private String resource; + private UUID deploymentId; + private String diagram; + private Boolean suspended; + private String tenantId; + private String versionTag; + private int historyTimeToLeave; + private Boolean startableInTasklist; +} diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/LinkDto.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/LinkDto.java new file mode 100644 index 00000000..64d45f21 --- /dev/null +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/LinkDto.java @@ -0,0 +1,16 @@ +package it.gov.pagopa.atmlayer.service.model.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class LinkDto { + private String method; + private String href; + private String rel; +} diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/TerminalConfigs.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/TerminalConfigs.java new file mode 100644 index 00000000..4101ff50 --- /dev/null +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/dto/TerminalConfigs.java @@ -0,0 +1,17 @@ +package it.gov.pagopa.atmlayer.service.model.dto; + +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +import java.util.List; +import java.util.UUID; + +@Data +public class TerminalConfigs { + @NotNull + private UUID templateId; + @NotNull + private Long templateVersion; + + private List terminalIds; +} diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/BpmnBankConfig.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/BpmnBankConfig.java index 50dab951..f3e24270 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/BpmnBankConfig.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/BpmnBankConfig.java @@ -1,18 +1,12 @@ package it.gov.pagopa.atmlayer.service.model.entity; -import com.fasterxml.jackson.annotation.JsonManagedReference; import io.quarkus.hibernate.reactive.panache.PanacheEntityBase; -import it.gov.pagopa.atmlayer.service.model.enumeration.functionTypeEnum; -import jakarta.persistence.CascadeType; +import it.gov.pagopa.atmlayer.service.model.enumeration.FunctionTypeEnum; import jakarta.persistence.Column; import jakarta.persistence.EmbeddedId; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; -import jakarta.persistence.FetchType; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.JoinColumns; -import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import lombok.AllArgsConstructor; import lombok.Getter; @@ -37,7 +31,7 @@ public class BpmnBankConfig extends PanacheEntityBase implements Serializable { @Column(name = "function_type") @Enumerated(EnumType.STRING) - private functionTypeEnum functionType; + private FunctionTypeEnum functionType; @Column(name = "enabled", columnDefinition = "boolean default true") private Boolean enabled; diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/BpmnBankConfigPK.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/BpmnBankConfigPK.java index 06201499..2a31bc7d 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/BpmnBankConfigPK.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/BpmnBankConfigPK.java @@ -29,8 +29,10 @@ public class BpmnBankConfigPK implements Serializable { @NotNull(message = "acquirer id cannot be null") @Column(name = "acquirer_id") private String acquirerId; + @Column(name = "branch_id") - private String branchId; + private String branchId = "null"; + @Column(name = "terminal_id") - private String terminalId; + private String terminalId = "null"; } diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/BpmnVersion.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/BpmnVersion.java index 44eb0b6d..2f84f134 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/BpmnVersion.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/entity/BpmnVersion.java @@ -1,8 +1,8 @@ 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.StatusEnum; -import it.gov.pagopa.atmlayer.service.model.enumeration.functionTypeEnum; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; @@ -47,9 +47,10 @@ public class BpmnVersion extends PanacheEntityBase implements Serializable { @Column(name = "function_type") @Enumerated(EnumType.STRING) - private functionTypeEnum functionType; + private FunctionTypeEnum functionType; @Column(name = "status") + @Enumerated(EnumType.STRING) private StatusEnum status; @Column(name = "sha256", unique = true) @@ -86,4 +87,5 @@ public class BpmnVersion extends PanacheEntityBase implements Serializable { @Column(name = "last_updated_by") private String lastUpdatedBy; + } 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 0f13ae2d..6569cf35 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 @@ -5,6 +5,10 @@ import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.CONSTRAINT_VIOLATION; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.GENERIC; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.INTERNAL; +import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.INVALID_FUNCTION_TYPE; +import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.NOT_DELETABLE; +import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.NOT_DEPLOYABLE_STATUS; +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; /** @@ -14,8 +18,12 @@ public enum AppErrorCodeEnum { ATMLM_500("ATMLM_500", "An unexpected error has occurred, see logs for more info", GENERIC), - BPMN_FILE_WITH_SAME_CONTENT_ALREADY_EXIST("ATMLM_4000001", "A BPMN file with the same content already Exist", CONSTRAINT_VIOLATION), - BPMN_FILE_DOES_NOT_EXIST("ATMLM_4000002", "The referenced BPMN file does not exists", NOT_EXISTING_REFERENCED_ENTITY), + BPMN_FILE_WITH_SAME_CONTENT_ALREADY_EXIST("ATMLM_4000001", "A BPMN file with the same content already exists", CONSTRAINT_VIOLATION), + BPMN_FILE_DOES_NOT_EXIST("ATMLM_4000002", "The referenced BPMN file does not exist", NOT_EXISTING_REFERENCED_ENTITY), + BPMN_FILE_NOT_DEPLOYED("ATMLM_4000003", "The referenced BPMN file is not deployed", NOT_DEPLOYED_STATUS), + BPMN_FILE_CANNOT_BE_DEPLOYED("ATMLM_4000004", "The referenced BPMN file can not be deployed", NOT_DEPLOYABLE_STATUS), + BPMN_FUNCTION_TYPE_DIFFERENT_FROM_REQUESTED("ATMLM_4000005", "The referenced BPMN file has a function type different from the requested", INVALID_FUNCTION_TYPE), + BPMN_CANNOT_BE_DELETED_FOR_STATUS("ATMLM_4000006", "The referenced BPMN file can not be deleted in the actual state", NOT_DELETABLE), OBJECT_STORE_SAVE_FILE_ERROR("ATMLM_4000100", "Error on persisting file on Object Store ", INTERNAL); private final String errorCode; 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 1bcf8a6d..0d4bdd4a 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 @@ -6,7 +6,12 @@ public enum AppErrorType { GENERIC, VALIDATION, - INTERNAL, CONSTRAINT_VIOLATION, - NOT_EXISTING_REFERENCED_ENTITY + NOT_EXISTING_REFERENCED_ENTITY, + NOT_VALID_REFERENCED_ENTITY, + NOT_DEPLOYABLE_STATUS, + NOT_DEPLOYED_STATUS, + INVALID_FUNCTION_TYPE, + NOT_DELETABLE, + INTERNAL } \ No newline at end of file diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/BankConfigUtilityValues.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/BankConfigUtilityValues.java new file mode 100644 index 00000000..2f04e379 --- /dev/null +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/BankConfigUtilityValues.java @@ -0,0 +1,12 @@ +package it.gov.pagopa.atmlayer.service.model.enumeration; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum BankConfigUtilityValues { + NULL_VALUE("NULL"); + + private String value; +} diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/FunctionTypeEnum.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/FunctionTypeEnum.java new file mode 100644 index 00000000..3f395824 --- /dev/null +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/FunctionTypeEnum.java @@ -0,0 +1,15 @@ +package it.gov.pagopa.atmlayer.service.model.enumeration; + +import com.fasterxml.jackson.annotation.JsonValue; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum FunctionTypeEnum { + MENU("MENU"), + SPONTANEOUS_PAYMENT("SPONTANEOUS_PAYMENT"); + + @JsonValue + private String value; +} 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 3c10423b..abd38b8a 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 @@ -1,15 +1,30 @@ package it.gov.pagopa.atmlayer.service.model.enumeration; +import com.fasterxml.jackson.annotation.JsonValue; import lombok.AllArgsConstructor; import lombok.Getter; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + @Getter @AllArgsConstructor public enum StatusEnum { CREATED("CREATED"), - WAITING_DEPLOY("WAITING_DEPLOY"), - DEPLOYED("DEPLOYED"); + WAITING_DEPLOY("DEPLOY_IN_PROGRESS"), + DEPLOYED("DEPLOYED"), + DEPLOY_ERROR("DEPLOY_ERROR"); + @JsonValue private String value; + public static Set getDeletableStatuses() { + return new HashSet<>(Arrays.asList(CREATED, DEPLOY_ERROR)); + } + + public static boolean isDeletable(StatusEnum status) { + return getDeletableStatuses().contains(status); + } + } 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 f3f063c2..f2e328c8 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 @@ -6,6 +6,5 @@ @Mapper public interface BpmnVersionMapper { - BpmnCreationDto toDto(BpmnVersion bpmnVersion); } diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/model/AssociationMetadata.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/model/AssociationMetadata.java deleted file mode 100644 index ed085155..00000000 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/model/AssociationMetadata.java +++ /dev/null @@ -1,24 +0,0 @@ -package it.gov.pagopa.atmlayer.service.model.model; - -import it.gov.pagopa.atmlayer.service.model.constraint.BankKeyConstraint; -import it.gov.pagopa.atmlayer.service.model.dto.BankKeyDto; -import it.gov.pagopa.atmlayer.service.model.enumeration.functionTypeEnum; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotNull; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.List; - -@Data -@NoArgsConstructor -public class AssociationMetadata { - @NotNull(message = "The function cannot be null") - private functionTypeEnum function; //enum - @NotNull(message = "The filename cannot be null") - private String fileName; //no extension - @NotNull(message = "The BPMN key cannot be null") - private String bpmnKey; - @NotNull(message = "The Bank Key list cannot be null") - private List<@BankKeyConstraint @Valid BankKeyDto> bankKeyDtoList; -} 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 f152b0cd..97387241 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 @@ -4,7 +4,7 @@ import io.smallrye.mutiny.Uni; import it.gov.pagopa.atmlayer.service.model.entity.BpmnBankConfig; import it.gov.pagopa.atmlayer.service.model.entity.BpmnBankConfigPK; -import it.gov.pagopa.atmlayer.service.model.enumeration.functionTypeEnum; +import it.gov.pagopa.atmlayer.service.model.enumeration.FunctionTypeEnum; import jakarta.enterprise.context.ApplicationScoped; import java.util.HashMap; @@ -14,7 +14,7 @@ @ApplicationScoped public class BpmnBankConfigRepository implements PanacheRepositoryBase { - public Uni deleteByAcquirerIdAndFunctionType(String acquirerId, functionTypeEnum functionType) { + public Uni deleteByAcquirerIdAndFunctionType(String acquirerId, FunctionTypeEnum functionType) { Map params = new HashMap<>(); params.put("acquirerId", acquirerId); params.put("functionType", functionType); @@ -22,7 +22,7 @@ public Uni deleteByAcquirerIdAndFunctionType(String acquirerId, functionTy "delete from BpmnBankConfig b where b.bpmnBankConfigPK.acquirerId = :acquirerId and b.functionType= :functionType", params); } - public Uni> findByAcquirerIdAndFunctionType(String acquirerId, functionTypeEnum functionType) { + public Uni> findByAcquirerIdAndFunctionType(String acquirerId, FunctionTypeEnum functionType) { Map params = new HashMap<>(); params.put("acquirerId", acquirerId); params.put("functionType", functionType); diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/repository/BpmnVersionRepository.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/repository/BpmnVersionRepository.java index 28e40edf..b731bc69 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/repository/BpmnVersionRepository.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/repository/BpmnVersionRepository.java @@ -20,5 +20,4 @@ public Uni> findByIds(Set ids) { Set bpmnIdVersion = ids.stream().map(x -> x.getBpmnId().toString().concat("_".concat(x.getModelVersion().toString()))).collect(Collectors.toSet()); return find("where concat(bpmnId,'_',modelVersion) in ?1", bpmnIdVersion).list(); } - } diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/resource/BpmnResource.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/resource/BpmnResource.java index 247473e4..aa147d8c 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/resource/BpmnResource.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/resource/BpmnResource.java @@ -3,13 +3,15 @@ import io.smallrye.common.annotation.NonBlocking; import io.smallrye.mutiny.Uni; import io.smallrye.mutiny.unchecked.Unchecked; +import it.gov.pagopa.atmlayer.service.model.client.ProcessClient; import it.gov.pagopa.atmlayer.service.model.dto.BpmnAssociationDto; import it.gov.pagopa.atmlayer.service.model.dto.BpmnCreationDto; import it.gov.pagopa.atmlayer.service.model.entity.BpmnBankConfig; -import it.gov.pagopa.atmlayer.service.model.entity.BpmnBankConfigPK; 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.enumeration.functionTypeEnum; +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.StatusEnum; import it.gov.pagopa.atmlayer.service.model.exception.AtmLayerException; import it.gov.pagopa.atmlayer.service.model.service.BpmnFileStorageService; import it.gov.pagopa.atmlayer.service.model.service.BpmnVersionService; @@ -32,6 +34,7 @@ import lombok.extern.slf4j.Slf4j; import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody; import org.eclipse.microprofile.openapi.annotations.tags.Tag; +import org.eclipse.microprofile.rest.client.inject.RestClient; import java.io.IOException; import java.security.NoSuchAlgorithmException; @@ -40,6 +43,7 @@ import java.util.UUID; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.BPMN_FILE_DOES_NOT_EXIST; +import static it.gov.pagopa.atmlayer.service.model.utils.BpmnUtils.getAcquirerConfigs; @ApplicationScoped @Path("/bpmn") @@ -55,15 +59,9 @@ public class BpmnResource { @Inject BpmnFileStorageService bpmnFileStorageService; - -// @GET -// @Consumes(MediaType.APPLICATION_JSON) -// @Produces(MediaType.TEXT_PLAIN) -// public String getEncodedFile(@QueryParam("string") String s) throws IOException { -// String xml = modelService.decodeBase64(s); -// logger.info("String file: " + xml); -// return "String file: " + xml; -// } + @Inject + @RestClient + ProcessClient processClient; @GET @Path("/{bpmnId}/version/{version}") @@ -86,41 +84,19 @@ public Uni getEncodedFile(@PathParam("bpmnId") UUID bpmnId, } @PUT - @Path("/bank/{acquirerId}/associations/function/{functionType}/{id}") + @Path("/bank/{acquirerId}/associations/function/{functionType}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Uni> associateBPMN(@PathParam("acquirerId") String acquirerId, - @PathParam("functionType") functionTypeEnum functionTypeEnum, - @PathParam("id") UUID id, - @RequestBody(required = true) @Valid BpmnAssociationDto bpmnAssociationDto) throws NoSuchAlgorithmException, IOException { - - // TO DO, metodo che dal DTO estrae la lista di configs - List configs = extractConfigs(acquirerId, functionTypeEnum, id); + @PathParam("functionType") FunctionTypeEnum functionTypeEnum, + @RequestBody(required = true) @Valid BpmnAssociationDto bpmnAssociationDto) + throws NoSuchAlgorithmException, IOException { + List configs = getAcquirerConfigs(bpmnAssociationDto, acquirerId, + functionTypeEnum); Set bpmnIds = BpmnUtils.extractBpmnUUIDFromAssociations(configs); - return bpmnEntityValidator.validateExistence(bpmnIds) - .onItem().transformToUni(x -> this.bpmnVersionService.putAssociations(acquirerId, functionTypeEnum, configs)); - } - - private static List extractConfigs(String acquirerId, functionTypeEnum functionTypeEnum, UUID id) { - BpmnBankConfigPK bpmnBankConfigPK = new BpmnBankConfigPK(); - bpmnBankConfigPK.setBpmnId(id); - bpmnBankConfigPK.setBpmnModelVersion(1L); - bpmnBankConfigPK.setAcquirerId(acquirerId); - bpmnBankConfigPK.setBranchId("1"); - bpmnBankConfigPK.setTerminalId("1"); - BpmnBankConfigPK bpmnBankConfigPK2 = new BpmnBankConfigPK(); - bpmnBankConfigPK2.setBpmnId(id); - bpmnBankConfigPK2.setBpmnModelVersion(1L); - bpmnBankConfigPK2.setAcquirerId(acquirerId); - bpmnBankConfigPK2.setBranchId("1"); - bpmnBankConfigPK2.setTerminalId("2"); - BpmnBankConfig bpmnBankConfig = new BpmnBankConfig(); - BpmnBankConfig bpmnBankConfig1 = new BpmnBankConfig(); - bpmnBankConfig.setBpmnBankConfigPK(bpmnBankConfigPK); - bpmnBankConfig.setFunctionType(functionTypeEnum); - bpmnBankConfig1.setBpmnBankConfigPK(bpmnBankConfigPK2); - bpmnBankConfig1.setFunctionType(functionTypeEnum); - return List.of(bpmnBankConfig, bpmnBankConfig1); + return bpmnEntityValidator.validateExistenceStatusAndFunctionType(bpmnIds,functionTypeEnum) + .onItem().transformToUni( + x -> this.bpmnVersionService.putAssociations(acquirerId, functionTypeEnum, configs)); } @POST @@ -142,4 +118,30 @@ public Uni deleteBpmn(@PathParam("bpmnId") UUID bpmnId, return this.bpmnVersionService.delete(new BpmnVersionPK(bpmnId, version)) .onItem().ignore().andSwitchTo(Uni.createFrom().voidItem()); } + + @POST + @Path("/deploy/{uuid}/version/{version}") + @Produces(MediaType.APPLICATION_JSON) + public Uni deployBPMN(@PathParam("uuid") UUID uuid, + @PathParam("version") Long version) { + return bpmnVersionService.checkBpmnFileExistence(uuid, version) + .onItem() + .transformToUni(Unchecked.function(x -> { + if (!x) { + String errorMessage = "The referenced BPMN file can not be deployed"; + throw new AtmLayerException(errorMessage, Response.Status.BAD_REQUEST, + AppErrorCodeEnum.BPMN_FILE_CANNOT_BE_DEPLOYED); + } + return bpmnVersionService.setBpmnVersionStatus(uuid, version, StatusEnum.WAITING_DEPLOY); + })) + .onItem() + .transformToUni(bpmnWaiting -> { + return processClient.deploy("url") + .onItem() + .transformToUni(response -> bpmnVersionService.setDeployInfo(uuid, version, response)) + .onItem() + .transformToUni(bpmnUpdated -> bpmnVersionService.setBpmnVersionStatus(uuid, version, + StatusEnum.DEPLOYED)); + }); + } } diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/BpmnVersionService.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/BpmnVersionService.java index ff34dc12..96260fb7 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/BpmnVersionService.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/BpmnVersionService.java @@ -1,10 +1,12 @@ package it.gov.pagopa.atmlayer.service.model.service; import io.smallrye.mutiny.Uni; +import it.gov.pagopa.atmlayer.service.model.dto.DeployResponseDto; import it.gov.pagopa.atmlayer.service.model.entity.BpmnBankConfig; 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.enumeration.functionTypeEnum; +import it.gov.pagopa.atmlayer.service.model.enumeration.FunctionTypeEnum; +import it.gov.pagopa.atmlayer.service.model.enumeration.StatusEnum; import java.io.File; import java.io.IOException; @@ -12,12 +14,12 @@ import java.util.List; import java.util.Optional; import java.util.Set; +import java.util.UUID; public interface BpmnVersionService { String decodeBase64(String s) throws IOException; - Uni> findByPKSet(Set bpmnVersionPKSet); String calculateSHA256(File file) throws NoSuchAlgorithmException, IOException; @@ -26,11 +28,19 @@ public interface BpmnVersionService { Uni delete(BpmnVersionPK bpmnVersionPK); - public Uni> findBySHA256(String sha256); + Uni> findBySHA256(String sha256); Uni> findByPk(BpmnVersionPK bpmnVersionPK); - Uni> putAssociations(String acquirerId, functionTypeEnum functionTypeEnum, List bpmnBankConfigs); + Uni> putAssociations(String acquirerId, FunctionTypeEnum functionTypeEnum, List bpmnBankConfigs); + + Uni setBpmnVersionStatus(UUID id, Long modelVersion, StatusEnum status); + + Uni checkBpmnFileExistence(UUID id, Long modelVersion); + + Uni setDeployInfo(UUID id, Long modelVersion, DeployResponseDto response); Uni saveAndUpload(BpmnVersion bpmnVersion, File file, String filename); + + } 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 39419a54..4c2a110c 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 @@ -3,7 +3,7 @@ import io.quarkus.hibernate.reactive.panache.common.WithTransaction; import io.smallrye.mutiny.Uni; import it.gov.pagopa.atmlayer.service.model.entity.BpmnBankConfig; -import it.gov.pagopa.atmlayer.service.model.enumeration.functionTypeEnum; +import it.gov.pagopa.atmlayer.service.model.enumeration.FunctionTypeEnum; import it.gov.pagopa.atmlayer.service.model.repository.BpmnBankConfigRepository; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; @@ -20,12 +20,12 @@ public Uni saveList(List bpmnBankConfigs) { return bankConfigRepository.persist(bpmnBankConfigs); } - public Uni> findByAcquirerIdAndFunctionType(String acquirerId, functionTypeEnum functionType){ - return this.bankConfigRepository.findByAcquirerIdAndFunctionType(acquirerId,functionType); + public Uni> findByAcquirerIdAndFunctionType(String acquirerId, FunctionTypeEnum functionType) { + return this.bankConfigRepository.findByAcquirerIdAndFunctionType(acquirerId, functionType); } @WithTransaction - public Uni deleteByAcquirerIdAndFunctionType(String acquirerId, functionTypeEnum functionTypeEnum) { + public Uni deleteByAcquirerIdAndFunctionType(String acquirerId, FunctionTypeEnum functionTypeEnum) { return this.bankConfigRepository.deleteByAcquirerIdAndFunctionType(acquirerId, functionTypeEnum); } } 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 5c355c2f..d847b053 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 @@ -1,15 +1,20 @@ package it.gov.pagopa.atmlayer.service.model.service.impl; +import io.quarkus.hibernate.reactive.panache.common.WithSession; import io.quarkus.hibernate.reactive.panache.common.WithTransaction; import io.smallrye.mutiny.Multi; import io.smallrye.mutiny.Uni; import io.smallrye.mutiny.unchecked.Unchecked; import io.vertx.core.Context; import io.vertx.core.Vertx; +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.BpmnBankConfig; 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.enumeration.functionTypeEnum; +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.StatusEnum; import it.gov.pagopa.atmlayer.service.model.exception.AtmLayerException; import it.gov.pagopa.atmlayer.service.model.model.BpmnIdDto; import it.gov.pagopa.atmlayer.service.model.repository.BpmnVersionRepository; @@ -25,8 +30,10 @@ import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.UUID; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.BPMN_FILE_WITH_SAME_CONTENT_ALREADY_EXIST; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.OBJECT_STORE_SAVE_FILE_ERROR; @@ -82,23 +89,36 @@ public Uni save(BpmnVersion bpmnVersion) { @Override public Uni delete(BpmnVersionPK bpmnVersionPK) { log.info("Deleting BPMN with id {}", bpmnVersionPK.toString()); - return this.bpmnVersionRepository.deleteById(bpmnVersionPK); + return this.findByPk(bpmnVersionPK) + .onItem() + .transformToUni(Unchecked.function(x -> { + if (x.isEmpty()) { + throw new AtmLayerException(String.format("BPMN with id %s does not exists", bpmnVersionPK), Response.Status.NOT_FOUND, AppErrorCodeEnum.BPMN_FILE_DOES_NOT_EXIST); + } + if (!StatusEnum.isDeletable(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); + } + return Uni.createFrom().item(x.get()); + })).onItem().transformToUni(y -> this.bpmnVersionRepository.deleteById(bpmnVersionPK)); } @Override + @WithSession public Uni> findBySHA256(String sha256) { return this.bpmnVersionRepository.findBySHA256(sha256) .onItem().transformToUni(x -> Uni.createFrom().item(Optional.ofNullable(x))); } @Override + @WithSession public Uni> findByPk(BpmnVersionPK bpmnVersionPK) { return bpmnVersionRepository.findById(bpmnVersionPK).onItem().transformToUni(bpmnVersion -> Uni.createFrom().item(Optional.ofNullable(bpmnVersion))); } @Override @WithTransaction - public Uni> putAssociations(String acquirerId, functionTypeEnum functionType, List bpmnBankConfigs) { + public Uni> putAssociations(String acquirerId, FunctionTypeEnum functionType, List bpmnBankConfigs) { Uni deleteExistingUni = this.bpmnBankConfigService.deleteByAcquirerIdAndFunctionType(acquirerId, functionType); return deleteExistingUni .onItem() @@ -107,6 +127,44 @@ public Uni> putAssociations(String acquirerId, functionType .transformToUni(y -> this.bpmnBankConfigService.findByAcquirerIdAndFunctionType(acquirerId, functionType)); } + @Override + @WithTransaction + public Uni setBpmnVersionStatus(UUID id, Long modelVersion, StatusEnum status) { + BpmnVersionPK key = new BpmnVersionPK(id, modelVersion); + return this.findByPk(key) + .onItem() + .transformToUni(Unchecked.function(optionalBpmn -> { + if (optionalBpmn.isEmpty()) { + String errorMessage = String.format( + "One or some of the referenced BPMN files do not exists: %s", key); + throw new AtmLayerException(errorMessage, Response.Status.BAD_REQUEST, + AppErrorCodeEnum.BPMN_FILE_DOES_NOT_EXIST); + } + BpmnVersion bpmnToDeploy = optionalBpmn.get(); + bpmnToDeploy.setStatus(status); + return this.bpmnVersionRepository.persist(bpmnToDeploy); + }) + ); + } + + @Override + public Uni checkBpmnFileExistence(UUID id, Long modelVersion) { + BpmnVersionPK key = new BpmnVersionPK(id, modelVersion); + return this.findByPk(key) + .onItem() + .transform(Unchecked.function(optionalBpmn -> { + if (optionalBpmn.isEmpty()) { + String errorMessage = String.format( + "One or some of the referenced BPMN files do not exists: %s", key); + throw new AtmLayerException(errorMessage, Response.Status.BAD_REQUEST, + AppErrorCodeEnum.BPMN_FILE_DOES_NOT_EXIST); + } + BpmnVersion bpmnVersion = optionalBpmn.get(); + return bpmnVersion.getStatus().equals(StatusEnum.CREATED) || bpmnVersion.getStatus() + .equals(StatusEnum.DEPLOY_ERROR); + }) + ); + } @Override public Uni saveAndUpload(BpmnVersion bpmnVersion, File file, String filename) { @@ -130,7 +188,39 @@ public Uni saveAndUpload(BpmnVersion bpmnVersion, File file, String }); } - private static Uni> addFunctionTypeToAssociations(List bpmnBankConfigs, functionTypeEnum functionType) { + @Override + @WithTransaction + public Uni setDeployInfo(UUID id, Long modelVersion, DeployResponseDto response) { + BpmnVersionPK key = new BpmnVersionPK(id, modelVersion); + return this.findByPk(key) + .onItem() + .transformToUni(Unchecked.function(optionalBpmn -> { + if (optionalBpmn.isEmpty()) { + String errorMessage = String.format( + "One or some of the referenced BPMN files do not exists: %s", key); + throw new AtmLayerException(errorMessage, Response.Status.BAD_REQUEST, + AppErrorCodeEnum.BPMN_FILE_DOES_NOT_EXIST); + } + BpmnVersion bpmnVersion = optionalBpmn.get(); + Map deployedProcessDefinitions = response.getDeployedProcessDefinitions(); + Optional optionalDeployedProcessInfo = deployedProcessDefinitions.values() + .stream().findFirst(); + if (optionalDeployedProcessInfo.isEmpty()) { + throw new RuntimeException("empty process info"); + } + DeployedProcessInfoDto deployedProcessInfo = optionalDeployedProcessInfo.get(); + bpmnVersion.setDefinitionVersionCamunda(deployedProcessInfo.getVersion()); + bpmnVersion.setDeploymentId(deployedProcessInfo.getDeploymentId()); + bpmnVersion.setCamundaDefinitionId(deployedProcessInfo.getId()); + bpmnVersion.setDefinitionKey(deployedProcessInfo.getKey()); + bpmnVersion.setDeployedFileName(deployedProcessInfo.getName()); + bpmnVersion.setDescription(deployedProcessInfo.getDescription()); + bpmnVersion.setResource(deployedProcessInfo.getResource()); + return this.bpmnVersionRepository.persist(bpmnVersion); + })); + } + + private static Uni> addFunctionTypeToAssociations(List bpmnBankConfigs, FunctionTypeEnum functionType) { return Multi.createFrom().items(bpmnBankConfigs.stream()).onItem().transform(bpmnBankConfig -> { bpmnBankConfig.setFunctionType(functionType); return bpmnBankConfig; 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 fd1ffc4a..65b64b88 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,20 +1,14 @@ package it.gov.pagopa.atmlayer.service.model.utils; -import it.gov.pagopa.atmlayer.service.model.dto.BankKeyDto; -import it.gov.pagopa.atmlayer.service.model.dto.BpmnAssociationDto; import it.gov.pagopa.atmlayer.service.model.dto.BpmnCreationDto; -import it.gov.pagopa.atmlayer.service.model.dto.BranchDto; 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 it.gov.pagopa.atmlayer.service.model.model.AssociationKey; import jakarta.enterprise.context.ApplicationScoped; import java.io.File; import java.io.IOException; import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.List; @ApplicationScoped public class BpmnDtoMapper { @@ -29,43 +23,8 @@ public static BpmnVersion toBpmnVersion(BpmnCreationDto bpmnCreationDto) throws return bpmnVersion; } -// public static List toListBpmnBankConfig(BpmnAssociationDto bpmnAssociationDto, UUID uuid, int version) { -// BpmnVersionPK bpmnVersionPK = new BpmnVersionPK(uuid, version); -// List bpmnBankConfigPKS = new ArrayList<>(); -// List associationKeys = getAllAssociation(bpmnAssociationDto); -// for (AssociationKey associationKey: associationKeys) { -// BpmnBankConfigPK bpmnBankConfigPK = new BpmnBankConfigPK(); -// bpmnBankConfigPK.setBpmnId(uuid); -// bpmnBankConfigPK.setBpmnModelVersion(version); -// bpmnBankConfigPK.setAcquirerId(associationKey.getAcquirerId()); -// bpmnBankConfigPK.setBranchId(associationKey.getBranchId()); -// bpmnBankConfigPK.setTerminalId(associationKey.getTerminalId()); -// bpmnBankConfigPKS.add(bpmnBankConfigPK); -// } -// } - public static String calculateSha256(File file) throws NoSuchAlgorithmException, IOException { - //TODO: Controllare che il file sia un xml .bpmn byte[] array = BpmnUtils.toSha256ByteArray(file); return BpmnUtils.toHexString(array); } - - public static List getAllAssociation(BpmnAssociationDto bpmnAssociationDto) { - List associationKeys = new ArrayList<>(); - List bankKeyDtoList = bpmnAssociationDto.getBankKeyDtoList(); - for (BankKeyDto bankKeyDto : bankKeyDtoList) { - String acquirerId = bankKeyDto.getAcquirerId(); - List branchDtoList = bankKeyDto.getBranches(); - for (BranchDto branchDto : branchDtoList) { - String branchId = branchDto.getBranchId(); - List terminalIdList = branchDto.getTerminalId(); - for (String terminalId : terminalIdList) { - AssociationKey associationKey = new AssociationKey(acquirerId, terminalId, branchId); - associationKeys.add(associationKey); - } - } - - } - return associationKeys; - } } diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/utils/BpmnUtils.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/utils/BpmnUtils.java index 3bf31ffd..a2d858ae 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/utils/BpmnUtils.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/utils/BpmnUtils.java @@ -1,8 +1,14 @@ package it.gov.pagopa.atmlayer.service.model.utils; import com.google.common.io.Files; +import it.gov.pagopa.atmlayer.service.model.dto.BpmnAssociationDto; +import it.gov.pagopa.atmlayer.service.model.dto.BranchConfigs; +import it.gov.pagopa.atmlayer.service.model.dto.TerminalConfigs; import it.gov.pagopa.atmlayer.service.model.entity.BpmnBankConfig; +import it.gov.pagopa.atmlayer.service.model.entity.BpmnBankConfigPK; import it.gov.pagopa.atmlayer.service.model.entity.BpmnVersionPK; +import it.gov.pagopa.atmlayer.service.model.enumeration.BankConfigUtilityValues; +import it.gov.pagopa.atmlayer.service.model.enumeration.FunctionTypeEnum; import jakarta.enterprise.context.ApplicationScoped; import java.io.File; @@ -11,6 +17,7 @@ import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; import java.util.Base64; import java.util.List; import java.util.Set; @@ -57,4 +64,55 @@ public static Set extractBpmnUUIDFromAssociations(List getAcquirerConfigs(BpmnAssociationDto bpmnAssociationDto, String acquirerId, FunctionTypeEnum functionTypeEnum) { + List bpmnBankConfigs = new ArrayList<>(); + BpmnBankConfig bpmnBankConfigAcquirerDefault = new BpmnBankConfig(); + bpmnBankConfigAcquirerDefault.setBpmnBankConfigPK(new BpmnBankConfigPK(bpmnAssociationDto.getDefaultTemplateId(), + bpmnAssociationDto.getDefaultTemplateVersion(), + acquirerId, BankConfigUtilityValues.NULL_VALUE.getValue(), BankConfigUtilityValues.NULL_VALUE.getValue())); + bpmnBankConfigAcquirerDefault.setFunctionType(functionTypeEnum); + bpmnBankConfigs.add(bpmnBankConfigAcquirerDefault); + if (bpmnAssociationDto.getBranchesConfigs() != null && !bpmnAssociationDto.getBranchesConfigs().isEmpty()) { + for (BranchConfigs branchConfig : bpmnAssociationDto.getBranchesConfigs()) { + BpmnBankConfig bpmnBankConfigBranchDefault = new BpmnBankConfig(); + BpmnBankConfigPK bpmnBankConfigPKBranch = getBpmnBankConfigPK(bpmnAssociationDto, acquirerId, branchConfig); + bpmnBankConfigBranchDefault.setFunctionType(functionTypeEnum); + bpmnBankConfigBranchDefault.setBpmnBankConfigPK(bpmnBankConfigPKBranch); + bpmnBankConfigs.add(bpmnBankConfigBranchDefault); + if (branchConfig.getTerminals() != null && !branchConfig.getTerminals().isEmpty()) { + for (TerminalConfigs terminalConfig : branchConfig.getTerminals()) { + for (String terminalId : terminalConfig.getTerminalIds()) { + BpmnBankConfig bpmnBankConfigTerminal = new BpmnBankConfig(); + BpmnBankConfigPK bpmnBankConfigPKTerminal = new BpmnBankConfigPK(); + bpmnBankConfigPKTerminal.setBpmnId(terminalConfig.getTemplateId()); + bpmnBankConfigPKTerminal.setBpmnModelVersion(terminalConfig.getTemplateVersion()); + bpmnBankConfigPKTerminal.setAcquirerId(acquirerId); + bpmnBankConfigPKTerminal.setBranchId(branchConfig.getBranchId()); + bpmnBankConfigPKTerminal.setTerminalId(terminalId); + bpmnBankConfigTerminal.setFunctionType(functionTypeEnum); + bpmnBankConfigTerminal.setBpmnBankConfigPK(bpmnBankConfigPKTerminal); + bpmnBankConfigs.add(bpmnBankConfigTerminal); + } + } + } + } + } + return bpmnBankConfigs; + } + + private static BpmnBankConfigPK getBpmnBankConfigPK(BpmnAssociationDto bpmnAssociationDto, String acquirerId, BranchConfigs branchConfig) { + BpmnBankConfigPK bpmnBankConfigPK = new BpmnBankConfigPK(); + if (branchConfig.getBranchDefaultTemplateId() == null && branchConfig.getBranchDefaultTemplateVersion() == null) { + bpmnBankConfigPK.setBpmnId(bpmnAssociationDto.getDefaultTemplateId()); + bpmnBankConfigPK.setBpmnModelVersion(bpmnAssociationDto.getDefaultTemplateVersion()); + } else { + bpmnBankConfigPK.setBpmnId(branchConfig.getBranchDefaultTemplateId()); + bpmnBankConfigPK.setBpmnModelVersion(branchConfig.getBranchDefaultTemplateVersion()); + } + bpmnBankConfigPK.setAcquirerId(acquirerId); + bpmnBankConfigPK.setBranchId(branchConfig.getBranchId()); + bpmnBankConfigPK.setTerminalId(BankConfigUtilityValues.NULL_VALUE.getValue()); + return bpmnBankConfigPK; + } + } diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/validators/BankKeyValidator.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/validators/BankKeyValidator.java index b7cd1640..cc753b62 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/validators/BankKeyValidator.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/validators/BankKeyValidator.java @@ -1,59 +1,52 @@ -package it.gov.pagopa.atmlayer.service.model.validators; - -import it.gov.pagopa.atmlayer.service.model.constraint.BankKeyConstraint; -import it.gov.pagopa.atmlayer.service.model.dto.BankKeyDto; -import it.gov.pagopa.atmlayer.service.model.dto.BranchDto; -import jakarta.validation.ConstraintValidator; -import jakarta.validation.ConstraintValidatorContext; - -import java.util.List; - -public class BankKeyValidator implements ConstraintValidator { - - public static boolean isStringValid(String str) { - return !str.trim().isEmpty(); - } - - public static boolean isListValid(List list) { - boolean check = false; - if (list == null) { - check = true; - } else if (!list.isEmpty()) { - for (String s: list) { - if (!isStringValid(s)){ - return false; - } - } - check = true; - } - return check; - } - - @Override - public void initialize(BankKeyConstraint constraintAnnotation) { - } - - @Override - public boolean isValid(BankKeyDto bankKeyDto, ConstraintValidatorContext constraintValidatorContext) throws RuntimeException{ - boolean isValid = false; - List branches = bankKeyDto.getBranches(); - for (BranchDto branch: branches) { - if (branch.getBranchId() == null) { - if (branch.getTerminalId() == null) { - isValid = true; - } - } else if (isStringValid(branch.getBranchId())){ - if (isListValid(branch.getTerminalId())) { - isValid = true; - } else { - isValid = false; - return isValid; - } - } else { - isValid = false; - return isValid; - } - } - return isValid; - } -} +//package it.gov.pagopa.atmlayer.service.model.validators; +// +//import it.gov.pagopa.atmlayer.service.model.constraint.BankKeyConstraint; +//import jakarta.validation.ConstraintValidator; +//import jakarta.validation.ConstraintValidatorContext; +// +//import java.util.List; +// +//public class BankKeyValidator implements ConstraintValidator { +// +// public static boolean isStringValid(String str) { +// return !str.trim().isEmpty(); +// } +// +// public static boolean isListValid(List list) { +// boolean check = false; +// if (list == null) { +// check = true; +// } else if (!list.isEmpty()) { +// for (String s: list) { +// if (!isStringValid(s)){ +// return false; +// } +// } +// check = true; +// } +// return check; +// } +// +// @Override +// public void initialize(BankKeyConstraint constraintAnnotation) { +// } +// +// @Override +// public boolean isValid(BankKeyDto bankKeyDto, ConstraintValidatorContext constraintValidatorContext) throws RuntimeException{ +// boolean isValid = false; +// if (bankKeyDto.getBranchId() == null) { +// if (bankKeyDto.getTerminalId() == null) { +// isValid = true; +// } +// } else if (isStringValid(bankKeyDto.getBranchId())){ +// if (isListValid(bankKeyDto.getTerminalId())) { +// isValid = true; +// } else { +// return isValid; +// } +// } else { +// return isValid; +// } +// return isValid; +// } +//} diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/validators/BpmnEntityValidator.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/validators/BpmnEntityValidator.java index 11304de5..f0a3e5a5 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/validators/BpmnEntityValidator.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/validators/BpmnEntityValidator.java @@ -3,13 +3,17 @@ import com.google.common.collect.Sets; import io.smallrye.mutiny.Uni; import io.smallrye.mutiny.unchecked.Unchecked; +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.enumeration.AppErrorCodeEnum; +import it.gov.pagopa.atmlayer.service.model.enumeration.FunctionTypeEnum; +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.service.BpmnVersionService; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import jakarta.ws.rs.core.Response; +import software.amazon.awssdk.utils.CollectionUtils; import java.util.Set; import java.util.stream.Collectors; @@ -24,16 +28,27 @@ public BpmnEntityValidator(BpmnVersionService bpmnVersionService) { this.bpmnVersionService = bpmnVersionService; } - public Uni validateExistence(Set ids) { + public Uni validateExistenceStatusAndFunctionType(Set ids, FunctionTypeEnum functionTypeEnum) { return this.bpmnVersionService.findByPKSet(ids) .onItem() .invoke(Unchecked.consumer(list -> { - if (list.isEmpty() || list.size() != ids.size()) { - Set extractedKeys = list.stream().map(x -> new BpmnVersionPK(x.getBpmnId(),x.getModelVersion())).collect(Collectors.toSet()); - Set missingBpm = Sets.difference(ids, extractedKeys); - String errorMessage = String.format("One or some of the referenced BPMN files do not exists: %s", missingBpm); + Set extractedKeys = list.stream().map(x -> new BpmnVersionPK(x.getBpmnId(), x.getModelVersion())).collect(Collectors.toSet()); + Set notDeployedBpmnFiles = list.stream().filter(bpmnVersion -> !bpmnVersion.getStatus().equals(StatusEnum.DEPLOYED)).collect(Collectors.toSet()); + if (!CollectionUtils.isNullOrEmpty(notDeployedBpmnFiles)) { + String errorMessage = String.format("One or some of the referenced BPMN files are not deployed: %s", notDeployedBpmnFiles.stream().map(x -> new BpmnVersionPK(x.getBpmnId(), x.getModelVersion())).collect(Collectors.toSet())); + throw new AtmLayerException(errorMessage, Response.Status.BAD_REQUEST, AppErrorCodeEnum.BPMN_FILE_NOT_DEPLOYED); + } + Set notValidFunctionTypeBpmnFiles = list.stream().filter(bpmnVersion -> !bpmnVersion.getFunctionType().equals(functionTypeEnum)).collect(Collectors.toSet()); + if (!CollectionUtils.isNullOrEmpty(notValidFunctionTypeBpmnFiles)) { + String errorMessage = String.format("One or some of the referenced BPMN do not have functionType %s: %s", functionTypeEnum.name(), notValidFunctionTypeBpmnFiles.stream().map(x -> new BpmnVersionPK(x.getBpmnId(), x.getModelVersion())).collect(Collectors.toSet())); + throw new AtmLayerException(errorMessage, Response.Status.BAD_REQUEST, AppErrorCodeEnum.BPMN_FUNCTION_TYPE_DIFFERENT_FROM_REQUESTED); + } + Set missingBpmn = Sets.difference(ids, extractedKeys); + if (!CollectionUtils.isNullOrEmpty(missingBpmn)) { + String errorMessage = String.format("One or some of the referenced BPMN files do not exists: %s", missingBpmn); throw new AtmLayerException(errorMessage, Response.Status.BAD_REQUEST, AppErrorCodeEnum.BPMN_FILE_DOES_NOT_EXIST); } + })) .onItem() .transformToUni(t -> Uni.createFrom().nullItem()); diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index f2313452..8af434b4 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -1,3 +1,4 @@ +quarkus.profile=local quarkus.http.port=${SERVER_PORT:8080} quarkus.datasource.db-kind=${MODEL_DB_TYPE:postgresql} quarkus.datasource.username=${MODEL_DB_USERNAME:postgres} @@ -15,6 +16,8 @@ quarkus.s3.aws.credentials.static-provider.secret-access-key=${OBJECT_STORE_ACCE quarkus.s3.aws.region=${MODEL_OBJECT_STORE_REGION:eu-south-1} quarkus.devservices.enabled=false quarkus.log.category."software.amazon.awssdk.services.s3".level=DEBUG +quarkus.hibernate-orm.physical-naming-strategy=org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy +quarkus.rest-client.process-deploy.url=http://localhost:3001 ################### # OBJECT STORE ################### diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 4a52913d..e5d3f411 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -57,7 +57,8 @@ quarkus.s3.aws.region=${MODEL_OBJECT_STORE_REGION:eu-south-1} ################### 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.bpmn.path-template=${MODEL_OBJECT_STORE_BPMN_TEMPLATE_PATH:BPMN/files/UUID/[uuid]/VERSION/[version]} +quarkus.rest-client.process-deploy.url=${MODEL_PROCESS_BASE_PATH}