Skip to content

Commit

Permalink
Fix Enum WorkflowResource
Browse files Browse the repository at this point in the history
  • Loading branch information
EmanueleValentini1 committed Nov 10, 2023
1 parent 5de9cdb commit 6dd41ab
Show file tree
Hide file tree
Showing 26 changed files with 115 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -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.S3ResourceTypeEnum;
import jakarta.annotation.Nullable;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
Expand All @@ -24,7 +24,7 @@ public class ResourceCreationDto {
private String filename;
@FormParam("resourceType")
@NotNull(message = "resource type is required")
private ResourceTypeEnum resourceType;
private S3ResourceTypeEnum resourceType;
@FormParam("path")
@Nullable
@Pattern(regexp = "^(?!/).*(?<!/)$", message = "String must not start or end with '/'")
Expand Down
Original file line number Diff line number Diff line change
@@ -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.DeployableResourceType;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.ws.rs.FormParam;
Expand All @@ -26,5 +26,5 @@ public class WorkflowResourceCreationDto {

@FormParam("resourceType")
@NotNull(message = "resource type is required")
private ResourceTypeEnum resourceType;
private DeployableResourceType resourceType;
}
Original file line number Diff line number Diff line change
@@ -1,7 +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.ResourceTypeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.S3ResourceTypeEnum;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
Expand Down Expand Up @@ -31,7 +31,7 @@ public class ResourceEntity extends PanacheEntityBase implements Serializable {
@Column(name = "sha256", unique = true)
private String sha256;
@Column(name="resourceType")
ResourceTypeEnum resourceTypeEnum;
S3ResourceTypeEnum s3ResourceTypeEnum;
@Column(name="file_name")
String fileName;
@CreationTimestamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.S3ResourceTypeEnum;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
Expand Down Expand Up @@ -45,7 +45,7 @@ public class ResourceFile extends PanacheEntityBase implements Serializable {

@Column(name = "resource_type")
@Enumerated(EnumType.STRING)
private ResourceTypeEnum resourceType;
private S3ResourceTypeEnum resourceType;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumns({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +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.ResourceTypeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.DeployableResourceType;
import it.gov.pagopa.atmlayer.service.model.enumeration.StatusEnum;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
Expand Down Expand Up @@ -45,7 +45,7 @@ public class WorkflowResource extends PanacheEntityBase implements Serializable

@Column(name = "resource_type")
@Enumerated(EnumType.STRING)
private ResourceTypeEnum resourceType;
private DeployableResourceType resourceType;

@Column(name = "status")
@Enumerated(EnumType.STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,7 @@

import lombok.Getter;

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_ARGUMENT;
import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.INVALID_DEPLOY;
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;
import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.ID_NOT_FOUND;
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;
import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorType.*;

/**
* Enumeration for application error codes and messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ public enum AppErrorType {
INVALID_DEPLOY,
ID_NOT_FOUND,
INVALID_ARGUMENT,
NOT_UPDATABLE
NOT_UPDATABLE,
NOT_UPLOADABLE
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package it.gov.pagopa.atmlayer.service.model.enumeration;


import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public enum ResourceTypeEnum {
public enum DeployableResourceType {
BPMN("bpmn","application/bpmn", "bpmn:process", "id"),
DMN("dmn", "application/dmn", "decision", "id");
DMN("dmn", "application/dmn", "decision", "id"),
FORM("json", "application/json", null, null);

String extension;
String mimetype;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package it.gov.pagopa.atmlayer.service.model.enumeration;

import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public enum NoDeployableResourceType {
HTML("html", "application/html", null, null);

String extension;
String mimetype;
String tagName;
String attribute;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package it.gov.pagopa.atmlayer.service.model.enumeration;


import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public enum S3ResourceTypeEnum {
BPMN("bpmn","application/bpmn", "bpmn:process", "id"),
DMN("dmn", "application/dmn", "decision", "id"),
FORM("json", "application/json", null, null),
HTML("html", "application/html", null, null);

String extension;
String mimetype;
String tagName;
String attribute;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.S3ResourceTypeEnum;
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;
Expand All @@ -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(S3ResourceTypeEnum.BPMN.getExtension()));
bpmnVersion.setEnabled(true);
return bpmnVersion;
}
Expand All @@ -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(S3ResourceTypeEnum.BPMN.getExtension()));
bpmnVersion.setEnabled(true);
bpmnVersion.setModelVersion(version);
bpmnVersion.setDefinitionKey(definitionKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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.setS3ResourceTypeEnum(resourceCreationDto.getResourceType());
resourceEntity.setFileName(resourceCreationDto.getFilename());
return resourceEntity;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.S3ResourceTypeEnum;
import lombok.Data;
import lombok.NoArgsConstructor;

Expand All @@ -12,7 +12,7 @@
public class ResourceDTO {
private UUID resourceId;
private String sha256;
ResourceTypeEnum resourceTypeEnum;
S3ResourceTypeEnum s3ResourceTypeEnum;
private Timestamp createdAt;
private Timestamp lastUpdatedAt;
private String createdBy;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.S3ResourceTypeEnum;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -20,7 +20,7 @@
@EqualsAndHashCode
public class ResourceFileDTO {
private UUID id;
private ResourceTypeEnum resourceType;
private S3ResourceTypeEnum resourceType;
private String storageKey;
private String fileName;
private String extension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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.S3ResourceTypeEnum;
import it.gov.pagopa.atmlayer.service.model.model.ObjectStorePutResponse;
import org.jboss.resteasy.reactive.RestMulti;

Expand All @@ -15,7 +15,7 @@ public interface ObjectStoreService {

ObjectStoreStrategyEnum getType();

Uni<ObjectStorePutResponse> uploadFile(File file, String path, ResourceTypeEnum fileType, String filename);
Uni<ObjectStorePutResponse> uploadFile(File file, String path, S3ResourceTypeEnum fileType, String filename);

Uni<URL> generatePresignedUrl(String objectKey);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.S3ResourceTypeEnum;
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;
Expand Down Expand Up @@ -50,7 +50,7 @@ public BpmnFileStorageServiceImpl(ObjectStoreStrategy objectStoreStrategy, Objec
public Uni<ResourceFile> writeResourceInfoToDatabase(BpmnVersion bpmn, ObjectStorePutResponse putObjectResponse, String filename) {
ResourceFile entity = ResourceFile.builder()
.fileName(filename)
.resourceType(ResourceTypeEnum.BPMN)
.resourceType(S3ResourceTypeEnum.BPMN)
.bpmn(bpmn)
.storageKey(putObjectResponse.getStorage_key())
.build();
Expand All @@ -61,10 +61,10 @@ public Uni<ResourceFile> writeResourceInfoToDatabase(BpmnVersion bpmn, ObjectSto
public Uni<ResourceFile> 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(S3ResourceTypeEnum.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, S3ResourceTypeEnum.BPMN, completeName)
.emitOn(command -> context.runOnContext(x -> command.run()))
.onItem()
.transformToUni(objectStorePutResponse -> this.writeResourceInfoToDatabase(bpmnVersion, objectStorePutResponse, filename));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
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.enumeration.AppErrorCodeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.DeployableResourceType;
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.S3ResourceTypeEnum;
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;
Expand Down Expand Up @@ -61,7 +62,7 @@ public class BpmnVersionServiceImpl implements BpmnVersionService {
@Inject
BpmnVersionMapper bpmnVersionMapper;

final ResourceTypeEnum resourceType = ResourceTypeEnum.BPMN;
final DeployableResourceType resourceType = DeployableResourceType.BPMN;

@Override
public Uni<List<BpmnVersion>> getAll() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import it.gov.pagopa.atmlayer.service.model.client.ProcessClient;
import it.gov.pagopa.atmlayer.service.model.entity.BpmnVersionPK;
import it.gov.pagopa.atmlayer.service.model.entity.ResourceEntity;
import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.S3ResourceTypeEnum;
import it.gov.pagopa.atmlayer.service.model.exception.AtmLayerException;
import it.gov.pagopa.atmlayer.service.model.repository.ResourceEntityRepository;
import it.gov.pagopa.atmlayer.service.model.service.ResourceEntityService;
Expand Down Expand Up @@ -39,7 +39,7 @@ public class ResourceEntityServiceImpl implements ResourceEntityService {
@RestClient
ProcessClient processClient;

final ResourceTypeEnum resourceType = ResourceTypeEnum.HTML;
final S3ResourceTypeEnum resourceType = S3ResourceTypeEnum.HTML;

@Override
@WithTransaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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.ObjectStoreStrategyEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.S3ResourceTypeEnum;
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.properties.ObjectStoreProperties;
Expand Down Expand Up @@ -51,7 +51,7 @@ public ResourceEntityStorageServiceImpl(ObjectStoreStrategy objectStoreStrategy,

@Override
public Uni<ResourceFile> uploadFile(ResourceEntity resourceEntity, File file, String filename, String relativePath) {
ResourceTypeEnum resourceType = resourceEntity.getResourceTypeEnum();
S3ResourceTypeEnum resourceType = resourceEntity.getS3ResourceTypeEnum();
String path = calculatePath(resourceType);
if (!relativePath.isBlank()) {
path = path.concat("/").concat(relativePath);
Expand Down Expand Up @@ -96,16 +96,16 @@ public Uni<ResourceFile> writeResourceInfoToDatabase(ResourceEntity resourceEnti
ObjectStorePutResponse putObjectResponse, String filename) {
ResourceFile entity = ResourceFile.builder()
.fileName(filename)
.resourceType(resourceEntity.getResourceTypeEnum())
.resourceType(resourceEntity.getS3ResourceTypeEnum())
.resourceEntity(resourceEntity)
.storageKey(putObjectResponse.getStorage_key())
.build();
return resourceFileService.save(entity);
}

private String calculatePath(ResourceTypeEnum resourceTypeEnum) {
private String calculatePath(S3ResourceTypeEnum s3ResourceTypeEnum) {
Map<String, String> valuesMap = new HashMap<>();
valuesMap.put("RESOURCE_TYPE", resourceTypeEnum.toString());
valuesMap.put("RESOURCE_TYPE", s3ResourceTypeEnum.toString());
StringSubstitutor stringSubstitutor = new StringSubstitutor(valuesMap);
Optional<String> resourceEntityPathTemplateProps = Optional.ofNullable(
objectStoreProperties.html().pathTemplate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.S3ResourceTypeEnum;
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;
Expand Down Expand Up @@ -90,7 +90,7 @@ public RestMulti<Buffer> download(String key) {
}


public Uni<ObjectStorePutResponse> uploadFile(File file, String path, ResourceTypeEnum fileType, String filename) {
public Uni<ObjectStorePutResponse> uploadFile(File file, String path, S3ResourceTypeEnum fileType, String filename) {
if (StringUtils.isBlank(filename)) {
String errorMessage = String.format("S3 File Upload - invalid filename %s", filename);
log.error(errorMessage);
Expand Down
Loading

0 comments on commit 6dd41ab

Please sign in to comment.