Skip to content

Commit

Permalink
Fix BpmnFile max size
Browse files Browse the repository at this point in the history
  • Loading branch information
EmanueleValentini1 committed Oct 14, 2024
1 parent e274474 commit 08973a1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -215,6 +216,7 @@ public Uni<BpmnVersion> saveAndUpload(BpmnVersion bpmnVersion, File file, String

@Override
public Uni<BpmnVersion> createBPMN(BpmnVersion bpmnVersion, File file, String filename) {
checkFileSize(file);
String definitionKey = extractIdValue(file, resourceType);
bpmnVersion.setDefinitionKey(definitionKey);
return findByDefinitionKey(definitionKey)
Expand Down Expand Up @@ -442,8 +444,9 @@ public Uni<BpmnVersion> getLatestVersion(UUID uuid, String functionType) {
});
}

@Override
public Uni<BpmnDTO> upgrade(BpmnUpgradeDto bpmnUpgradeDto) {
checkFileSize(bpmnUpgradeDto.getFile());

String definitionKey = extractIdValue(bpmnUpgradeDto.getFile(), resourceType);
return this.getLatestVersion(bpmnUpgradeDto.getUuid(), bpmnUpgradeDto.getFunctionType())
.onItem()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 08973a1

Please sign in to comment.