Search in sources :

Example 6 with IdmRequestIdentityRoleFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter in project CzechIdMng by bcvsolutions.

the class ChangeIdentityPermissionTest method testAccessIsAddedForOwnerAndImplementerToSubprocesses.

@Test
public void testAccessIsAddedForOwnerAndImplementerToSubprocesses() {
    // reset approvers
    getHelper().setConfigurationValue(APPROVE_BY_USERMANAGER_ENABLE, false);
    getHelper().setConfigurationValue(APPROVE_BY_SECURITY_ENABLE, false);
    getHelper().setConfigurationValue(APPROVE_BY_MANAGER_ENABLE, false);
    getHelper().setConfigurationValue(APPROVE_BY_HELPDESK_ENABLE, false);
    // role with guarantees and critical 2 => approve by guarantee
    IdmRoleDto role = new IdmRoleDto();
    role.setCode(getHelper().createName());
    // default by configuration
    role.setPriority(2);
    IdmRoleDto roleOne = roleService.save(role);
    role = new IdmRoleDto();
    role.setCode(getHelper().createName());
    // default by configuration
    role.setPriority(2);
    IdmRoleDto roleTwo = roleService.save(role);
    // 
    IdmIdentityDto implementer = getHelper().createIdentity();
    IdmIdentityDto applicant = getHelper().createIdentity();
    IdmIdentityContractDto applicantContract = getHelper().getPrimeContract(applicant);
    IdmIdentityDto guaranteeOne = getHelper().createIdentity();
    IdmIdentityDto guaranteeTwo = getHelper().createIdentity();
    // 
    getHelper().createRoleGuarantee(roleOne, guaranteeOne);
    getHelper().createRoleGuarantee(roleTwo, guaranteeTwo);
    // 
    // login as implementer
    loginAsAdmin(implementer.getUsername());
    // 
    IdmRoleRequestDto request = createRoleRequest(applicant);
    request = roleRequestService.save(request);
    IdmConceptRoleRequestDto concept = createRoleConcept(roleOne, applicantContract, request);
    conceptRoleRequestService.save(concept);
    concept = createRoleConcept(roleTwo, applicantContract, request);
    conceptRoleRequestService.save(concept);
    roleRequestService.startRequestInternal(request.getId(), true);
    request = roleRequestService.get(request.getId());
    Assert.assertEquals(RoleRequestState.IN_PROGRESS, request.getState());
    IdmRequestIdentityRoleFilter requestIdentityRoleFilter = new IdmRequestIdentityRoleFilter();
    requestIdentityRoleFilter.setIncludeCandidates(true);
    requestIdentityRoleFilter.setRoleRequestId(request.getId());
    requestIdentityRoleFilter.setIdentityId(applicant.getId());
    List<IdmRequestIdentityRoleDto> requestIdentityRoles = requestIdentityRoleService.find(requestIdentityRoleFilter, null).getContent();
    Assert.assertEquals(2, requestIdentityRoles.size());
    Assert.assertTrue(requestIdentityRoles.stream().anyMatch(rir -> rir.getRole().equals(roleOne.getId()) && rir.getCandidates().size() == 1 && rir.getCandidates().iterator().next().getId().equals(guaranteeOne.getId())));
    Assert.assertTrue(requestIdentityRoles.stream().anyMatch(rir -> rir.getRole().equals(roleTwo.getId()) && rir.getCandidates().size() == 1 && rir.getCandidates().iterator().next().getId().equals(guaranteeTwo.getId())));
    // 
    // check applicant and implemented can read process instance
    getHelper().login(implementer);
    List<WorkflowProcessInstanceDto> processes = workflowProcessInstanceService.find(new WorkflowFilterDto(), null, IdmBasePermission.READ).getContent();
    Assert.assertEquals(3, processes.size());
    getHelper().login(applicant);
    Assert.assertEquals(3, workflowProcessInstanceService.find(new WorkflowFilterDto(), null, IdmBasePermission.READ).getTotalElements());
    getHelper().login(guaranteeOne);
    Assert.assertEquals(1, workflowProcessInstanceService.find(new WorkflowFilterDto(), null, IdmBasePermission.READ).getTotalElements());
    getHelper().login(guaranteeTwo);
    Assert.assertEquals(1, workflowProcessInstanceService.find(new WorkflowFilterDto(), null, IdmBasePermission.READ).getTotalElements());
    // 
    // test identity links are created (=> access added)
    processes.forEach(process -> {
        List<IdentityLink> links = runtimeService.getIdentityLinksForProcessInstance(process.getProcessInstanceId());
        Assert.assertTrue(links.stream().anyMatch(l -> l.getUserId().equals(implementer.getId().toString()) && l.getType().equals(IdentityLinkType.STARTER)));
        Assert.assertTrue(links.stream().anyMatch(l -> l.getUserId().equals(applicant.getId().toString()) && l.getType().equals(IdentityLinkType.OWNER)));
    });
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) ZonedDateTime(java.time.ZonedDateTime) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) Autowired(org.springframework.beans.factory.annotation.Autowired) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmRequestIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmRequestIdentityRoleService) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) After(org.junit.After) WorkflowTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowTaskInstanceService) Assert.fail(org.junit.Assert.fail) LoginService(eu.bcvsolutions.idm.core.security.api.service.LoginService) IdentityLink(org.activiti.engine.task.IdentityLink) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) Set(java.util.Set) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) RoleConfiguration(eu.bcvsolutions.idm.core.api.config.domain.RoleConfiguration) WorkflowHistoricProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) LocalDate(java.time.LocalDate) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) RoleRequestedByType(eu.bcvsolutions.idm.core.api.domain.RoleRequestedByType) IdmConfigurationService(eu.bcvsolutions.idm.core.api.service.IdmConfigurationService) IdentityLinkType(org.activiti.engine.task.IdentityLinkType) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) InitTestDataProcessor(eu.bcvsolutions.idm.core.model.event.processor.module.InitTestDataProcessor) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) WorkflowHistoricTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowHistoricTaskInstanceService) Before(org.junit.Before) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) WorkflowHistoricProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowHistoricProcessInstanceService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) IdmIncompatibleRoleService(eu.bcvsolutions.idm.core.api.service.IdmIncompatibleRoleService) HttpStatus(org.springframework.http.HttpStatus) Assert.assertNull(org.junit.Assert.assertNull) ChronoUnit(java.time.temporal.ChronoUnit) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) WorkflowHistoricTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) ResolvedIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto) IdmRequestIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter) IdmGroupPermission(eu.bcvsolutions.idm.core.security.api.domain.IdmGroupPermission) Assert(org.junit.Assert) IdmIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) IdentityLink(org.activiti.engine.task.IdentityLink) IdmRequestIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 7 with IdmRequestIdentityRoleFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter in project CzechIdMng by bcvsolutions.

the class DefaultIdmRequestIdentityRoleService method compileIdentityRolesWithConcepts.

/**
 * Find concepts for given identity-roles. If some exists (in given request),
 * then will be altered for concept metadata (operation, EAVs)
 *
 * @param requestIdentityRoles
 * @param identityRoles
 * @param filter
 * @param permission
 */
private void compileIdentityRolesWithConcepts(List<IdmRequestIdentityRoleDto> requestIdentityRoles, List<IdmIdentityRoleDto> identityRoles, IdmRequestIdentityRoleFilter filter, BasePermission... permission) {
    // Convert identity-roles to Set of IDs.
    Set<UUID> identityRoleIds = identityRoles.stream().map(IdmIdentityRoleDto::getId).collect(Collectors.toSet());
    // Find concepts by identity-roles IDs.
    IdmConceptRoleRequestFilter conceptFilter = new IdmConceptRoleRequestFilter();
    conceptFilter.setIdentityRoleIds(identityRoleIds);
    conceptFilter.setRoleRequestId(filter.getRoleRequestId());
    List<IdmConceptRoleRequestDto> conceptsForThisPage = conceptRoleService.find(conceptFilter, null, permission).getContent();
    // 
    conceptsForThisPage.stream().filter(// 
    concept -> ConceptRoleRequestOperation.ADD != concept.getOperation()).forEach(concept -> {
        // 
        IdmRequestIdentityRoleDto requestIdentityRoleWithConcept = // 
        requestIdentityRoles.stream().filter(requestIdentityRole -> requestIdentityRole.getIdentityRole() != null && requestIdentityRole.getIdentityRole().equals(concept.getIdentityRole()) && requestIdentityRole.getId().equals(requestIdentityRole.getIdentityRole())).findFirst().orElse(// 
        null);
        if (requestIdentityRoleWithConcept != null) {
            requestIdentityRoleWithConcept.setOperation(concept.getOperation());
            requestIdentityRoleWithConcept.setId(concept.getId());
            requestIdentityRoleWithConcept.setValidFrom(concept.getValidFrom());
            requestIdentityRoleWithConcept.setValidTill(concept.getValidTill());
            requestIdentityRoleWithConcept.setRoleRequest(concept.getRoleRequest());
            IdmFormInstanceDto formInstanceDto;
            // For updated identity-role replace EAVs from the concept
            if (ConceptRoleRequestOperation.UPDATE == concept.getOperation()) {
                // Check on change of values is made only on ended request! 'Original' value is current value and in audit it was confusing (only 'new' value is show now).
                formInstanceDto = conceptRoleService.getRoleAttributeValues(concept, !concept.getState().isTerminatedState());
                this.addEav(requestIdentityRoleWithConcept, formInstanceDto);
            }
        }
    });
}
Also used : IdmConceptRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter) IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) AbstractReadDtoService(eu.bcvsolutions.idm.core.api.service.AbstractReadDtoService) Autowired(org.springframework.beans.factory.annotation.Autowired) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) RoleBasePermission(eu.bcvsolutions.idm.core.security.api.domain.RoleBasePermission) IdmRequestIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmRequestIdentityRoleService) IdmConceptRoleRequest_(eu.bcvsolutions.idm.core.model.entity.IdmConceptRoleRequest_) AbstractBaseDtoService(eu.bcvsolutions.idm.core.rest.AbstractBaseDtoService) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) Pageable(org.springframework.data.domain.Pageable) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) Set(java.util.Set) PageRequest(org.springframework.data.domain.PageRequest) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) ContractBasePermission(eu.bcvsolutions.idm.core.security.api.domain.ContractBasePermission) PermissionUtils(eu.bcvsolutions.idm.core.security.api.utils.PermissionUtils) LocalDate(java.time.LocalDate) PageImpl(org.springframework.data.domain.PageImpl) IdmIdentityRole_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole_) RoleRequestedByType(eu.bcvsolutions.idm.core.api.domain.RoleRequestedByType) IdmRoleSystemService(eu.bcvsolutions.idm.core.api.service.IdmRoleSystemService) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ModelMapper(org.modelmapper.ModelMapper) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Service(org.springframework.stereotype.Service) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) IdmRoleSystemFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleSystemFilter) BaseFilter(eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) IdmConceptRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) InvalidFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.InvalidFormAttributeDto) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) UUID(java.util.UUID)

Example 8 with IdmRequestIdentityRoleFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter in project CzechIdMng by bcvsolutions.

the class ChangeIdentityPermissionTest method testFindCandidatesWithSubprocess.

@Test
public void testFindCandidatesWithSubprocess() {
    ZonedDateTime now = ZonedDateTime.now().truncatedTo(ChronoUnit.MILLIS);
    getHelper().waitForResult(null, 1, 1);
    // approve only by help desk
    configurationService.setValue(APPROVE_BY_USERMANAGER_ENABLE, "false");
    configurationService.setValue(APPROVE_BY_SECURITY_ENABLE, "false");
    configurationService.setValue(APPROVE_BY_MANAGER_ENABLE, "false");
    configurationService.setValue(APPROVE_BY_HELPDESK_ENABLE, "true");
    loginAsAdmin();
    // helpdesk role and identity
    IdmRoleDto helpdeskRole = getHelper().createRole();
    IdmIdentityDto helpdeskIdentity = getHelper().createIdentity();
    // add role directly
    getHelper().createIdentityRole(helpdeskIdentity, helpdeskRole);
    configurationService.setValue(APPROVE_BY_HELPDESK_ROLE, helpdeskRole.getCode());
    IdmIdentityDto identity = identityService.getByUsername(InitTestDataProcessor.TEST_USER_1);
    IdmIdentityDto guarantee = identityService.getByUsername(InitTestDataProcessor.TEST_USER_2);
    // Guarantee
    int priority = 500;
    IdmRoleDto adminRole = roleConfiguration.getAdminRole();
    adminRole.setPriority(priority);
    getHelper().createRoleGuarantee(adminRole, guarantee);
    adminRole = roleService.save(adminRole);
    configurationService.setValue(IdmRoleService.WF_BY_ROLE_PRIORITY_PREFIX + priority, APPROVE_ROLE_BY_MANAGER_KEY);
    IdmIdentityContractDto contract = getHelper().getPrimeContract(identity.getId());
    IdmRoleRequestDto request = createRoleRequest(identity);
    request = roleRequestService.save(request);
    IdmConceptRoleRequestDto concept = createRoleConcept(adminRole, contract, request);
    concept = conceptRoleRequestService.save(concept);
    IdmRequestIdentityRoleFilter requestIdentityRoleFilter = new IdmRequestIdentityRoleFilter();
    requestIdentityRoleFilter.setIncludeCandidates(true);
    requestIdentityRoleFilter.setRoleRequestId(request.getId());
    requestIdentityRoleFilter.setIdentityId(identity.getId());
    List<IdmRequestIdentityRoleDto> requestIdentityRoles = requestIdentityRoleService.find(requestIdentityRoleFilter, null).getContent();
    assertEquals(1, requestIdentityRoles.size());
    IdmRequestIdentityRoleDto requestIdentityRoleDto = requestIdentityRoles.get(0);
    assertNull(requestIdentityRoleDto.getCandidates());
    roleRequestService.startRequestInternal(request.getId(), true);
    request = roleRequestService.get(request.getId());
    assertEquals(RoleRequestState.IN_PROGRESS, request.getState());
    WorkflowFilterDto taskFilter = new WorkflowFilterDto();
    taskFilter.setCreatedAfter(now);
    taskFilter.setCandidateOrAssigned(securityService.getCurrentUsername());
    List<WorkflowTaskInstanceDto> tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
    assertEquals(0, tasks.size());
    Set<IdmIdentityDto> candidates = workflowProcessInstanceService.getApproversForProcess(request.getWfProcessId());
    assertEquals(1, candidates.size());
    candidates = workflowProcessInstanceService.getApproversForSubprocess(request.getWfProcessId());
    assertEquals(0, candidates.size());
    requestIdentityRoleFilter = new IdmRequestIdentityRoleFilter();
    requestIdentityRoleFilter.setIncludeCandidates(true);
    requestIdentityRoleFilter.setRoleRequestId(request.getId());
    requestIdentityRoleFilter.setIdentityId(identity.getId());
    requestIdentityRoles = requestIdentityRoleService.find(requestIdentityRoleFilter, null).getContent();
    assertEquals(1, requestIdentityRoles.size());
    requestIdentityRoleDto = requestIdentityRoles.get(0);
    assertNull(requestIdentityRoleDto.getCandidates());
    IdmRoleRequestFilter filter = new IdmRoleRequestFilter();
    filter.setIncludeApprovers(true);
    IdmRoleRequestDto requestDto = roleRequestService.get(request.getId(), filter);
    assertEquals(1, requestDto.getApprovers().size());
    // HELPDESK
    loginAsAdmin(helpdeskIdentity.getUsername());
    taskFilter.setCandidateOrAssigned(helpdeskIdentity.getUsername());
    checkAndCompleteOneTask(taskFilter, InitTestDataProcessor.TEST_USER_1, "approve");
    filter.setIncludeApprovers(false);
    requestDto = roleRequestService.get(request.getId(), filter);
    assertNull(requestDto.getApprovers());
    // Subprocess - approve by Manager
    request = roleRequestService.get(request.getId());
    loginAsAdmin(guarantee.getUsername());
    taskFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_USER_2);
    tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
    assertEquals(1, tasks.size());
    concept = conceptRoleRequestService.get(concept.getId());
    String conceptWf = concept.getWfProcessId();
    assertNotNull(conceptWf);
    assertNotNull(workflowProcessInstanceService.get(conceptWf));
    candidates = workflowProcessInstanceService.getApproversForProcess(request.getWfProcessId());
    assertEquals(1, candidates.size());
    IdmIdentityDto approversFromProcess = candidates.stream().findFirst().get();
    candidates = workflowProcessInstanceService.getApproversForSubprocess(request.getWfProcessId());
    assertEquals(1, candidates.size());
    IdmIdentityDto approversFromSubProcess = candidates.stream().findFirst().get();
    assertEquals(approversFromProcess.getId(), approversFromSubProcess.getId());
    requestIdentityRoleFilter = new IdmRequestIdentityRoleFilter();
    requestIdentityRoleFilter.setIncludeCandidates(true);
    requestIdentityRoleFilter.setRoleRequestId(request.getId());
    requestIdentityRoleFilter.setIdentityId(identity.getId());
    requestIdentityRoles = requestIdentityRoleService.find(requestIdentityRoleFilter, null).getContent();
    assertEquals(1, requestIdentityRoles.size());
    requestIdentityRoleDto = requestIdentityRoles.get(0);
    assertEquals(1, requestIdentityRoleDto.getCandidates().size());
    requestIdentityRoleFilter.setIncludeCandidates(false);
    requestIdentityRoles = requestIdentityRoleService.find(requestIdentityRoleFilter, null).getContent();
    assertEquals(1, requestIdentityRoles.size());
    requestIdentityRoleDto = requestIdentityRoles.get(0);
    assertNull(requestIdentityRoleDto.getCandidates());
    filter = new IdmRoleRequestFilter();
    filter.setIncludeApprovers(true);
    requestDto = roleRequestService.get(request.getId(), filter);
    assertEquals(1, requestDto.getApprovers().size());
    filter.setIncludeApprovers(false);
    requestDto = roleRequestService.get(request.getId(), filter);
    assertNull(requestDto.getApprovers());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmRequestIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter) ZonedDateTime(java.time.ZonedDateTime) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 9 with IdmRequestIdentityRoleFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter in project CzechIdMng by bcvsolutions.

the class DefaultIdmRequestIdentityRoleService method conceptsToRequestIdentityRoles.

/**
 * Converts concepts to request-identity-roles
 *
 * @param concepts
 * @param filter
 * @return
 */
private List<IdmRequestIdentityRoleDto> conceptsToRequestIdentityRoles(List<IdmConceptRoleRequestDto> concepts, IdmRequestIdentityRoleFilter filter) {
    List<IdmRequestIdentityRoleDto> results = Lists.newArrayList();
    if (concepts == null) {
        return results;
    }
    // Mark duplicates
    // TODO: Rewrite to query, this is very ineffective!!
    UUID identityId = filter.getIdentityId();
    LOG.debug(MessageFormat.format("Start searching duplicates for identity [{1}].", identityId));
    Assert.notNull(identityId, "Identity identifier is required.");
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findValidRoles(identityId, null).getContent();
    // Add to all identity roles form instance. For identity role can exists only
    // one form instance.
    identityRoles.forEach(identityRole -> {
        IdmFormInstanceDto formInstance = identityRoleService.getRoleAttributeValues(identityRole);
        if (formInstance != null) {
            identityRole.setEavs(Lists.newArrayList(formInstance));
        }
    });
    // Find potential duplicated concepts (only ADD and not in terminated state)
    List<IdmConceptRoleRequestDto> conceptsForMarkDuplicates = // 
    concepts.stream().filter(// 
    concept -> ConceptRoleRequestOperation.ADD == concept.getOperation()).filter(// 
    concept -> !concept.getState().isTerminatedState()).collect(// 
    Collectors.toList());
    roleRequestService.markDuplicates(conceptsForMarkDuplicates, identityRoles);
    // End mark duplicates
    LOG.debug(MessageFormat.format("End searching duplicates for identity [{1}].", identityId));
    concepts.forEach(concept -> {
        IdmRequestIdentityRoleDto requestIdentityRoleDto = conceptToRequestIdentityRole(concept, filter);
        results.add(requestIdentityRoleDto);
    });
    return results;
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) AbstractReadDtoService(eu.bcvsolutions.idm.core.api.service.AbstractReadDtoService) Autowired(org.springframework.beans.factory.annotation.Autowired) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) RoleBasePermission(eu.bcvsolutions.idm.core.security.api.domain.RoleBasePermission) IdmRequestIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmRequestIdentityRoleService) IdmConceptRoleRequest_(eu.bcvsolutions.idm.core.model.entity.IdmConceptRoleRequest_) AbstractBaseDtoService(eu.bcvsolutions.idm.core.rest.AbstractBaseDtoService) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) Pageable(org.springframework.data.domain.Pageable) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) Set(java.util.Set) PageRequest(org.springframework.data.domain.PageRequest) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) ContractBasePermission(eu.bcvsolutions.idm.core.security.api.domain.ContractBasePermission) PermissionUtils(eu.bcvsolutions.idm.core.security.api.utils.PermissionUtils) LocalDate(java.time.LocalDate) PageImpl(org.springframework.data.domain.PageImpl) IdmIdentityRole_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole_) RoleRequestedByType(eu.bcvsolutions.idm.core.api.domain.RoleRequestedByType) IdmRoleSystemService(eu.bcvsolutions.idm.core.api.service.IdmRoleSystemService) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ModelMapper(org.modelmapper.ModelMapper) Lists(com.google.common.collect.Lists) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Service(org.springframework.stereotype.Service) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) IdmRoleSystemFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleSystemFilter) BaseFilter(eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) IdmConceptRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) InvalidFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.InvalidFormAttributeDto) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) UUID(java.util.UUID) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)

Example 10 with IdmRequestIdentityRoleFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter in project CzechIdMng by bcvsolutions.

the class IdmRequestIdentityRoleServiceIntegrationTest method testFindByRoleText.

@Test
@Transactional
public void testFindByRoleText() {
    IdmIdentityDto identity = this.getHelper().createIdentity(new GuardedString());
    IdmIdentityContractDto contract = this.getHelper().getPrimeContract(identity);
    IdmRoleDto assignedRole = this.getHelper().createRole();
    IdmIdentityRoleDto identityRole = this.getHelper().createIdentityRole(contract, assignedRole);
    IdmRoleDto role = this.getHelper().createRole();
    IdmRequestIdentityRoleFilter filter = new IdmRequestIdentityRoleFilter();
    filter.setIdentityId(identity.getId());
    filter.setRoleText(assignedRole.getCode());
    // We expecting only one already assigned identity-role
    List<IdmRequestIdentityRoleDto> requestIdentityRoles = requestIdentityRoleService.find(filter, null).getContent();
    Assert.assertEquals(1, requestIdentityRoles.size());
    Assert.assertEquals(identityRole.getId(), requestIdentityRoles.get(0).getId());
    // Create request for new identity-role
    IdmRequestIdentityRoleDto dto = new IdmRequestIdentityRoleDto();
    dto.setIdentityContract(contract.getId());
    dto.setRole(role.getId());
    dto.setValidFrom(LocalDate.now().minusDays(1));
    dto.setValidTill(LocalDate.now().plusDays(10));
    IdmRequestIdentityRoleDto createdRequestIdentityRole = requestIdentityRoleService.save(dto);
    Assert.assertNotNull(createdRequestIdentityRole);
    // Request must been created
    Assert.assertNotNull(createdRequestIdentityRole.getRoleRequest());
    // Filter will be filtering by this request
    filter.setRoleRequestId(createdRequestIdentityRole.getRoleRequest());
    // We expecting one item
    requestIdentityRoles = requestIdentityRoleService.find(filter, null).getContent();
    Assert.assertEquals(1, requestIdentityRoles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmRequestIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter)12 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)11 IdmRequestIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto)11 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)11 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)9 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)9 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)9 Test (org.junit.Test)9 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)8 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)8 Transactional (org.springframework.transaction.annotation.Transactional)8 ConceptRoleRequestOperation (eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation)6 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)6 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)6 IdmRequestIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmRequestIdentityRoleService)6 IdmRoleRequestService (eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService)6 IdmRoleService (eu.bcvsolutions.idm.core.api.service.IdmRoleService)6 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)6 LocalDate (java.time.LocalDate)6 List (java.util.List)6