From ee83c8c152b99f4e4260a5b9a09d4d90a0113659 Mon Sep 17 00:00:00 2001 From: empassaro Date: Mon, 25 Nov 2024 18:56:15 +0100 Subject: [PATCH 1/8] [SELC-6064] feat: added origin IPA for import/pa api --- .../selfcare/external_api/mapper/OnboardingMapper.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/it/pagopa/selfcare/external_api/mapper/OnboardingMapper.java b/src/main/java/it/pagopa/selfcare/external_api/mapper/OnboardingMapper.java index 0c8b1724..11478a62 100644 --- a/src/main/java/it/pagopa/selfcare/external_api/mapper/OnboardingMapper.java +++ b/src/main/java/it/pagopa/selfcare/external_api/mapper/OnboardingMapper.java @@ -53,7 +53,13 @@ public interface OnboardingMapper { target = "contractImported.activatedAt", source = "contractImported.activatedAt", qualifiedByName = "convertDate") - OnboardingImportRequest toOnboardingImportRequest(OnboardingData onboardingData); + OnboardingImportRequest mapToOnboardingImportRequest(OnboardingData onboardingData); + + default OnboardingImportRequest toOnboardingImportRequest(OnboardingData onboardingData) { + OnboardingImportRequest onboardingImportRequest = mapToOnboardingImportRequest(onboardingData); + onboardingImportRequest.getInstitution().setOrigin(Origin.IPA); + return onboardingImportRequest; + } GeographicTaxonomyDto toGeographicTaxonomyDto(GeographicTaxonomy geographicTaxonomy); From 9f10fde975601501dc890b6995d5698ff9d66408 Mon Sep 17 00:00:00 2001 From: empassaro Date: Mon, 25 Nov 2024 19:06:31 +0100 Subject: [PATCH 2/8] [SELC-6064] fix: junit --- .../selfcare/external_api/service/OnboardingServiceImplTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/it/pagopa/selfcare/external_api/service/OnboardingServiceImplTest.java b/src/test/java/it/pagopa/selfcare/external_api/service/OnboardingServiceImplTest.java index 322c2298..43ebab66 100644 --- a/src/test/java/it/pagopa/selfcare/external_api/service/OnboardingServiceImplTest.java +++ b/src/test/java/it/pagopa/selfcare/external_api/service/OnboardingServiceImplTest.java @@ -57,6 +57,7 @@ public void setUp() { void oldContractOnboardingTest() { OnboardingData onboardingData = new OnboardingData(); onboardingData.setInstitutionExternalId("externalId"); + onboardingData.setInstitutionUpdate(new InstitutionUpdate()); Assertions.assertDoesNotThrow(() -> onboardingService.oldContractOnboardingV2(onboardingData)); } From 8afc69963e4b94758dbc7daa41a7dfda96e08682 Mon Sep 17 00:00:00 2001 From: empassaro Date: Tue, 26 Nov 2024 09:08:13 +0100 Subject: [PATCH 3/8] [SELC-6064] fix: sonar smells --- .../selfcare/external_api/mapper/OnboardingMapper.java | 5 ++--- .../external_api/service/OnboardingServiceImplTest.java | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/it/pagopa/selfcare/external_api/mapper/OnboardingMapper.java b/src/main/java/it/pagopa/selfcare/external_api/mapper/OnboardingMapper.java index 11478a62..9047700e 100644 --- a/src/main/java/it/pagopa/selfcare/external_api/mapper/OnboardingMapper.java +++ b/src/main/java/it/pagopa/selfcare/external_api/mapper/OnboardingMapper.java @@ -18,7 +18,6 @@ import java.util.List; import java.util.Objects; import java.util.Optional; -import java.util.stream.Collectors; @Mapper(componentModel = "spring") public interface OnboardingMapper { @@ -97,7 +96,7 @@ default InstitutionBaseRequest toInstitutionBase(OnboardingData onboardingData) geotaxes -> geotaxes.stream() .map(this::toGeographicTaxonomyDto) - .collect(Collectors.toList())) + .toList()) .orElse(null)); institution.rea(onboardingData.getInstitutionUpdate().getRea()); institution.shareCapital(onboardingData.getInstitutionUpdate().getShareCapital()); @@ -139,7 +138,7 @@ default InstitutionPspRequest toInstitutionPsp(OnboardingData onboardingData) { geotaxes -> geotaxes.stream() .map(this::toGeographicTaxonomyDto) - .collect(Collectors.toList())) + .toList()) .orElse(null)); institutionPsp.rea(onboardingData.getInstitutionUpdate().getRea()); institutionPsp.shareCapital(onboardingData.getInstitutionUpdate().getShareCapital()); diff --git a/src/test/java/it/pagopa/selfcare/external_api/service/OnboardingServiceImplTest.java b/src/test/java/it/pagopa/selfcare/external_api/service/OnboardingServiceImplTest.java index 43ebab66..d71755f2 100644 --- a/src/test/java/it/pagopa/selfcare/external_api/service/OnboardingServiceImplTest.java +++ b/src/test/java/it/pagopa/selfcare/external_api/service/OnboardingServiceImplTest.java @@ -148,6 +148,6 @@ void onboardingUsers_happyPath() throws Exception { List result = onboardingService.onboardingUsers(onboardingUsersRequest, "userName", "surname"); - assertEquals(result.size(), 2); + assertEquals(2, result.size()); } } From f29805c78e08f1c71573c765e763208db4e3aba3 Mon Sep 17 00:00:00 2001 From: empassaro Date: Tue, 26 Nov 2024 18:01:06 +0100 Subject: [PATCH 4/8] [SELC-6064] fix: added origin mapping via annotation --- .../selfcare/external_api/mapper/OnboardingMapper.java | 7 +------ .../external_api/service/OnboardingServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/it/pagopa/selfcare/external_api/mapper/OnboardingMapper.java b/src/main/java/it/pagopa/selfcare/external_api/mapper/OnboardingMapper.java index 9047700e..49f3b750 100644 --- a/src/main/java/it/pagopa/selfcare/external_api/mapper/OnboardingMapper.java +++ b/src/main/java/it/pagopa/selfcare/external_api/mapper/OnboardingMapper.java @@ -44,6 +44,7 @@ public interface OnboardingMapper { @Mapping(target = "institution", source = "institutionUpdate") @Mapping(target = "institution.institutionType", ignore = true) + @Mapping(target = "institution.origin", constant = "IPA") @Mapping( target = "contractImported.createdAt", source = "contractImported.createdAt", @@ -54,12 +55,6 @@ public interface OnboardingMapper { qualifiedByName = "convertDate") OnboardingImportRequest mapToOnboardingImportRequest(OnboardingData onboardingData); - default OnboardingImportRequest toOnboardingImportRequest(OnboardingData onboardingData) { - OnboardingImportRequest onboardingImportRequest = mapToOnboardingImportRequest(onboardingData); - onboardingImportRequest.getInstitution().setOrigin(Origin.IPA); - return onboardingImportRequest; - } - GeographicTaxonomyDto toGeographicTaxonomyDto(GeographicTaxonomy geographicTaxonomy); @Named("convertDate") diff --git a/src/main/java/it/pagopa/selfcare/external_api/service/OnboardingServiceImpl.java b/src/main/java/it/pagopa/selfcare/external_api/service/OnboardingServiceImpl.java index d21cbc5b..f095157e 100644 --- a/src/main/java/it/pagopa/selfcare/external_api/service/OnboardingServiceImpl.java +++ b/src/main/java/it/pagopa/selfcare/external_api/service/OnboardingServiceImpl.java @@ -43,7 +43,7 @@ public void oldContractOnboardingV2(OnboardingData onboardingImportData) { log.trace("oldContractOnboarding start"); log.debug("oldContractOnboarding = {}", onboardingImportData); onboardingControllerApi._onboardingPaImport( - onboardingMapper.toOnboardingImportRequest(onboardingImportData)); + onboardingMapper.mapToOnboardingImportRequest(onboardingImportData)); log.trace("oldContractOnboarding end"); } From 16633f59c462d65801ead4a2015d43f5a9a2df76 Mon Sep 17 00:00:00 2001 From: empassaro Date: Tue, 26 Nov 2024 18:20:27 +0100 Subject: [PATCH 5/8] [SELC-6064] fix: coverage junit --- .../external_api/service/OnboardingServiceImplTest.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/test/java/it/pagopa/selfcare/external_api/service/OnboardingServiceImplTest.java b/src/test/java/it/pagopa/selfcare/external_api/service/OnboardingServiceImplTest.java index d71755f2..6e68be4f 100644 --- a/src/test/java/it/pagopa/selfcare/external_api/service/OnboardingServiceImplTest.java +++ b/src/test/java/it/pagopa/selfcare/external_api/service/OnboardingServiceImplTest.java @@ -9,6 +9,7 @@ import it.pagopa.selfcare.external_api.exception.ResourceNotFoundException; import it.pagopa.selfcare.external_api.mapper.OnboardingMapperImpl; import it.pagopa.selfcare.external_api.mapper.UserResourceMapper; +import it.pagopa.selfcare.external_api.model.institution.GeographicTaxonomy; import it.pagopa.selfcare.external_api.model.onboarding.InstitutionUpdate; import it.pagopa.selfcare.external_api.model.onboarding.OnboardingData; import it.pagopa.selfcare.external_api.model.onboarding.OnboardingUsersRequest; @@ -65,8 +66,10 @@ void oldContractOnboardingTest() { void autoApprovalOnboardingProductV2TestPA() { OnboardingData onboardingData = new OnboardingData(); onboardingData.setInstitutionExternalId("externalId"); - onboardingData.setInstitutionUpdate(new InstitutionUpdate()); + InstitutionUpdate institutionUpdate = new InstitutionUpdate(); onboardingData.setInstitutionType(PA); + institutionUpdate.setGeographicTaxonomies(List.of(new GeographicTaxonomy())); + onboardingData.setInstitutionUpdate(institutionUpdate); Assertions.assertDoesNotThrow( () -> onboardingService.autoApprovalOnboardingProductV2(onboardingData)); } @@ -95,7 +98,9 @@ void autoApprovalOnboardingProductV2Test() { void autoApprovalOnboardingImportProductV2Test() { OnboardingData onboardingData = new OnboardingData(); onboardingData.setInstitutionExternalId("externalId"); - onboardingData.setInstitutionUpdate(new InstitutionUpdate()); + InstitutionUpdate institutionUpdate = new InstitutionUpdate(); + institutionUpdate.setGeographicTaxonomies(List.of(new GeographicTaxonomy())); + onboardingData.setInstitutionUpdate(institutionUpdate); onboardingData.setInstitutionType(PSP); Assertions.assertDoesNotThrow( () -> onboardingService.autoApprovalOnboardingImportProductV2(onboardingData)); From dbb61b059004f1f5b73605aace3998061a387766 Mon Sep 17 00:00:00 2001 From: empassaro Date: Wed, 27 Nov 2024 10:39:56 +0100 Subject: [PATCH 6/8] [SELC-6064] fix: mapping origin ipa if absent --- .../external_api/mapper/OnboardingMapper.java | 47 ++++++++++++++++--- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/src/main/java/it/pagopa/selfcare/external_api/mapper/OnboardingMapper.java b/src/main/java/it/pagopa/selfcare/external_api/mapper/OnboardingMapper.java index 49f3b750..e91b00a2 100644 --- a/src/main/java/it/pagopa/selfcare/external_api/mapper/OnboardingMapper.java +++ b/src/main/java/it/pagopa/selfcare/external_api/mapper/OnboardingMapper.java @@ -4,11 +4,9 @@ import it.pagopa.selfcare.external_api.model.institution.GeographicTaxonomy; import it.pagopa.selfcare.external_api.model.institution.Institution; import it.pagopa.selfcare.external_api.model.institution.Onboarding; -import it.pagopa.selfcare.external_api.model.onboarding.Billing; -import it.pagopa.selfcare.external_api.model.onboarding.DataProtectionOfficer; -import it.pagopa.selfcare.external_api.model.onboarding.OnboardingData; -import it.pagopa.selfcare.external_api.model.onboarding.PaymentServiceProvider; +import it.pagopa.selfcare.external_api.model.onboarding.*; import it.pagopa.selfcare.onboarding.generated.openapi.v1.dto.*; +import it.pagopa.selfcare.onboarding.generated.openapi.v1.dto.GeographicTaxonomyDto; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Named; @@ -42,9 +40,7 @@ public interface OnboardingMapper { @Mapping(target = "institution", source = ".", qualifiedByName = "toInstitutionBase") OnboardingDefaultRequest toOnboardingDefaultRequest(OnboardingData onboardingData); - @Mapping(target = "institution", source = "institutionUpdate") - @Mapping(target = "institution.institutionType", ignore = true) - @Mapping(target = "institution.origin", constant = "IPA") + @Mapping(target = "institution", source = ".", qualifiedByName = "toInstitutionImport") @Mapping( target = "contractImported.createdAt", source = "contractImported.createdAt", @@ -55,6 +51,43 @@ public interface OnboardingMapper { qualifiedByName = "convertDate") OnboardingImportRequest mapToOnboardingImportRequest(OnboardingData onboardingData); + @Named("toInstitutionImport") + default InstitutionImportRequest toInstitutionImport(OnboardingData onboardingData) { + InstitutionUpdate institutionUpdate = onboardingData.getInstitutionUpdate(); + if ( institutionUpdate == null ) { + return null; + } + + InstitutionImportRequest.InstitutionImportRequestBuilder institutionImportRequest = InstitutionImportRequest.builder(); + + institutionImportRequest.taxCode( institutionUpdate.getTaxCode() ); + institutionImportRequest.city( institutionUpdate.getCity() ); + institutionImportRequest.country( institutionUpdate.getCountry() ); + institutionImportRequest.county( institutionUpdate.getCounty() ); + institutionImportRequest.description( institutionUpdate.getDescription() ); + institutionImportRequest.digitalAddress( institutionUpdate.getDigitalAddress() ); + institutionImportRequest.address( institutionUpdate.getAddress() ); + institutionImportRequest.zipCode( institutionUpdate.getZipCode() ); + institutionImportRequest.rea( institutionUpdate.getRea() ); + institutionImportRequest.shareCapital( institutionUpdate.getShareCapital() ); + institutionImportRequest.businessRegisterPlace( institutionUpdate.getBusinessRegisterPlace() ); + institutionImportRequest.supportEmail( institutionUpdate.getSupportEmail() ); + institutionImportRequest.supportPhone( institutionUpdate.getSupportPhone() ); + institutionImportRequest.imported( institutionUpdate.getImported() ); + + institutionImportRequest.origin( originIpaIfAbsent(onboardingData) ); + + return institutionImportRequest.build(); + } + + default Origin originIpaIfAbsent(OnboardingData onboardingData) { + if(Objects.isNull(onboardingData.getOrigin())) { + return Origin.IPA; + } + + return Origin.fromValue(onboardingData.getOrigin()); + } + GeographicTaxonomyDto toGeographicTaxonomyDto(GeographicTaxonomy geographicTaxonomy); @Named("convertDate") From 7aa775cc3a7b7edaa01238a94ec01d250c1d287f Mon Sep 17 00:00:00 2001 From: empassaro Date: Wed, 27 Nov 2024 12:55:30 +0100 Subject: [PATCH 7/8] [SELC-6064] fix: new mapping implementation --- .../external_api/mapper/OnboardingMapper.java | 35 ++++--------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/src/main/java/it/pagopa/selfcare/external_api/mapper/OnboardingMapper.java b/src/main/java/it/pagopa/selfcare/external_api/mapper/OnboardingMapper.java index e91b00a2..775f9123 100644 --- a/src/main/java/it/pagopa/selfcare/external_api/mapper/OnboardingMapper.java +++ b/src/main/java/it/pagopa/selfcare/external_api/mapper/OnboardingMapper.java @@ -40,7 +40,7 @@ public interface OnboardingMapper { @Mapping(target = "institution", source = ".", qualifiedByName = "toInstitutionBase") OnboardingDefaultRequest toOnboardingDefaultRequest(OnboardingData onboardingData); - @Mapping(target = "institution", source = ".", qualifiedByName = "toInstitutionImport") + @Mapping(target = "institution", expression = "java(toInstitutionImportRequest(onboardingData, onboardingData.getInstitutionUpdate()))") @Mapping( target = "contractImported.createdAt", source = "contractImported.createdAt", @@ -51,34 +51,11 @@ public interface OnboardingMapper { qualifiedByName = "convertDate") OnboardingImportRequest mapToOnboardingImportRequest(OnboardingData onboardingData); - @Named("toInstitutionImport") - default InstitutionImportRequest toInstitutionImport(OnboardingData onboardingData) { - InstitutionUpdate institutionUpdate = onboardingData.getInstitutionUpdate(); - if ( institutionUpdate == null ) { - return null; - } - - InstitutionImportRequest.InstitutionImportRequestBuilder institutionImportRequest = InstitutionImportRequest.builder(); - - institutionImportRequest.taxCode( institutionUpdate.getTaxCode() ); - institutionImportRequest.city( institutionUpdate.getCity() ); - institutionImportRequest.country( institutionUpdate.getCountry() ); - institutionImportRequest.county( institutionUpdate.getCounty() ); - institutionImportRequest.description( institutionUpdate.getDescription() ); - institutionImportRequest.digitalAddress( institutionUpdate.getDigitalAddress() ); - institutionImportRequest.address( institutionUpdate.getAddress() ); - institutionImportRequest.zipCode( institutionUpdate.getZipCode() ); - institutionImportRequest.rea( institutionUpdate.getRea() ); - institutionImportRequest.shareCapital( institutionUpdate.getShareCapital() ); - institutionImportRequest.businessRegisterPlace( institutionUpdate.getBusinessRegisterPlace() ); - institutionImportRequest.supportEmail( institutionUpdate.getSupportEmail() ); - institutionImportRequest.supportPhone( institutionUpdate.getSupportPhone() ); - institutionImportRequest.imported( institutionUpdate.getImported() ); - - institutionImportRequest.origin( originIpaIfAbsent(onboardingData) ); - - return institutionImportRequest.build(); - } + @Named("toInstitutionImportRequest") + @Mapping(target="institutionType", ignore = true) + @Mapping(target="taxCode", source="institutionUpdate.taxCode") + @Mapping(target = "origin", expression = "java(originIpaIfAbsent(onboardingData))") + InstitutionImportRequest toInstitutionImportRequest(OnboardingData onboardingData, InstitutionUpdate institutionUpdate); default Origin originIpaIfAbsent(OnboardingData onboardingData) { if(Objects.isNull(onboardingData.getOrigin())) { From 9b98a64241f52d806f46872efc0e37630f2bde0b Mon Sep 17 00:00:00 2001 From: empassaro Date: Wed, 27 Nov 2024 14:10:54 +0100 Subject: [PATCH 8/8] [SELC-6064] fix: sonar coverage --- .../external_api/service/OnboardingServiceImplTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/java/it/pagopa/selfcare/external_api/service/OnboardingServiceImplTest.java b/src/test/java/it/pagopa/selfcare/external_api/service/OnboardingServiceImplTest.java index 6e68be4f..d999cb72 100644 --- a/src/test/java/it/pagopa/selfcare/external_api/service/OnboardingServiceImplTest.java +++ b/src/test/java/it/pagopa/selfcare/external_api/service/OnboardingServiceImplTest.java @@ -62,6 +62,15 @@ void oldContractOnboardingTest() { Assertions.assertDoesNotThrow(() -> onboardingService.oldContractOnboardingV2(onboardingData)); } + @Test + void oldContractOnboardingTestWithOrigin() { + OnboardingData onboardingData = new OnboardingData(); + onboardingData.setInstitutionExternalId("externalId"); + onboardingData.setInstitutionUpdate(new InstitutionUpdate()); + onboardingData.setOrigin("ADE"); + Assertions.assertDoesNotThrow(() -> onboardingService.oldContractOnboardingV2(onboardingData)); + } + @Test void autoApprovalOnboardingProductV2TestPA() { OnboardingData onboardingData = new OnboardingData();