Skip to content

Commit

Permalink
Uat (#200)
Browse files Browse the repository at this point in the history
Co-authored-by: SMANUM <[email protected]>
Co-authored-by: adrrossi <[email protected]>
Co-authored-by: GitHub Action <[email protected]>
Co-authored-by: adrrss <[email protected]>
Co-authored-by: LuciaM1 <[email protected]>
Co-authored-by: LuciaM1 <[email protected]>
Co-authored-by: GiacomoB <[email protected]>
Co-authored-by: Simone Munao <[email protected]>
Co-authored-by: ElisKina-dev <[email protected]>
Co-authored-by: ElisKina-dev <[email protected]>
Co-authored-by: Gabriele Maiocchi <[email protected]>
Co-authored-by: Giacomo Brancazi <[email protected]>
  • Loading branch information
13 people authored Nov 12, 2024
1 parent e911572 commit f40c789
Show file tree
Hide file tree
Showing 20 changed files with 29,791 additions and 15,674 deletions.
16 changes: 10 additions & 6 deletions _TMP/coverage-results.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

| Outcome | Value |
|-------------------------|---------------------------------------------------------------------|
| Code Coverage % | 91.42% |
| :heavy_check_mark: Number of Lines Covered | 2301 |
| :x: Number of Lines Missed | 216 |
| Total Number of Lines | 2517 |
| Code Coverage % | 91.32% |
| :heavy_check_mark: Number of Lines Covered | 2325 |
| :x: Number of Lines Missed | 221 |
| Total Number of Lines | 2546 |


## Details:
Expand Down Expand Up @@ -600,6 +600,10 @@
#### Lines Missed:
- Line #190
```
} catch (AtmLayerException ex) {
```
</details>


Expand All @@ -612,11 +616,11 @@
#### Lines Missed:
- Line #96
- Line #97
```
.recoverWithUni(failure -> {
```
- Line #257
- Line #259
```
.recoverWithUni(failure -> {
```
Expand Down
2 changes: 1 addition & 1 deletion helm-chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: v1.32.0
version: v1.38.0
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
Expand Down
5 changes: 1 addition & 4 deletions helm-chart/environments/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@ objectStore:
resource_template_path: RESOURCE/files/[RESOURCE_TYPE]

cdn:
resourceBasePath: "https://resources.dev.atmlayer-pagopa.it"
offset_path: RESOURCE/
credentialsSecretEnabled: true
credentialsSecretName: "pagopa-dev-atm-layer-model-cdn-base-path"
credentialsSecretKeys:
cdn_base_path: CDN_BASE_PATH

secretProviderClass:
enabled: true
Expand Down
5 changes: 1 addition & 4 deletions helm-chart/environments/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@ objectStore:
resource_template_path: RESOURCE/files/[RESOURCE_TYPE]

cdn:
resourceBasePath: "https://resources.atmlayer-pagopa.it"
offset_path: RESOURCE/
credentialsSecretEnabled: true
credentialsSecretName: "pagopa-prod-atm-layer-model-cdn-base-path"
credentialsSecretKeys:
cdn_base_path: CDN_BASE_PATH

secretProviderClass:
enabled: true
Expand Down
6 changes: 2 additions & 4 deletions helm-chart/environments/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ objectStore:
resource_template_path: RESOURCE/files/[RESOURCE_TYPE]

cdn:
resourceBasePath: "https://resources.uat.atmlayer-pagopa.it"
offset_path: RESOURCE/
credentialsSecretEnabled: true
credentialsSecretName: "pagopa-uat-atm-layer-model-cdn-base-path"
credentialsSecretKeys:
cdn_base_path: CDN_BASE_PATH


secretProviderClass:
enabled: true
Expand Down
10 changes: 3 additions & 7 deletions helm-chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,9 @@ spec:
value: "{{ .Values.tracing.endpointBasePath }}"
- name: TRACING_ENABLE_JDBC_MONITORING
value: "{{ .Values.tracing.enableJDBCMonitoring }}"
{{- if .Values.cdn.credentialsSecretEnabled }}
- name: CDN_BASE_PATH
valueFrom:
secretKeyRef:
name: {{ .Values.cdn.credentialsSecretName }}
key: {{ .Values.cdn.credentialsSecretKeys.cdn_base_path }}
{{- end }}
- name: RESOURCES_BASE_PATH
value: "{{ .Values.cdn.resourceBasePath }}"

volumeMounts:
{{- if .Values.secretProviderClass.enabled }}
- name: secrets-store-inline
Expand Down
10 changes: 0 additions & 10 deletions helm-chart/templates/secretproviderclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ spec:
objectAlias: username
- path: password
objectAlias: password
- objectName: "pagopa-{{ .Values.secretProviderClass.env }}-atm-layer/cloudfront"
objectType: "secretsmanager"
jmesPath:
- path: url
objectAlias: url
secretObjects:
- secretName: {{ .Values.database.credentialsSecretName }}
type: Opaque
Expand All @@ -27,9 +22,4 @@ spec:
key: {{ .Values.database.credentialsSecretKeys.username }}
- objectName: "password" # reference the corresponding parameter
key: {{ .Values.database.credentialsSecretKeys.password }}
- secretName: {{ .Values.cdn.credentialsSecretName }}
type: Opaque
data:
- objectName: "url" # reference the corresponding parameter
key: {{ .Values.cdn.credentialsSecretKeys.cdn_base_path }}
{{- end }}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>it.gov.pagopa</groupId>
<artifactId>atm-layer-model</artifactId>
<version>1.32.0</version>
<version>1.38.0</version>
<name>atm-layer-model</name>
<properties>
<compiler-plugin.version>3.11.0</compiler-plugin.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ public enum AppErrorCodeEnum {
BPMN_INTERNAL_ERROR("ATMLM_4000051", "Nessun file associato a BPMN o nessuna storageKey trovata", INTERNAL),
BPMN_FILE_CANNOT_BE_UNDEPLOYED("ATMLM_4000052", "La risorsa di processo indicata non può essere rilasciata", INTERNAL),
NO_ASSOCIATION_FOUND("ATMLM_4000060","Nessuna associazione trovata", CONSTRAINT_VIOLATION),
ALL_FIELDS_ARE_BLANK("ATMLM_4000061", "Tutti i campi sono vuoti", AppErrorType.BLANK_FIELDS),
ALL_FIELDS_ARE_BLANK("ATMLM_4000061", "Tutti i campi sono vuoti", 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),
OBJECT_STORE_COPY_FILE_ERROR("ATMLM_4000065", "Errore nella copia del file nella cartella DELETE su Object Store", 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),
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 @@ -26,5 +26,7 @@ public enum AppErrorType {
CANNOT_ASSOCIATE,
NOT_EXISTING_USER_ID,
NOT_EXISTING_USER_PROFILE, CANNOT_REPLACE_ASSOCIATION,
BLANK_FIELDS
BLANK_FIELDS,
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 @@ -29,7 +29,6 @@
import org.eclipse.microprofile.rest.client.inject.RestClient;

import java.io.File;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.*;

Expand Down Expand Up @@ -120,12 +119,14 @@ public Uni<ResourceFile> upload(ResourceEntity resourceEntity, File file,
@Override
public Uni<ResourceEntity> createResource(ResourceEntity resourceEntity, File file,
String filename, String path, String description) {
validateFileExtension(filename, Arrays.asList("html", "jpeg", "jpg", "png", "svg"));

return findBySHA256(resourceEntity.getSha256())
.onItem().transformToUni(Unchecked.function(x -> {
if (x.isPresent()) {
throw new AtmLayerException(String.format("Esiste già una risorsa con lo stesso contenuto: %s", x.get().getResourceFile().getStorageKey().substring(15)),
Response.Status.BAD_REQUEST,
RESOURCE_WITH_SAME_SHA256_ALREADY_EXISTS);
throw new AtmLayerException(String.format("Esiste già una risorsa con lo stesso contenuto: %s",
x.get().getResourceFile().getStorageKey().substring(15)),
Response.Status.BAD_REQUEST, RESOURCE_WITH_SAME_SHA256_ALREADY_EXISTS);
}
return resourceFileService.findByStorageKey(resourceEntity.getStorageKey())
.onItem()
Expand All @@ -148,16 +149,49 @@ public Uni<ResourceEntity> createResource(ResourceEntity resourceEntity, File fi
}));
}


private void validateFileExtension(String filename, List<String> validExtensions) {
String fileExtension = Optional.ofNullable(filename)
.filter(f -> f.contains("."))
.map(f -> f.substring(filename.lastIndexOf(".") + 1).toLowerCase())
.orElse("");

if (!validExtensions.contains(fileExtension)) {
throw new AtmLayerException(String.format("Estensione del file non valida: %s. Estensioni consentite: %s",
fileExtension, String.join(", ", validExtensions)),
Response.Status.BAD_REQUEST, AppErrorCodeEnum.INVALID_FILE_EXTENSION);
}
}


@Override
@WithTransaction
public Uni<List<String>> createResourceMultiple(List<ResourceEntity> resourceEntityList, List<ResourceCreationDto> resourceCreationDtoList) {
List<String> errors = new ArrayList<>();
List<String> 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);
File file = resourceCreationDtoList.get(index).getFile();
String filename = resourceCreationDtoList.get(index).getFilename();

try {
validateFileExtension(filename, Arrays.asList("html", "jpeg", "jpg", "png", "svg"));
} catch (AtmLayerException ex) {
errors.add(String.format("%s-%s", filename, ex.getMessage()));
return Uni.createFrom().nullItem();
}

return findBySHA256(resourceEntity.getSha256())
.onItem().transformToUni(x -> {
if (x.isPresent()) {
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);
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/application-local.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ quarkus.devservices.enabled=false
quarkus.log.category."software.amazon.awssdk.services.s3".level=DEBUG
quarkus.hibernate-orm.physical-naming-strategy=org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy
quarkus.rest-client.process-deploy.url=http://localhost:3001
quarkus.http.limits.max-body-size=15M
###################
# OBJECT STORE
###################
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ quarkus.rest-client.process-deploy.url=${MODEL_PROCESS_BASE_PATH:http://pagopa-d
###################
# CDN
###################
cdn.base-url=${CDN_BASE_PATH}
cdn.base-url=${RESOURCES_BASE_PATH}
cdn.offset-path=${CDN_OFFSET_PATH:RESOURCE/}
#quarkus.log.console.format=%d{HH:mm:ss} %-5p traceId=%X{traceId}, parentId=%X{parentId}, spanId=%X{spanId}, sampled=%X{sampled} [%c{2.}] (%t) %s%e%n
###################
Expand All @@ -81,5 +81,5 @@ quarkus.otel.traces.enabled=${TRACING_ENABLED:false}
quarkus.otel.exporter.otlp.traces.endpoint=${TRACING_ENDPOINT_BASE_PATH:http://jaeger-collector.default.svc.cluster.local:4317}
quarkus.datasource.jdbc.telemetry=${TRACING_ENABLE_JDBC_MONITORING:true}



# Client config
quarkus.http.limits.max-body-size=15M
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void testCreateAlreadyExists() {
resourceEntity.setStorageKey("storageKey");
when(resourceEntityRepository.findBySHA256(any(String.class))).thenReturn(Uni.createFrom().nullItem());
when(resourceFileService.findByStorageKey(any(String.class))).thenReturn(Uni.createFrom().item(Optional.of(resourceFile)));
resourceEntityService.createResource(resourceEntity, file, "filename", "path", "description")
resourceEntityService.createResource(resourceEntity, file, "filename.html", "path", "description")
.subscribe().withSubscriber(UniAssertSubscriber.create())
.assertFailedWith(AtmLayerException.class, "Impossibile caricare storageKey: la risorsa con lo stesso nome file e percorso esiste già");
}
Expand All @@ -92,7 +92,7 @@ void testCreateSyncError() {
when(resourceEntityStorageService.saveFile(any(ResourceEntity.class), any(File.class), any(String.class), any(String.class)))
.thenReturn(Uni.createFrom().item(resourceFile));
when(resourceEntityRepository.findById(any(UUID.class))).thenReturn(Uni.createFrom().nullItem());
resourceEntityService.createResource(resourceEntity, new File("path/to/file"), "filename.xml", "path", "description")
resourceEntityService.createResource(resourceEntity, new File("path/to/file"), "filename.jpeg", "path", "description")
.subscribe().withSubscriber(UniAssertSubscriber.create())
.assertFailedWith(AtmLayerException.class, "Problema di sincronizzazione sulla creazione della risorsa");
}
Expand All @@ -110,7 +110,7 @@ void testCreateResourceWithDuplicateSHA256() {

when(resourceEntityRepository.findBySHA256(sha256)).thenReturn(Uni.createFrom().item(existingResourceEntity));

resourceEntityService.createResource(existingResourceEntity, file, "filename", "path", "description")
resourceEntityService.createResource(existingResourceEntity, file, "filename.jpg", "path", "description")
.subscribe().withSubscriber(UniAssertSubscriber.create())
.assertFailedWith(AtmLayerException.class, "Esiste già una risorsa con lo stesso contenuto");
}
Expand All @@ -128,10 +128,10 @@ void testCreateResourceSuccess() {
when(resourceEntityRepository.findBySHA256(sha256)).thenReturn(Uni.createFrom().nullItem());
when(resourceFileService.findByStorageKey(any(String.class))).thenReturn(Uni.createFrom().item(Optional.empty()));
when(resourceEntityRepository.persist(any(ResourceEntity.class))).thenReturn(Uni.createFrom().item(resourceEntity1));
when(resourceEntityStorageService.saveFile(resourceEntity1, file, "prova.txt", "/file/prova")).thenReturn(Uni.createFrom().item(resourceFile));
when(resourceEntityStorageService.saveFile(resourceEntity1, file, "prova.png", "/file/prova")).thenReturn(Uni.createFrom().item(resourceFile));
when(resourceEntityRepository.findById(uuid)).thenReturn(Uni.createFrom().item(resourceEntity1));

resourceEntityService.createResource(resourceEntity1, file, "filename", "path", "description")
resourceEntityService.createResource(resourceEntity1, file, "filename.svg", "path", "description")
.subscribe().withSubscriber(UniAssertSubscriber.create())
.assertCompleted()
.assertItem(resourceEntity1);
Expand Down Expand Up @@ -315,7 +315,7 @@ void testCreateResourceMultipleOK() {
}

private List<ResourceCreationDto> getResourceCreationDtoInstance(){
ResourceCreationDto resourceCreationDto = new ResourceCreationDto(new File("test.txt"), "filename", NoDeployableResourceType.HTML, "path", "description");
ResourceCreationDto resourceCreationDto = new ResourceCreationDto(new File("test.jpg"), "filename.jpg", NoDeployableResourceType.HTML, "path", "description");
List<ResourceCreationDto> dtoList = new ArrayList<>();
dtoList.add(resourceCreationDto);
return dtoList;
Expand Down
Loading

0 comments on commit f40c789

Please sign in to comment.