diff --git a/apps/pom.xml b/apps/pom.xml index 79327159..e7f3bc5e 100644 --- a/apps/pom.xml +++ b/apps/pom.xml @@ -21,12 +21,12 @@ it.pagopa.selfcare onboarding-sdk-common - 0.2.0 + 0.3.0 it.pagopa.selfcare onboarding-sdk-product - 0.2.0 + 0.3.0 it.pagopa.selfcare diff --git a/apps/user-ms/src/main/docs/openapi.json b/apps/user-ms/src/main/docs/openapi.json index 18d6eb02..203722f4 100644 --- a/apps/user-ms/src/main/docs/openapi.json +++ b/apps/user-ms/src/main/docs/openapi.json @@ -224,7 +224,7 @@ "tags" : [ "Institution" ], "summary" : "Retrieve users with optional filters", "description" : "Fetches a list of users associated with a specific institution, applying optional filters such as userId, roles, states, products, and productRoles. This allows for flexible querying based on various user attributes and statuses.", - "operationId" : "retrieveUsers", + "operationId" : "retrieveUserInstitutions", "parameters" : [ { "name" : "institutionId", "in" : "path", diff --git a/apps/user-ms/src/main/docs/openapi.yaml b/apps/user-ms/src/main/docs/openapi.yaml index 3173d723..04eee396 100644 --- a/apps/user-ms/src/main/docs/openapi.yaml +++ b/apps/user-ms/src/main/docs/openapi.yaml @@ -169,7 +169,7 @@ paths: description: "Fetches a list of users associated with a specific institution,\ \ applying optional filters such as userId, roles, states, products, and productRoles.\ \ This allows for flexible querying based on various user attributes and statuses." - operationId: retrieveUsers + operationId: retrieveUserInstitutions parameters: - name: institutionId in: path diff --git a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/controller/InstitutionController.java b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/controller/InstitutionController.java index c211a91e..f0eaa5be 100644 --- a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/controller/InstitutionController.java +++ b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/controller/InstitutionController.java @@ -63,7 +63,7 @@ public Multi getInstitutionUsers(@PathParam(value = "instit @GET @Path(value = "/{institutionId}/user-institutions") @Produces(MediaType.APPLICATION_JSON) - public Multi retrieveUsers(@PathParam(value = "institutionId") String institutionId, + public Multi retrieveUserInstitutions(@PathParam(value = "institutionId") String institutionId, @QueryParam(value = "userId") String userId, @QueryParam(value = "roles") List roles, @QueryParam(value = "states") List states, diff --git a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/mapper/UserMapper.java b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/mapper/UserMapper.java index 6b0f0c71..5c6027b1 100644 --- a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/mapper/UserMapper.java +++ b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/mapper/UserMapper.java @@ -14,7 +14,12 @@ import org.mapstruct.Mapping; import org.mapstruct.Named; import org.mapstruct.factory.Mappers; -import org.openapi.quarkus.user_registry_json.model.*; +import org.openapi.quarkus.user_registry_json.model.CertifiableFieldResourceOfstring; +import org.openapi.quarkus.user_registry_json.model.MutableUserFieldsDto; +import org.openapi.quarkus.user_registry_json.model.UserResource; +import org.openapi.quarkus.user_registry_json.model.WorkContactResource; +import org.openapi.quarkus.user_registry_json.model.SaveUserDto; +import org.openapi.quarkus.user_registry_json.model.CertifiableFieldResourceOfLocalDate; import java.time.LocalDate; import java.util.*; diff --git a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserNotificationServiceImpl.java b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserNotificationServiceImpl.java index 180c8f32..56452d61 100644 --- a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserNotificationServiceImpl.java +++ b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserNotificationServiceImpl.java @@ -7,6 +7,7 @@ import io.smallrye.mutiny.infrastructure.Infrastructure; import it.pagopa.selfcare.product.entity.Product; import it.pagopa.selfcare.product.entity.ProductRole; +import it.pagopa.selfcare.product.utils.ProductUtils; import it.pagopa.selfcare.user.client.EventHubRestClient; import it.pagopa.selfcare.user.conf.CloudTemplateLoader; import it.pagopa.selfcare.user.entity.UserInstitution; @@ -100,22 +101,24 @@ public Uni sendCreateUserNotification(String institutionDescription, List< .onItem().invoke(() -> log.debug("sendCreateNotification end")); } - private Map buildCreateEmailDataModel(LoggedUser loggedUser, Product product, String institutionDescription, List roleLabels) { + private Map buildCreateEmailDataModel(LoggedUser loggedUser, Product product, String institutionDescription, List productRoleCodes) { Map dataModel = new HashMap<>(); dataModel.put("requesterName", Optional.ofNullable(loggedUser.getName()).orElse("")); dataModel.put("requesterSurname", Optional.ofNullable(loggedUser.getFamilyName()).orElse("")); dataModel.put("productName", Optional.ofNullable(product.getTitle()).orElse("")); dataModel.put("institutionName", Optional.ofNullable(institutionDescription).orElse("")); - if (roleLabels.size() > 1) { + if (productRoleCodes.size() > 1) { List roleLabel = new ArrayList<>(); - if (CollectionUtils.isNotEmpty(product.getRoleMappings())) { - roleLabel = product.getRoleMappings().values().stream() + if (CollectionUtils.isNotEmpty(product.getAllRoleMappings())) { + roleLabel = product.getAllRoleMappings().values().stream() + .flatMap(List::stream) .filter(productRoleInfo -> !CollectionUtils.isNullOrEmpty(productRoleInfo.getRoles())) .flatMap(productRoleInfo -> productRoleInfo.getRoles().stream() - .filter(productRole -> roleLabels.contains(productRole.getCode()))) + .filter(productRole -> productRoleCodes.contains(productRole.getCode()))) .map(ProductRole::getLabel) + .distinct() .toList(); } @@ -123,7 +126,7 @@ private Map buildCreateEmailDataModel(LoggedUser loggedUser, Pro roleLabel = List.of("no_role_found"); } - dataModel.put("productRoles", roleLabel.stream().limit(roleLabels.size() - 1L) + dataModel.put("productRoles", roleLabel.stream().limit(productRoleCodes.size() - 1L) .collect(Collectors.joining(", "))); if(roleLabel.size() > 1) { dataModel.put("lastProductRole", roleLabel.get(roleLabel.size() - 1)); @@ -131,10 +134,11 @@ private Map buildCreateEmailDataModel(LoggedUser loggedUser, Pro } else { String roleLabel = "no_role_found"; - if (CollectionUtils.isNotEmpty(product.getRoleMappings())) { - roleLabel = product.getRoleMappings().values().stream() + if (CollectionUtils.isNotEmpty(product.getAllRoleMappings())) { + roleLabel = product.getAllRoleMappings().values().stream() + .flatMap(List::stream) .flatMap(productRoleInfo -> productRoleInfo.getRoles().stream()) - .filter(productRole -> productRole.getCode().equals(roleLabels.get(0))) + .filter(productRole -> productRole.getCode().equals(productRoleCodes.get(0))) .map(ProductRole::getLabel) .findAny() .orElse("no_role_found"); @@ -150,12 +154,13 @@ private Map buildEmailDataModel(UserInstitution institution, Pro && (StringUtils.isBlank(givenProductRole) || StringUtils.equals(p.getProductRole(), givenProductRole))).findFirst(); Optional roleLabel = Optional.empty(); - if (productDb.isPresent() && CollectionUtils.isNotEmpty(product.getRoleMappings())) { - roleLabel = product.getRoleMappings().values().stream() - .filter(productRoleInfo -> !CollectionUtils.isNullOrEmpty(productRoleInfo.getRoles())) - .flatMap(productRoleInfo -> productRoleInfo.getRoles().stream()) - .filter(productRole -> productRole.getCode().equals(productDb.get().getProductRole())) - .map(ProductRole::getLabel).findAny(); + if (productDb.isPresent() ) { + try { + ProductRole productRole = ProductUtils.getProductRole(productDb.get().getProductRole(), + productDb.get().getRole(), + product); + roleLabel = Optional.ofNullable(productRole.getLabel()); + } catch (IllegalArgumentException ignored) { } } Map dataModel = new HashMap<>(); diff --git a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserRegistryService.java b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserRegistryService.java index 5b5c8dc8..d4f103d9 100644 --- a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserRegistryService.java +++ b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserRegistryService.java @@ -3,13 +3,17 @@ import io.smallrye.mutiny.Uni; import it.pagopa.selfcare.user.entity.UserInstitution; import it.pagopa.selfcare.user.model.UpdateUserRequest; -import org.openapi.quarkus.user_registry_json.model.*; +import org.openapi.quarkus.user_registry_json.model.SaveUserDto; +import org.openapi.quarkus.user_registry_json.model.UserId; +import org.openapi.quarkus.user_registry_json.model.UserResource; +import org.openapi.quarkus.user_registry_json.model.UserSearchDto; +import org.openapi.quarkus.user_registry_json.model.MutableUserFieldsDto; import java.util.List; public interface UserRegistryService { Uni> updateUserRegistry(UpdateUserRequest updateUserRequest, String userId, String institutionId); - Uni findByIdUsingGET( String fl, String id); + Uni findByIdUsingGET(String fl, String id); Uni saveUsingPATCH(SaveUserDto saveUserDto); Uni searchUsingPOST(String fl, UserSearchDto userSearchDto); Uni updateUsingPATCH(String id, MutableUserFieldsDto mutableUserFieldsDto ); diff --git a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserRegistryServiceImpl.java b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserRegistryServiceImpl.java index 656b4823..0e93c13d 100644 --- a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserRegistryServiceImpl.java +++ b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserRegistryServiceImpl.java @@ -6,9 +6,6 @@ import it.pagopa.selfcare.user.entity.filter.UserInstitutionFilter; import it.pagopa.selfcare.user.mapper.UserMapper; import it.pagopa.selfcare.user.model.UpdateUserRequest; -import it.pagopa.selfcare.user.model.UserNotificationToSend; -import it.pagopa.selfcare.user.model.constants.QueueEvent; -import it.pagopa.selfcare.user.util.UserUtils; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import jakarta.ws.rs.WebApplicationException; @@ -19,7 +16,11 @@ import org.eclipse.microprofile.rest.client.inject.RestClient; import org.gradle.internal.impldep.org.apache.commons.lang.StringUtils; import org.openapi.quarkus.user_registry_json.api.UserApi; -import org.openapi.quarkus.user_registry_json.model.*; +import org.openapi.quarkus.user_registry_json.model.MutableUserFieldsDto; +import org.openapi.quarkus.user_registry_json.model.SaveUserDto; +import org.openapi.quarkus.user_registry_json.model.UserId; +import org.openapi.quarkus.user_registry_json.model.UserResource; +import org.openapi.quarkus.user_registry_json.model.UserSearchDto; import java.time.Duration; import java.util.*; @@ -35,23 +36,21 @@ public class UserRegistryServiceImpl implements UserRegistryService { private static final String USERS_FIELD_LIST_WITHOUT_FISCAL_CODE = "name,familyName,email,workContacts"; private final UserInstitutionService userInstitutionService; - private final UserUtils userUtils; - private final UserNotificationService userNotificationService; private final UserMapper userMapper; @ConfigProperty(name = "user-ms.retry.min-backoff") - private Integer retryMinBackOff; + Integer retryMinBackOff; @ConfigProperty(name = "user-ms.retry.max-backoff") - private Integer retryMaxBackOff; + Integer retryMaxBackOff; @ConfigProperty(name = "user-ms.retry") - private Integer maxRetry; + Integer maxRetry; @RestClient @Inject - private UserApi userRegistryApi; + UserApi userRegistryApi; @Override public Uni findByIdUsingGET(String fl, String id) { @@ -107,12 +106,12 @@ public Uni> updateUserRegistry(UpdateUserRequest updateUse .onItem().ifNotNull().invoke(() -> log.debug("UserInstitution founded for userId: {} and institutionId: {}", userId, institutionId))) .asTuple() .onItem().transformToMulti(tuple -> findMailUuidAndUpdateUserRegistry(tuple.getItem1(), updateUserRequest) - .onItem().transformToMulti(uuidMail -> updateUserInstitution(tuple.getItem1(), tuple.getItem2(), uuidMail))) + .onItem().transformToMulti(uuidMail -> updateUserInstitution(tuple.getItem2(), uuidMail))) .collect().asList() .onItem().invoke(items -> log.trace("update {} users on userRegistry", items.size())); } - private Multi updateUserInstitution(UserResource userResource, List userInstitutions, String mailUuid) { + private Multi updateUserInstitution(List userInstitutions, String mailUuid) { return Multi.createFrom().iterable(userInstitutions.stream() .peek(userInstitution -> userInstitution.setUserMailUuid(mailUuid)) .toList())