Search in sources :

Example 51 with IdmRoleTreeNodeDto

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

the class IdentityContractUpdateByAutomaticRoleProcessor method process.

@Override
public EventResult<IdmIdentityContractDto> process(EntityEvent<IdmIdentityContractDto> event) {
    IdmIdentityContractDto contract = event.getContent();
    IdmIdentityContractDto previous = event.getOriginalSource();
    UUID previousPosition = previous == null ? null : previous.getWorkPosition();
    UUID newPosition = contract.getWorkPosition();
    boolean validityChangedToValid = previous == null ? false : contract.isValidNowOrInFuture() && previous.isValidNowOrInFuture() != contract.isValidNowOrInFuture();
    IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
    // flag can be processed afterwards
    if (getBooleanProperty(AutomaticRoleManager.SKIP_RECALCULATION, event.getProperties())) {
        LOG.debug("Automatic roles are skipped for contract [{}], state [{}] " + "for position will be created only.", contract.getId(), CoreResultCode.AUTOMATIC_ROLE_SKIPPED.getCode());
        // 
        Map<String, Serializable> properties = new HashMap<>();
        // original contract as property
        properties.put(EntityEvent.EVENT_PROPERTY_ORIGINAL_SOURCE, event.getOriginalSource());
        entityStateManager.createState(contract, OperationState.BLOCKED, contract.isValidNowOrInFuture() ? CoreResultCode.AUTOMATIC_ROLE_SKIPPED : CoreResultCode.AUTOMATIC_ROLE_SKIPPED_INVALID_CONTRACT, properties);
        // 
        return new DefaultEventResult<>(event, this);
    }
    if (!contract.isValidNowOrInFuture()) {
        // but we need to add skipped flag above, even when invalid contract is updated
        return new DefaultEventResult<>(event, this);
    }
    // 
    if (previous == null || !Objects.equals(newPosition, previousPosition) || validityChangedToValid) {
        // work positions has some difference or validity changes
        List<IdmIdentityRoleDto> assignedRoles = getAssignedAutomaticRoles(contract.getId());
        // remove all automatic roles by attribute and by other contract position
        if (!assignedRoles.isEmpty()) {
            assignedRoles = assignedRoles.stream().filter(autoRole -> {
                // remove automatic roles by attribute - solved by different process
                AbstractIdmAutomaticRoleDto automaticRoleDto = DtoUtils.getEmbedded(autoRole, IdmIdentityRole_.automaticRole, (AbstractIdmAutomaticRoleDto) null);
                if (automaticRoleDto instanceof IdmRoleTreeNodeDto) {
                    return true;
                }
                return false;
            }).filter(identityRole -> {
                // remove automatic roles by attribute - solved by different process
                return identityRole.getContractPosition() == null;
            }).collect(Collectors.toList());
        }
        // 
        Set<UUID> previousAutomaticRoles = assignedRoles.stream().filter(identityRole -> {
            return identityRole.getAutomaticRole() != null;
        }).map(identityRole -> {
            return identityRole.getAutomaticRole();
        }).collect(Collectors.toSet());
        Set<IdmRoleTreeNodeDto> addedAutomaticRoles = new HashSet<>();
        if (newPosition != null && contract.isValidNowOrInFuture()) {
            addedAutomaticRoles = roleTreeNodeService.getAutomaticRolesByTreeNode(newPosition);
        }
        // prevent to remove newly added or still exists roles
        Set<UUID> removedAutomaticRoles = new HashSet<>(previousAutomaticRoles);
        removedAutomaticRoles.removeAll(addedAutomaticRoles.stream().map(IdmRoleTreeNodeDto::getId).collect(Collectors.toList()));
        addedAutomaticRoles.removeIf(a -> {
            return previousAutomaticRoles.contains(a.getId());
        });
        // 
        for (UUID removedAutomaticRole : removedAutomaticRoles) {
            Iterator<IdmIdentityRoleDto> iter = assignedRoles.iterator();
            while (iter.hasNext()) {
                IdmIdentityRoleDto identityRole = iter.next();
                if (Objects.equals(identityRole.getAutomaticRole(), removedAutomaticRole)) {
                    // check, if role will be added by new automatic roles and prevent removing
                    IdmRoleTreeNodeDto addedAutomaticRole = getByRole(identityRole.getRole(), addedAutomaticRoles);
                    if (addedAutomaticRole == null) {
                        // remove assigned role
                        IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
                        conceptRoleRequest.setIdentityRole(identityRole.getId());
                        conceptRoleRequest.setRole(identityRole.getRole());
                        conceptRoleRequest.setOperation(ConceptRoleRequestOperation.REMOVE);
                        // 
                        roleRequest.getConceptRoles().add(conceptRoleRequest);
                        iter.remove();
                    } else {
                        // change relation only
                        IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
                        conceptRoleRequest.setIdentityRole(identityRole.getId());
                        conceptRoleRequest.setAutomaticRole(addedAutomaticRole.getId());
                        conceptRoleRequest.setIdentityContract(contract.getId());
                        conceptRoleRequest.setValidFrom(contract.getValidFrom());
                        conceptRoleRequest.setValidTill(contract.getValidTill());
                        conceptRoleRequest.setRole(identityRole.getRole());
                        conceptRoleRequest.setOperation(ConceptRoleRequestOperation.UPDATE);
                        // 
                        roleRequest.getConceptRoles().add(conceptRoleRequest);
                        // 
                        // new automatic role is not needed
                        addedAutomaticRoles.remove(addedAutomaticRole);
                    }
                }
            }
        }
        // change date - for unchanged assigned roles only
        if (previous != null && EntityUtils.validableChanged(previous, contract)) {
            roleRequest.getConceptRoles().addAll(changeValidable(contract, assignedRoles));
        }
        // add identity roles
        for (AbstractIdmAutomaticRoleDto autoRole : addedAutomaticRoles) {
            IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
            conceptRoleRequest.setIdentityContract(contract.getId());
            conceptRoleRequest.setValidFrom(contract.getValidFrom());
            conceptRoleRequest.setValidTill(contract.getValidTill());
            conceptRoleRequest.setRole(autoRole.getRole());
            conceptRoleRequest.setAutomaticRole(autoRole.getId());
            conceptRoleRequest.setOperation(ConceptRoleRequestOperation.ADD);
            // 
            roleRequest.getConceptRoles().add(conceptRoleRequest);
        }
        // contract is enabled => process all contract positions
        if (validityChangedToValid) {
            IdmContractPositionFilter filter = new IdmContractPositionFilter();
            filter.setIdentityContractId(contract.getId());
            // 
            for (IdmContractPositionDto position : contractPositionService.find(filter, null).getContent()) {
                CoreEvent<IdmContractPositionDto> positionEvent = new CoreEvent<>(CoreEventType.NOTIFY, position);
                // we don't need the second asynchronicity
                positionEvent.setPriority(PriorityType.IMMEDIATE);
                positionEvent.getProperties().put(EVENT_PROPERTY_REQUEST, roleRequest);
                // recount automatic roles for given position
                EventContext<IdmContractPositionDto> context = contractPositionService.publish(positionEvent, event);
                // get modified prepared request
                if (context.getLastResult() != null) {
                    roleRequest = (IdmRoleRequestDto) context.getLastResult().getEvent().getProperties().get(EVENT_PROPERTY_REQUEST);
                }
            }
        }
    } else if (previous != null && EntityUtils.validableChanged(previous, contract)) {
        // process validable change only
        roleRequest.getConceptRoles().addAll(changeValidable(contract, getAssignedAutomaticRoles(contract.getId())));
    }
    // start request at end asynchronously
    roleRequest.setApplicant(contract.getIdentity());
    RoleRequestEvent requestEvent = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest);
    roleRequestService.startConcepts(requestEvent, event);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmContractPositionService(eu.bcvsolutions.idm.core.api.service.IdmContractPositionService) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmIdentityRole_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole_) IdmRoleTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmRoleTreeNodeService) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) CoreEventProcessor(eu.bcvsolutions.idm.core.api.event.CoreEventProcessor) IdentityContractProcessor(eu.bcvsolutions.idm.core.api.event.processor.IdentityContractProcessor) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AutomaticRoleManager(eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) EntityStateManager(eu.bcvsolutions.idm.core.api.service.EntityStateManager) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) Map(java.util.Map) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Description(org.springframework.context.annotation.Description) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) Iterator(java.util.Iterator) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdentityContractEventType(eu.bcvsolutions.idm.core.model.event.IdentityContractEvent.IdentityContractEventType) Set(java.util.Set) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) Serializable(java.io.Serializable) Objects(java.util.Objects) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) List(java.util.List) Component(org.springframework.stereotype.Component) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) CoreEventType(eu.bcvsolutions.idm.core.api.event.CoreEvent.CoreEventType) RoleRequestEventType(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent.RoleRequestEventType) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) Serializable(java.io.Serializable) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) HashMap(java.util.HashMap) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) UUID(java.util.UUID) HashSet(java.util.HashSet) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)

Example 52 with IdmRoleTreeNodeDto

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

the class DefaultIdmAutomaticRoleRequestService method executeRequestInternal.

private IdmAutomaticRoleRequestDto executeRequestInternal(UUID requestId) {
    Assert.notNull(requestId, "Role request ID is required!");
    IdmAutomaticRoleRequestDto request = this.get(requestId);
    Assert.notNull(request, "Role request is required!");
    IdmAutomaticRoleAttributeRuleRequestFilter ruleFilter = new IdmAutomaticRoleAttributeRuleRequestFilter();
    ruleFilter.setRoleRequestId(requestId);
    List<IdmAutomaticRoleAttributeRuleRequestDto> ruleConcepts = automaticRoleRuleRequestService.find(ruleFilter, null).getContent();
    UUID automaticRoleId = request.getAutomaticRole();
    if (AutomaticRoleRequestType.ATTRIBUTE == request.getRequestType()) {
        // Automatic role by attributes
        if (RequestOperationType.REMOVE == request.getOperation()) {
            // Remove automatic role by attributes
            Assert.notNull(automaticRoleId, "Id of automatic role in the request (for delete) is required!");
            automaticRoleAttributeService.delete(automaticRoleAttributeService.get(automaticRoleId));
            request.setAutomaticRole(null);
        } else {
            // Add new or update (rules) for automatic role by attributes
            IdmAutomaticRoleAttributeDto automaticRole = null;
            if (automaticRoleId != null) {
                automaticRole = automaticRoleAttributeService.get(automaticRoleId);
            } else {
                automaticRole = new IdmAutomaticRoleAttributeDto();
                automaticRole = initAttributeAutomaticRole(request, automaticRole);
                automaticRole = automaticRoleAttributeService.save(automaticRole);
                request.setAutomaticRole(automaticRole.getId());
            }
            UUID roleId = automaticRole.getRole() != null ? automaticRole.getRole() : request.getRole();
            Assert.notNull(roleId, "Id of role is required in the automatic role request!");
            IdmRoleDto role = roleService.get(request.getRole());
            Assert.notNull(role, "Role is required in the automatic role request!");
            // Before we do any change, we have to sets the automatic role to concept state
            automaticRole.setConcept(true);
            automaticRoleAttributeService.save(automaticRole);
            // Realize changes for rules
            realizeAttributeRules(request, automaticRole, ruleConcepts);
            // Sets automatic role as no concept -> execute recalculation this role
            automaticRole.setConcept(false);
            automaticRoleAttributeService.recalculate(automaticRoleAttributeService.save(automaticRole).getId());
        }
    } else if (AutomaticRoleRequestType.TREE == request.getRequestType()) {
        // Automatic role by node in a tree
        if (RequestOperationType.REMOVE == request.getOperation()) {
            // Remove tree automatic role
            Assert.notNull(automaticRoleId, "Id of automatic role in the request (for delete) is required!");
            // Recount (remove) assigned roles ensures LRT during delete
            try {
                automaticRoleTreeService.delete(automaticRoleTreeService.get(automaticRoleId));
            } catch (AcceptedException ex) {
                LOG.info("Automatic role [{}] will be removed asynchronously.", automaticRoleId);
            }
            request.setAutomaticRole(null);
        } else if (RequestOperationType.ADD == request.getOperation()) {
            // Create new tree automatic role
            IdmRoleTreeNodeDto treeAutomaticRole = new IdmRoleTreeNodeDto();
            treeAutomaticRole = initTreeAutomaticRole(request, treeAutomaticRole);
            // Recount of assigned roles ensures LRT
            try {
                treeAutomaticRole = automaticRoleTreeService.save(treeAutomaticRole);
                request.setAutomaticRole(treeAutomaticRole.getId());
            } catch (AcceptedException ex) {
                // automatic role will be processed asynchronously, but it's persisted
                String treeAutomaticRoleIdentifier = ex.getIdentifier();
                if (StringUtils.isEmpty(treeAutomaticRoleIdentifier)) {
                    throw ex;
                }
                request.setAutomaticRole(DtoUtils.toUuid(treeAutomaticRoleIdentifier));
            }
        } else {
            // Update is not supported
            throw new ResultCodeException(CoreResultCode.METHOD_NOT_ALLOWED, "Tree automatic role update is not supported");
        }
    }
    request.setState(RequestState.EXECUTED);
    request.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).build());
    return this.save(request);
}
Also used : IdmAutomaticRoleAttributeRuleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleRequestFilter) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmAutomaticRoleAttributeRuleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)

Example 53 with IdmRoleTreeNodeDto

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

the class DefaultIdmTreeNodeServiceIntegrationTest method testRecountAutomaticRoleMultipleTimes.

@Test
public void testRecountAutomaticRoleMultipleTimes() {
    IdmTreeNodeDto node = getHelper().createTreeNode();
    // define automatic role for parent
    IdmRoleDto role = getHelper().createRole();
    IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, node, RecursionType.NO, true);
    // create identity with contract on node
    entityStateManager.createState(automaticRole, OperationState.BLOCKED, CoreResultCode.AUTOMATIC_ROLE_SKIPPED, null);
    entityStateManager.createState(automaticRole, OperationState.BLOCKED, CoreResultCode.AUTOMATIC_ROLE_SKIPPED, null);
    Assert.assertEquals(2, entityStateManager.findStates(automaticRole, null).getTotalElements());
    // 
    // recount skipped automatic roles
    LongRunningFutureTask<Boolean> executor = longRunningTaskManager.execute(new ProcessSkippedAutomaticRoleByTreeTaskExecutor());
    IdmLongRunningTaskDto longRunningTask = longRunningTaskManager.getLongRunningTask(executor);
    Assert.assertEquals(Long.valueOf(2), longRunningTask.getSuccessItemCount());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) ProcessSkippedAutomaticRoleByTreeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessSkippedAutomaticRoleByTreeTaskExecutor) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 54 with IdmRoleTreeNodeDto

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

the class DefaultIdmTreeNodeServiceIntegrationTest method testAssignAutomaticRoleOnPositionAfterNodeIsMovedWithDownRecursion.

@Test
public void testAssignAutomaticRoleOnPositionAfterNodeIsMovedWithDownRecursion() {
    IdmTreeNodeDto parentNode = getHelper().createTreeNode();
    IdmTreeNodeDto node = getHelper().createTreeNode();
    // define automatic role for parent
    IdmRoleDto role = getHelper().createRole();
    IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, parentNode, RecursionType.DOWN, true);
    // create identity with contract on node
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    getHelper().createContractPosition(getHelper().getPrimeContract(identity), node);
    // no role should be assigned now
    List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertTrue(assignedRoles.isEmpty());
    // 
    node.setParent(parentNode.getId());
    node = service.save(node);
    // 
    assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertEquals(1, assignedRoles.size());
    Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
    // 
    IdmTreeNodeDto otherNode = getHelper().createTreeNode();
    IdmRoleTreeNodeDto otherAutomaticRole = getHelper().createRoleTreeNode(role, otherNode, RecursionType.DOWN, true);
    node.setParent(otherNode.getId());
    node = service.save(node);
    // 
    assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    UUID assignedRoleId = assignedRoles.get(0).getId();
    Assert.assertEquals(1, assignedRoles.size());
    Assert.assertEquals(otherAutomaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
    // 
    // recalculate role => nothing happend
    ProcessAutomaticRoleByTreeTaskExecutor automaticRoleTask = AutowireHelper.createBean(ProcessAutomaticRoleByTreeTaskExecutor.class);
    automaticRoleTask.setAutomaticRoles(Lists.newArrayList(otherAutomaticRole.getId()));
    longRunningTaskManager.execute(automaticRoleTask);
    // 
    assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertEquals(1, assignedRoles.size());
    Assert.assertEquals(otherAutomaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
    Assert.assertEquals(assignedRoleId, assignedRoles.get(0).getId());
    // 
    // move node deeper in sub tree => nothing should happend
    IdmTreeNodeDto subNode = getHelper().createTreeNode(null, null, getHelper().createTreeNode(null, null, otherNode));
    node.setParent(subNode.getId());
    node = service.save(node);
    // 
    assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertEquals(1, assignedRoles.size());
    Assert.assertEquals(otherAutomaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
    Assert.assertEquals(assignedRoleId, assignedRoles.get(0).getId());
}
Also used : ProcessAutomaticRoleByTreeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) UUID(java.util.UUID) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 55 with IdmRoleTreeNodeDto

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

the class DefaultIdmTreeNodeServiceIntegrationTest method testAssignAutomaticRoleOnPositionAfterNodeIsMovedWithUpRecursion.

@Test
public void testAssignAutomaticRoleOnPositionAfterNodeIsMovedWithUpRecursion() {
    IdmTreeNodeDto parentNode = getHelper().createTreeNode();
    IdmTreeNodeDto node = getHelper().createTreeNode();
    // define automatic role for parent
    IdmRoleDto role = getHelper().createRole();
    IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, node, RecursionType.UP, true);
    // create identity with contract on node
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    getHelper().createContractPosition(getHelper().getPrimeContract(identity), parentNode);
    // no role should be assigned now
    List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertTrue(assignedRoles.isEmpty());
    // 
    node.setParent(parentNode.getId());
    node = service.save(node);
    // 
    assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertEquals(1, assignedRoles.size());
    Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
    // 
    IdmTreeNodeDto otherNode = getHelper().createTreeNode(null, null, node);
    IdmRoleDto roleOther = getHelper().createRole();
    IdmRoleTreeNodeDto otherAutomaticRole = getHelper().createRoleTreeNode(roleOther, otherNode, RecursionType.UP, false);
    // 
    assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertEquals(2, assignedRoles.size());
    Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> automaticRole.getId().equals(ir.getAutomaticRole())));
    Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> otherAutomaticRole.getId().equals(ir.getAutomaticRole())));
}
Also used : Lists(org.testng.collections.Lists) ProcessAutomaticRoleByTreeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) IdmTreeNodeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) AutomaticRoleManager(eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) EntityStateManager(eu.bcvsolutions.idm.core.api.service.EntityStateManager) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) ForestIndexService(eu.bcvsolutions.forest.index.service.api.ForestIndexService) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) IdmTreeNodeForestContentService(eu.bcvsolutions.idm.core.model.service.api.IdmTreeNodeForestContentService) Before(org.junit.Before) IdmForestIndexEntity(eu.bcvsolutions.idm.core.model.entity.IdmForestIndexEntity) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) RecursionType(eu.bcvsolutions.idm.core.api.domain.RecursionType) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) TreeNodeEvent(eu.bcvsolutions.idm.core.model.event.TreeNodeEvent) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LongRunningFutureTask(eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask) ProcessSkippedAutomaticRoleByTreeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessSkippedAutomaticRoleByTreeTaskExecutor) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) IdmEntityStateFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmEntityStateFilter) TreeNodeException(eu.bcvsolutions.idm.core.exception.TreeNodeException) UUID(java.util.UUID) ApplicationContext(org.springframework.context.ApplicationContext) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) LocalDate(java.time.LocalDate) TreeNodeEventType(eu.bcvsolutions.idm.core.model.event.TreeNodeEvent.TreeNodeEventType) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ProcessAllAutomaticRoleByTreeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAllAutomaticRoleByTreeTaskExecutor) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)83 Test (org.junit.Test)56 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)48 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)46 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)42 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)39 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)38 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)38 UUID (java.util.UUID)32 Autowired (org.springframework.beans.factory.annotation.Autowired)20 IdmContractPositionDto (eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto)19 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)19 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)19 List (java.util.List)19 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)18 ProcessAutomaticRoleByTreeTaskExecutor (eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor)18 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)17 Transactional (org.springframework.transaction.annotation.Transactional)17 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)16 Assert (org.junit.Assert)16