Skip to content

Commit

Permalink
added modifyPath method
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrieleMaiocchiFilippo committed Jun 18, 2024
1 parent 9997656 commit 28c3ab7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.*;

import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.*;
import static it.gov.pagopa.atmlayer.service.model.utils.FileStorageS3Utils.modifyPath;
import static it.gov.pagopa.atmlayer.service.model.utils.FileUtilities.calculateSha256;

@ApplicationScoped
Expand Down Expand Up @@ -112,6 +113,7 @@ public Uni<ResourceFile> upload(ResourceEntity resourceEntity, File file,
@Override
public Uni<ResourceEntity> createResource(ResourceEntity resourceEntity, File file,
String filename, String path, String description) {
modifyPath("RESOURCE/files/HTML/ciao/mi/chiamo/mario/filename.html");
return findBySHA256(resourceEntity.getSha256())
.onItem().transformToUni(Unchecked.function(x -> {
if (x.isPresent()) {
Expand Down Expand Up @@ -188,7 +190,7 @@ public Uni<List<String>> createResourceMultiple(List<ResourceEntity> resourceEnt
if (!errors.isEmpty()) {
throw new AtmLayerException("Alcuni file non sono stati creati: " + String.join(", ", errors),
Response.Status.BAD_REQUEST, RESOURCES_CREATION_ERROR);
}else{
} else {
errors.add("file creati senza errori");
}
return errors; // This will be empty if no errors occurred
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package it.gov.pagopa.atmlayer.service.model.utils;

import io.quarkus.logging.Log;
import it.gov.pagopa.atmlayer.service.model.properties.ObjectStoreProperties;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@ApplicationScoped
public class FileStorageS3Utils {
@Inject
Expand All @@ -32,4 +39,35 @@ public GetObjectRequest buildGetRequest(String key) {
.build();
}

public static String modifyPath(String inputPath) {
Path path = Paths.get(inputPath);
log.info("valore input: {}", inputPath);

int count = path.getNameCount();
StringBuilder outputPath = new StringBuilder();

outputPath.append(path.getRoot() != null ? path.getRoot() : ""); // se esiste una root (es. C:\), aggiungila
outputPath.append(path.getName(0));
outputPath.append("/");
outputPath.append(path.getName(1));
outputPath.append("/");
outputPath.append(path.getName(2));
outputPath.append("/DELETE");

for (int i = 3; i < count - 1; i++) {
outputPath.append("/");
outputPath.append(path.getName(i));
}

String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss"));
outputPath.append("/");
outputPath.append(timestamp);

outputPath.append("/");
outputPath.append(path.getFileName().toString());

log.info("valore output: {}", outputPath);
return outputPath.toString();
}

}

0 comments on commit 28c3ab7

Please sign in to comment.