Skip to content

Commit

Permalink
hotfix: limit result post search users (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
manuraf committed Apr 23, 2024
1 parent 41ca4c4 commit f1688b1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr_ms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand Down Expand Up @@ -167,16 +168,19 @@ public List<OnboardedInstitutionInfo> getOnboardedInstitutionsDetails(String use

institutions.forEach(institution -> {
List<OnboardedInstitutionInfo> 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;
Expand Down

0 comments on commit f1688b1

Please sign in to comment.