Skip to content

Commit

Permalink
resolved problem on Transaction when calling s3Services
Browse files Browse the repository at this point in the history
added mappers, added dto
  • Loading branch information
candreac committed Nov 1, 2023
1 parent bda3d51 commit 5b216a7
Show file tree
Hide file tree
Showing 32 changed files with 448 additions and 322 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ public class BpmnBankConfig extends PanacheEntityBase implements Serializable {
@Enumerated(EnumType.STRING)
private FunctionTypeEnum functionType;

@Column(name = "enabled", columnDefinition = "boolean default true")
private Boolean enabled;

@CreationTimestamp
@Column(name = "created_at")
private Timestamp createdAt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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 jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
Expand All @@ -11,6 +12,7 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -39,6 +41,9 @@ public class BpmnVersion extends PanacheEntityBase implements Serializable {
@Id
private Long modelVersion = 1L;

@OneToOne(mappedBy = "bpmn",cascade = CascadeType.ALL)
ResourceFile resourceFile;

@Column(name = "deployed_file_name")
private String deployedFileName;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package it.gov.pagopa.atmlayer.service.model.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.quarkus.hibernate.reactive.panache.PanacheEntityBase;
import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinColumns;
import jakarta.persistence.OneToOne;
import jakarta.persistence.PrePersist;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

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

@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Table(name = "resource_file_model")
public class ResourceFile extends PanacheEntityBase implements Serializable {

@GeneratedValue(strategy = GenerationType.UUID)
@Column(name = "id", nullable = false, updatable = false)
@Id
private UUID id;

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

@OneToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "bpmn_id", referencedColumnName = "bpmn_id"),
@JoinColumn(name = "bpmn_model_version", referencedColumnName = "model_version")
})
@JsonIgnore
private BpmnVersion bpmn;

@NotNull
@Column(name = "storage_key")
private String storageKey;

@Column(name = "file_name")
private String fileName;

private String extension;

@CreationTimestamp
@Column(name = "created_at")
private Timestamp createdAt;

@UpdateTimestamp
@Column(name = "last_updated_at")
private Timestamp lastUpdatedAt;

@Column(name = "created_by")
private String createdBy;

@Column(name = "last_updated_by")
private String lastUpdatedBy;

@PrePersist
void onPrePersist() {
this.extension = resourceType.getExtension();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package it.gov.pagopa.atmlayer.service.model.mapper;

import it.gov.pagopa.atmlayer.service.model.entity.BpmnBankConfig;
import it.gov.pagopa.atmlayer.service.model.model.BpmnBankConfigDTO;
import org.mapstruct.IterableMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.NullValuePropertyMappingStrategy;

import java.util.Collection;

@Mapper(componentModel = "cdi", nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
public interface BpmnConfigMapper {

@Mapping(source = "bpmnBankConfigPK.bpmnId", target = "bpmnId")
@Mapping(source = "bpmnBankConfigPK.bpmnModelVersion", target = "bpmnModelVersion")
@Mapping(source = "bpmnBankConfigPK.acquirerId", target = "acquirerId")
@Mapping(source = "bpmnBankConfigPK.branchId", target = "branchId")
@Mapping(source = "bpmnBankConfigPK.terminalId", target = "terminalId")
@Named("toBpmnBankConfigDTO")
BpmnBankConfigDTO toDTO(BpmnBankConfig bpmnBankConfig);

@Mapping(source = "bpmnId", target = "bpmnBankConfigPK.bpmnId")
@Mapping(source = "bpmnModelVersion", target = "bpmnBankConfigPK.bpmnModelVersion")
@Mapping(source = "acquirerId", target = "bpmnBankConfigPK.acquirerId")
@Mapping(source = "branchId", target = "bpmnBankConfigPK.branchId")
@Mapping(source = "terminalId", target = "bpmnBankConfigPK.terminalId")
BpmnBankConfig toEntity(BpmnBankConfigDTO bankConfigDTO);

@IterableMapping(qualifiedByName = "toBpmnBankConfigDTO")
Collection<BpmnBankConfigDTO> toDTOList(Collection<BpmnBankConfig> bpmnBankConfig);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,36 @@

import it.gov.pagopa.atmlayer.service.model.dto.BpmnCreationDto;
import it.gov.pagopa.atmlayer.service.model.entity.BpmnVersion;
import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.StatusEnum;
import it.gov.pagopa.atmlayer.service.model.model.BpmnDTO;
import it.gov.pagopa.atmlayer.service.model.utils.BpmnUtils;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper
public interface BpmnVersionMapper {
BpmnCreationDto toDto(BpmnVersion bpmnVersion);
import java.io.IOException;
import java.security.NoSuchAlgorithmException;

@Mapper(componentModel = "cdi")
public abstract class BpmnVersionMapper {

@Mapping(ignore = true, target = "file")
@Mapping(ignore = true, target = "filename")
public abstract BpmnCreationDto toDtoCreation(BpmnVersion bpmnVersion);

public BpmnVersion toEntityCreation(BpmnCreationDto bpmnCreationDto) throws NoSuchAlgorithmException, IOException {
BpmnVersion bpmnVersion = new BpmnVersion();
bpmnVersion.setFunctionType(bpmnCreationDto.getFunctionType());
bpmnVersion.setStatus(StatusEnum.CREATED);
bpmnVersion.setSha256(BpmnUtils.calculateSha256(bpmnCreationDto.getFile()));
bpmnVersion.setDeployedFileName(bpmnCreationDto.getFilename().concat(".").concat(ResourceTypeEnum.BPMN.getExtension()));
bpmnVersion.setEnabled(true);
return bpmnVersion;
}

public abstract BpmnDTO toDTO(BpmnVersion bpmnVersion);

@Mapping(ignore = true, target = "enabled")
@Mapping(target = "resourceFile.bpmn",ignore = true)
public abstract BpmnVersion toEntity(BpmnDTO bpmnDTO);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package it.gov.pagopa.atmlayer.service.model.mapper;

import it.gov.pagopa.atmlayer.service.model.entity.ResourceFile;
import it.gov.pagopa.atmlayer.service.model.model.ResourceFileDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(componentModel = "cdi")
public interface ResourceFileMapper {

ResourceFileDTO toDTO(ResourceFile bpmnVersion);
@Mapping(ignore = true, target = "bpmn")
ResourceFile toEntity(ResourceFileDTO bpmnDTO);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package it.gov.pagopa.atmlayer.service.model.model;

import it.gov.pagopa.atmlayer.service.model.enumeration.FunctionTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

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

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ToString
@EqualsAndHashCode
public class BpmnBankConfigDTO {
private UUID bpmnId;
private Long bpmnModelVersion;
private String acquirerId;
private String branchId;
private String terminalId;
private FunctionTypeEnum functionType;
private Timestamp createdAt;
private Timestamp lastUpdatedAt;
private String createdBy;
private String lastUpdatedBy;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package it.gov.pagopa.atmlayer.service.model.model;

import it.gov.pagopa.atmlayer.service.model.enumeration.FunctionTypeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.StatusEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

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

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ToString
@EqualsAndHashCode
public class BpmnDTO {

private UUID bpmnId;
private Long modelVersion;
private String deployedFileName;
private String definitionKey;
private FunctionTypeEnum functionType;
private StatusEnum status;
private String sha256;
private Integer definitionVersionCamunda;
private String camundaDefinitionId;
private String description;
private ResourceFileDTO resourceFile;
private String resource;
private UUID deploymentId;
private Timestamp createdAt;
private Timestamp lastUpdatedAt;
private String createdBy;
private String lastUpdatedBy;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package it.gov.pagopa.atmlayer.service.model.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@ToString
@EqualsAndHashCode
public class ObjectStorePutResponse {
String storage_key;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package it.gov.pagopa.atmlayer.service.model.model;

import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

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

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
@EqualsAndHashCode
public class ResourceFileDTO {
private UUID id;
private ResourceTypeEnum resourceType;
private String storageKey;
private String fileName;
private String extension;
private Timestamp createdAt;
private Timestamp lastUpdatedAt;
private String createdBy;
private String lastUpdatedBy;
}

This file was deleted.

Loading

0 comments on commit 5b216a7

Please sign in to comment.