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..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 @@ -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; @@ -18,7 +16,6 @@ import java.util.List; import java.util.Objects; import java.util.Optional; -import java.util.stream.Collectors; @Mapper(componentModel = "spring") public interface OnboardingMapper { @@ -43,8 +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", expression = "java(toInstitutionImportRequest(onboardingData, onboardingData.getInstitutionUpdate()))") @Mapping( target = "contractImported.createdAt", source = "contractImported.createdAt", @@ -53,7 +49,21 @@ public interface OnboardingMapper { target = "contractImported.activatedAt", source = "contractImported.activatedAt", qualifiedByName = "convertDate") - OnboardingImportRequest toOnboardingImportRequest(OnboardingData onboardingData); + OnboardingImportRequest mapToOnboardingImportRequest(OnboardingData onboardingData); + + @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())) { + return Origin.IPA; + } + + return Origin.fromValue(onboardingData.getOrigin()); + } GeographicTaxonomyDto toGeographicTaxonomyDto(GeographicTaxonomy geographicTaxonomy); @@ -91,7 +101,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()); @@ -133,7 +143,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/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"); } 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..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 @@ -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; @@ -57,15 +58,27 @@ public void setUp() { void oldContractOnboardingTest() { OnboardingData onboardingData = new OnboardingData(); onboardingData.setInstitutionExternalId("externalId"); + onboardingData.setInstitutionUpdate(new InstitutionUpdate()); Assertions.assertDoesNotThrow(() -> onboardingService.oldContractOnboardingV2(onboardingData)); } @Test - void autoApprovalOnboardingProductV2TestPA() { + 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(); + onboardingData.setInstitutionExternalId("externalId"); + InstitutionUpdate institutionUpdate = new InstitutionUpdate(); onboardingData.setInstitutionType(PA); + institutionUpdate.setGeographicTaxonomies(List.of(new GeographicTaxonomy())); + onboardingData.setInstitutionUpdate(institutionUpdate); Assertions.assertDoesNotThrow( () -> onboardingService.autoApprovalOnboardingProductV2(onboardingData)); } @@ -94,7 +107,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)); @@ -147,6 +162,6 @@ void onboardingUsers_happyPath() throws Exception { List result = onboardingService.onboardingUsers(onboardingUsersRequest, "userName", "surname"); - assertEquals(result.size(), 2); + assertEquals(2, result.size()); } }