From 08973a11a836b7e305ea44f8762133f4aa0fb9ac Mon Sep 17 00:00:00 2001 From: EmVal Date: Mon, 14 Oct 2024 14:44:22 +0200 Subject: [PATCH] Fix BpmnFile max size --- .../service/model/enumeration/AppErrorCodeEnum.java | 3 ++- .../service/model/enumeration/AppErrorType.java | 3 ++- .../model/service/impl/BpmnVersionServiceImpl.java | 5 ++++- .../pagopa/atmlayer/service/model/utils/BpmnUtils.java | 10 ++++++++-- 4 files changed, 16 insertions(+), 5 deletions(-) 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 cb869a0e..73150d4a 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 @@ -64,7 +64,8 @@ public enum AppErrorCodeEnum { 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), OBJECT_STORE_COPY_FILE_ERROR("ATMLM_4000065", "Errore nella copia del file nella cartella DELETE su Object Store", INTERNAL), - INVALID_FILE_EXTENSION("ATMLM_4000066", "Estensione del file non valida", INVALID_EXTENSION); + INVALID_FILE_EXTENSION("ATMLM_4000066", "Estensione del file non valida", INVALID_EXTENSION), + BPMN_FILE_SIZE_EXCEEDS_LIMIT("ATMLM_4000066", "La dimensione del file supera quella consentita", FILE_SIZE_EXCEEDED); private final String errorCode; private final String errorMessage; private final AppErrorType type; diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorType.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorType.java index 18d078b9..fdff259f 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorType.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/enumeration/AppErrorType.java @@ -27,5 +27,6 @@ public enum AppErrorType { NOT_EXISTING_USER_ID, NOT_EXISTING_USER_PROFILE, CANNOT_REPLACE_ASSOCIATION, BLANK_FIELDS, - INVALID_EXTENSION + INVALID_EXTENSION, + FILE_SIZE_EXCEEDED, } \ No newline at end of file diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnVersionServiceImpl.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnVersionServiceImpl.java index 9c62710b..41f99390 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnVersionServiceImpl.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/service/impl/BpmnVersionServiceImpl.java @@ -30,6 +30,7 @@ import java.util.regex.Pattern; import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.*; +import static it.gov.pagopa.atmlayer.service.model.utils.BpmnUtils.checkFileSize; import static it.gov.pagopa.atmlayer.service.model.utils.BpmnUtils.getSingleConfig; import static it.gov.pagopa.atmlayer.service.model.utils.FileUtilities.extractIdValue; @@ -215,6 +216,7 @@ public Uni saveAndUpload(BpmnVersion bpmnVersion, File file, String @Override public Uni createBPMN(BpmnVersion bpmnVersion, File file, String filename) { + checkFileSize(file); String definitionKey = extractIdValue(file, resourceType); bpmnVersion.setDefinitionKey(definitionKey); return findByDefinitionKey(definitionKey) @@ -442,8 +444,9 @@ public Uni getLatestVersion(UUID uuid, String functionType) { }); } - @Override public Uni upgrade(BpmnUpgradeDto bpmnUpgradeDto) { + checkFileSize(bpmnUpgradeDto.getFile()); + String definitionKey = extractIdValue(bpmnUpgradeDto.getFile(), resourceType); return this.getLatestVersion(bpmnUpgradeDto.getUuid(), bpmnUpgradeDto.getFunctionType()) .onItem() diff --git a/src/main/java/it/gov/pagopa/atmlayer/service/model/utils/BpmnUtils.java b/src/main/java/it/gov/pagopa/atmlayer/service/model/utils/BpmnUtils.java index ced42195..27bf16f4 100644 --- a/src/main/java/it/gov/pagopa/atmlayer/service/model/utils/BpmnUtils.java +++ b/src/main/java/it/gov/pagopa/atmlayer/service/model/utils/BpmnUtils.java @@ -13,11 +13,11 @@ import jakarta.ws.rs.core.Response; import org.apache.commons.lang3.StringUtils; +import java.io.File; import java.util.*; import java.util.stream.Collectors; -import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.DUPLICATE_ASSOCIATION_CONFIGS; -import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.ILLEGAL_CONFIGURATION_TRIPLET; +import static it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum.*; @ApplicationScoped public class BpmnUtils { @@ -129,4 +129,10 @@ public static BpmnBankConfig getSingleConfig(BpmnVersionPK bpmnVersionPK, String bpmnBankConfig.setFunctionType(functionType); return bpmnBankConfig; } + + public static void checkFileSize(File file) { + if (file.length() > 1024 * 1024) { + throw new AtmLayerException("La dimensione del file supera 1MB", Response.Status.BAD_REQUEST, BPMN_FILE_SIZE_EXCEEDS_LIMIT); + } + } }