Skip to content

Commit

Permalink
Enum Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
EmanueleValentini1 committed Nov 10, 2023
1 parent d7812d7 commit 682b244
Show file tree
Hide file tree
Showing 19 changed files with 45 additions and 46 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.WorkflowResourceTypeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.ws.rs.FormParam;
Expand All @@ -21,5 +21,5 @@ public class ResourceCreationDto {
private String filename;
@FormParam("resourceType")
@NotNull(message = "resource type is required")
private WorkflowResourceTypeEnum resourceType;
private ResourceTypeEnum resourceType;
}
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.WorkflowResourceTypeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum;
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 WorkflowResourceTypeEnum resourceType;
private ResourceTypeEnum 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.WorkflowResourceTypeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum;
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")
WorkflowResourceTypeEnum workflowResourceTypeEnum;
ResourceTypeEnum resourceTypeEnum;
@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.WorkflowResourceTypeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum;
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 WorkflowResourceTypeEnum resourceType;
private ResourceTypeEnum 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.WorkflowResourceTypeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum;
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 WorkflowResourceTypeEnum resourceType;
private ResourceTypeEnum resourceType;

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

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

Expand Down
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.WorkflowResourceTypeEnum;
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.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(WorkflowResourceTypeEnum.BPMN.getExtension()));
bpmnVersion.setDeployedFileName(bpmnCreationDto.getFilename().concat(".").concat(ResourceTypeEnum.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(WorkflowResourceTypeEnum.BPMN.getExtension()));
bpmnVersion.setDeployedFileName(bpmnUpgradeDto.getFilename().concat(".").concat(ResourceTypeEnum.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.setWorkflowResourceTypeEnum(resourceCreationDto.getResourceType());
resourceEntity.setResourceTypeEnum(resourceCreationDto.getResourceType());
resourceEntity.setFileName(resourceCreationDto.getFilename());
return resourceEntity;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package it.gov.pagopa.atmlayer.service.model.model;

import it.gov.pagopa.atmlayer.service.model.enumeration.WorkflowResourceTypeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum;

import java.sql.Timestamp;
import java.util.UUID;

public class ResourceEntityDTO {
private UUID resourceId;
private String sha256;
WorkflowResourceTypeEnum workflowResourceTypeEnum;
ResourceTypeEnum resourceTypeEnum;
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.WorkflowResourceTypeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -20,7 +20,7 @@
@EqualsAndHashCode
public class ResourceFileDTO {
private UUID id;
private WorkflowResourceTypeEnum resourceType;
private ResourceTypeEnum 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.WorkflowResourceTypeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum;
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, WorkflowResourceTypeEnum fileType, String filename);
Uni<ObjectStorePutResponse> uploadFile(File file, String path, ResourceTypeEnum 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.WorkflowResourceTypeEnum;
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.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(WorkflowResourceTypeEnum.BPMN)
.resourceType(ResourceTypeEnum.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(WorkflowResourceTypeEnum.BPMN.getExtension());
String completeName = filename.concat(".").concat(ResourceTypeEnum.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, WorkflowResourceTypeEnum.BPMN, completeName)
return objectStoreService.uploadFile(file, path, ResourceTypeEnum.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 @@ -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.WorkflowResourceTypeEnum;
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.exception.AtmLayerException;
import it.gov.pagopa.atmlayer.service.model.mapper.BpmnVersionMapper;
Expand Down Expand Up @@ -61,7 +61,7 @@ public class BpmnVersionServiceImpl implements BpmnVersionService {
@Inject
BpmnVersionMapper bpmnVersionMapper;

final WorkflowResourceTypeEnum resourceType = WorkflowResourceTypeEnum.BPMN;
final ResourceTypeEnum resourceType = ResourceTypeEnum.BPMN;

@Override
public Uni<List<BpmnVersion>> getAll() {
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.WorkflowResourceTypeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum;
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, WorkflowResourceTypeEnum fileType, String filename) {
public Uni<ObjectStorePutResponse> uploadFile(File file, String path, ResourceTypeEnum fileType, String filename) {
if (StringUtils.isBlank(filename)) {
String errorMessage = String.format("S3 File Upload - invalid filename %s", filename);
log.error(errorMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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.StatusEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.WorkflowResourceTypeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum;
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;
Expand Down Expand Up @@ -52,7 +52,7 @@ public class WorkflowResourceServiceImpl implements WorkflowResourceService {
@RestClient
ProcessClient processClient;

WorkflowResourceTypeEnum resourceType;
ResourceTypeEnum resourceType;

@Override
@WithTransaction
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.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.WorkflowResourceTypeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum;
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;
Expand Down Expand Up @@ -54,7 +54,7 @@ public WorkflowResourceStorageServiceImpl(ObjectStoreStrategy objectStoreStrateg
@Override
public Uni<ResourceFile> uploadFile(WorkflowResource workflowResource, File file, String filename) {
UUID uuid = workflowResource.getWorkflowResourceId();
WorkflowResourceTypeEnum resourceType = workflowResource.getResourceType();
ResourceTypeEnum resourceType = workflowResource.getResourceType();
String path = calculatePath(uuid, resourceType);
String completeName = filename.concat(".").concat(resourceType.getExtension());
log.info("Requesting to write file {} in Object Store at path {}", file.getName(), path);
Expand Down Expand Up @@ -87,7 +87,7 @@ public RestMulti<Buffer> download(String storageKey) {
return this.objectStoreService.download(storageKey);
}

private String calculatePath(UUID uuid, WorkflowResourceTypeEnum resourceType) {
private String calculatePath(UUID uuid, ResourceTypeEnum resourceType) {
Map<String, String> valuesMap = new HashMap<>();
valuesMap.put("uuid", uuid.toString());
valuesMap.put("RESOURCE_TYPE", resourceType.toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package it.gov.pagopa.atmlayer.service.model.utils;

import it.gov.pagopa.atmlayer.service.model.enumeration.WorkflowResourceTypeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum;
import it.gov.pagopa.atmlayer.service.model.exception.AtmLayerException;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.core.Response;
Expand All @@ -17,13 +17,12 @@

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;

@ApplicationScoped
@Slf4j
public class FileUtils {

public static String extractIdValue(File file, WorkflowResourceTypeEnum workflowResourceTypeEnum) {
public static String extractIdValue(File file, ResourceTypeEnum resourceTypeEnum) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
Document document = null;
Expand All @@ -34,8 +33,8 @@ public static String extractIdValue(File file, WorkflowResourceTypeEnum workflow
log.error(e.getMessage());
throw new AtmLayerException("Malformed File", Response.Status.BAD_REQUEST, MALFORMED_FILE);
}
Element definitionsElement = (Element) document.getElementsByTagName(workflowResourceTypeEnum.getTagName()).item(0);
String definitionKey = definitionsElement.getAttribute(workflowResourceTypeEnum.getAttribute());
Element definitionsElement = (Element) document.getElementsByTagName(resourceTypeEnum.getTagName()).item(0);
String definitionKey = definitionsElement.getAttribute(resourceTypeEnum.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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
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.WorkflowResourceTypeEnum;
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.exception.AtmLayerException;
import it.gov.pagopa.atmlayer.service.model.mapper.BpmnVersionMapper;
Expand Down Expand Up @@ -394,7 +394,7 @@ void testDeployOK() throws MalformedURLException {
bpmnVersion.setStatus(StatusEnum.CREATED);
ResourceFile resourceFile=new ResourceFile();
resourceFile.setId(UUID.randomUUID());
resourceFile.setResourceType(WorkflowResourceTypeEnum.BPMN);
resourceFile.setResourceType(ResourceTypeEnum.BPMN);
resourceFile.setStorageKey("storage key");
bpmnVersion.setResourceFile(resourceFile);
BpmnVersion bpmnVersionUpdated=new BpmnVersion();
Expand Down Expand Up @@ -422,7 +422,7 @@ void testDeployNotDeployable() throws MalformedURLException {
bpmnVersion.setStatus(StatusEnum.DEPLOYED);
ResourceFile resourceFile=new ResourceFile();
resourceFile.setId(UUID.randomUUID());
resourceFile.setResourceType(WorkflowResourceTypeEnum.BPMN);
resourceFile.setResourceType(ResourceTypeEnum.BPMN);
resourceFile.setStorageKey("storage key");
bpmnVersion.setResourceFile(resourceFile);
URL url=new URL("http://localhost:8081/test");
Expand Down Expand Up @@ -478,7 +478,7 @@ void testDeployURLGenerationFailure() throws MalformedURLException {
bpmnVersion.setStatus(StatusEnum.CREATED);
ResourceFile resourceFile=new ResourceFile();
resourceFile.setId(UUID.randomUUID());
resourceFile.setResourceType(WorkflowResourceTypeEnum.BPMN);
resourceFile.setResourceType(ResourceTypeEnum.BPMN);
resourceFile.setStorageKey("storage key");
bpmnVersion.setResourceFile(resourceFile);
BpmnVersion bpmnVersionUpdated=new BpmnVersion();
Expand Down Expand Up @@ -512,7 +512,7 @@ void testDeployClientFailure() throws MalformedURLException {
bpmnVersion.setStatus(StatusEnum.CREATED);
ResourceFile resourceFile=new ResourceFile();
resourceFile.setId(UUID.randomUUID());
resourceFile.setResourceType(WorkflowResourceTypeEnum.BPMN);
resourceFile.setResourceType(ResourceTypeEnum.BPMN);
resourceFile.setStorageKey("storage key");
bpmnVersion.setResourceFile(resourceFile);
URL url=new URL("http://localhost:8081/test");
Expand Down
Loading

0 comments on commit 682b244

Please sign in to comment.