From c69dab2414f4f58d832644880dc49110b63874c2 Mon Sep 17 00:00:00 2001 From: LuciaM1 Date: Mon, 30 Sep 2024 13:01:43 +0200 Subject: [PATCH] starting implementation --- .../impl/ResourceEntityServiceImpl.java | 51 +++++++++++-------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/ResourceEntityServiceImpl.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/ResourceEntityServiceImpl.java index e144c7e0..36dc2393 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/ResourceEntityServiceImpl.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/ResourceEntityServiceImpl.java @@ -29,11 +29,22 @@ import org.eclipse.microprofile.rest.client.inject.RestClient; import java.io.File; -import java.io.IOException; import java.sql.Timestamp; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; -import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.*; +import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.ATMLM_500; +import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.DATABASE_SAVE_FILE_ERROR; +import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.OBJECT_STORE_SAVE_FILE_ERROR; +import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.RESOURCES_CREATION_ERROR; +import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.RESOURCE_DOES_NOT_EXIST; +import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.RESOURCE_WITH_SAME_SHA256_ALREADY_EXISTS; import static it.gov.pagopa.atmlayer.service.model.utils.FileUtilities.calculateSha256; @ApplicationScoped @@ -98,8 +109,8 @@ public Uni saveAndUpload(ResourceEntity resourceEntity, File fil return Uni.createFrom().item(element); })) .onFailure().recoverWithUni(dbException -> Uni.createFrom().failure(new AtmLayerException( - String.format("Errore nel salvataggio della risorsa. %s", dbException.getMessage()), - Response.Status.INTERNAL_SERVER_ERROR, DATABASE_SAVE_FILE_ERROR)) + String.format("Errore nel salvataggio della risorsa. %s", dbException.getMessage()), + Response.Status.INTERNAL_SERVER_ERROR, DATABASE_SAVE_FILE_ERROR)) ); } @@ -194,18 +205,17 @@ public Uni> createResourceMultiple(List resourceEnt FileUtilities.cleanDecodedFilesDirectory(); return Uni.createFrom().item(errors); // This will be empty if no errors occurred }); - } - public Uni> deleteResourcesFromStorage(List storageKeys, List errorMessages){ + public Uni> deleteResourcesFromStorage(List storageKeys, List errorMessages) { return Multi.createFrom().items(storageKeys.stream()) .onItem().transformToUniAndConcatenate(uploadedStorageKey -> resourceEntityStorageService.delete(uploadedStorageKey) - .onItem().transform(objectStoreResponse -> String.format("Deleted %s",objectStoreResponse.getStorageKey()))) - .collect().asList() + .onItem().transform(objectStoreResponse -> String.format("Deleted %s", objectStoreResponse.getStorageKey()))) + .collect().asList() .onItem().transform(deletedKeys -> { FileUtilities.cleanDecodedFilesDirectory(); throw new AtmLayerException("Errore nel caricamento dovuto ai seguenti file: " + String.join(", ", errorMessages), - Response.Status.BAD_REQUEST, RESOURCES_CREATION_ERROR); + Response.Status.BAD_REQUEST, RESOURCES_CREATION_ERROR); }); } @@ -287,20 +297,21 @@ public Uni disable(UUID uuid) { .onItem() .transform(deletedCopy -> { throw new AtmLayerException( - deleteException.getMessage(), - Response.Status.INTERNAL_SERVER_ERROR, OBJECT_STORE_COPY_FILE_ERROR);})) + deleteException.getMessage(), + Response.Status.INTERNAL_SERVER_ERROR, ATMLM_500); + })) ) .onFailure().recoverWithUni(failure -> Uni.createFrom().failure(new AtmLayerException( failure.getMessage(), - Response.Status.INTERNAL_SERVER_ERROR, OBJECT_STORE_COPY_FILE_ERROR)) - ) - .onFailure().recoverWithUni(failure -> - Uni.createFrom().failure(new AtmLayerException( - failure.getMessage(), - Response.Status.INTERNAL_SERVER_ERROR, DATABASE_SAVE_FILE_ERROR)) - ) - )); + Response.Status.INTERNAL_SERVER_ERROR, ATMLM_500)) + ) + .onFailure().recoverWithUni(failure -> + Uni.createFrom().failure(new AtmLayerException( + failure.getMessage(), + Response.Status.INTERNAL_SERVER_ERROR, ATMLM_500)) + ) + )); }); }