Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
[SELC-5170] : Fix PR
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenbegiqi committed Jul 5, 2024
1 parent 48a4fa7 commit 7ce6e90
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
6 changes: 3 additions & 3 deletions app/src/main/resources/swagger/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public interface InstitutionConnector {

void deleteById(String id);

void findAndDeleteOnboarding(String institutionId, String productId);

List<Institution> findByTaxCodeSubunitCodeAndOrigin(String taxtCode, String subunitCode, String origin, String originId);

Boolean existsByTaxCodeAndSubunitCodeAndProductAndStatusList(String taxtCode, String subunitCode, Optional<String> productId, List<RelationshipState> validRelationshipStates);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Institution> findByTaxCodeSubunitCodeAndOrigin(String taxCode, String subunitCode, String origin, String originId) {
return repository.find(Query.query(CriteriaBuilder.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 7ce6e90

Please sign in to comment.