diff --git a/app/src/main/resources/swagger/api-docs.json b/app/src/main/resources/swagger/api-docs.json index 84812096..936ecd7f 100644 --- a/app/src/main/resources/swagger/api-docs.json +++ b/app/src/main/resources/swagger/api-docs.json @@ -1871,11 +1871,11 @@ } ] } }, - "/institutions/{id}/{productId}" : { + "/institutions/{id}/products/{productId}" : { "delete" : { "tags" : [ "Institution" ], - "summary" : "The service delete the users changing the user status to 'DELETE' and remove from DB the PecNotification record by productId and institutionId", - "description" : "The service delete the users changing the user status to 'DELETE' and remove from DB the PecNotification record by productId and institutionId", + "summary" : "The service set DELETE status on onboarding association with the product and institutionId", + "description" : "The service set DELETE status on onboarding association with the product and institutionId", "operationId" : "deleteOnboardedInstitutionUsingDELETE", "parameters" : [ { "name" : "productId", diff --git a/connector-api/src/main/java/it/pagopa/selfcare/mscore/api/InstitutionConnector.java b/connector-api/src/main/java/it/pagopa/selfcare/mscore/api/InstitutionConnector.java index d5059d40..661f7a40 100644 --- a/connector-api/src/main/java/it/pagopa/selfcare/mscore/api/InstitutionConnector.java +++ b/connector-api/src/main/java/it/pagopa/selfcare/mscore/api/InstitutionConnector.java @@ -18,6 +18,8 @@ public interface InstitutionConnector { void deleteById(String id); + void findAndDeleteOnboarding(String institutionId, String productId); + List findByTaxCodeSubunitCodeAndOrigin(String taxtCode, String subunitCode, String origin, String originId); Boolean existsByTaxCodeAndSubunitCodeAndProductAndStatusList(String taxtCode, String subunitCode, Optional productId, List validRelationshipStates); diff --git a/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/InstitutionConnectorImpl.java b/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/InstitutionConnectorImpl.java index 930df73d..04bea06b 100644 --- a/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/InstitutionConnectorImpl.java +++ b/connector/dao/src/main/java/it/pagopa/selfcare/mscore/connector/dao/InstitutionConnectorImpl.java @@ -7,6 +7,7 @@ import it.pagopa.selfcare.mscore.connector.dao.model.inner.OnboardingEntity; import it.pagopa.selfcare.mscore.connector.dao.model.mapper.InstitutionEntityMapper; import it.pagopa.selfcare.mscore.connector.dao.model.mapper.InstitutionMapperHelper; +import it.pagopa.selfcare.mscore.constant.GenericError; import it.pagopa.selfcare.mscore.constant.RelationshipState; import it.pagopa.selfcare.mscore.constant.SearchMode; import it.pagopa.selfcare.mscore.exception.InvalidRequestException; @@ -191,6 +192,25 @@ public void findAndRemoveOnboarding(String institutionId, Onboarding onboarding) repository.findAndModify(query, update, findAndModifyOptions, InstitutionEntity.class); } + @Override + public void findAndDeleteOnboarding(String institutionId, String productId) { + + Query query = Query.query( + Criteria.where(InstitutionEntity.Fields.id.name()).is(institutionId)); + + Update update = new Update(); + update.set(InstitutionEntity.Fields.updatedAt.name(), OffsetDateTime.now()); + update.set("onboarding.$[elem].status", RelationshipState.DELETED.name()); + update.set("onboarding.$[elem].updatedAt", OffsetDateTime.now()); + + update.filterArray(Criteria.where("elem.productId").is(productId) + .and("elem.status").is(RelationshipState.ACTIVE.name())); + + FindAndModifyOptions options = FindAndModifyOptions.options().upsert(false).returnNew(false); + InstitutionEntity updatedEntity = repository.findAndModify(query, update, options, InstitutionEntity.class); + } + + @Override public List findByTaxCodeSubunitCodeAndOrigin(String taxCode, String subunitCode, String origin, String originId) { return repository.find(Query.query(CriteriaBuilder.builder() diff --git a/core/src/main/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImpl.java index 5d6f7424..1b153038 100644 --- a/core/src/main/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImpl.java +++ b/core/src/main/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImpl.java @@ -110,10 +110,7 @@ public Institution persistOnboarding(String institutionId, String public void deleteOnboardedInstitution(String institutionId, String productId) { log.trace("persist logic delete Onboarding - start"); - Onboarding onboarding = new Onboarding(); - onboarding.setStatus(RelationshipState.DELETED); - onboarding.setProductId(productId); - institutionConnector.findAndRemoveOnboarding(institutionId, onboarding); + institutionConnector.findAndDeleteOnboarding(institutionId, productId); log.trace("persist logic delete Onboarding - end"); log.trace("persist delete PecNotification - start"); diff --git a/core/src/test/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImplTest.java b/core/src/test/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImplTest.java index a9d3ab49..5af062ee 100644 --- a/core/src/test/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImplTest.java +++ b/core/src/test/java/it/pagopa/selfcare/mscore/core/OnboardingServiceImplTest.java @@ -265,7 +265,7 @@ void deleteOnboardedInstitution_success() { onboardingServiceImpl.deleteOnboardedInstitution(institutionId, productId); - verify(institutionConnector, times(1)).findAndRemoveOnboarding(institutionId, onboarding); + verify(institutionConnector, times(1)).findAndDeleteOnboarding(institutionId, productId); verify(pecNotificationConnector, times(1)).findAndDeletePecNotification(institutionId, productId); } @@ -288,7 +288,7 @@ void deleteOnboardedInstitution_deletePecNotificationFails() { assertEquals(DELETE_NOTIFICATION_OPERATION_ERROR.getMessage(), exception.getMessage()); assertEquals(ONBOARDING_OPERATION_ERROR.getCode(), exception.getCode()); - verify(institutionConnector, times(1)).findAndRemoveOnboarding(institutionId, onboarding); + verify(institutionConnector, times(1)).findAndDeleteOnboarding(institutionId, productId); verify(pecNotificationConnector, times(1)).findAndDeletePecNotification(institutionId, productId); } } diff --git a/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/InstitutionControllerTest.java b/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/InstitutionControllerTest.java index acd2ce6a..6b9aa3e0 100644 --- a/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/InstitutionControllerTest.java +++ b/web/src/test/java/it/pagopa/selfcare/mscore/web/controller/InstitutionControllerTest.java @@ -1381,7 +1381,7 @@ void deleteOnboardedInstitution_test() throws Exception { doNothing().when(onboardingService).deleteOnboardedInstitution(institutionId, productId); - MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.delete("/institutions/{id}/{productId}", institutionId, productId); + MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.delete("/institutions/{id}/products/{productId}", institutionId, productId); ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(institutionController) .build()