Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SELC-5757] Feat: Removed old code on UserV2ServiceImpl #494

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading