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 583dca3d..c60c0a64 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 @@ -62,7 +62,8 @@ public enum AppErrorCodeEnum { 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 ), - DATABASE_SAVE_FILE_ERROR("ATMLM_4000064", "Errore nella persistenza del file sul database", INTERNAL); + DATABASE_SAVE_FILE_ERROR("ATMLM_4000064", "Errore nella persistenza del file sul database", INTERNAL), + OBJECT_STORE_COPY_FILE_ERROR("ATMLM_4000065", "Errore nella copia del file nella cartella DELETE su Object Store", 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 1b684038..e144c7e0 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 @@ -97,13 +97,10 @@ public Uni saveAndUpload(ResourceEntity resourceEntity, File fil 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)); - }); + .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)) + ); } @Override @@ -285,15 +282,25 @@ public Uni disable(UUID uuid) { .transformToUni(itemToDelete -> resourceEntityStorageService.delete(originalStorageKey) .onItem() .transformToUni(deletedFile -> Uni.createFrom().voidItem()) - //TODO: onFailure() rollback del metodo uploadDisabledFile() + .onFailure() + .recoverWithUni(deleteException -> resourceEntityStorageService.delete(resourceFileUpdated.getStorageKey()) + .onItem() + .transform(deletedCopy -> { + throw new AtmLayerException( + deleteException.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, OBJECT_STORE_COPY_FILE_ERROR)) ) .onFailure().recoverWithUni(failure -> Uni.createFrom().failure(new AtmLayerException( failure.getMessage(), Response.Status.INTERNAL_SERVER_ERROR, DATABASE_SAVE_FILE_ERROR)) ) - ); + )); }); }