Skip to content

Commit

Permalink
[SELC-5757] Feat: Removed old code on UserV2ServiceImpl (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
flaminiaScarciofolo authored Nov 7, 2024
1 parent 7a1d02d commit 2c7d06e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@
import it.pagopa.selfcare.dashboard.connector.model.product.mapper.ProductMapper;
import it.pagopa.selfcare.dashboard.connector.model.user.*;
import it.pagopa.selfcare.dashboard.core.exception.InvalidOnboardingStatusException;
import it.pagopa.selfcare.dashboard.core.exception.InvalidProductRoleException;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import it.pagopa.selfcare.product.entity.PHASE_ADDITION_ALLOWED;
import it.pagopa.selfcare.product.entity.Product;
import it.pagopa.selfcare.product.entity.ProductRoleInfo;
import it.pagopa.selfcare.product.utils.ProductUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -171,27 +167,14 @@ private Institution verifyOnboardingStatus(String institutionId, String productI
* It maps each product role to a CreateUserDto.Role object, which includes the label and party role.
* To retrieve the party role, it uses the roleMappings of the product filtering by a white list of party roles (Only SUB_DELEGATE and OPERATOR are allowed
* as Role to be assigned to a user in add Users ProductRoles operation).
* If the party role is not valid, it throws an InvalidProductRoleException.
*/
private List<CreateUserDto.Role> retrieveRole(String productId, Set<String> productRoles, PartyRole partyRole) {
Product product = productsConnector.getProduct(productId);
return productRoles.stream().map(productRole -> {

CreateUserDto.Role role = new CreateUserDto.Role();
role.setProductRole(productRole);

role.setLabel(ProductMapper.getLabel(productRole, product.getRoleMappings(null)).orElse(null));

//TODO: https://pagopa.atlassian.net/browse/SELC-5757
if(Objects.isNull(partyRole)){
List<PartyRole> partyRoles = ProductUtils.validRolesByProductRole(product, PHASE_ADDITION_ALLOWED.DASHBOARD, productRole, null);
if(Objects.isNull(partyRoles) || partyRoles.isEmpty()){
throw new InvalidProductRoleException(String.format("Product role '%s' is not valid", productRole));
}
role.setPartyRole(partyRoles.get(0));
} else{
role.setPartyRole(partyRole);
}
role.setPartyRole(partyRole);
return role;
}).toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import it.pagopa.selfcare.dashboard.connector.model.institution.RelationshipState;
import it.pagopa.selfcare.dashboard.connector.model.user.*;
import it.pagopa.selfcare.dashboard.core.exception.InvalidOnboardingStatusException;
import it.pagopa.selfcare.dashboard.core.exception.InvalidProductRoleException;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import it.pagopa.selfcare.product.entity.PHASE_ADDITION_ALLOWED;
import it.pagopa.selfcare.product.entity.Product;
Expand All @@ -34,12 +33,11 @@
import java.util.*;

import static it.pagopa.selfcare.commons.utils.TestUtils.mockInstance;
import static it.pagopa.selfcare.onboarding.common.PartyRole.MANAGER;
import static it.pagopa.selfcare.onboarding.common.PartyRole.OPERATOR;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.verifyNoMoreInteractions;

@ExtendWith(MockitoExtension.class)
public class UserV2ServiceImplTest extends BaseServiceTest {
Expand Down Expand Up @@ -337,13 +335,13 @@ void addUserProductRoles_ok_withoutPartyRole() {
CreateUserDto.Role roleDto = new CreateUserDto.Role();
roleDto.setProductRole("operator");
roleDto.setLabel("operator");
roleDto.setPartyRole(PartyRole.OPERATOR);
roleDto.setPartyRole(OPERATOR);

when(msCoreConnectorMock.getInstitution(institutionId)).thenReturn(institution);
when(productsConnectorMock.getProduct(productId)).thenReturn(product);
doNothing().when(userApiConnectorMock).createOrUpdateUserByUserId(institution, productId, userId, List.of(roleDto));

userV2ServiceImpl.addUserProductRoles(institutionId, productId, userId, productRoles, null);
userV2ServiceImpl.addUserProductRoles(institutionId, productId, userId, productRoles, OPERATOR.name());

verify(userApiConnectorMock, times(1))
.createOrUpdateUserByUserId(institution, productId, userId, List.of(roleDto));
Expand Down Expand Up @@ -376,6 +374,7 @@ void createUsersByFiscalCode() {
UserToCreate userToCreate = new UserToCreate();
HashSet<String> productRoles = new HashSet<>();
productRoles.add(productRole);
userToCreate.setRole(PartyRole.MANAGER);
userToCreate.setProductRoles(productRoles);

Product product = getProduct();
Expand All @@ -390,7 +389,7 @@ void createUsersByFiscalCode() {
CreateUserDto.Role roleDto = new CreateUserDto.Role();
roleDto.setProductRole("operator");
roleDto.setLabel("operator");
roleDto.setPartyRole(PartyRole.OPERATOR);
roleDto.setPartyRole(MANAGER);


when(productsConnectorMock.getProduct(productId)).thenReturn(product);
Expand Down Expand Up @@ -481,7 +480,7 @@ private static Product getProduct() {
productRole.setCode("operator");
productRole.setLabel("operator");
productRoleInfoOperator.setRoles(List.of(productRole));
map.put(PartyRole.OPERATOR, productRoleInfoOperator);
map.put(OPERATOR, productRoleInfoOperator);

ProductRoleInfo productRoleInfoDelegate= new ProductRoleInfo();
productRoleInfoDelegate.setPhasesAdditionAllowed(List.of(PHASE_ADDITION_ALLOWED.DASHBOARD.value));
Expand Down

0 comments on commit 2c7d06e

Please sign in to comment.