From 9e4890357e6f924e6819b11f0d1d811b8c777dd9 Mon Sep 17 00:00:00 2001 From: Giulia Tremolada Date: Mon, 2 Dec 2024 10:26:50 +0100 Subject: [PATCH] modify toUserNotificationToSend mapper to retrieve mail from workContacts --- .../user/mapper/NotificationMapper.java | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/mapper/NotificationMapper.java b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/mapper/NotificationMapper.java index e4ba85f3..03d1746d 100644 --- a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/mapper/NotificationMapper.java +++ b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/mapper/NotificationMapper.java @@ -7,6 +7,7 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Named; +import org.openapi.quarkus.user_registry_json.model.CertifiableFieldResourceOfstring; import org.openapi.quarkus.user_registry_json.model.UserResource; import java.util.Collections; @@ -21,13 +22,7 @@ public interface NotificationMapper { @Mapping(target = "productId", source = "product.productId") @Mapping(target = "createdAt", source = "product.createdAt") @Mapping(target = "updatedAt", expression = "java((null == product.getUpdatedAt()) ? product.getCreatedAt() : product.getUpdatedAt())") - @Mapping(target = "user.role", source = "product.role") - @Mapping(target = "user.productRole", source = "product.productRole") - @Mapping(target = "user.relationshipStatus", source = "product.status") - @Mapping(target = "user.userId", source = "userResource.id", ignore = true) - @Mapping(target = "user.name", source = "userResource.name.value") - @Mapping(target = "user.familyName", source = "userResource.familyName.value") - @Mapping(target = "user.email", source = "userResource.email.value") + @Mapping(target = "user", expression = "java(mapUser(userResource, userInstitution.getUserMailUuid(), product))") @Mapping(target = "id", expression = "java(toUniqueIdNotification(userInstitution, product))") @Mapping(target = "eventType", expression = "java(it.pagopa.selfcare.user.model.constants.QueueEvent.UPDATE)") UserNotificationToSend toUserNotificationToSend(UserInstitution userInstitution, it.pagopa.selfcare.user.model.OnboardedProduct product, UserResource userResource); @@ -54,4 +49,25 @@ default UserToNotify mapUserForFD(String userId, OnboardedProduct onboardedProdu userToNotify.setRole(Optional.ofNullable(onboardedProduct.getRole()).map(Enum::name).orElse(null)); return userToNotify; } + + @Named("mapUser") + default UserToNotify mapUser(UserResource userResource, String userMailUuid, OnboardedProduct onboardedProduct) { + UserToNotify userToNotify = new UserToNotify(); + userToNotify.setUserId(Optional.ofNullable(userResource.getId()).map(UUID::toString).orElse(null)); + userToNotify.setName(Optional.ofNullable(userResource.getName()).map(CertifiableFieldResourceOfstring::getValue).orElse(null)); + userToNotify.setFamilyName(Optional.ofNullable(userResource.getFamilyName()).map(CertifiableFieldResourceOfstring::getValue).orElse(null)); + userToNotify.setEmail(Optional.ofNullable(userMailUuid).map(mailUuid -> retrieveMailFromWorkContacts(userResource, mailUuid)).orElse(null)); + userToNotify.setProductRole(onboardedProduct.getProductRole()); + userToNotify.setRole(Optional.ofNullable(onboardedProduct.getRole()).map(Enum::name).orElse(null)); + userToNotify.setRelationshipStatus(onboardedProduct.getStatus()); + return userToNotify; + } + + default String retrieveMailFromWorkContacts(UserResource userResource, String userMailUuid) { + return Optional.ofNullable(userResource.getWorkContacts()) + .flatMap(stringWorkContactResourceMap -> Optional.ofNullable(stringWorkContactResourceMap.get(userMailUuid)) + .flatMap(workContactResource -> Optional.ofNullable(workContactResource.getEmail()) + .map(CertifiableFieldResourceOfstring::getValue))) + .orElse(null); + } }