Skip to content

Commit

Permalink
starting implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciaM1 committed Sep 30, 2024
1 parent e8ead54 commit 7ef8052
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,10 @@ public Uni<ResourceEntity> 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
Expand Down Expand Up @@ -285,15 +282,25 @@ public Uni<Void> 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))
)
);
));
});
}

Expand Down

0 comments on commit 7ef8052

Please sign in to comment.