Skip to content

Commit

Permalink
[SELC-5476] Feat: Added user mapping for aggregate users (#489)
Browse files Browse the repository at this point in the history
  • Loading branch information
flaminiaScarciofolo authored Sep 18, 2024
1 parent 8fe35fd commit 57cc1c3
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class AggregateInstitution {
private String zipCode;
private String originId;
private Origin origin;
private List<User> users;

public String getTaxCode() {
return taxCode;
Expand All @@ -27,6 +28,10 @@ public void setTaxCode(String taxCode) {
this.taxCode = taxCode;
}

public List<User> getUsers() {return users;}

public void setUsers(List<User> users) {this.users = users;}

public String getSubunitCode() {
return subunitCode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
import it.pagopa.selfcare.onboarding.entity.AggregateInstitution;
import it.pagopa.selfcare.onboarding.entity.Institution;
import it.pagopa.selfcare.onboarding.entity.Onboarding;
import it.pagopa.selfcare.onboarding.entity.User;

import org.apache.commons.collections4.CollectionUtils;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

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

@Mapper(componentModel = "cdi")
Expand All @@ -20,6 +24,7 @@ public interface OnboardingMapper {
Onboarding mapToOnboarding(OnboardingAggregateOrchestratorInput input);

@Mapping(target = "aggregate", expression = "java(mapFromAggregateInstitution(aggregateInstitution))")
@Mapping(target = "users", expression = "java(mapAggregateUsers(onboarding, aggregateInstitution))")
OnboardingAggregateOrchestratorInput mapToOnboardingAggregateOrchestratorInput(Onboarding onboarding, AggregateInstitution aggregateInstitution);

/**
Expand All @@ -36,5 +41,13 @@ default Institution mapInstitution(Institution aggregate, Institution institutio
return aggregate;
}

@Named("mapAggregateUsers")
default List<User> mapAggregateUsers(Onboarding onboarding, AggregateInstitution aggregateInstitution) {
if (Objects.nonNull(aggregateInstitution) && !CollectionUtils.isEmpty(aggregateInstitution.getUsers())) {
return aggregateInstitution.getUsers();
}
return onboarding.getUsers();
}

Institution mapFromAggregateInstitution(AggregateInstitution aggregateInstitution);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package it.pagopa.selfcare.onboarding;

import io.quarkus.test.junit.QuarkusTest;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import it.pagopa.selfcare.onboarding.dto.OnboardingAggregateOrchestratorInput;
import it.pagopa.selfcare.onboarding.entity.AggregateInstitution;
import it.pagopa.selfcare.onboarding.entity.Onboarding;
import it.pagopa.selfcare.onboarding.entity.User;
import it.pagopa.selfcare.onboarding.mapper.OnboardingMapperImpl;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.Collections;
import java.util.List;

@QuarkusTest
class OnboardingMapperTest {

@Inject
private OnboardingMapperImpl onboardingMapper;

@Test
void mapToOnboardingAggregateOrchestratorInputTestWithAggregateUsers(){
Onboarding onboarding = new Onboarding();
onboarding.setId("example");
onboarding.setProductId("productId");
User user = new User();
user.setId("aggregatorUser");
user.setRole(PartyRole.MANAGER);
user.setProductRole("aggregatorProductRole");
onboarding.setUsers(List.of(user));

User user2 = new User();
user2.setId("aggregateUser");
user2.setRole(PartyRole.MANAGER);
user2.setProductRole("aggregateProductRole");
AggregateInstitution aggregateInstitution = new AggregateInstitution();
aggregateInstitution.setUsers(List.of(user2));
onboarding.setAggregates(List.of(aggregateInstitution));

OnboardingAggregateOrchestratorInput response = onboardingMapper.mapToOnboardingAggregateOrchestratorInput(onboarding, aggregateInstitution);
Assertions.assertEquals(1, response.getUsers().size());
Assertions.assertEquals("aggregateUser", response.getUsers().get(0).getId());
Assertions.assertEquals(PartyRole.MANAGER, response.getUsers().get(0).getRole());
Assertions.assertEquals("aggregateProductRole", response.getUsers().get(0).getProductRole());

}

@Test
void mapToOnboardingAggregateOrchestratorInputTestWithoutAggregatesUser(){
Onboarding onboarding = new Onboarding();
onboarding.setId("example");
onboarding.setProductId("productId");
User user = new User();
user.setId("aggregatorUser");
user.setRole(PartyRole.MANAGER);
user.setProductRole("aggregatorProductRole");
onboarding.setUsers(List.of(user));

AggregateInstitution aggregateInstitution = new AggregateInstitution();
aggregateInstitution.setUsers(null);
onboarding.setAggregates(List.of(aggregateInstitution));

OnboardingAggregateOrchestratorInput response = onboardingMapper.mapToOnboardingAggregateOrchestratorInput(onboarding, aggregateInstitution);
Assertions.assertEquals(1, response.getUsers().size());
Assertions.assertEquals("aggregatorUser", response.getUsers().get(0).getId());
Assertions.assertEquals(PartyRole.MANAGER, response.getUsers().get(0).getRole());
Assertions.assertEquals("aggregatorProductRole", response.getUsers().get(0).getProductRole());
}

@Test
void mapToOnboardingAggregateOrchestratorInputTestWithAggregatesUserEmptyList(){
Onboarding onboarding = new Onboarding();
onboarding.setId("example");
onboarding.setProductId("productId");
User user = new User();
user.setId("aggregatorUser");
user.setRole(PartyRole.MANAGER);
user.setProductRole("aggregatorProductRole");
onboarding.setUsers(List.of(user));

AggregateInstitution aggregateInstitution = new AggregateInstitution();
aggregateInstitution.setUsers(Collections.emptyList());
onboarding.setAggregates(List.of(aggregateInstitution));

OnboardingAggregateOrchestratorInput response = onboardingMapper.mapToOnboardingAggregateOrchestratorInput(onboarding, aggregateInstitution);
Assertions.assertEquals(1, response.getUsers().size());
Assertions.assertEquals("aggregatorUser", response.getUsers().get(0).getId());
Assertions.assertEquals(PartyRole.MANAGER, response.getUsers().get(0).getRole());
Assertions.assertEquals("aggregatorProductRole", response.getUsers().get(0).getProductRole());
}
}

0 comments on commit 57cc1c3

Please sign in to comment.