diff --git a/apps/onboarding-ms/src/main/docs/openapi.json b/apps/onboarding-ms/src/main/docs/openapi.json index 7047f045f..afe5cb2e8 100644 --- a/apps/onboarding-ms/src/main/docs/openapi.json +++ b/apps/onboarding-ms/src/main/docs/openapi.json @@ -25,7 +25,7 @@ "name" : "support" } ], "paths" : { - "/v1/aggregates/verification" : { + "/v1/aggregates/verification/prod-io" : { "post" : { "tags" : [ "Aggregates Controller" ], "summary" : "Validate the data related to the aggregated entities present in a CSV file", @@ -68,6 +68,92 @@ } ] } }, + "/v1/aggregates/verification/prod-pagopa" : { + "post" : { + "tags" : [ "Aggregates Controller" ], + "summary" : "Validate the data related to the aggregated entities present in a CSV file", + "requestBody" : { + "content" : { + "multipart/form-data" : { + "schema" : { + "required" : [ "aggregates" ], + "type" : "object", + "properties" : { + "aggregates" : { + "format" : "binary", + "type" : "string" + } + } + } + } + } + }, + "responses" : { + "200" : { + "description" : "OK", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/VerifyAggregateResponse" + } + } + } + }, + "401" : { + "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" + } + }, + "security" : [ { + "SecurityScheme" : [ ] + } ] + } + }, + "/v1/aggregates/verification/prod-pn" : { + "post" : { + "tags" : [ "Aggregates Controller" ], + "summary" : "Validate the data related to the aggregated entities present in a CSV file", + "requestBody" : { + "content" : { + "multipart/form-data" : { + "schema" : { + "required" : [ "aggregates" ], + "type" : "object", + "properties" : { + "aggregates" : { + "format" : "binary", + "type" : "string" + } + } + } + } + } + }, + "responses" : { + "200" : { + "description" : "OK", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/VerifyAggregateSendResponse" + } + } + } + }, + "401" : { + "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" + } + }, + "security" : [ { + "SecurityScheme" : [ ] + } ] + } + }, "/v1/notification/resend" : { "post" : { "tags" : [ "Notification Controller" ], @@ -1291,6 +1377,67 @@ } } }, + "AggregateSend" : { + "type" : "object", + "properties" : { + "description" : { + "type" : "string" + }, + "pec" : { + "type" : "string" + }, + "taxCode" : { + "type" : "string" + }, + "vatNumber" : { + "type" : "string" + }, + "codeSDI" : { + "type" : "string" + }, + "address" : { + "type" : "string" + }, + "city" : { + "type" : "string" + }, + "province" : { + "type" : "string" + }, + "subunitType" : { + "type" : "string" + }, + "subunitCode" : { + "type" : "string" + }, + "users" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/AggregateUser" + } + } + } + }, + "AggregateUser" : { + "type" : "object", + "properties" : { + "name" : { + "type" : "string" + }, + "surname" : { + "type" : "string" + }, + "taxCode" : { + "type" : "string" + }, + "email" : { + "type" : "string" + }, + "role" : { + "type" : "string" + } + } + }, "BillingPaRequest" : { "type" : "object", "properties" : { @@ -2343,6 +2490,23 @@ } } } + }, + "VerifyAggregateSendResponse" : { + "type" : "object", + "properties" : { + "aggregates" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/AggregateSend" + } + }, + "errors" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/RowError" + } + } + } } }, "securitySchemes" : { diff --git a/apps/onboarding-ms/src/main/docs/openapi.yaml b/apps/onboarding-ms/src/main/docs/openapi.yaml index be41357e2..5c807b060 100644 --- a/apps/onboarding-ms/src/main/docs/openapi.yaml +++ b/apps/onboarding-ms/src/main/docs/openapi.yaml @@ -16,7 +16,7 @@ tags: - name: internal-v1 - name: support paths: - /v1/aggregates/verification: + /v1/aggregates/verification/prod-io: post: tags: - Aggregates Controller @@ -46,6 +46,66 @@ paths: description: Not Allowed security: - SecurityScheme: [] + /v1/aggregates/verification/prod-pagopa: + post: + tags: + - Aggregates Controller + summary: Validate the data related to the aggregated entities present in a CSV + file + requestBody: + content: + multipart/form-data: + schema: + required: + - aggregates + type: object + properties: + aggregates: + format: binary + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/VerifyAggregateResponse" + "401": + description: Not Authorized + "403": + description: Not Allowed + security: + - SecurityScheme: [] + /v1/aggregates/verification/prod-pn: + post: + tags: + - Aggregates Controller + summary: Validate the data related to the aggregated entities present in a CSV + file + requestBody: + content: + multipart/form-data: + schema: + required: + - aggregates + type: object + properties: + aggregates: + format: binary + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/VerifyAggregateSendResponse" + "401": + description: Not Authorized + "403": + description: Not Allowed + security: + - SecurityScheme: [] /v1/notification/resend: post: tags: @@ -914,6 +974,46 @@ components: type: string origin: $ref: "#/components/schemas/Origin" + AggregateSend: + type: object + properties: + description: + type: string + pec: + type: string + taxCode: + type: string + vatNumber: + type: string + codeSDI: + type: string + address: + type: string + city: + type: string + province: + type: string + subunitType: + type: string + subunitCode: + type: string + users: + type: array + items: + $ref: "#/components/schemas/AggregateUser" + AggregateUser: + type: object + properties: + name: + type: string + surname: + type: string + taxCode: + type: string + email: + type: string + role: + type: string BillingPaRequest: type: object properties: @@ -1689,6 +1789,17 @@ components: type: array items: $ref: "#/components/schemas/RowError" + VerifyAggregateSendResponse: + type: object + properties: + aggregates: + type: array + items: + $ref: "#/components/schemas/AggregateSend" + errors: + type: array + items: + $ref: "#/components/schemas/RowError" securitySchemes: SecurityScheme: type: http diff --git a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/controller/AggregatesController.java b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/controller/AggregatesController.java index 29060608d..7b0926d6c 100644 --- a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/controller/AggregatesController.java +++ b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/controller/AggregatesController.java @@ -3,13 +3,11 @@ import io.quarkus.security.Authenticated; import io.smallrye.mutiny.Uni; import it.pagopa.selfcare.onboarding.model.VerifyAggregateResponse; +import it.pagopa.selfcare.onboarding.model.VerifyAggregateSendResponse; import it.pagopa.selfcare.onboarding.service.AggregatesService; import jakarta.inject.Inject; import jakarta.validation.constraints.NotNull; -import jakarta.ws.rs.Consumes; -import jakarta.ws.rs.POST; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.Produces; +import jakarta.ws.rs.*; import jakarta.ws.rs.core.MediaType; import lombok.AllArgsConstructor; import org.eclipse.microprofile.openapi.annotations.Operation; @@ -29,12 +27,32 @@ public class AggregatesController { @Operation(summary = "Validate the data related to the aggregated entities present in a CSV file") @POST - @Path("/verification") + @Path("/verification/prod-io") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.MULTIPART_FORM_DATA) - public Uni verifyAggregatesCsv(@NotNull @RestForm("aggregates") File file){ + public Uni verifyAppIoAggregatesCsv(@NotNull @RestForm("aggregates") File file){ - return aggregatesService.validateAggregatesCsv(file); + return aggregatesService.validateAppIoAggregatesCsv(file); + } + + @Operation(summary = "Validate the data related to the aggregated entities present in a CSV file") + @POST + @Path("/verification/prod-pn") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.MULTIPART_FORM_DATA) + public Uni verifySendAggregatesCsv(@NotNull @RestForm("aggregates") File file){ + + return aggregatesService.validateSendAggregatesCsv(file); + } + + @Operation(summary = "Validate the data related to the aggregated entities present in a CSV file") + @POST + @Path("/verification/prod-pagopa") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.MULTIPART_FORM_DATA) + public Uni verifyPagoPaAggregatesCsv(@NotNull @RestForm("aggregates") File file){ + + return aggregatesService.validatePagoPaAggregatesCsv(file); } diff --git a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/mapper/OnboardingMapper.java b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/mapper/OnboardingMapper.java index d1026d56b..762920b16 100644 --- a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/mapper/OnboardingMapper.java +++ b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/mapper/OnboardingMapper.java @@ -5,20 +5,19 @@ import it.pagopa.selfcare.onboarding.controller.request.*; import it.pagopa.selfcare.onboarding.controller.response.OnboardingGet; import it.pagopa.selfcare.onboarding.controller.response.OnboardingResponse; +import it.pagopa.selfcare.onboarding.entity.Institution; import it.pagopa.selfcare.onboarding.entity.Onboarding; import it.pagopa.selfcare.onboarding.entity.User; -import it.pagopa.selfcare.onboarding.model.AggregatesCsvResponse; -import it.pagopa.selfcare.onboarding.model.VerifyAggregateResponse; -import org.mapstruct.Context; -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.Named; +import it.pagopa.selfcare.onboarding.model.*; +import org.mapstruct.*; import org.openapi.quarkus.onboarding_functions_json.model.PartyRole; import java.time.OffsetDateTime; +import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.UUID; +import java.util.stream.Collectors; @Mapper(componentModel = "cdi", imports = { UUID.class, WorkflowType.class, OnboardingStatus.class }) public interface OnboardingMapper { @@ -119,4 +118,34 @@ default OffsetDateTime toOffsetDateTime(java.time.LocalDateTime localDateTime) { @Mapping(target = "errors", source = "rowErrorList") @Mapping(target = "aggregates", source = "validAggregates") VerifyAggregateResponse toVerifyAggregateResponse(AggregatesCsvResponse aggregatesCsvResponse); + + @Mapping(target = "errors", source = "rowErrorList") + @Mapping(target = "aggregates", source = "validAggregates") + VerifyAggregateSendResponse toVerifyAggregateSendResponse(AggregatesCsvResponse aggregatesCsvResponse); + + @Mapping(target = "users", source = ".") + AggregateSend csvToAggregateSend(CsvAggregateSend csvAggregateSend); + + default List mapCsvAggregatesToAggregates(List csvAggregateSendList) { + if (csvAggregateSendList == null) { + return null; + } + return csvAggregateSendList.stream() + .map(this::csvToAggregateSend) + .collect(Collectors.toList()); + } + + default List mapUsers(CsvAggregateSend csvAggregateSend) { + if (csvAggregateSend == null) { + return Collections.emptyList(); + } + AggregateUser user = new AggregateUser(); + user.setName(csvAggregateSend.getAdminAggregateName()); + user.setSurname(csvAggregateSend.getAdminAggregateSurname()); + user.setTaxCode(csvAggregateSend.getAdminAggregateTaxCode()); + user.setEmail(csvAggregateSend.getAdminAggregateEmail()); + user.setRole("Delegate"); + + return Collections.singletonList(user); + } } diff --git a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/AggregateSend.java b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/AggregateSend.java new file mode 100644 index 000000000..8b3564ab5 --- /dev/null +++ b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/AggregateSend.java @@ -0,0 +1,20 @@ +package it.pagopa.selfcare.onboarding.model; + +import lombok.Data; + +import java.util.List; + +@Data +public class AggregateSend { + private String description; + private String pec; + private String taxCode; + private String vatNumber; + private String codeSDI; + private String address; + private String city; + private String province; + private String subunitType; + private String subunitCode; + private List users; +} \ No newline at end of file diff --git a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/AggregateUser.java b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/AggregateUser.java new file mode 100644 index 000000000..d4329ab1e --- /dev/null +++ b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/AggregateUser.java @@ -0,0 +1,12 @@ +package it.pagopa.selfcare.onboarding.model; + +import lombok.Data; + +@Data +public class AggregateUser { + private String name; + private String surname; + private String taxCode; + private String email; + private String role; +} \ No newline at end of file diff --git a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/AggregatesCsvResponse.java b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/AggregatesCsvResponse.java index ab7bc9978..2d5e6f574 100644 --- a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/AggregatesCsvResponse.java +++ b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/AggregatesCsvResponse.java @@ -3,29 +3,29 @@ import java.util.ArrayList; import java.util.List; -public class AggregatesCsvResponse { - private List csvAggregateList; - private List validAggregates = new ArrayList<>(); +public class AggregatesCsvResponse { + private List csvAggregateList; + private List validAggregates = new ArrayList<>(); private List rowErrorList; - public AggregatesCsvResponse(List csvAggregateList, List rowErrorList) { + public AggregatesCsvResponse(List csvAggregateList, List rowErrorList) { this.csvAggregateList = csvAggregateList; this.rowErrorList = rowErrorList; } - public List getCsvAggregateList() { + public List getCsvAggregateList() { return csvAggregateList; } - public void setCsvAggregateList(List csvAggregateList) { + public void setCsvAggregateList(List Csv) { this.csvAggregateList = csvAggregateList; } - public List getValidAggregates() { + public List getValidAggregates() { return validAggregates; } - public void setValidAggregates(List validAggregates) { + public void setValidAggregates(List Csv) { this.validAggregates = validAggregates; } diff --git a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/Csv.java b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/Csv.java new file mode 100644 index 000000000..c5a9964ae --- /dev/null +++ b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/Csv.java @@ -0,0 +1,5 @@ +package it.pagopa.selfcare.onboarding.model; + +public interface Csv { + void setRowNumber(int lineNumber); +} diff --git a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregate.java b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregateAppIo.java similarity index 59% rename from apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregate.java rename to apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregateAppIo.java index cf24afa18..77f27e035 100644 --- a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregate.java +++ b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregateAppIo.java @@ -4,24 +4,45 @@ import lombok.Data; @Data -public class CsvAggregate { +public class CsvAggregateAppIo implements Csv { @CsvBindByPosition(position = 0) - private String taxCode; - @CsvBindByPosition(position = 1) private String description; + + @CsvBindByPosition(position = 1) + private String pec; + @CsvBindByPosition(position = 2) - private String vatNumber; + private String taxCode; + @CsvBindByPosition(position = 3) - private String subunitType; + private String vatNumber; + @CsvBindByPosition(position = 4) - private String subunitCode; - @CsvBindByPosition(position = 5) private String address; + + @CsvBindByPosition(position = 5) + private String city; + @CsvBindByPosition(position = 6) - private String originId; + private String province; + + @CsvBindByPosition(position = 7) + private String ipaCode; + @CsvBindByPosition(position = 8) + private String subunitType; + + @CsvBindByPosition(position = 9) + private String subunitCode; + + @CsvBindByPosition(position = 10) + private String originId; private Integer rowNumber; + @Override + public void setRowNumber(int lineNumber) { + this.rowNumber = lineNumber; + } } diff --git a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregatePagoPa.java b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregatePagoPa.java new file mode 100644 index 000000000..25c0e7ceb --- /dev/null +++ b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregatePagoPa.java @@ -0,0 +1,51 @@ +package it.pagopa.selfcare.onboarding.model; + +import com.opencsv.bean.CsvBindByPosition; +import lombok.Data; + +@Data +public class CsvAggregatePagoPa implements Csv { + + @CsvBindByPosition(position = 0) + private String description; + + @CsvBindByPosition(position = 1) + private String pec; + + @CsvBindByPosition(position = 2) + private String taxCode; + + @CsvBindByPosition(position = 3) + private String vatNumber; + + @CsvBindByPosition(position = 4) + private String address; + + @CsvBindByPosition(position = 5) + private String city; + + @CsvBindByPosition(position = 6) + private String province; + + @CsvBindByPosition(position = 7) + private String aggragateNamePT; + + @CsvBindByPosition(position = 8) + private String taxCodePT; + + @CsvBindByPosition(position = 9) + private String iban; + + @CsvBindByPosition(position = 10) + private String service; + + @CsvBindByPosition(position = 11) + private String syncAsyncMode; + + private Integer rowNumber; + + @Override + public void setRowNumber(int lineNumber) { + this.rowNumber = lineNumber; + } +} diff --git a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregateSend.java b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregateSend.java new file mode 100644 index 000000000..fb859a316 --- /dev/null +++ b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/CsvAggregateSend.java @@ -0,0 +1,59 @@ +package it.pagopa.selfcare.onboarding.model; + +import com.opencsv.bean.CsvBindByPosition; +import lombok.Data; + +@Data +public class CsvAggregateSend implements Csv { + + @CsvBindByPosition(position = 0) + private String description; + + @CsvBindByPosition(position = 1) + private String pec; + + @CsvBindByPosition(position = 2) + private String taxCode; + + @CsvBindByPosition(position = 3) + private String vatNumber; + + @CsvBindByPosition(position = 4) + private String codeSDI; + + @CsvBindByPosition(position = 5) + private String address; + + @CsvBindByPosition(position = 6) + private String city; + + @CsvBindByPosition(position = 7) + private String province; + + @CsvBindByPosition(position = 8) + private String ipaCode; + + @CsvBindByPosition(position = 9) + private String subunitType; + + @CsvBindByPosition(position = 10) + private String subunitCode; + + @CsvBindByPosition(position = 11) + private String adminAggregateName; + + @CsvBindByPosition(position = 12) + private String adminAggregateSurname; + + @CsvBindByPosition(position = 13) + private String adminAggregateTaxCode; + + @CsvBindByPosition(position = 14) + private String adminAggregateEmail; + private Integer rowNumber; + @Override + public void setRowNumber(int lineNumber) { + this.rowNumber = lineNumber; + } + +} diff --git a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/VerifyAggregateSendResponse.java b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/VerifyAggregateSendResponse.java new file mode 100644 index 000000000..e86dd5f86 --- /dev/null +++ b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/model/VerifyAggregateSendResponse.java @@ -0,0 +1,17 @@ +package it.pagopa.selfcare.onboarding.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class VerifyAggregateSendResponse { + + private List aggregates; + private List errors; + +} diff --git a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/service/AggregatesService.java b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/service/AggregatesService.java index ffbe3506e..a9ee5269f 100644 --- a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/service/AggregatesService.java +++ b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/service/AggregatesService.java @@ -3,10 +3,15 @@ import io.smallrye.mutiny.Uni; import it.pagopa.selfcare.onboarding.common.InstitutionType; import it.pagopa.selfcare.onboarding.model.VerifyAggregateResponse; +import it.pagopa.selfcare.onboarding.model.VerifyAggregateSendResponse; import java.io.File; public interface AggregatesService { - Uni validateAggregatesCsv(File file); + Uni validateAppIoAggregatesCsv (File file); + + Uni validateSendAggregatesCsv (File file); + + Uni validatePagoPaAggregatesCsv (File file); } diff --git a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/service/AggregatesServiceDefault.java b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/service/AggregatesServiceDefault.java index 36670455e..fb55426d2 100644 --- a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/service/AggregatesServiceDefault.java +++ b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/service/AggregatesServiceDefault.java @@ -9,10 +9,7 @@ import it.pagopa.selfcare.onboarding.exception.InvalidRequestException; import it.pagopa.selfcare.onboarding.exception.ResourceNotFoundException; import it.pagopa.selfcare.onboarding.mapper.OnboardingMapper; -import it.pagopa.selfcare.onboarding.model.AggregatesCsvResponse; -import it.pagopa.selfcare.onboarding.model.CsvAggregate; -import it.pagopa.selfcare.onboarding.model.RowError; -import it.pagopa.selfcare.onboarding.model.VerifyAggregateResponse; +import it.pagopa.selfcare.onboarding.model.*; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import jakarta.ws.rs.WebApplicationException; @@ -40,6 +37,7 @@ public class AggregatesServiceDefault implements AggregatesService{ private static final Logger LOG = Logger.getLogger(AggregatesServiceDefault.class); + @Inject OnboardingMapper onboardingMapper; @@ -65,12 +63,28 @@ public class AggregatesServiceDefault implements AggregatesService{ public static final String ERROR_AOO_UO = "In caso di AOO/UO è necessario specificare la tipologia e il codice univoco IPA AOO/UO"; public static final String ERROR_VATNUMBER = "La partita IVA è obbligatoria"; + public static final String ERROR_ADDRESS = "Indirizzo è obbligatorio"; + public static final String ERROR_CITY = "La città è obbligatoria"; + public static final String ERROR_PROVINCE = "La provincia è obbligatoria"; + public static final String ERROR_PEC = "Indirizzo PEC è obbligatorio"; + public static final String ERROR_ADMIN_NAME = "Nome Amministratore Ente Aggregato è obbligatorio"; + public static final String ERROR_ADMIN_SURNAME = "Cognome Amministratore Ente Aggregato è obbligatorio"; + public static final String ERROR_ADMIN_EMAIL = "Email Amministratore Ente Aggregato è obbligatorio"; + public static final String ERROR_ADMIN_TAXCODE = "Codice Fiscale Amministratore Ente Aggregato è obbligatorio"; + public static final String ERROR_AGGREGATE_NAME_PT = "Ragine Sociale Partner Tecnologico è obbligatorio"; + public static final String ERROR_TAXCODE_PT = "Codice Fiscale Partner Tecnologico è obbligatorio"; + public static final String ERROR_IBAN = "IBAN è obbligatorio"; + public static final String ERROR_SERVICE = "Servizio è obbligatorio"; + public static final String ERROR_SYNC_ASYNC_MODE = "Modalità Sincrona/Asincrona è obbligatorio"; + private static final String ERROR_IPA_CODE = "Codice IPA è obbligatorio in caso di ente centrale"; + + @Override - public Uni validateAggregatesCsv(File file){ - AggregatesCsvResponse aggregatesCsvResponse = readItemsFromCsv(file); - List csvAggregates = aggregatesCsvResponse.getCsvAggregateList(); + public Uni validateAppIoAggregatesCsv(File file){ + AggregatesCsvResponse aggregatesCsvResponse = readItemsFromCsv(file, CsvAggregateAppIo.class); + List csvAggregates = aggregatesCsvResponse.getCsvAggregateList(); return Multi.createFrom().iterable(csvAggregates) - .onItem().transformToUniAndMerge(csvAggregate -> checkCsvAggregateAndFillAggregateOrErrorList(csvAggregate, aggregatesCsvResponse)) + .onItem().transformToUniAndMerge(csvAggregate -> checkCsvAggregateAppIoAndFillAggregateOrErrorList(csvAggregate, aggregatesCsvResponse)) .collect().asList() .onItem().transform(list -> onboardingMapper.toVerifyAggregateResponse(aggregatesCsvResponse)) .onItem().invoke(() -> LOG.infof("CSV file validated end: %s valid row and %s invalid row", @@ -78,24 +92,100 @@ public Uni validateAggregatesCsv(File file){ aggregatesCsvResponse.getRowErrorList().size())); } - private Uni checkCsvAggregateAndFillAggregateOrErrorList(CsvAggregate csvAggregate, AggregatesCsvResponse aggregatesCsvResponse) { - return checkCsvAggregate(csvAggregate) + @Override + public Uni validateSendAggregatesCsv(File file) { + AggregatesCsvResponse aggregatesCsvResponse = readItemsFromCsv(file, CsvAggregateSend.class); + List csvAggregates = aggregatesCsvResponse.getCsvAggregateList(); + return Multi.createFrom().iterable(csvAggregates) + .onItem().transformToUniAndMerge(csvAggregate -> checkCsvAggregateSendAndFillAggregateOrErrorList(csvAggregate, aggregatesCsvResponse)) + .collect().asList() + .onItem().transform(list -> onboardingMapper.toVerifyAggregateSendResponse(aggregatesCsvResponse)) + .onItem().invoke(() -> LOG.infof("CSV file validated end: %s valid row and %s invalid row", + aggregatesCsvResponse.getValidAggregates().size(), + aggregatesCsvResponse.getRowErrorList().size())); + } + + @Override + public Uni validatePagoPaAggregatesCsv(File file) { + AggregatesCsvResponse aggregatesCsvResponse = readItemsFromCsv(file, CsvAggregatePagoPa.class); + List csvAggregates = aggregatesCsvResponse.getCsvAggregateList(); + return Multi.createFrom().iterable(csvAggregates) + .onItem().transformToUniAndMerge(csvAggregate -> checkCsvAggregatePagoPaAndFillAggregateOrErrorList(csvAggregate, aggregatesCsvResponse)) + .collect().asList() + .onItem().transform(list -> onboardingMapper.toVerifyAggregateResponse(aggregatesCsvResponse)) + .onItem().invoke(() -> LOG.infof("CSV file validated end: %s valid row and %s invalid row", + aggregatesCsvResponse.getValidAggregates().size(), + aggregatesCsvResponse.getRowErrorList().size())); + + } + + private Uni checkCsvAggregateAppIoAndFillAggregateOrErrorList(Csv csv, AggregatesCsvResponse aggregatesCsvResponse) { + CsvAggregateAppIo csvAggregateAppIo = (CsvAggregateAppIo) csv; + return checkCsvAggregateAppIo(csvAggregateAppIo) + .onItem().invoke(() -> aggregatesCsvResponse.getValidAggregates().add(csvAggregateAppIo)) + .onFailure(ResourceNotFoundException.class).recoverWithUni(throwable -> mapToErrorRow(csvAggregateAppIo, throwable, aggregatesCsvResponse)) + .onFailure(InvalidRequestException.class).recoverWithUni(throwable -> mapToErrorRow(csvAggregateAppIo, throwable, aggregatesCsvResponse)); + } + + private Uni checkCsvAggregateSendAndFillAggregateOrErrorList(Csv csv, AggregatesCsvResponse aggregatesCsvResponse) { + CsvAggregateSend csvAggregate = (CsvAggregateSend) csv; + return checkCsvAggregateSend(csvAggregate) .onItem().invoke(() -> aggregatesCsvResponse.getValidAggregates().add(csvAggregate)) .onFailure(ResourceNotFoundException.class).recoverWithUni(throwable -> mapToErrorRow(csvAggregate, throwable, aggregatesCsvResponse)) .onFailure(InvalidRequestException.class).recoverWithUni(throwable -> mapToErrorRow(csvAggregate, throwable, aggregatesCsvResponse)); } - private static Uni mapToErrorRow(CsvAggregate csvAggregate, Throwable throwable, AggregatesCsvResponse aggregatesCsvResponse) { - aggregatesCsvResponse.getRowErrorList().add(new RowError(csvAggregate.getRowNumber(), csvAggregate.getTaxCode(), throwable.getMessage())); + private Uni checkCsvAggregatePagoPaAndFillAggregateOrErrorList(Csv csv, AggregatesCsvResponse aggregatesCsvResponse) { + CsvAggregatePagoPa csvAggregate = (CsvAggregatePagoPa) csv; + + return checkCsvAggregatePagoPa(csvAggregate) + .onItem().invoke(() -> aggregatesCsvResponse.getValidAggregates().add(csvAggregate)) + .onFailure(ResourceNotFoundException.class).recoverWithUni(throwable -> mapToErrorRow(csvAggregate, throwable, aggregatesCsvResponse)) + .onFailure(InvalidRequestException.class).recoverWithUni(throwable -> mapToErrorRow(csvAggregate, throwable, aggregatesCsvResponse)); + } + + private static Uni mapToErrorRow(Csv csv, Throwable throwable, AggregatesCsvResponse aggregatesCsvResponse) { + CsvAggregateAppIo csvAggregateAppIo = (CsvAggregateAppIo) csv; + aggregatesCsvResponse.getRowErrorList().add(new RowError(csvAggregateAppIo.getRowNumber(), csvAggregateAppIo.getTaxCode(), throwable.getMessage())); return Uni.createFrom().voidItem(); } - private Uni checkCsvAggregate(CsvAggregate csvAggregate) { - return checkRequiredFields(csvAggregate) - .onItem().transformToUni(unused -> checkSubunitType(csvAggregate)); + private Uni checkCsvAggregateAppIo(Csv csvAggregate) { + return checkRequiredFieldsAppIo(csvAggregate) + .onItem().transformToUni(unused -> checkSubunitTypeAppIo(csvAggregate)); + } + + private Uni checkCsvAggregateSend(CsvAggregateSend csvAggregate) { + return checkRequiredFieldsSend(csvAggregate) + .onItem().transformToUni(unused -> checkSubunitTypeSend(csvAggregate)); + } + + private Uni checkCsvAggregatePagoPa(CsvAggregatePagoPa csvAggregate) { + return checkRequiredFieldsPagoPa(csvAggregate); + } + + private Uni checkSubunitTypeAppIo(Csv csv) { + CsvAggregateAppIo csvAggregateAppIo = (CsvAggregateAppIo) csv; + + if (StringUtils.isEmpty(csvAggregateAppIo.getSubunitType())) { + return institutionApi.findInstitutionUsingGET(csvAggregateAppIo.getTaxCode(), null, null) + .onFailure(this::checkIfNotFound).recoverWithUni(Uni.createFrom().failure(new ResourceNotFoundException(ERROR_IPA))) + .replaceWith(Uni.createFrom().voidItem()); + } else if (InstitutionPaSubunitType.AOO.name().equals(csvAggregateAppIo.getSubunitType())) { + return aooApi.findByUnicodeUsingGET(csvAggregateAppIo.getSubunitCode(), null) + .onFailure(this::checkIfNotFound).recoverWithUni(Uni.createFrom().failure(new ResourceNotFoundException(ERROR_IPA))) + .replaceWith(Uni.createFrom().voidItem()); + } else if (InstitutionPaSubunitType.UO.name().equals(csvAggregateAppIo.getSubunitType())) { + return uoApi.findByUnicodeUsingGET1(csvAggregateAppIo.getSubunitCode(), null) + .onFailure(this::checkIfNotFound).recoverWithUni(Uni.createFrom().failure(new ResourceNotFoundException(ERROR_IPA))) + .replaceWith(Uni.createFrom().voidItem()); + } else { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_SUBUNIT_TYPE)); + } } - private Uni checkSubunitType(CsvAggregate csvAggregate) { + private Uni checkSubunitTypeSend(CsvAggregateSend csvAggregate) { + if (StringUtils.isEmpty(csvAggregate.getSubunitType())) { return institutionApi.findInstitutionUsingGET(csvAggregate.getTaxCode(), null, null) .onFailure(this::checkIfNotFound).recoverWithUni(Uni.createFrom().failure(new ResourceNotFoundException(ERROR_IPA))) @@ -117,22 +207,130 @@ private boolean checkIfNotFound(Throwable throwable) { return throwable instanceof WebApplicationException webApplicationException && webApplicationException.getResponse().getStatus() == 404; } - private Uni checkRequiredFields(CsvAggregate csvAggregate) { - if (StringUtils.isEmpty(csvAggregate.getTaxCode())) { + private Uni checkRequiredFieldsAppIo(Csv csv) { + CsvAggregateAppIo csvAggregateAppIo = (CsvAggregateAppIo) csv; + + if (StringUtils.isEmpty(csvAggregateAppIo.getDescription())){ + return Uni.createFrom().failure(new InvalidRequestException(ERROR_DESCRIPTION)); + } + else if (StringUtils.isEmpty(csvAggregateAppIo.getPec())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_PEC)); + } + else if (StringUtils.isEmpty(csvAggregateAppIo.getTaxCode())) { return Uni.createFrom().failure(new InvalidRequestException(ERROR_TAXCODE)); - } else if (StringUtils.isEmpty(csvAggregate.getDescription())) { + } + else if (StringUtils.isEmpty(csvAggregateAppIo.getVatNumber())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_VATNUMBER)); + } + else if (StringUtils.isEmpty(csvAggregateAppIo.getAddress())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_ADDRESS)); + } + else if (StringUtils.isEmpty(csvAggregateAppIo.getCity())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_CITY)); + } + else if (StringUtils.isEmpty(csvAggregateAppIo.getProvince())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_PROVINCE)); + } + else if ((StringUtils.isEmpty(csvAggregateAppIo.getSubunitType()) && StringUtils.isNotEmpty(csvAggregateAppIo.getSubunitCode())) + || (StringUtils.isNotEmpty(csvAggregateAppIo.getSubunitType()) && StringUtils.isEmpty(csvAggregateAppIo.getSubunitCode()))) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_AOO_UO)); + } + else if ((StringUtils.isEmpty(csvAggregateAppIo.getSubunitType()) && StringUtils.isEmpty(csvAggregateAppIo.getSubunitCode())) + && (StringUtils.isEmpty(csvAggregateAppIo.getIpaCode()))) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_IPA_CODE)); + } + return Uni.createFrom().voidItem(); + } + + private Uni checkRequiredFieldsSend(CsvAggregateSend csvAggregate) { + + if (StringUtils.isEmpty(csvAggregate.getDescription())) { return Uni.createFrom().failure(new InvalidRequestException(ERROR_DESCRIPTION)); - } else if (StringUtils.isEmpty(csvAggregate.getVatNumber())) { + } + else if (StringUtils.isEmpty(csvAggregate.getPec())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_PEC)); + } + if (StringUtils.isEmpty(csvAggregate.getTaxCode())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_TAXCODE)); + } + else if (StringUtils.isEmpty(csvAggregate.getVatNumber())) { return Uni.createFrom().failure(new InvalidRequestException(ERROR_VATNUMBER)); - } else if ((StringUtils.isEmpty(csvAggregate.getSubunitType()) && StringUtils.isNotEmpty(csvAggregate.getSubunitCode())) + } + else if (StringUtils.isEmpty(csvAggregate.getAddress())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_ADDRESS)); + } + else if (StringUtils.isEmpty(csvAggregate.getCity())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_CITY)); + } + else if (StringUtils.isEmpty(csvAggregate.getProvince())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_PROVINCE)); + } + else if ((StringUtils.isEmpty(csvAggregate.getSubunitType()) && StringUtils.isNotEmpty(csvAggregate.getSubunitCode())) || (StringUtils.isNotEmpty(csvAggregate.getSubunitType()) && StringUtils.isEmpty(csvAggregate.getSubunitCode()))) { return Uni.createFrom().failure(new InvalidRequestException(ERROR_AOO_UO)); } + else if (StringUtils.isEmpty(csvAggregate.getAdminAggregateName())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_ADMIN_NAME)); + } + else if (StringUtils.isEmpty(csvAggregate.getAdminAggregateSurname())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_ADMIN_SURNAME)); + } + else if (StringUtils.isEmpty(csvAggregate.getAdminAggregateTaxCode())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_ADMIN_TAXCODE)); + } + else if (StringUtils.isEmpty(csvAggregate.getAdminAggregateEmail())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_ADMIN_EMAIL)); + } + else if ((StringUtils.isEmpty(csvAggregate.getSubunitType()) && StringUtils.isEmpty(csvAggregate.getSubunitCode())) + && (StringUtils.isEmpty(csvAggregate.getIpaCode()))) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_IPA_CODE)); + } + return Uni.createFrom().voidItem(); + } + + private Uni checkRequiredFieldsPagoPa(CsvAggregatePagoPa csvAggregate) { + + if (StringUtils.isEmpty(csvAggregate.getDescription())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_DESCRIPTION)); + } + else if (StringUtils.isEmpty(csvAggregate.getPec())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_PEC)); + } + if (StringUtils.isEmpty(csvAggregate.getTaxCode())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_TAXCODE)); + } + else if (StringUtils.isEmpty(csvAggregate.getVatNumber())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_VATNUMBER)); + } + else if (StringUtils.isEmpty(csvAggregate.getAddress())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_ADDRESS)); + } + else if (StringUtils.isEmpty(csvAggregate.getCity())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_CITY)); + } + else if (StringUtils.isEmpty(csvAggregate.getProvince())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_PROVINCE)); + } + else if (StringUtils.isEmpty(csvAggregate.getAggragateNamePT())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_AGGREGATE_NAME_PT)); + } + else if (StringUtils.isEmpty(csvAggregate.getTaxCodePT())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_TAXCODE_PT)); + } + else if (StringUtils.isEmpty(csvAggregate.getIban())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_IBAN)); + } + else if (StringUtils.isEmpty(csvAggregate.getService())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_SERVICE)); + } + else if (StringUtils.isEmpty(csvAggregate.getSyncAsyncMode())) { + return Uni.createFrom().failure(new InvalidRequestException(ERROR_SYNC_ASYNC_MODE)); + } return Uni.createFrom().voidItem(); } - public AggregatesCsvResponse readItemsFromCsv(File file) { - List resultList = new ArrayList<>(); + public AggregatesCsvResponse readItemsFromCsv(File file, Class csv) { + List resultList = new ArrayList<>(); List errors = new ArrayList<>(); try { @@ -146,7 +344,7 @@ public AggregatesCsvResponse readItemsFromCsv(File file) { while ((nextLine = bufferedReader.readLine()) != null) { if(!nextLine.startsWith("(*")){ - parseLine(nextLine, lineNumber, resultList, errors); + parseLine(nextLine, lineNumber, resultList, errors, csv); lineNumber++; } } @@ -159,13 +357,13 @@ public AggregatesCsvResponse readItemsFromCsv(File file) { } } - private void parseLine(String nextLine, int lineNumber, List resultList, List errors) { + private void parseLine(String nextLine, int lineNumber, List resultList, List errors, Class csv) { try { StringReader lineReader = new StringReader(nextLine); - CsvToBean csvToBean = getAggregateCsvToBean(new BufferedReader(lineReader)); - List csvAggregateList = csvToBean.parse(); + CsvToBean csvToBean = getAggregateCsvToBean(new BufferedReader(lineReader), csv); + List csvAggregateList = csvToBean.parse(); if (!csvAggregateList.isEmpty()) { - CsvAggregate csvAggregate = csvAggregateList.get(0); + Csv csvAggregate = csvAggregateList.get(0); csvAggregate.setRowNumber(lineNumber); resultList.add(csvAggregateList.get(0)); } @@ -176,9 +374,9 @@ private void parseLine(String nextLine, int lineNumber, List resul } } - private CsvToBean getAggregateCsvToBean(BufferedReader bufferedReader) { - CsvToBeanBuilder csvToBeanBuilder = new CsvToBeanBuilder<>(bufferedReader); - csvToBeanBuilder.withType(CsvAggregate.class); + private CsvToBean getAggregateCsvToBean(BufferedReader bufferedReader, Class csv) { + CsvToBeanBuilder csvToBeanBuilder = new CsvToBeanBuilder<>(bufferedReader); + csvToBeanBuilder.withType(csv); csvToBeanBuilder.withSeparator(';'); csvToBeanBuilder.withQuoteChar(DEFAULT_QUOTE_CHARACTER); csvToBeanBuilder.withOrderedResults(true); diff --git a/apps/onboarding-ms/src/main/resources/application.properties b/apps/onboarding-ms/src/main/resources/application.properties index 330ce5a32..2afa5224c 100644 --- a/apps/onboarding-ms/src/main/resources/application.properties +++ b/apps/onboarding-ms/src/main/resources/application.properties @@ -6,6 +6,7 @@ quarkus.http.port=8080 ## JWT quarkus.http.auth.proactive=false mp.jwt.verify.publickey=${JWT-PUBLIC-KEY} + mp.jwt.verify.issuer=SPID #smallrye.jwt.verify.key-format=JWK_BASE64URL diff --git a/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/controller/AggregatesControllerTest.java b/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/controller/AggregatesControllerTest.java index 7c3a2f5db..298eb530c 100644 --- a/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/controller/AggregatesControllerTest.java +++ b/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/controller/AggregatesControllerTest.java @@ -9,6 +9,7 @@ import io.restassured.http.ContentType; import io.smallrye.mutiny.Uni; import it.pagopa.selfcare.onboarding.model.VerifyAggregateResponse; +import it.pagopa.selfcare.onboarding.model.VerifyAggregateSendResponse; import it.pagopa.selfcare.onboarding.service.AggregatesService; import org.junit.jupiter.api.Test; @@ -21,28 +22,67 @@ @QuarkusTest @TestHTTPEndpoint(AggregatesController.class) @QuarkusTestResource(MongoTestResource.class) +@TestSecurity(user = "userJwt") public class AggregatesControllerTest { @InjectMock AggregatesService aggregatesService; @Test - @TestSecurity(user = "userJwt") void verifyAggregatesCsv_succeeds() { - File testFile = new File("src/test/resources/aggregates.csv"); + File testFile = new File("src/test/resources/aggregates-appio.csv"); + + when(aggregatesService.validateAppIoAggregatesCsv(any())) + .thenReturn(Uni.createFrom().item(new VerifyAggregateResponse())); + + given() + .when() + .contentType(ContentType.MULTIPART) + .multiPart("aggregates", testFile) + .post("/verification/prod-io") + .then() + .statusCode(200); + + verify(aggregatesService, times(1)) + .validateAppIoAggregatesCsv(any()); + } + + @Test + void verifyAggregatesPagoPaCsv_succeeds() { + File testFile = new File("src/test/resources/aggregates-pagopa.csv"); - when(aggregatesService.validateAggregatesCsv(any())) + when(aggregatesService.validatePagoPaAggregatesCsv(any())) .thenReturn(Uni.createFrom().item(new VerifyAggregateResponse())); given() .when() .contentType(ContentType.MULTIPART) .multiPart("aggregates", testFile) - .post("/verification") + .post("/verification/prod-pagopa") + .then() + .statusCode(200); + + verify(aggregatesService, times(1)) + .validatePagoPaAggregatesCsv(any()); + } + + @TestSecurity(user = "userJwt") + @Test + void verifyAggregatesSendCsv_succeeds() { + File testFile = new File("src/test/resources/aggregates-send.csv"); + + when(aggregatesService.validateSendAggregatesCsv(any())) + .thenReturn(Uni.createFrom().item(new VerifyAggregateSendResponse())); + + given() + .when() + .contentType(ContentType.MULTIPART) + .multiPart("aggregates", testFile) + .post("/verification/prod-pn") .then() .statusCode(200); verify(aggregatesService, times(1)) - .validateAggregatesCsv(any()); + .validateSendAggregatesCsv(any()); } } diff --git a/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/model/CsvAggregateAppIoTest.java b/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/model/CsvAggregateAppIoTest.java new file mode 100644 index 000000000..ff167dcea --- /dev/null +++ b/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/model/CsvAggregateAppIoTest.java @@ -0,0 +1,74 @@ +package it.pagopa.selfcare.onboarding.model; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +class CsvAggregateAppIoTest { + + @Test + void testCsvAggregateAppIoConstructorAndGetters() { + + String description = "Test Description"; + String pec = "test@example.com"; + String taxCode = "TAX12345"; + String vatNumber = "VAT12345678"; + String address = "Test Address"; + String city = "Test City"; + String province = "Test Province"; + String ipaCode = "IPA12345"; + String subunitType = "Department"; + String subunitCode = "DEP001"; + String originId = "ORI123"; + Integer rowNumber = 5; + + CsvAggregateAppIo csvAggregateAppIo = new CsvAggregateAppIo(); + csvAggregateAppIo.setDescription(description); + csvAggregateAppIo.setPec(pec); + csvAggregateAppIo.setTaxCode(taxCode); + csvAggregateAppIo.setVatNumber(vatNumber); + csvAggregateAppIo.setAddress(address); + csvAggregateAppIo.setCity(city); + csvAggregateAppIo.setProvince(province); + csvAggregateAppIo.setIpaCode(ipaCode); + csvAggregateAppIo.setSubunitType(subunitType); + csvAggregateAppIo.setSubunitCode(subunitCode); + csvAggregateAppIo.setOriginId(originId); + csvAggregateAppIo.setRowNumber(rowNumber); + + assertEquals(description, csvAggregateAppIo.getDescription()); + assertEquals(pec, csvAggregateAppIo.getPec()); + assertEquals(taxCode, csvAggregateAppIo.getTaxCode()); + assertEquals(vatNumber, csvAggregateAppIo.getVatNumber()); + assertEquals(address, csvAggregateAppIo.getAddress()); + assertEquals(city, csvAggregateAppIo.getCity()); + assertEquals(province, csvAggregateAppIo.getProvince()); + assertEquals(ipaCode, csvAggregateAppIo.getIpaCode()); + assertEquals(subunitType, csvAggregateAppIo.getSubunitType()); + assertEquals(subunitCode, csvAggregateAppIo.getSubunitCode()); + assertEquals(originId, csvAggregateAppIo.getOriginId()); + assertEquals(rowNumber, csvAggregateAppIo.getRowNumber()); + } + + @Test + void testSetRowNumber() { + CsvAggregateAppIo csvAggregateAppIo = new CsvAggregateAppIo(); + int expectedRowNumber = 10; + + csvAggregateAppIo.setRowNumber(expectedRowNumber); + + assertEquals(expectedRowNumber, csvAggregateAppIo.getRowNumber()); + } + + @Test + void testCsvBindByPositionAnnotations() { + CsvAggregateAppIo csvAggregateAppIo = new CsvAggregateAppIo(); + csvAggregateAppIo.setDescription("Sample Description"); + csvAggregateAppIo.setPec("sample@example.com"); + csvAggregateAppIo.setTaxCode("SAMPLETAXCODE"); + + assertNotNull(csvAggregateAppIo); + assertEquals("Sample Description", csvAggregateAppIo.getDescription()); + assertEquals("sample@example.com", csvAggregateAppIo.getPec()); + assertEquals("SAMPLETAXCODE", csvAggregateAppIo.getTaxCode()); + } +} diff --git a/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/model/CsvAggregatePagoPaTest.java b/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/model/CsvAggregatePagoPaTest.java new file mode 100644 index 000000000..ed99bae8b --- /dev/null +++ b/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/model/CsvAggregatePagoPaTest.java @@ -0,0 +1,78 @@ +package it.pagopa.selfcare.onboarding.model; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +class CsvAggregatePagoPaTest { + + @Test + void testCsvAggregatePagoPaConstructorAndGetters() { + String description = "PagoPa Description"; + String pec = "pagopa@example.com"; + String taxCode = "PAGOTAX12345"; + String vatNumber = "PAGOVAT12345678"; + String address = "PagoPa Address"; + String city = "PagoPa City"; + String province = "PagoPa Province"; + String aggragateNamePT = "PagoPa Name PT"; + String taxCodePT = "PTTAXCODE123"; + String iban = "IT60X0542811101000000123456"; + String service = "PagoPa Service"; + String syncAsyncMode = "SYNC"; + Integer rowNumber = 2; + + CsvAggregatePagoPa csvAggregatePagoPa = new CsvAggregatePagoPa(); + csvAggregatePagoPa.setDescription(description); + csvAggregatePagoPa.setPec(pec); + csvAggregatePagoPa.setTaxCode(taxCode); + csvAggregatePagoPa.setVatNumber(vatNumber); + csvAggregatePagoPa.setAddress(address); + csvAggregatePagoPa.setCity(city); + csvAggregatePagoPa.setProvince(province); + csvAggregatePagoPa.setAggragateNamePT(aggragateNamePT); + csvAggregatePagoPa.setTaxCodePT(taxCodePT); + csvAggregatePagoPa.setIban(iban); + csvAggregatePagoPa.setService(service); + csvAggregatePagoPa.setSyncAsyncMode(syncAsyncMode); + csvAggregatePagoPa.setRowNumber(rowNumber); + + assertEquals(description, csvAggregatePagoPa.getDescription()); + assertEquals(pec, csvAggregatePagoPa.getPec()); + assertEquals(taxCode, csvAggregatePagoPa.getTaxCode()); + assertEquals(vatNumber, csvAggregatePagoPa.getVatNumber()); + assertEquals(address, csvAggregatePagoPa.getAddress()); + assertEquals(city, csvAggregatePagoPa.getCity()); + assertEquals(province, csvAggregatePagoPa.getProvince()); + assertEquals(aggragateNamePT, csvAggregatePagoPa.getAggragateNamePT()); + assertEquals(taxCodePT, csvAggregatePagoPa.getTaxCodePT()); + assertEquals(iban, csvAggregatePagoPa.getIban()); + assertEquals(service, csvAggregatePagoPa.getService()); + assertEquals(syncAsyncMode, csvAggregatePagoPa.getSyncAsyncMode()); + assertEquals(rowNumber, csvAggregatePagoPa.getRowNumber()); + } + + @Test + void testSetRowNumber() { + CsvAggregatePagoPa csvAggregatePagoPa = new CsvAggregatePagoPa(); + int expectedRowNumber = 15; + + csvAggregatePagoPa.setRowNumber(expectedRowNumber); + + assertEquals(expectedRowNumber, csvAggregatePagoPa.getRowNumber()); + } + + @Test + void testCsvBindByPositionAnnotations() { + CsvAggregatePagoPa csvAggregatePagoPa = new CsvAggregatePagoPa(); + csvAggregatePagoPa.setDescription("Test Description"); + csvAggregatePagoPa.setPec("test@pagopa.it"); + csvAggregatePagoPa.setTaxCode("TESTTAXCODE"); + csvAggregatePagoPa.setIban("IT60X0542811101000000123456"); + + assertNotNull(csvAggregatePagoPa); + assertEquals("Test Description", csvAggregatePagoPa.getDescription()); + assertEquals("test@pagopa.it", csvAggregatePagoPa.getPec()); + assertEquals("TESTTAXCODE", csvAggregatePagoPa.getTaxCode()); + assertEquals("IT60X0542811101000000123456", csvAggregatePagoPa.getIban()); + } +} diff --git a/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/model/CsvAggregateSendTest.java b/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/model/CsvAggregateSendTest.java new file mode 100644 index 000000000..18ae8267d --- /dev/null +++ b/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/model/CsvAggregateSendTest.java @@ -0,0 +1,87 @@ +package it.pagopa.selfcare.onboarding.model; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +class CsvAggregateSendTest { + + @Test + void testCsvAggregateSendConstructorAndGetters() { + String description = "Test Description"; + String pec = "test@example.com"; + String taxCode = "TAX12345"; + String vatNumber = "VAT12345678"; + String codeSDI = "SDI123456"; + String address = "Test Address"; + String city = "Test City"; + String province = "Test Province"; + String ipaCode = "IPA12345"; + String subunitType = "Department"; + String subunitCode = "DEP001"; + String adminAggregateName = "Admin Name"; + String adminAggregateSurname = "Admin Surname"; + String adminAggregateTaxCode = "ADMIN12345"; + String adminAggregateEmail = "admin@example.com"; + Integer rowNumber = 5; + + CsvAggregateSend csvAggregateSend = new CsvAggregateSend(); + csvAggregateSend.setDescription(description); + csvAggregateSend.setPec(pec); + csvAggregateSend.setTaxCode(taxCode); + csvAggregateSend.setVatNumber(vatNumber); + csvAggregateSend.setCodeSDI(codeSDI); + csvAggregateSend.setAddress(address); + csvAggregateSend.setCity(city); + csvAggregateSend.setProvince(province); + csvAggregateSend.setIpaCode(ipaCode); + csvAggregateSend.setSubunitType(subunitType); + csvAggregateSend.setSubunitCode(subunitCode); + csvAggregateSend.setAdminAggregateName(adminAggregateName); + csvAggregateSend.setAdminAggregateSurname(adminAggregateSurname); + csvAggregateSend.setAdminAggregateTaxCode(adminAggregateTaxCode); + csvAggregateSend.setAdminAggregateEmail(adminAggregateEmail); + csvAggregateSend.setRowNumber(rowNumber); + + assertEquals(description, csvAggregateSend.getDescription()); + assertEquals(pec, csvAggregateSend.getPec()); + assertEquals(taxCode, csvAggregateSend.getTaxCode()); + assertEquals(vatNumber, csvAggregateSend.getVatNumber()); + assertEquals(codeSDI, csvAggregateSend.getCodeSDI()); + assertEquals(address, csvAggregateSend.getAddress()); + assertEquals(city, csvAggregateSend.getCity()); + assertEquals(province, csvAggregateSend.getProvince()); + assertEquals(ipaCode, csvAggregateSend.getIpaCode()); + assertEquals(subunitType, csvAggregateSend.getSubunitType()); + assertEquals(subunitCode, csvAggregateSend.getSubunitCode()); + assertEquals(adminAggregateName, csvAggregateSend.getAdminAggregateName()); + assertEquals(adminAggregateSurname, csvAggregateSend.getAdminAggregateSurname()); + assertEquals(adminAggregateTaxCode, csvAggregateSend.getAdminAggregateTaxCode()); + assertEquals(adminAggregateEmail, csvAggregateSend.getAdminAggregateEmail()); + assertEquals(rowNumber, csvAggregateSend.getRowNumber()); + } + + @Test + void testSetRowNumber() { + CsvAggregateSend csvAggregateSend = new CsvAggregateSend(); + int expectedRowNumber = 10; + + csvAggregateSend.setRowNumber(expectedRowNumber); + + assertEquals(expectedRowNumber, csvAggregateSend.getRowNumber()); + } + + @Test + void testCsvBindByPositionAnnotations() { + CsvAggregateSend csvAggregateSend = new CsvAggregateSend(); + csvAggregateSend.setDescription("Sample Description"); + csvAggregateSend.setPec("sample@example.com"); + csvAggregateSend.setTaxCode("SAMPLETAXCODE"); + csvAggregateSend.setAdminAggregateEmail("admin@example.com"); + + assertNotNull(csvAggregateSend); + assertEquals("Sample Description", csvAggregateSend.getDescription()); + assertEquals("sample@example.com", csvAggregateSend.getPec()); + assertEquals("SAMPLETAXCODE", csvAggregateSend.getTaxCode()); + assertEquals("admin@example.com", csvAggregateSend.getAdminAggregateEmail()); + } +} diff --git a/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/model/VerifyAggregateSendResponseTest.java b/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/model/VerifyAggregateSendResponseTest.java new file mode 100644 index 000000000..a02c8fbca --- /dev/null +++ b/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/model/VerifyAggregateSendResponseTest.java @@ -0,0 +1,68 @@ +package it.pagopa.selfcare.onboarding.model; + +import org.junit.jupiter.api.Test; +import java.util.List; +import java.util.ArrayList; + +import static org.junit.jupiter.api.Assertions.*; + +class VerifyAggregateSendResponseTest { + + @Test + void testVerifyAggregateSendResponseConstructorAndGetters() { + + List aggregates = new ArrayList<>(); + List errors = new ArrayList<>(); + + AggregateSend aggregateSend = new AggregateSend(); + aggregateSend.setDescription("Description"); + aggregateSend.setPec("example@pec.it"); + aggregateSend.setTaxCode("XYZ12345"); + aggregateSend.setVatNumber("IT123456789"); + aggregateSend.setCodeSDI("AB123CD"); + aggregateSend.setAddress("Street 123"); + aggregateSend.setCity("Rome"); + aggregateSend.setProvince("RM"); + aggregateSend.setSubunitType("Subunit Type"); + aggregateSend.setSubunitCode("Subunit Code"); + + AggregateUser user = new AggregateUser(); + user.setName("John"); + user.setSurname("Doe"); + user.setTaxCode("JD12345"); + user.setEmail("john.doe@example.com"); + user.setRole("Admin"); + + aggregateSend.setUsers(List.of(user)); + aggregates.add(aggregateSend); + + VerifyAggregateSendResponse response = new VerifyAggregateSendResponse(aggregates, errors); + + assertNotNull(response.getAggregates()); + assertEquals(1, response.getAggregates().size()); + assertEquals("Description", response.getAggregates().get(0).getDescription()); + assertEquals("example@pec.it", response.getAggregates().get(0).getPec()); + assertEquals("XYZ12345", response.getAggregates().get(0).getTaxCode()); + assertEquals("IT123456789", response.getAggregates().get(0).getVatNumber()); + assertEquals("AB123CD", response.getAggregates().get(0).getCodeSDI()); + assertEquals("Street 123", response.getAggregates().get(0).getAddress()); + assertEquals("Rome", response.getAggregates().get(0).getCity()); + assertEquals("RM", response.getAggregates().get(0).getProvince()); + assertEquals("Subunit Type", response.getAggregates().get(0).getSubunitType()); + assertEquals("Subunit Code", response.getAggregates().get(0).getSubunitCode()); + assertEquals(1, response.getAggregates().get(0).getUsers().size()); + assertEquals("John", response.getAggregates().get(0).getUsers().get(0).getName()); + assertEquals("Doe", response.getAggregates().get(0).getUsers().get(0).getSurname()); + assertEquals("JD12345", response.getAggregates().get(0).getUsers().get(0).getTaxCode()); + assertEquals("john.doe@example.com", response.getAggregates().get(0).getUsers().get(0).getEmail()); + assertEquals("Admin", response.getAggregates().get(0).getUsers().get(0).getRole()); + } + + @Test + void testNoArgsConstructor() { + VerifyAggregateSendResponse response = new VerifyAggregateSendResponse(); + + assertNull(response.getAggregates()); + assertNull(response.getErrors()); + } +} diff --git a/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/service/AggregatesServiceDefaultTest.java b/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/service/AggregatesServiceDefaultTest.java index a1ea4ab30..f03001f71 100644 --- a/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/service/AggregatesServiceDefaultTest.java +++ b/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/service/AggregatesServiceDefaultTest.java @@ -1,6 +1,5 @@ package it.pagopa.selfcare.onboarding.service; -import com.fasterxml.jackson.databind.ObjectMapper; import io.quarkus.test.InjectMock; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.vertx.RunOnVertxContext; @@ -8,7 +7,7 @@ import io.smallrye.mutiny.helpers.test.UniAssertSubscriber; import it.pagopa.selfcare.onboarding.exception.ResourceNotFoundException; import it.pagopa.selfcare.onboarding.mapper.OnboardingMapper; -import it.pagopa.selfcare.onboarding.model.VerifyAggregateResponse; +import it.pagopa.selfcare.onboarding.model.*; import jakarta.inject.Inject; import org.eclipse.microprofile.rest.client.inject.RestClient; import org.junit.jupiter.api.Test; @@ -20,10 +19,14 @@ import org.openapi.quarkus.party_registry_proxy_json.model.UOResource; import java.io.File; -import java.io.IOException; -import java.nio.file.Files; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.Mockito.*; + +import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.when; @QuarkusTest public class AggregatesServiceDefaultTest { @@ -59,9 +62,161 @@ void validateAggregates(){ when(institutionApi.findInstitutionUsingGET("345645", null, null)).thenThrow(ResourceNotFoundException.class); when(uoApi.findByUnicodeUsingGET1("AQ66",null)).thenThrow(ResourceNotFoundException.class); - aggregatesServiceDefault.validateAggregatesCsv(testFile) + aggregatesServiceDefault.validateAppIoAggregatesCsv(testFile) .subscribe().withSubscriber(UniAssertSubscriber.create()) .assertCompleted(); } + @Test + @RunOnVertxContext + void validatePagoPaAggregates(){ + File testFile = new File("src/test/resources/aggregates-pagopa.csv"); + + when(aooApi.findByUnicodeUsingGET("1437190414", null)).thenReturn(Uni.createFrom().item(new AOOResource())); + when(institutionApi.findInstitutionUsingGET("00297110389", null, null)).thenReturn(Uni.createFrom().item(new InstitutionResource())); + when(uoApi.findByUnicodeUsingGET1("4551120274", null)).thenReturn(Uni.createFrom().item(new UOResource())); + + when(aooApi.findByUnicodeUsingGET("AQ66",null)).thenThrow(ResourceNotFoundException.class); + when(institutionApi.findInstitutionUsingGET("345645", null, null)).thenThrow(ResourceNotFoundException.class); + when(uoApi.findByUnicodeUsingGET1("AQ66",null)).thenThrow(ResourceNotFoundException.class); + + aggregatesServiceDefault.validatePagoPaAggregatesCsv(testFile) + .subscribe().withSubscriber(UniAssertSubscriber.create()) + .assertCompleted(); + } + + @Test + @RunOnVertxContext + void validateSendAggregates(){ + File testFile = new File("src/test/resources/aggregates-send.csv"); + + when(aooApi.findByUnicodeUsingGET("1437190414", null)).thenReturn(Uni.createFrom().item(new AOOResource())); + when(institutionApi.findInstitutionUsingGET("00297110389", null, null)).thenReturn(Uni.createFrom().item(new InstitutionResource())); + when(uoApi.findByUnicodeUsingGET1("4551120274", null)).thenReturn(Uni.createFrom().item(new UOResource())); + + when(aooApi.findByUnicodeUsingGET("AQ66",null)).thenThrow(ResourceNotFoundException.class); + when(institutionApi.findInstitutionUsingGET("345645", null, null)).thenThrow(ResourceNotFoundException.class); + when(uoApi.findByUnicodeUsingGET1("AQ66",null)).thenThrow(ResourceNotFoundException.class); + + aggregatesServiceDefault.validateSendAggregatesCsv(testFile) + .subscribe().withSubscriber(UniAssertSubscriber.create()) + .assertCompleted(); + } + + + @Test + void testValidateAppIoAggregatesCsv() { + + File file = new File("src/test/resources/aggregates-appio.csv"); + + CsvAggregateAppIo csvAggregate = new CsvAggregateAppIo(); + csvAggregate.setSubunitType("AOO"); + csvAggregate.setSubunitCode("AOO_CODE"); + + List csvAggregateList = new ArrayList<>(); + csvAggregateList.add(csvAggregate); + + AggregatesCsvResponse aggregatesCsvResponse = aggregatesServiceDefault.readItemsFromCsv(file, CsvAggregateAppIo.class); + when(aooApi.findByUnicodeUsingGET("1437190414", null)).thenReturn(Uni.createFrom().item(new AOOResource())); + when(institutionApi.findInstitutionUsingGET("00297110389", null, null)).thenReturn(Uni.createFrom().item(new InstitutionResource())); + + Uni result = aggregatesServiceDefault.validateAppIoAggregatesCsv(file); + + VerifyAggregateResponse verifyAggregateResponse = result.await().indefinitely(); + assertNotNull(verifyAggregateResponse.getAggregates()); + assertNotNull(aggregatesCsvResponse.getValidAggregates()); + + assertTrue(!aggregatesCsvResponse.getCsvAggregateList().isEmpty()); + assertTrue(aggregatesCsvResponse.getRowErrorList().isEmpty()); + + assertNotNull(((CsvAggregateAppIo) aggregatesCsvResponse.getCsvAggregateList().get(0)).getAddress()); + assertNotNull(((CsvAggregateAppIo) aggregatesCsvResponse.getCsvAggregateList().get(0)).getCity()); + assertNotNull(((CsvAggregateAppIo) aggregatesCsvResponse.getCsvAggregateList().get(0)).getPec()); + assertNotNull(((CsvAggregateAppIo) aggregatesCsvResponse.getCsvAggregateList().get(0)).getDescription()); + assertNotNull(((CsvAggregateAppIo) aggregatesCsvResponse.getCsvAggregateList().get(0)).getRowNumber()); + assertNotNull(((CsvAggregateAppIo) aggregatesCsvResponse.getCsvAggregateList().get(0)).getSubunitCode()); + assertNotNull(((CsvAggregateAppIo) aggregatesCsvResponse.getCsvAggregateList().get(0)).getTaxCode()); + assertNotNull(((CsvAggregateAppIo) aggregatesCsvResponse.getCsvAggregateList().get(0)).getProvince()); + assertNotNull(((CsvAggregateAppIo) aggregatesCsvResponse.getCsvAggregateList().get(0)).getSubunitType()); + assertNotNull(((CsvAggregateAppIo) aggregatesCsvResponse.getCsvAggregateList().get(0)).getVatNumber()); + + verify(aooApi,times(0)).findByUnicodeUsingGET("1437190414", null); + verify(institutionApi,times(0)).findInstitutionUsingGET("00297110389", null, null); + + } + + @Test + void testValidateSendAggregatesCsv() { + + File file = new File("src/test/resources/aggregates-send.csv"); + + CsvAggregateSend csvAggregate = new CsvAggregateSend(); + csvAggregate.setSubunitType("AOO"); + csvAggregate.setSubunitCode("AOO_CODE"); + + List csvAggregateList = new ArrayList<>(); + csvAggregateList.add(csvAggregate); + + AggregatesCsvResponse aggregatesCsvResponse = aggregatesServiceDefault.readItemsFromCsv(file, CsvAggregateSend.class); + when(aooApi.findByUnicodeUsingGET("1437190414", null)).thenReturn(Uni.createFrom().item(new AOOResource())); + when(institutionApi.findInstitutionUsingGET("00297110389", null, null)).thenReturn(Uni.createFrom().item(new InstitutionResource())); + when(uoApi.findByUnicodeUsingGET1("4551120274", null)).thenReturn(Uni.createFrom().item(new UOResource())); + + Uni result = aggregatesServiceDefault.validateAppIoAggregatesCsv(file); + + VerifyAggregateResponse verifyAggregateResponse = result.await().indefinitely(); + assertNotNull(verifyAggregateResponse); + assertNotNull(aggregatesCsvResponse.getValidAggregates()); + + assertTrue(!aggregatesCsvResponse.getCsvAggregateList().isEmpty()); + assertTrue(aggregatesCsvResponse.getRowErrorList().isEmpty()); + + assertNotNull(((CsvAggregateSend) aggregatesCsvResponse.getCsvAggregateList().get(0)).getAddress()); + assertNotNull(((CsvAggregateSend) aggregatesCsvResponse.getCsvAggregateList().get(0)).getCity()); + assertNotNull(((CsvAggregateSend) aggregatesCsvResponse.getCsvAggregateList().get(0)).getPec()); + assertNotNull(((CsvAggregateSend) aggregatesCsvResponse.getCsvAggregateList().get(0)).getDescription()); + assertNotNull(((CsvAggregateSend) aggregatesCsvResponse.getCsvAggregateList().get(0)).getRowNumber()); + assertNotNull(((CsvAggregateSend) aggregatesCsvResponse.getCsvAggregateList().get(0)).getSubunitCode()); + assertNotNull(((CsvAggregateSend) aggregatesCsvResponse.getCsvAggregateList().get(0)).getTaxCode()); + assertNotNull(((CsvAggregateSend) aggregatesCsvResponse.getCsvAggregateList().get(0)).getProvince()); + assertNotNull(((CsvAggregateSend) aggregatesCsvResponse.getCsvAggregateList().get(0)).getSubunitType()); + assertNotNull(((CsvAggregateSend) aggregatesCsvResponse.getCsvAggregateList().get(0)).getVatNumber()); + + verify(aooApi,times(0)).findByUnicodeUsingGET("1437190414", null); + verify(institutionApi,times(0)).findInstitutionUsingGET("00297110389", null, null); + verify(uoApi,times(0)).findByUnicodeUsingGET1("4551120274", null); + + } + + @Test + void testValidatePagoPaAggregatesCsv() { + + File file = new File("src/test/resources/aggregates-pagopa.csv"); + + CsvAggregatePagoPa csvAggregate = new CsvAggregatePagoPa(); + + List csvAggregateList = new ArrayList<>(); + csvAggregateList.add(csvAggregate); + + AggregatesCsvResponse aggregatesCsvResponse = aggregatesServiceDefault.readItemsFromCsv(file, CsvAggregatePagoPa.class); + Uni result = aggregatesServiceDefault.validateAppIoAggregatesCsv(file); + + VerifyAggregateResponse verifyAggregateResponse = result.await().indefinitely(); + assertNotNull(verifyAggregateResponse); + assertNotNull(aggregatesCsvResponse.getValidAggregates()); + + assertTrue(!aggregatesCsvResponse.getCsvAggregateList().isEmpty()); + assertTrue(aggregatesCsvResponse.getRowErrorList().isEmpty()); + + assertNotNull(((CsvAggregatePagoPa) aggregatesCsvResponse.getCsvAggregateList().get(0)).getAddress()); + assertNotNull(((CsvAggregatePagoPa) aggregatesCsvResponse.getCsvAggregateList().get(0)).getCity()); + assertNotNull(((CsvAggregatePagoPa) aggregatesCsvResponse.getCsvAggregateList().get(0)).getPec()); + assertNotNull(((CsvAggregatePagoPa) aggregatesCsvResponse.getCsvAggregateList().get(0)).getDescription()); + assertNotNull(((CsvAggregatePagoPa) aggregatesCsvResponse.getCsvAggregateList().get(0)).getRowNumber()); + assertNotNull(((CsvAggregatePagoPa) aggregatesCsvResponse.getCsvAggregateList().get(0)).getTaxCode()); + assertNotNull(((CsvAggregatePagoPa) aggregatesCsvResponse.getCsvAggregateList().get(0)).getProvince()); + assertNotNull(((CsvAggregatePagoPa) aggregatesCsvResponse.getCsvAggregateList().get(0)).getVatNumber()); + + } + } diff --git a/apps/onboarding-ms/src/test/resources/aggregates-appio.csv b/apps/onboarding-ms/src/test/resources/aggregates-appio.csv new file mode 100644 index 000000000..29d2f039f --- /dev/null +++ b/apps/onboarding-ms/src/test/resources/aggregates-appio.csv @@ -0,0 +1,4 @@ +Ragione Sociale*;PEC*;Codice Fiscale*;P.IVA*;Sede legale - Indirizzo*;Sede legale - Città*;Sede legale - Provincia (sigla)*;Codice IPA***;AOO/UO**;Codice Univoco** +Ufficio del Sindaco;uff.sindaco@pec.comune.fi.it;1307110484;1307110484;Palazzo Vecchio Piazza Della Signoria;Firenze;FI;;UO;18SU3R +(**) campo obbligatorio in caso di AOO/UO;;;;;;;;; +(***) campo obbligatorio in caso di Ente Centrale;;;;;;;;; diff --git a/apps/onboarding-ms/src/test/resources/aggregates-pagopa.csv b/apps/onboarding-ms/src/test/resources/aggregates-pagopa.csv new file mode 100644 index 000000000..96347c38d --- /dev/null +++ b/apps/onboarding-ms/src/test/resources/aggregates-pagopa.csv @@ -0,0 +1,2 @@ +Ragione Sociale*;PEC*;Codice Fiscale*;P.IVA*;Sede legale - Indirizzo*;Sede legale - Città*;Sede legale - Provincia (sigla)*;Ragine Sociale Partner Tecnologico*;Codice Fiscale Partner Tecnologico*;IBAN*;Servizio*;Modalità Sincrona/Asincrona* +Acme srl.;acme@pec.aruba.it;12345678901;12345678901;Via Roma, 12;Bologna;BO;MyPartnerTech;98765432101;IT60 X054 2811 1010 0000 0123 456;XXXXXXX;Sincrona diff --git a/apps/onboarding-ms/src/test/resources/aggregates-send.csv b/apps/onboarding-ms/src/test/resources/aggregates-send.csv new file mode 100644 index 000000000..c8baf22de --- /dev/null +++ b/apps/onboarding-ms/src/test/resources/aggregates-send.csv @@ -0,0 +1,4 @@ +Ragione Sociale*;PEC*;Codice Fiscale*;P.IVA*;Codice SDI*;Sede legale - Indirizzo*;Sede legale - Città*;Sede legale - Provincia (sigla)*;Codice IPA***;AOO/UO**;Codice Univoco**;Nome Amministratore Ente Aggregato*;Cognome Amministratore Ente Aggregato*;Codice Fiscale Amministratore Ente Aggregato*;email Amministratore Ente Aggregato* +Ufficio centrale di fatturazione;protocollo.rivalta@cert.legalmail.it;1864440019;1864440019;NYJTPK;Via Balma , 5;Rivalta di Torino;TO;;UO;NYJTPK;Mario;Rossi;RSSMRA66A01H501W;mario.rossi@acme.it +(**) campo obbligatorio in caso di AOO/UO;;;;;;;;;;;;;; +(***) campo obbligatorio in caso di Ente Centrale;;;;;;;;;;;;;;