Skip to content

Commit

Permalink
Sostituiti concat e path con commonutils
Browse files Browse the repository at this point in the history
  • Loading branch information
asioleLab committed Nov 14, 2023
1 parent 846d8d6 commit 6be318d
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import it.gov.pagopa.atmlayer.service.model.service.ResourceFileService;
import it.gov.pagopa.atmlayer.service.model.service.WorkflowResourceStorageService;
import it.gov.pagopa.atmlayer.service.model.strategy.ObjectStoreStrategy;
import it.gov.pagopa.atmlayer.service.model.utils.CommonUtils;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -70,20 +71,18 @@ public Uni<ResourceFile> updateFile(WorkflowResource workflowResource, File file
String storageKey = workflowResource.getResourceFile().getStorageKey();
S3ResourceTypeEnum resourceType = convertEnum(workflowResource.getResourceType());
String path = FilenameUtils.getFullPath(storageKey);
String fileName = FilenameUtils.getBaseName(storageKey);
String extension = FilenameUtils.getExtension(storageKey);
Context context = Vertx.currentContext();
log.info("Requesting to write file {} in Object Store at path {}", fileName.concat(".").concat(extension), path);
return objectStoreService.uploadFile(file, path.substring(0,path.length()-1), resourceType, fileName.concat(".").concat(extension))
log.info("Requesting to write file {} in Object Store at path {}", CommonUtils.getFilenameWithExtensionFromStorageKey(storageKey), path);
return objectStoreService.uploadFile(file, CommonUtils.getPathWithoutFilename(path), resourceType, CommonUtils.getFilenameWithExtensionFromStorageKey(storageKey))
.emitOn(command -> context.runOnContext(x -> command.run()))
.onItem().transformToUni(x -> this.resourceFileService.findByStorageKey(storageKey))
.onItem().transformToUni(y -> Uni.createFrom().item(y.get()));
}

private Uni<ResourceFile> doUploadFile(WorkflowResource workflowResource, File file, String path, String filename, String extension, S3ResourceTypeEnum resourceType) {
Context context = Vertx.currentContext();
log.info("Requesting to write file {} in Object Store at path {}", filename.concat(".").concat(extension), path);
return objectStoreService.uploadFile(file, path, resourceType, filename.concat(".").concat(extension))
log.info("Requesting to write file {} in Object Store at path {}", CommonUtils.getFilenameWithExtension(filename, extension), path);
return objectStoreService.uploadFile(file, path, resourceType, CommonUtils.getFilenameWithExtension(filename, extension))
.emitOn(command -> context.runOnContext(x -> command.run()))
.onItem()
.transformToUni(objectStorePutResponse -> this.writeResourceInfoToDatabase(workflowResource, objectStorePutResponse, filename));
Expand Down

0 comments on commit 6be318d

Please sign in to comment.