Skip to content

Commit

Permalink
Added method to format query parameter list and fixed error in status…
Browse files Browse the repository at this point in the history
… parameter's name
  • Loading branch information
[email protected] authored and [email protected] committed Jan 26, 2024
1 parent 794e066 commit 42e2dde
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 63 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public Multi<UserProductResponse> getInstitutionUsers(@PathParam(value = "instit
@Produces(MediaType.APPLICATION_JSON)
public Multi<UserInstitutionResponse> retrieveUsers(@PathParam(value = "institutionId") String institutionId,
@QueryParam(value = "userId") String userId,
@QueryParam(value = "roles") List<PartyRole> roles,
@QueryParam(value = "roles") List<OnboardedProductState> states,
@QueryParam(value = "roles") List<String> roles,
@QueryParam(value = "states") List<String> states,
@QueryParam(value = "products") List<String> products,
@QueryParam(value = "productRoles") List<String> productRoles) {
return userService.findAllUserInstitutions(institutionId, userId, roles, states, products, productRoles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public interface UserService {
Uni<UserResource> retrievePerson(String userId, String productId, String institutionId);
Multi<UserInstitutionResponse> findAllUserInstitutions(String institutionId,
String userId,
List<PartyRole> roles,
List<OnboardedProductState> states,
List<String> roles,
List<String> states,
List<String> products,
List<String> productRoles);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import it.pagopa.selfcare.user.constant.OnboardedProductState;
import it.pagopa.selfcare.user.controller.response.UserInstitutionResponse;
import it.pagopa.selfcare.user.controller.response.UserProductResponse;
import it.pagopa.selfcare.user.entity.UserInstitution;
Expand All @@ -12,7 +10,6 @@
import it.pagopa.selfcare.user.exception.ResourceNotFoundException;
import it.pagopa.selfcare.user.mapper.OnboardedProductMapper;
import it.pagopa.selfcare.user.mapper.UserInstitutionMapper;
import it.pagopa.selfcare.user.util.QueryUtils;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import lombok.RequiredArgsConstructor;
Expand All @@ -25,11 +22,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.*;

import static it.pagopa.selfcare.user.constant.CustomError.USER_NOT_FOUND_ERROR;

import java.util.*;
import static it.pagopa.selfcare.user.util.GeneralUtils.formatQueryParameterList;

@RequiredArgsConstructor
@ApplicationScoped
Expand All @@ -44,8 +40,6 @@ public class UserServiceImpl implements UserService {
private static final String USERS_WORKS_FIELD_LIST = "fiscalCode,familyName,email,name,workContacts";
private static final String WORK_CONTACTS = "workContacts";
private static final Logger log = LoggerFactory.getLogger(UserServiceImpl.class);
@Inject
private QueryUtils queryUtils;

@Override
public Uni<List<String>> getUsersEmails(String institutionId, String productId) {
Expand Down Expand Up @@ -93,8 +87,8 @@ public Uni<UserResource> retrievePerson(String userId, String productId, String
@Override
public Multi<UserInstitutionResponse> findAllUserInstitutions(String institutionId,
String userId,
List<PartyRole> roles,
List<OnboardedProductState> states,
List<String> roles,
List<String> states,
List<String> products,
List<String> productRoles) {
var userInstitutionFilters = constructUserInstitutionFilterMap(institutionId, userId);
Expand Down Expand Up @@ -128,14 +122,14 @@ private Map<String, Object> constructUserInstitutionFilterMap(String institution
}

private Map<String, Object> constructOnboardedProductFilterMap(List<String> products,
List<OnboardedProductState> states,
List<PartyRole> roles,
List<String> states,
List<String> roles,
List<String> productRoles) {
return OnboardedProductFilter.builder()
.productId(products)
.role(roles)
.status(states)
.productRole(productRoles)
.productId(formatQueryParameterList(products))
.role(formatQueryParameterList(roles))
.status(formatQueryParameterList(states))
.productRole(formatQueryParameterList(productRoles))
.build()
.constructMap();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package it.pagopa.selfcare.user.util;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

public class GeneralUtils {

private static final String DELIMITER = ",";

public static List<String> formatQueryParameterList(List<String> list) {
if(Objects.nonNull(list) && list.size() == 1 && list.get(0).contains(DELIMITER)) {
return Arrays.asList(list.get(0).split(DELIMITER));
}
return list;
}
}

0 comments on commit 42e2dde

Please sign in to comment.