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 899a44f commit e8ead54
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,14 @@ public Uni<ResourceEntity> 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
Expand Down Expand Up @@ -278,8 +285,14 @@ 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(failure ->
Uni.createFrom().failure(new AtmLayerException(
failure.getMessage(),
Response.Status.INTERNAL_SERVER_ERROR, DATABASE_SAVE_FILE_ERROR))
)
);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -71,7 +72,12 @@ public Uni<ResourceFile> 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
Expand Down

0 comments on commit e8ead54

Please sign in to comment.