Skip to content

Commit

Permalink
resources create
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciaM1 committed Nov 8, 2023
1 parent 165c23d commit 645a244
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
@NoArgsConstructor
@Table(name = "resource_entity")
public class ResourceEntity extends PanacheEntityBase implements Serializable {
@Column(name = "bpmn_id", nullable = false, updatable = false)
@Column(name = "resource_id", nullable = false, updatable = false)
@GeneratedValue(strategy = GenerationType.UUID)
@Id
private UUID resourceId;
//@OneToOne(mappedBy = "resourceEntity", cascade = CascadeType.ALL)
//ResourceFile resourceFile;
@OneToOne(mappedBy = "resourceEntity", cascade = CascadeType.ALL)
ResourceFile resourceFile;
@Column(name = "sha256", unique = true)
private String sha256;
@Column(name="resourceType")
@Column(name = "resourceType")
ResourceTypeEnum resourceTypeEnum;
@Column(name="file_name")
@Column(name = "file_name")
String fileName;
@CreationTimestamp
@Column(name = "created_at")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ public class ResourceFile extends PanacheEntityBase implements Serializable {
@JsonIgnore
private WorkflowResource workflowResource;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "resource_id", referencedColumnName = "resource_id")
})
@JsonIgnore
private ResourceEntity resourceEntity;

@NotNull
@Column(name = "storage_key")
private String storageKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ public ResourceEntity toEntityCreation(ResourceCreationDto resourceCreationDto)
}

//TODO: IMPLEMENT toDto(ResourceEntity resourceEntity) METHOD
public abstract ResourceEntityDTO toDTO(ResourceEntity resourceEntity);
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
package it.gov.pagopa.atmlayer.service.model.model;

import it.gov.pagopa.atmlayer.service.model.entity.ResourceFile;
import it.gov.pagopa.atmlayer.service.model.enumeration.ResourceTypeEnum;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Id;
import jakarta.persistence.OneToOne;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

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

public class ResourceEntityDTO {

private UUID resourceId;
private String sha256;
@Column(name="resourceType")
ResourceTypeEnum resourceTypeEnum;
@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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,20 @@
@Tag(name = "RESOURCES", description = "RESOURCES operations")
@Slf4j
public class ResourceEntityResource {

@Inject
ResourceEntityMapper resourceEntityMapper;

@Inject
ResourceEntityService resourceEntityService;

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@NonBlocking
public Uni<ResourceEntity> createResource(@RequestBody(required = true) @Valid ResourceCreationDto resourceCreationDto) throws NoSuchAlgorithmException, IOException {
ResourceEntity resourceEntity=resourceEntityMapper.toEntityCreation(resourceCreationDto);
return resourceEntityService.createResource(resourceEntity,resourceCreationDto.getFile(),resourceCreationDto.getFilename())
.onItem().transformToUni(resource -> Uni.createFrom().item(resource));
public Uni<ResourceEntityDTO> createResource(@RequestBody(required = true) @Valid ResourceCreationDto resourceCreationDto) throws NoSuchAlgorithmException, IOException {
ResourceEntity resourceEntity = resourceEntityMapper.toEntityCreation(resourceCreationDto);
return resourceEntityService.createResource(resourceEntity, resourceCreationDto.getFile(), resourceCreationDto.getFilename())
//.onItem().transformToUni(resource -> Uni.createFrom().item(resource));
//quando il metodo toDto è implementato nel mapper, sostituire con:
//.onItem().transformToUni(resource -> Uni.createFrom().item(resourceEntityMapper.toDTO(resource)));

.onItem().transformToUni(resource -> Uni.createFrom().item(resourceEntityMapper.toDTO(resource)));
}

}
2 changes: 1 addition & 1 deletion src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ quarkus.devservices.enabled=false
object-store.type=${MODEL_OBJECT_STORE_TYPE:AWS_S3}
object-store.bucket.name=${MODEL_OBJECT_STORE_BUCKET_NAME:pagopa-dev-atm-layer-s3-model}
object-store.bpmn.path-template=${MODEL_OBJECT_STORE_BPMN_TEMPLATE_PATH:/BPMN/files/UUID/[uuid]/VERSION/[version]}
object-store.dmn.path-template=${MODEL_OBJECT_STORE_DMN_TEMPLATE_PATH:WORKFLOW_RESOURCE/files/[RESOURCE_TYPE]/[uuid]}
object-store.dmn.path-template=${MODEL_OBJECT_STORE_DMN_TEMPLATE_PATH:/WORKFLOW_RESOURCE/files/[RESOURCE_TYPE]/[uuid]}
object-store.bucket.region=${MODEL_OBJECT_STORE_REGION:eu-south-1}

0 comments on commit 645a244

Please sign in to comment.