From e4d35d2898b037b306085806c32b4131ae3f8ff7 Mon Sep 17 00:00:00 2001 From: EmVal Date: Tue, 15 Oct 2024 12:25:09 +0200 Subject: [PATCH] Add log to multipleUpload static resources --- .../model/service/impl/ResourceEntityServiceImpl.java | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 b8155da2..e88d1cdd 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 @@ -169,6 +169,16 @@ private void validateFileExtension(String filename, List validExtensions public Uni> createResourceMultiple(List resourceEntityList, List resourceCreationDtoList) { List errors = new ArrayList<>(); List uploadedFiles = new ArrayList<>(); + + long totalFileSize = resourceCreationDtoList.stream() + .mapToLong(dto -> dto.getFile().length()) // ottieni la dimensione del file in byte + .sum(); + + // Se la somma delle dimensioni dei file supera 10MB, solleva un'eccezione + if (totalFileSize > 10 * 1024 * 1024) { + throw new AtmLayerException("La dimensione totale dei file supera il limite di 10MB", Response.Status.INTERNAL_SERVER_ERROR, ATMLM_500); + } + return Multi.createFrom().items(resourceEntityList.stream()) .onItem().transformToUniAndConcatenate(resourceEntity -> { int index = resourceEntityList.indexOf(resourceEntity); @@ -208,6 +218,7 @@ public Uni> createResourceMultiple(List resourceEnt }); }) .onFailure().recoverWithItem(throwable -> { + log.error("Error processing file {}: {}", filename, throwable.getMessage()); errors.add(String.format("%s: %s", filename, throwable.getMessage())); return null; });