From f1688b1cad4364ad13dade31e738b9453723e6b2 Mon Sep 17 00:00:00 2001 From: Manuel Rafeli Date: Tue, 23 Apr 2024 11:56:51 +0200 Subject: [PATCH] hotfix: limit result post search users (#221) --- .github/workflows/pr_ms.yml | 2 +- .../connector/rest/decoder/FeignErrorDecoder.java | 2 +- .../client/MsPartyRegistryProxyRestClientTest.java | 3 ++- .../rest/client/UserRegistryRestClientTest.java | 9 +++++---- .../selfcare/external_api/core/UserServiceImpl.java | 10 +++++++--- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/workflows/pr_ms.yml b/.github/workflows/pr_ms.yml index 227166c7..e6cd39ba 100644 --- a/.github/workflows/pr_ms.yml +++ b/.github/workflows/pr_ms.yml @@ -19,7 +19,7 @@ jobs: uses: pagopa/selfcare-commons/.github/workflows/call_code_review_spring.yml@main name: 'Code Review' secrets: inherit - if: github.base_ref == 'main' && github.event_name == 'pull_request' + if: github.event_name == 'pull_request' with: pr_number: ${{ github.event.pull_request.number }} source_branch: ${{ github.head_ref }} diff --git a/connector/rest/src/main/java/it/pagopa/selfcare/external_api/connector/rest/decoder/FeignErrorDecoder.java b/connector/rest/src/main/java/it/pagopa/selfcare/external_api/connector/rest/decoder/FeignErrorDecoder.java index e54ff68f..c7f869a1 100644 --- a/connector/rest/src/main/java/it/pagopa/selfcare/external_api/connector/rest/decoder/FeignErrorDecoder.java +++ b/connector/rest/src/main/java/it/pagopa/selfcare/external_api/connector/rest/decoder/FeignErrorDecoder.java @@ -11,7 +11,7 @@ public class FeignErrorDecoder extends ErrorDecoder.Default { @Override public Exception decode(String methodKey, Response response) { if (response.status() == 404) { - throw new ResourceNotFoundException(); + throw new ResourceNotFoundException(response.reason()); } else if (response.status() == 400 && response.request().httpMethod().equals(Request.HttpMethod.HEAD)) { throw new InstitutionDoesNotExistException(); } else { diff --git a/connector/rest/src/test/java/it/pagopa/selfcare/external_api/connector/rest/client/MsPartyRegistryProxyRestClientTest.java b/connector/rest/src/test/java/it/pagopa/selfcare/external_api/connector/rest/client/MsPartyRegistryProxyRestClientTest.java index 57373385..db690a63 100644 --- a/connector/rest/src/test/java/it/pagopa/selfcare/external_api/connector/rest/client/MsPartyRegistryProxyRestClientTest.java +++ b/connector/rest/src/test/java/it/pagopa/selfcare/external_api/connector/rest/client/MsPartyRegistryProxyRestClientTest.java @@ -5,6 +5,7 @@ import it.pagopa.selfcare.commons.connector.rest.BaseFeignRestClientTest; import it.pagopa.selfcare.commons.connector.rest.RestTestUtils; import it.pagopa.selfcare.external_api.connector.rest.config.MsPartyRegistryProxyRestClientTestConfig; +import it.pagopa.selfcare.external_api.exceptions.ResourceNotFoundException; import it.pagopa.selfcare.external_api.model.institutions.InstitutionResource; import lombok.SneakyThrows; import org.junit.jupiter.api.Order; @@ -73,6 +74,6 @@ void findInstitution_notFound() { // when Executable executable = () -> restClient.findInstitution(institutionExternalId, null, null); //then - assertThrows(FeignException.NotFound.class, executable); + assertThrows(ResourceNotFoundException.class, executable); } } diff --git a/connector/rest/src/test/java/it/pagopa/selfcare/external_api/connector/rest/client/UserRegistryRestClientTest.java b/connector/rest/src/test/java/it/pagopa/selfcare/external_api/connector/rest/client/UserRegistryRestClientTest.java index ca20622e..5f29a41d 100644 --- a/connector/rest/src/test/java/it/pagopa/selfcare/external_api/connector/rest/client/UserRegistryRestClientTest.java +++ b/connector/rest/src/test/java/it/pagopa/selfcare/external_api/connector/rest/client/UserRegistryRestClientTest.java @@ -7,6 +7,7 @@ import it.pagopa.selfcare.commons.utils.TestUtils; import it.pagopa.selfcare.external_api.connector.rest.config.UserRegistryRestClientTestConfig; import it.pagopa.selfcare.external_api.connector.rest.model.user_registry.EmbeddedExternalId; +import it.pagopa.selfcare.external_api.exceptions.ResourceNotFoundException; import it.pagopa.selfcare.external_api.model.user.MutableUserFieldsDto; import it.pagopa.selfcare.external_api.model.user.SaveUserDto; import it.pagopa.selfcare.external_api.model.user.User; @@ -71,8 +72,8 @@ void getUserByInternalId_nullFieldList() { //when final Executable executable = () -> restClient.getUserByInternalId(userId, fieldList); //then - final FeignException.NotFound e = assertThrows(FeignException.NotFound.class, executable); - assertTrue(e.getMessage().contains("Request was not matched")); + final ResourceNotFoundException e = assertThrows(ResourceNotFoundException.class, executable); + assertTrue(e.getMessage().contains("Not Found")); } @Test @@ -83,8 +84,8 @@ void getUserByInternalId_emptyFieldList() { //when final Executable executable = () -> restClient.getUserByInternalId(userId, fieldList); //then - final FeignException.NotFound e = assertThrows(FeignException.NotFound.class, executable); - assertTrue(e.getMessage().contains("Request was not matched")); + final ResourceNotFoundException e = assertThrows(ResourceNotFoundException.class, executable); + assertTrue(e.getMessage().contains("Not Found")); } @Test diff --git a/core/src/main/java/it/pagopa/selfcare/external_api/core/UserServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/external_api/core/UserServiceImpl.java index a9d5782f..078b3210 100644 --- a/core/src/main/java/it/pagopa/selfcare/external_api/core/UserServiceImpl.java +++ b/core/src/main/java/it/pagopa/selfcare/external_api/core/UserServiceImpl.java @@ -17,6 +17,7 @@ import java.time.ZoneId; import java.util.*; +import java.util.stream.Collectors; import static it.pagopa.selfcare.external_api.model.user.User.Fields.*; @@ -167,16 +168,19 @@ public List getOnboardedInstitutionsDetails(String use institutions.forEach(institution -> { List onboardedInstitutionResponse = msCoreConnector.getInstitutionDetails(institution.getInstitutionId()); - onboardedInstitutionResponse.stream() + onboardedInstitutionsInfo.addAll(onboardedInstitutionResponse.stream() .filter(onboardedInstitution -> onboardedInstitution.getId().equals(institution.getInstitutionId())) + .filter(onboardedInstitutionInfo -> institution.getProducts().stream() + .anyMatch(onboardedProductResponse -> onboardedProductResponse.getProductId().equals(onboardedInstitutionInfo.getProductInfo().getId())) + ) .peek(onboardedInstitution -> { onboardedInstitution.getProductInfo().setRole(institution.getProducts().stream() .filter(product -> product.getProductId().equals(onboardedInstitution.getProductInfo().getId()) && product.getStatus().equals(onboardedInstitution.getProductInfo().getStatus())) .map(OnboardedProductResponse::getProductRole).findFirst().orElse(null)); onboardedInstitution.setUserMailUuid(institution.getUserMailUuid()); - }); - onboardedInstitutionsInfo.addAll(onboardedInstitutionResponse); + }) + .toList()); }); return onboardedInstitutionsInfo;