From d7cb2b47fe8402e2672d704f3cedae2561523cc9 Mon Sep 17 00:00:00 2001 From: flaminiaScarciofolo <113031535+flaminiaScarciofolo@users.noreply.github.com> Date: Fri, 21 Jun 2024 16:26:56 +0200 Subject: [PATCH] [SELC-5076] Feat: Added call to /onboarding/pa/aggregation in onboardingProduct API (#318) --- app/src/main/resources/swagger/api-docs.json | 14 +- .../connector/api/OnboardingMsConnector.java | 2 + .../model/onboarding/OnboardingData.java | 3 + .../openapi/api-selfcare-onboarding-docs.json | 363 +++++++++++++++--- .../connector/OnboardingMsConnectorImpl.java | 6 + .../rest/mapper/OnboardingMapper.java | 3 + .../OnboardingMsConnectorImplTest.java | 37 ++ .../onboarding/core/InstitutionService.java | 2 + .../core/InstitutionServiceImpl.java | 15 + .../core/InstitutionServiceImplTest.java | 48 +++ .../controller/InstitutionV2Controller.java | 6 +- .../web/model/AggregateInstitution.java | 3 +- .../mapper/OnboardingResourceMapper.java | 3 + .../InstitutionV2ControllerTest.java | 2 +- .../onboardingProductsDtoWithAggregates.json | 2 +- 15 files changed, 432 insertions(+), 77 deletions(-) diff --git a/app/src/main/resources/swagger/api-docs.json b/app/src/main/resources/swagger/api-docs.json index aa1ef8ba..396ba6e9 100644 --- a/app/src/main/resources/swagger/api-docs.json +++ b/app/src/main/resources/swagger/api-docs.json @@ -2290,7 +2290,7 @@ "geographicTaxonomies" : { "type" : "array", "items" : { - "$ref" : "#/components/schemas/GeographicTaxonomy" + "$ref" : "#/components/schemas/GeographicTaxonomyDto" } }, "origin" : { @@ -2616,18 +2616,6 @@ } } }, - "GeographicTaxonomy" : { - "title" : "GeographicTaxonomy", - "type" : "object", - "properties" : { - "code" : { - "type" : "string" - }, - "desc" : { - "type" : "string" - } - } - }, "GeographicTaxonomyDto" : { "title" : "GeographicTaxonomyDto", "required" : [ "code", "desc" ], diff --git a/connector-api/src/main/java/it/pagopa/selfcare/onboarding/connector/api/OnboardingMsConnector.java b/connector-api/src/main/java/it/pagopa/selfcare/onboarding/connector/api/OnboardingMsConnector.java index c575b019..2706988e 100644 --- a/connector-api/src/main/java/it/pagopa/selfcare/onboarding/connector/api/OnboardingMsConnector.java +++ b/connector-api/src/main/java/it/pagopa/selfcare/onboarding/connector/api/OnboardingMsConnector.java @@ -27,4 +27,6 @@ public interface OnboardingMsConnector { OnboardingData getOnboardingWithUserInfo(String onboardingId); Resource getContract(String onboardingId); + + void onboardingPaAggregation(OnboardingData onboardingData); } diff --git a/connector-api/src/main/java/it/pagopa/selfcare/onboarding/connector/model/onboarding/OnboardingData.java b/connector-api/src/main/java/it/pagopa/selfcare/onboarding/connector/model/onboarding/OnboardingData.java index 579178b9..bd178e73 100644 --- a/connector-api/src/main/java/it/pagopa/selfcare/onboarding/connector/model/onboarding/OnboardingData.java +++ b/connector-api/src/main/java/it/pagopa/selfcare/onboarding/connector/model/onboarding/OnboardingData.java @@ -13,6 +13,7 @@ package it.pagopa.selfcare.onboarding.connector.model.onboarding; import it.pagopa.selfcare.onboarding.common.InstitutionType; +import it.pagopa.selfcare.onboarding.connector.model.institutions.Institution; import lombok.Data; import lombok.NoArgsConstructor; @@ -48,6 +49,8 @@ public class OnboardingData { private LocalDateTime updatedAt; private LocalDateTime expiringDate; private String reasonForReject; + private Boolean isAggregator; + private List aggregates; public List getUsers() { return Optional.ofNullable(users).orElse(Collections.emptyList()); } diff --git a/connector/rest/docs/openapi/api-selfcare-onboarding-docs.json b/connector/rest/docs/openapi/api-selfcare-onboarding-docs.json index 836215a7..71f7f7a4 100644 --- a/connector/rest/docs/openapi/api-selfcare-onboarding-docs.json +++ b/connector/rest/docs/openapi/api-selfcare-onboarding-docs.json @@ -12,11 +12,51 @@ "description" : "Auto generated value" } ], "tags" : [ { + "name" : "Notification Controller" + }, { "name" : "Onboarding" + }, { + "name" : "Onboarding Controller" }, { "name" : "support" } ], "paths" : { + "/v1/notification/resend" : { + "post" : { + "tags" : [ "Notification Controller" ], + "summary" : "Resend onboarding notifications for onboarding which are retrieved given a set of filters", + "requestBody" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/OnboardingGetFilters" + } + } + } + }, + "responses" : { + "200" : { + "description" : "OK", + "content" : { + "application/json" : { + "schema" : { + "type" : "string" + } + } + } + }, + "401" : { + "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" + } + }, + "security" : [ { + "SecurityScheme" : [ ] + } ] + } + }, "/v1/onboarding" : { "get" : { "tags" : [ "Onboarding Controller" ], @@ -27,6 +67,18 @@ "schema" : { "type" : "string" } + }, { + "name" : "institutionId", + "in" : "query", + "schema" : { + "type" : "string" + } + }, { + "name" : "onboardingId", + "in" : "query", + "schema" : { + "type" : "string" + } }, { "name" : "page", "in" : "query", @@ -79,11 +131,11 @@ } } }, - "403" : { - "description" : "Not Allowed" - }, "401" : { "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" } }, "security" : [ { @@ -113,11 +165,11 @@ } } }, - "403" : { - "description" : "Not Allowed" - }, "401" : { "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" } }, "security" : [ { @@ -149,11 +201,11 @@ } } }, - "403" : { - "description" : "Not Allowed" - }, "401" : { "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" } }, "security" : [ { @@ -163,7 +215,7 @@ }, "/v1/onboarding/institutionOnboardings" : { "get" : { - "tags" : [ "Onboarding Controller" ], + "tags" : [ "support", "Onboarding" ], "summary" : "Returns onboardings record by institution taxCode/subunitCode/origin/originId", "parameters" : [ { "name" : "origin", @@ -210,11 +262,11 @@ } } }, - "403" : { - "description" : "Not Allowed" - }, "401" : { "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" } }, "security" : [ { @@ -246,11 +298,47 @@ } } }, + "401" : { + "description" : "Not Authorized" + }, "403" : { "description" : "Not Allowed" + } + }, + "security" : [ { + "SecurityScheme" : [ ] + } ] + } + }, + "/v1/onboarding/pa/aggregation" : { + "post" : { + "tags" : [ "Onboarding Controller" ], + "summary" : "Perform onboarding aggregation request for PA institution type, it require billing.recipientCode in additition to default requestUsers data will be saved on personal data vault if it doesn't already exist.At the end, function triggers async activities related to onboarding aggregation that consist of create contract and sending mail to institution's digital address.", + "requestBody" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/OnboardingPaRequest" + } + } + } + }, + "responses" : { + "200" : { + "description" : "OK", + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/OnboardingResponse" + } + } + } }, "401" : { "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" } }, "security" : [ { @@ -282,11 +370,11 @@ } } }, - "403" : { - "description" : "Not Allowed" - }, "401" : { "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" } }, "security" : [ { @@ -318,11 +406,11 @@ } } }, - "403" : { - "description" : "Not Allowed" - }, "401" : { "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" } }, "security" : [ { @@ -353,11 +441,11 @@ } } }, - "403" : { - "description" : "Not Allowed" - }, "401" : { "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" } }, "security" : [ { @@ -389,11 +477,11 @@ } } }, - "403" : { - "description" : "Not Allowed" - }, "401" : { "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" } }, "security" : [ { @@ -425,11 +513,11 @@ } } }, - "403" : { - "description" : "Not Allowed" - }, "401" : { "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" } }, "security" : [ { @@ -461,11 +549,11 @@ } } }, - "403" : { - "description" : "Not Allowed" - }, "401" : { "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" } }, "security" : [ { @@ -496,11 +584,11 @@ } } }, - "403" : { - "description" : "Not Allowed" - }, "401" : { "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" } }, "security" : [ { @@ -527,11 +615,11 @@ "application/json" : { } } }, - "403" : { - "description" : "Not Allowed" - }, "401" : { "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" } }, "security" : [ { @@ -574,11 +662,11 @@ "application/json" : { } } }, - "403" : { - "description" : "Not Allowed" - }, "401" : { "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" } }, "security" : [ { @@ -621,11 +709,11 @@ "application/json" : { } } }, - "403" : { - "description" : "Not Allowed" - }, "401" : { "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" } }, "security" : [ { @@ -635,7 +723,7 @@ }, "/v1/onboarding/{onboardingId}/consume" : { "put" : { - "tags" : [ "Onboarding Controller" ], + "tags" : [ "support", "Onboarding" ], "summary" : "Perform complete operation of an onboarding request as /complete but without signature verification of the contract", "parameters" : [ { "name" : "onboardingId", @@ -668,11 +756,11 @@ "application/json" : { } } }, - "403" : { - "description" : "Not Allowed" - }, "401" : { "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" } }, "security" : [ { @@ -703,11 +791,11 @@ } } }, - "403" : { - "description" : "Not Allowed" - }, "401" : { "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" } }, "security" : [ { @@ -743,11 +831,57 @@ "application/json" : { } } }, + "401" : { + "description" : "Not Authorized" + }, "403" : { "description" : "Not Allowed" + } + }, + "security" : [ { + "SecurityScheme" : [ ] + } ] + } + }, + "/v1/onboarding/{onboardingId}/update" : { + "put" : { + "tags" : [ "Onboarding Controller" ], + "summary" : "Update onboarding request receiving onboarding id.Function can change some values. ", + "parameters" : [ { + "name" : "onboardingId", + "in" : "path", + "required" : true, + "schema" : { + "type" : "string" + } + }, { + "name" : "status", + "in" : "query", + "schema" : { + "$ref" : "#/components/schemas/OnboardingStatus" + } + } ], + "requestBody" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/OnboardingDefaultRequest" + } + } + } + }, + "responses" : { + "200" : { + "description" : "OK", + "content" : { + "application/json" : { } + } }, "401" : { "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" } }, "security" : [ { @@ -778,11 +912,11 @@ } } }, - "403" : { - "description" : "Not Allowed" - }, "401" : { "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" } }, "security" : [ { @@ -815,11 +949,11 @@ } } }, - "403" : { - "description" : "Not Allowed" - }, "401" : { "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" } }, "security" : [ { @@ -851,11 +985,11 @@ } } }, - "403" : { - "description" : "Not Allowed" - }, "401" : { "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" } }, "security" : [ { @@ -898,6 +1032,42 @@ } } }, + "AggregateInstitutionRequest" : { + "required" : [ "taxCode", "description" ], + "type" : "object", + "properties" : { + "taxCode" : { + "type" : "string" + }, + "description" : { + "type" : "string" + }, + "subunitCode" : { + "type" : "string" + }, + "subunitType" : { + "type" : "string" + }, + "geographicTaxonomies" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/GeographicTaxonomy" + } + }, + "address" : { + "type" : "string" + }, + "zipCode" : { + "type" : "string" + }, + "originId" : { + "type" : "string" + }, + "origin" : { + "$ref" : "#/components/schemas/Origin" + } + } + }, "BillingPaRequest" : { "type" : "object", "properties" : { @@ -957,6 +1127,17 @@ } } }, + "GeographicTaxonomy" : { + "type" : "object", + "properties" : { + "code" : { + "type" : "string" + }, + "desc" : { + "type" : "string" + } + } + }, "GeographicTaxonomyDto" : { "type" : "object", "properties" : { @@ -1283,6 +1464,15 @@ "$ref" : "#/components/schemas/UserRequest" } }, + "aggregates" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/AggregateInstitutionRequest" + } + }, + "isAggregator" : { + "type" : "boolean" + }, "pricingPlan" : { "type" : "string" }, @@ -1353,6 +1543,40 @@ } } }, + "OnboardingGetFilters" : { + "type" : "object", + "properties" : { + "productId" : { + "type" : "string" + }, + "institutionId" : { + "type" : "string" + }, + "onboardingId" : { + "type" : "string" + }, + "taxCode" : { + "type" : "string" + }, + "status" : { + "type" : "string" + }, + "from" : { + "type" : "string" + }, + "to" : { + "type" : "string" + }, + "page" : { + "format" : "int32", + "type" : "integer" + }, + "size" : { + "format" : "int32", + "type" : "integer" + } + } + }, "OnboardingGetResponse" : { "type" : "object", "properties" : { @@ -1426,6 +1650,15 @@ "$ref" : "#/components/schemas/UserRequest" } }, + "aggregates" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/AggregateInstitutionRequest" + } + }, + "isAggregator" : { + "type" : "boolean" + }, "pricingPlan" : { "type" : "string" }, @@ -1487,6 +1720,15 @@ "$ref" : "#/components/schemas/UserRequest" } }, + "aggregates" : { + "type" : "array", + "items" : { + "$ref" : "#/components/schemas/AggregateInstitutionRequest" + } + }, + "isAggregator" : { + "type" : "boolean" + }, "pricingPlan" : { "type" : "string" }, @@ -1536,6 +1778,9 @@ }, "userRequestUid" : { "type" : "string" + }, + "isAggregator" : { + "type" : "boolean" } } }, diff --git a/connector/rest/src/main/java/it/pagopa/selfcare/onboarding/connector/OnboardingMsConnectorImpl.java b/connector/rest/src/main/java/it/pagopa/selfcare/onboarding/connector/OnboardingMsConnectorImpl.java index 8b9d4462..5a3c1b5d 100644 --- a/connector/rest/src/main/java/it/pagopa/selfcare/onboarding/connector/OnboardingMsConnectorImpl.java +++ b/connector/rest/src/main/java/it/pagopa/selfcare/onboarding/connector/OnboardingMsConnectorImpl.java @@ -109,4 +109,10 @@ public OnboardingData getOnboardingWithUserInfo(String onboardingId) { public Resource getContract(String onboardingId) { return msOnboardingTokenApiClient._v1TokensOnboardingIdContractGet(onboardingId).getBody(); } + + @Override + @Retry(name = "retryTimeout") + public void onboardingPaAggregation(OnboardingData onboardingData) { + msOnboardingApiClient._v1OnboardingPaAggregationPost(onboardingMapper.toOnboardingPaAggregationRequest(onboardingData)); + } } diff --git a/connector/rest/src/main/java/it/pagopa/selfcare/onboarding/connector/rest/mapper/OnboardingMapper.java b/connector/rest/src/main/java/it/pagopa/selfcare/onboarding/connector/rest/mapper/OnboardingMapper.java index 0e15deaa..69f5344c 100644 --- a/connector/rest/src/main/java/it/pagopa/selfcare/onboarding/connector/rest/mapper/OnboardingMapper.java +++ b/connector/rest/src/main/java/it/pagopa/selfcare/onboarding/connector/rest/mapper/OnboardingMapper.java @@ -117,4 +117,7 @@ default InstitutionPspRequest toInstitutionPsp(OnboardingData onboardingData) { OnboardingData toOnboardingData(OnboardingGet onboardingGet); OnboardingUserRequest toOnboardingUsersRequest(OnboardingData onboardingData); + + @Mapping(target = "institution", source = ".", qualifiedByName = "toInstitutionBase") + OnboardingPaRequest toOnboardingPaAggregationRequest(OnboardingData onboardingData); } diff --git a/connector/rest/src/test/java/it/pagopa/selfcare/onboarding/connector/OnboardingMsConnectorImplTest.java b/connector/rest/src/test/java/it/pagopa/selfcare/onboarding/connector/OnboardingMsConnectorImplTest.java index cfb4476e..8c2a25e5 100644 --- a/connector/rest/src/test/java/it/pagopa/selfcare/onboarding/connector/OnboardingMsConnectorImplTest.java +++ b/connector/rest/src/test/java/it/pagopa/selfcare/onboarding/connector/OnboardingMsConnectorImplTest.java @@ -1,6 +1,7 @@ package it.pagopa.selfcare.onboarding.connector; import it.pagopa.selfcare.onboarding.common.InstitutionType; +import it.pagopa.selfcare.onboarding.connector.model.institutions.Institution; import it.pagopa.selfcare.onboarding.connector.model.onboarding.*; import it.pagopa.selfcare.onboarding.connector.rest.client.MsOnboardingApiClient; import it.pagopa.selfcare.onboarding.connector.rest.client.MsOnboardingTokenApiClient; @@ -282,4 +283,40 @@ void onboardingUsers() { ._v1OnboardingUsersPost(request); verifyNoMoreInteractions(msOnboardingApiClient); } + + @Test + void onboardingPaAggregation() { + // given + OnboardingData onboardingData = new OnboardingData(); + onboardingData.setProductId("produictId"); + onboardingData.setTaxCode("taxCode"); + onboardingData.setInstitutionType(InstitutionType.PG); + InstitutionUpdate institutionUpdate = new InstitutionUpdate(); + institutionUpdate.setTaxCode("taxCode"); + institutionUpdate.setDescription("description"); + onboardingData.setUsers(List.of(mockInstance(new User()))); + onboardingData.setInstitutionUpdate(institutionUpdate); + Institution institution = new Institution(); + institution.setTaxCode("taxCode"); + institution.setDescription("description"); + onboardingData.setAggregates(List.of(institution)); + onboardingData.setIsAggregator(Boolean.TRUE); + // when + onboardingMsConnector.onboardingPaAggregation(onboardingData); + // then + ArgumentCaptor onboardingRequestCaptor = ArgumentCaptor.forClass(OnboardingPaRequest.class); + verify(msOnboardingApiClient, times(1)) + ._v1OnboardingPaAggregationPost(onboardingRequestCaptor.capture()); + OnboardingPaRequest actual = onboardingRequestCaptor.getValue(); + assertEquals(actual.getProductId(), onboardingData.getProductId()); + assertEquals(actual.getAggregates().size(), onboardingData.getAggregates().size()); + assertEquals(actual.getAggregates().get(0).getTaxCode(), onboardingData.getAggregates().get(0).getTaxCode()); + assertEquals(actual.getAggregates().get(0).getDescription(), onboardingData.getAggregates().get(0).getDescription()); + assertEquals(actual.getInstitution().getTaxCode(), onboardingData.getTaxCode()); + assertEquals(actual.getInstitution().getTaxCode(), onboardingData.getInstitutionUpdate().getTaxCode() ); + assertEquals(actual.getInstitution().getDescription(), onboardingData.getInstitutionUpdate().getDescription()); + assertEquals(actual.getUsers().size(), onboardingData.getUsers().size()); + + verifyNoMoreInteractions(msOnboardingApiClient); + } } diff --git a/core/src/main/java/it/pagopa/selfcare/onboarding/core/InstitutionService.java b/core/src/main/java/it/pagopa/selfcare/onboarding/core/InstitutionService.java index 0f0ab4da..045358de 100644 --- a/core/src/main/java/it/pagopa/selfcare/onboarding/core/InstitutionService.java +++ b/core/src/main/java/it/pagopa/selfcare/onboarding/core/InstitutionService.java @@ -21,6 +21,8 @@ public interface InstitutionService { void onboardingProduct(OnboardingData onboardingData); + void onboardingPaAggregator(OnboardingData entity); + Collection getInstitutions(String productId, String userId); InstitutionOnboardingData getInstitutionOnboardingDataById(String institutionId, String productId); diff --git a/core/src/main/java/it/pagopa/selfcare/onboarding/core/InstitutionServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/onboarding/core/InstitutionServiceImpl.java index b6a0c16b..67c5bcfa 100644 --- a/core/src/main/java/it/pagopa/selfcare/onboarding/core/InstitutionServiceImpl.java +++ b/core/src/main/java/it/pagopa/selfcare/onboarding/core/InstitutionServiceImpl.java @@ -39,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; import javax.validation.ValidationException; import java.util.*; @@ -63,6 +64,8 @@ class InstitutionServiceImpl implements InstitutionService { private static final String ONBOARDING_NOT_ALLOWED_ERROR_MESSAGE_TEMPLATE = "Institution with external id '%s' is not allowed to onboard '%s' product"; public static final String UNABLE_TO_COMPLETE_THE_ONBOARDING_FOR_INSTITUTION_FOR_PRODUCT_DISMISSED = "Unable to complete the onboarding for institution with taxCode '%s' to product '%s', the product is dismissed."; public static final String FIELD_PSP_DATA_IS_REQUIRED_FOR_PSP_INSTITUTION_ONBOARDING = "Field 'pspData' is required for PSP institution onboarding"; + + private static final String REQUIRED_AGGREGATE_INSTITUTIONS = "Aggregate institutions are required if given institution is an Aggregator"; static final String DESCRIPTION_TO_REPLACE_REGEX = " - COMUNE"; private final OnboardingMsConnector onboardingMsConnector; private final PartyConnector partyConnector; @@ -100,6 +103,18 @@ public void onboardingProductV2(OnboardingData onboardingData) { onboardingMsConnector.onboarding(onboardingData); log.trace("onboarding end"); } + + + @Override + public void onboardingPaAggregator(OnboardingData onboardingData) { + log.trace("onboardingPaAggregator start"); + if(CollectionUtils.isEmpty(onboardingData.getAggregates())){ + throw new ValidationException(REQUIRED_AGGREGATE_INSTITUTIONS); + } + onboardingMsConnector.onboardingPaAggregation(onboardingData); + log.trace("onboarding end"); + } + @Override public void onboardingCompanyV2(OnboardingData onboardingData) { log.trace("onboardingProductAsync start"); diff --git a/core/src/test/java/it/pagopa/selfcare/onboarding/core/InstitutionServiceImplTest.java b/core/src/test/java/it/pagopa/selfcare/onboarding/core/InstitutionServiceImplTest.java index dc102692..261ccd90 100644 --- a/core/src/test/java/it/pagopa/selfcare/onboarding/core/InstitutionServiceImplTest.java +++ b/core/src/test/java/it/pagopa/selfcare/onboarding/core/InstitutionServiceImplTest.java @@ -152,6 +152,54 @@ void onboardingCompanyV2() { .onboardingCompany(any()); } + @Test + void onboardingPaAggregator() { + // given + OnboardingData onboardingData = mockInstance(new OnboardingData(), "setInstitutionType", "setUsers", "isAggregator", "aggregates"); + onboardingData.setInstitutionType(InstitutionType.PG); + onboardingData.setUsers(List.of(dummyManager, dummyDelegate)); + onboardingData.setIsAggregator(Boolean.TRUE); + Institution institution = mock(Institution.class); + onboardingData.setAggregates(List.of(institution)); + // when + institutionService.onboardingPaAggregator(onboardingData); + // then + verify(onboardingMsConnector, times(1)) + .onboardingPaAggregation(any()); + } + + @Test + void onboardingPaAggregatorWithEmptyAggregateList() { + // given + OnboardingData onboardingData = mockInstance(new OnboardingData(), "setInstitutionType", "setUsers", "isAggregator", "aggregates"); + onboardingData.setInstitutionType(InstitutionType.PG); + onboardingData.setUsers(List.of(dummyManager, dummyDelegate)); + onboardingData.setIsAggregator(Boolean.TRUE); + onboardingData.setAggregates(Collections.emptyList()); + // when + Assertions.assertThrows(ValidationException.class, + () -> institutionService.onboardingPaAggregator(onboardingData), + "Aggregate institutions is request if given institution is an Aggregator"); + // then + verifyNoInteractions(onboardingMsConnector); + } + + @Test + void onboardingPaAggregatorWithNullAggregateList() { + // given + OnboardingData onboardingData = mockInstance(new OnboardingData(), "setInstitutionType", "setUsers", "isAggregator", "aggregates"); + onboardingData.setInstitutionType(InstitutionType.PG); + onboardingData.setUsers(List.of(dummyManager, dummyDelegate)); + onboardingData.setIsAggregator(Boolean.TRUE); + // when + Assertions.assertThrows(ValidationException.class, + () -> institutionService.onboardingPaAggregator(onboardingData), + "Aggregate institutions is request if given institution is an Aggregator"); + // then + verifyNoInteractions(onboardingMsConnector); + } + + @Test void shouldOnboardingProductInstitutionNotPa() { // given diff --git a/web/src/main/java/it/pagopa/selfcare/onboarding/web/controller/InstitutionV2Controller.java b/web/src/main/java/it/pagopa/selfcare/onboarding/web/controller/InstitutionV2Controller.java index 290b02ea..b6c8b431 100644 --- a/web/src/main/java/it/pagopa/selfcare/onboarding/web/controller/InstitutionV2Controller.java +++ b/web/src/main/java/it/pagopa/selfcare/onboarding/web/controller/InstitutionV2Controller.java @@ -50,7 +50,11 @@ public InstitutionV2Controller(InstitutionService institutionService, Onboarding public void onboarding(@RequestBody @Valid OnboardingProductDto request) { log.trace(ONBOARDING_START); log.debug("onboarding request = {}", request); - institutionService.onboardingProductV2(onboardingResourceMapper.toEntity(request)); + if (Boolean.TRUE.equals(request.getIsAggregator())) { + institutionService.onboardingPaAggregator(onboardingResourceMapper.toEntity(request)); + } else { + institutionService.onboardingProductV2(onboardingResourceMapper.toEntity(request)); + } log.trace(ONBOARDING_END); } diff --git a/web/src/main/java/it/pagopa/selfcare/onboarding/web/model/AggregateInstitution.java b/web/src/main/java/it/pagopa/selfcare/onboarding/web/model/AggregateInstitution.java index 37319153..0b30e928 100644 --- a/web/src/main/java/it/pagopa/selfcare/onboarding/web/model/AggregateInstitution.java +++ b/web/src/main/java/it/pagopa/selfcare/onboarding/web/model/AggregateInstitution.java @@ -1,7 +1,6 @@ package it.pagopa.selfcare.onboarding.web.model; import it.pagopa.selfcare.onboarding.common.Origin; -import it.pagopa.selfcare.onboarding.connector.model.onboarding.GeographicTaxonomy; import lombok.Data; import javax.validation.constraints.NotNull; @@ -18,7 +17,7 @@ public class AggregateInstitution { private String subunitCode; private String subunitType; - private List geographicTaxonomies; + private List geographicTaxonomies; private String address; private String zipCode; private String originId; diff --git a/web/src/main/java/it/pagopa/selfcare/onboarding/web/model/mapper/OnboardingResourceMapper.java b/web/src/main/java/it/pagopa/selfcare/onboarding/web/model/mapper/OnboardingResourceMapper.java index 07fbb4a5..7fbeab06 100644 --- a/web/src/main/java/it/pagopa/selfcare/onboarding/web/model/mapper/OnboardingResourceMapper.java +++ b/web/src/main/java/it/pagopa/selfcare/onboarding/web/model/mapper/OnboardingResourceMapper.java @@ -2,6 +2,7 @@ import it.pagopa.selfcare.commons.base.security.PartyRole; import it.pagopa.selfcare.onboarding.connector.model.InstitutionLegalAddressData; +import it.pagopa.selfcare.onboarding.connector.model.institutions.Institution; import it.pagopa.selfcare.onboarding.connector.model.onboarding.OnboardingData; import it.pagopa.selfcare.onboarding.connector.model.onboarding.User; import it.pagopa.selfcare.onboarding.web.model.*; @@ -31,6 +32,8 @@ public interface OnboardingResourceMapper { @Mapping(source = "originId", target = "originId") OnboardingData toEntity(OnboardingProductDto dto); + Institution toInstitution(AggregateInstitution aggregateInstitution); + @Mapping(source = "billingData", target = "billing") @Mapping(source = "billingData.businessName", target = "institutionUpdate.description") @Mapping(source = "billingData.taxCode", target = "institutionUpdate.taxCode") diff --git a/web/src/test/java/it/pagopa/selfcare/onboarding/web/controller/InstitutionV2ControllerTest.java b/web/src/test/java/it/pagopa/selfcare/onboarding/web/controller/InstitutionV2ControllerTest.java index 29ed6056..2c3b46ec 100644 --- a/web/src/test/java/it/pagopa/selfcare/onboarding/web/controller/InstitutionV2ControllerTest.java +++ b/web/src/test/java/it/pagopa/selfcare/onboarding/web/controller/InstitutionV2ControllerTest.java @@ -69,7 +69,7 @@ void onboardingProductForAggregatorAsync(@Value("classpath:stubs/onboardingProdu .andExpect(content().string(emptyString())); // then verify(institutionServiceMock, times(1)) - .onboardingProductV2(any(OnboardingData.class)); + .onboardingPaAggregator(any(OnboardingData.class)); verifyNoMoreInteractions(institutionServiceMock); } diff --git a/web/src/test/resources/stubs/onboardingProductsDtoWithAggregates.json b/web/src/test/resources/stubs/onboardingProductsDtoWithAggregates.json index 750320f5..dbd18d04 100644 --- a/web/src/test/resources/stubs/onboardingProductsDtoWithAggregates.json +++ b/web/src/test/resources/stubs/onboardingProductsDtoWithAggregates.json @@ -25,7 +25,7 @@ "taxCode": "string" } ], - "isAggregate": true, + "isAggregator": true, "aggregates": [ { "taxCode": "taxCode",