From ecec92a84bfdf81f9c55b6c195d00dbd0f2d9f27 Mon Sep 17 00:00:00 2001 From: Giulia Tremolada Date: Wed, 3 Jul 2024 16:09:21 +0200 Subject: [PATCH] remove product pagoPa condition in createDelegation --- .../mscore/core/DelegationServiceImpl.java | 41 +------------ .../core/DelegationServiceImplTest.java | 61 ------------------- 2 files changed, 3 insertions(+), 99 deletions(-) diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/DelegationServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/DelegationServiceImpl.java index 3b5687a5..69e9b5cb 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/DelegationServiceImpl.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/DelegationServiceImpl.java @@ -1,6 +1,5 @@ package it.pagopa.selfcare.mscore.core; -import it.pagopa.selfcare.commons.base.utils.InstitutionType; import it.pagopa.selfcare.mscore.api.DelegationConnector; import it.pagopa.selfcare.mscore.constant.CustomError; import it.pagopa.selfcare.mscore.constant.DelegationState; @@ -30,7 +29,6 @@ public class DelegationServiceImpl implements DelegationService { private final DelegationConnector delegationConnector; private final MailNotificationService notificationService; private final InstitutionService institutionService; - private static final String PROD_PAGOPA = "prod-pagopa"; public DelegationServiceImpl(DelegationConnector delegationConnector, MailNotificationService notificationService, @@ -42,17 +40,11 @@ public DelegationServiceImpl(DelegationConnector delegationConnector, @Override public Delegation createDelegation(Delegation delegation) { - /* - In case of prod-pagopa product, in the attribute "to" of the delegation object a taxCode is inserted. - So we have to retrieve the institutionId from the taxCode and set it in the "to" attribute. - */ - if(PROD_PAGOPA.equals(delegation.getProductId())) { - setPartnerByInstitutionTaxCode(delegation); - } else { - setTaxCodesByInstitutionIds(delegation); - } + + setTaxCodesByInstitutionIds(delegation); Delegation savedDelegation = checkIfExistsAndSaveDelegation(delegation); + try { notificationService.sendMailForDelegation(delegation.getInstitutionFromName(), delegation.getProductId(), delegation.getTo()); } catch (Exception e) { @@ -84,33 +76,6 @@ private Delegation checkIfExistsAndSaveDelegation(Delegation delegation) { return savedDelegation; } - private void setPartnerByInstitutionTaxCode(Delegation delegation) { - /* - In case the api returns more institutions we always try to take the PT, - otherwise it is okay to take the first one - It is caused by this issue https://pagopa.atlassian.net/wiki/spaces/SCP/pages/1058832442/RFC+-+Gestione+di+pi+institutionType+su+una+Institution - */ - List institutionsTo = institutionService.getInstitutions(delegation.getTo(), null); - Institution partner = institutionsTo.stream() - .filter(institution -> institution.getInstitutionType() == InstitutionType.PT) - .findFirst() - .orElse(institutionsTo.stream().findFirst() - .orElseThrow(() -> new ResourceNotFoundException( - String.format(INSTITUTION_TAX_CODE_NOT_FOUND.getMessage(), delegation.getTo()), - INSTITUTION_TAX_CODE_NOT_FOUND.getCode()) - )); - delegation.setToTaxCode(partner.getTaxCode()); - delegation.setBrokerType(partner.getInstitutionType()); - delegation.setTo(partner.getId()); - - /* - Retrieve delegator's institution to set taxCodeFrom - */ - Institution institutionFrom = institutionService.retrieveInstitutionById(delegation.getFrom()); - delegation.setFromTaxCode(institutionFrom.getTaxCode()); - delegation.setInstitutionType(institutionFrom.getInstitutionType()); - } - private void setTaxCodesByInstitutionIds(Delegation delegation){ /* Retrieve both delegator's and partner's institutions to set taxCodeFrom and taxCodeTo diff --git a/core/src/test/java/it/pagopa/selfcare/mscore/core/DelegationServiceImplTest.java b/core/src/test/java/it/pagopa/selfcare/mscore/core/DelegationServiceImplTest.java index 91191ed1..8ab55f52 100644 --- a/core/src/test/java/it/pagopa/selfcare/mscore/core/DelegationServiceImplTest.java +++ b/core/src/test/java/it/pagopa/selfcare/mscore/core/DelegationServiceImplTest.java @@ -95,57 +95,6 @@ void testCreateDelegationWithProductProdIo() { assertEquals(institutionFrom.getInstitutionType(), response.getInstitutionType()); } - /** - * Method under test: {@link DelegationServiceImpl#createDelegation(Delegation)} - */ - @Test - void testCreateDelegationForPTWithProductPagopa() { - Institution institutionTo = new Institution(); - institutionTo.setId("id"); - institutionTo.setInstitutionType(InstitutionType.PT); - institutionTo.setTaxCode("taxCodeTo"); - Institution institutionFrom = new Institution(); - institutionFrom.setId("id"); - institutionFrom.setTaxCode("taxCodeFrom"); - when(delegationConnector.save(dummyDelegationProdPagopa)).thenAnswer(arg ->arg.getArguments()[0]); - doNothing().when(mailNotificationService).sendMailForDelegation(any(), any(), any()); - when(institutionService.getInstitutions(dummyDelegationProdPagopa.getTo(), null)).thenReturn(List.of(institutionTo)); - doNothing().when(institutionService).updateInstitutionDelegation(any(),anyBoolean()); - when(institutionService.retrieveInstitutionById(dummyDelegationProdPagopa.getFrom())).thenReturn(institutionFrom); - Delegation response = delegationServiceImpl.createDelegation(dummyDelegationProdPagopa); - verify(institutionService).getInstitutions(any(), any()); - verify(delegationConnector).save(any()); - assertNotNull(response); - assertNotNull(response.getId()); - assertEquals(dummyDelegationProdPagopa.getId(), response.getId()); - } - - /** - * Method under test: {@link DelegationServiceImpl#createDelegation(Delegation)} - */ - @Test - void testCreateDelegationForEcWithProductPagopa() { - Institution institutionTo = new Institution(); - institutionTo.setId("to"); - institutionTo.setInstitutionType(InstitutionType.PT); - institutionTo.setTaxCode("taxCodeTo"); - Institution institutionFrom = new Institution(); - institutionFrom.setId("from"); - institutionFrom.setTaxCode("taxCodeFrom"); - when(delegationConnector.findAndActivate(institutionFrom.getId(), institutionTo.getId(), dummyDelegationProdPagopa.getProductId())).thenReturn(dummyDelegationProdPagopa); - doNothing().when(mailNotificationService).sendMailForDelegation(any(), any(), any()); - when(institutionService.getInstitutions(dummyDelegationProdPagopa.getTo(), null)).thenReturn(List.of(institutionTo)); - doNothing().when(institutionService).updateInstitutionDelegation(any(),anyBoolean()); - when(delegationServiceImpl.checkIfExistsWithStatus(dummyDelegationProdPagopa, DelegationState.DELETED)).thenReturn(true); - when(institutionService.retrieveInstitutionById(dummyDelegationProdPagopa.getFrom())).thenReturn(institutionFrom); - Delegation response = delegationServiceImpl.createDelegation(dummyDelegationProdPagopa); - verify(delegationConnector).findAndActivate(institutionFrom.getId(), institutionTo.getId(), dummyDelegationProdPagopa.getProductId()); - verify(institutionService).getInstitutions(any(), any()); - assertNotNull(response); - assertNotNull(response.getId()); - assertEquals(dummyDelegationProdPagopa.getId(), response.getId()); - } - /** * Method under test: {@link DelegationServiceImpl#createDelegation(Delegation)} */ @@ -153,7 +102,6 @@ void testCreateDelegationForEcWithProductPagopa() { void testCreateDelegationWithSendMailError() { Institution institution = new Institution(); institution.setId("id"); - when(institutionService.getInstitutions(any(), any())).thenReturn(List.of(institution)); when(institutionService.retrieveInstitutionById(any())).thenReturn(institution); doThrow(new MsCoreException(SEND_MAIL_FOR_DELEGATION_ERROR.getMessage(), SEND_MAIL_FOR_DELEGATION_ERROR.getCode())) .when(mailNotificationService) @@ -175,15 +123,6 @@ void testCreateDelegationWithError() { verify(delegationConnector).save(any()); } - /** - * Method under test: {@link DelegationServiceImpl#createDelegation(Delegation)} - */ - @Test - void testCreateDelegationWithResourceNotFoundException() { - when(institutionService.getInstitutions(any(), any())).thenReturn(List.of()); - assertThrows(ResourceNotFoundException.class, () -> delegationServiceImpl.createDelegation(dummyDelegationProdPagopa)); - } - /** * Method under test: {@link DelegationServiceImpl#createDelegation(Delegation)} */