diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorCodeEnum.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorCodeEnum.java index 03a1bbcf..583dca3d 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorCodeEnum.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorCodeEnum.java @@ -61,7 +61,8 @@ public enum AppErrorCodeEnum { NO_ASSOCIATION_FOUND("ATMLM_4000060","Nessuna associazione trovata", CONSTRAINT_VIOLATION), ALL_FIELDS_ARE_BLANK("ATMLM_4000061", "Tutti i campi sono vuoti", AppErrorType.BLANK_FIELDS), RESOURCES_CREATION_ERROR("ATMLM_4000062", "Errore nella creazione di resource multipli", GENERIC ), - FILE_DECODE_ERROR("ATMLM_4000063", "Errore nella decodifica del file", GENERIC ); + FILE_DECODE_ERROR("ATMLM_4000063", "Errore nella decodifica del file", GENERIC ), + DATABASE_SAVE_FILE_ERROR("ATMLM_4000064", "Errore nella persistenza del file sul database", INTERNAL); private final String errorCode; private final String errorMessage; private final AppErrorType type; 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 93352931..1b684038 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 @@ -96,7 +96,14 @@ public Uni saveAndUpload(ResourceEntity resourceEntity, File fil .onItem().transformToUni(putObjectResponse -> { log.info("Completed Resource Entity Creation"); return Uni.createFrom().item(element); - })); + })) + //TODO: quest'eccezione copre quella dell'object store se a fallire รจ l'upload > adeguare messaggio d'errore generico + .onFailure().recoverWithUni(dbException -> { + log.error(dbException.getMessage()); + return Uni.createFrom().failure(new AtmLayerException( + "Errore nel salvataggio della risorsa nel database. Vedere log per i dettagli", + Response.Status.INTERNAL_SERVER_ERROR, DATABASE_SAVE_FILE_ERROR)); + }); } @Override @@ -278,8 +285,14 @@ public Uni disable(UUID uuid) { .transformToUni(itemToDelete -> resourceEntityStorageService.delete(originalStorageKey) .onItem() .transformToUni(deletedFile -> Uni.createFrom().voidItem()) + //TODO: onFailure() rollback del metodo uploadDisabledFile() ) ) + .onFailure().recoverWithUni(failure -> + Uni.createFrom().failure(new AtmLayerException( + failure.getMessage(), + Response.Status.INTERNAL_SERVER_ERROR, DATABASE_SAVE_FILE_ERROR)) + ) ); }); } diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/ResourceEntityStorageServiceImpl.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/ResourceEntityStorageServiceImpl.java index e1285681..3efd5779 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/ResourceEntityStorageServiceImpl.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/ResourceEntityStorageServiceImpl.java @@ -7,9 +7,11 @@ import io.vertx.core.buffer.Buffer; import it.gov.pagopa.atmlayer.service.model.entity.ResourceEntity; import it.gov.pagopa.atmlayer.service.model.entity.ResourceFile; +import it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum; import it.gov.pagopa.atmlayer.service.model.enumeration.NoDeployableResourceType; import it.gov.pagopa.atmlayer.service.model.enumeration.ObjectStoreStrategyEnum; import it.gov.pagopa.atmlayer.service.model.enumeration.S3ResourceTypeEnum; +import it.gov.pagopa.atmlayer.service.model.exception.AtmLayerException; import it.gov.pagopa.atmlayer.service.model.model.ObjectStoreResponse; import it.gov.pagopa.atmlayer.service.model.properties.ObjectStoreProperties; import it.gov.pagopa.atmlayer.service.model.service.ObjectStoreService; @@ -18,6 +20,7 @@ import it.gov.pagopa.atmlayer.service.model.strategy.ObjectStoreStrategy; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; +import jakarta.ws.rs.core.Response; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.commons.text.StringSubstitutor; diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/ResourceFileServiceImpl.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/ResourceFileServiceImpl.java index b9ba8946..91611f43 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/ResourceFileServiceImpl.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/ResourceFileServiceImpl.java @@ -17,6 +17,7 @@ import java.util.Optional; +import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.DATABASE_SAVE_FILE_ERROR; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.RESOURCE_DOES_NOT_EXIST; import static it.gov.pagopa.atmlayer.service.model.utils.FileStorageS3Utils.modifyPath; import static java.lang.String.valueOf; @@ -71,7 +72,12 @@ public Uni updateStorageKey(ResourceEntity resourceEntity) { return resourceFileRepository.persist(resourceFileFound) .onItem() .transformToUni(newResourceFile -> Uni.createFrom().item(newResourceFile)); - }); + }) + .onFailure().recoverWithUni(failure -> + Uni.createFrom().failure(new AtmLayerException( + "Impossibile eliminare la risorsa. Aggiornamento della storage key interrotto", + Response.Status.INTERNAL_SERVER_ERROR, DATABASE_SAVE_FILE_ERROR)) + ); } @Override