Skip to content

Commit

Permalink
Dev (#197)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Action <[email protected]>
Co-authored-by: LuciaM1 <[email protected]>
Co-authored-by: adrrossi <[email protected]>
Co-authored-by: GiacomoB <[email protected]>
Co-authored-by: Simone Munao <[email protected]>
Co-authored-by: LuciaM1 <[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
11 people authored Oct 10, 2024
1 parent cc93f71 commit f4b05d7
Show file tree
Hide file tree
Showing 11 changed files with 30,111 additions and 16,268 deletions.
14 changes: 9 additions & 5 deletions _TMP/coverage-results.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

# Coverage Report: JaCoCo

* IntegrationTest (QuarkusTest)
* S3PreSignerLocalTest (QuarkusTest)


| 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.36% |
| :heavy_check_mark: Number of Lines Covered | 2315 |
| :x: Number of Lines Missed | 219 |
| Total Number of Lines | 2534 |


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


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.31.0-dev.3
# 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
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.31.0-dev.3</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,12 @@ 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);
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,6 @@ public enum AppErrorType {
CANNOT_ASSOCIATE,
NOT_EXISTING_USER_ID,
NOT_EXISTING_USER_PROFILE, CANNOT_REPLACE_ASSOCIATION,
BLANK_FIELDS
BLANK_FIELDS,
INVALID_EXTENSION
}
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,6 +149,21 @@ 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) {
Expand All @@ -158,6 +174,14 @@ public Uni<List<String>> createResourceMultiple(List<ResourceEntity> resourceEnt
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 @@ -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 f4b05d7

Please sign in to comment.