Skip to content

Commit

Permalink
[SELC-5887] fix user data for fd events
Browse files Browse the repository at this point in the history
  • Loading branch information
flaminiaScarciofolo committed Oct 30, 2024
1 parent ddfd593 commit ff3894f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.pagopa.selfcare.user.event.mapper;

import com.microsoft.applicationinsights.web.dependencies.apachecommons.lang3.StringUtils;
import it.pagopa.selfcare.user.UserUtils;
import it.pagopa.selfcare.user.event.entity.UserInstitution;
import it.pagopa.selfcare.user.model.*;
Expand All @@ -10,9 +11,7 @@
import org.openapi.quarkus.user_registry_json.model.UserResource;

import javax.swing.text.html.Option;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.*;

@Mapper(componentModel = "cdi", imports = UUID.class)
public interface NotificationMapper {
Expand All @@ -36,10 +35,18 @@ default String toUniqueIdNotification(UserInstitution userInstitution, Onboarded
@Mapping(target = "product", source = "product.productId")
@Mapping(target = "createdAt", source = "product.createdAt")
@Mapping(target = "updatedAt", expression = "java((null == product.getUpdatedAt()) ? product.getCreatedAt() : product.getUpdatedAt())")
@Mapping(target = "user", expression = "java(mapUser(userResource, userInstitutionChanged.getUserMailUuid(), product))")
@Mapping(target = "user", expression = "java(mapUserForFD(userResource, product))")
@Mapping(target = "type", source = "type")
FdUserNotificationToSend toFdUserNotificationToSend(UserInstitution userInstitutionChanged, OnboardedProduct product, UserResource userResource, NotificationUserType type);

@Named("mapUserForFD")
default UserToNotify mapUserForFD(UserResource userResource,OnboardedProduct onboardedProduct) {
UserToNotify userToNotify = new UserToNotify();
userToNotify.setUserId(Optional.ofNullable(userResource.getId()).map(UUID::toString).orElse(null));
userToNotify.setRoles(StringUtils.isNotBlank(onboardedProduct.getProductRole()) ? List.of(onboardedProduct.getProductRole()) : Collections.emptyList());
userToNotify.setRole(Optional.ofNullable(onboardedProduct.getRole()).map(Enum::name).orElse(null));
return userToNotify;
}

@Named("mapUser")
default UserToNotify mapUser(UserResource userResource, String userMailUuid, OnboardedProduct onboardedProduct) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.openapi.quarkus.user_registry_json.model.WorkContactResource;

import static org.junit.jupiter.api.Assertions.*;

import java.util.List;
import java.util.Map;
import java.util.UUID;

Expand Down Expand Up @@ -38,6 +40,21 @@ void mapUser_withValidData_shouldMapFieldsCorrectly() {
assertEquals(OnboardedProductState.ACTIVE, result.getRelationshipStatus());
}

@Test
void mapUserForFdTest() {
UserResource userResource = new UserResource();
userResource.setId(UUID.randomUUID());
OnboardedProduct onboardedProduct = new OnboardedProduct();
onboardedProduct.setProductRole("Admin");
onboardedProduct.setRole(PartyRole.MANAGER);

UserToNotify result = new NotificationMapperImpl().mapUserForFD(userResource, onboardedProduct);

assertEquals(userResource.getId().toString(), result.getUserId());
assertEquals(List.of("Admin"), result.getRoles());
assertEquals("MANAGER", result.getRole());
}

@Test
void mapUser_withNullFields_shouldHandleNullValues() {
UserResource userResource = new UserResource();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package it.pagopa.selfcare.user.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import it.pagopa.selfcare.user.model.constants.OnboardedProductState;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.eclipse.microprofile.openapi.annotations.media.Schema;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class UserToNotify {

private String userId;
Expand All @@ -18,6 +22,7 @@ public class UserToNotify {
@Schema(description = "Available values: MANAGER, DELEGATE, SUB_DELEGATE, OPERATOR, ADMIN_EA")
private String role;
private String productRole;
private List<String> roles;
private OnboardedProductState relationshipStatus;

}

0 comments on commit ff3894f

Please sign in to comment.