Search in sources :

Example 1 with ProcessAutomaticRoleByTreeTaskExecutor

use of eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor in project CzechIdMng by bcvsolutions.

the class TreeNodeAfterMoveAutomaticRoleProcessor method process.

@Override
public EventResult<IdmTreeNodeDto> process(EntityEvent<IdmTreeNodeDto> event) {
    IdmTreeNodeDto treeNode = event.getContent();
    // 
    // preserve order => new automatic roles first
    Set<UUID> automaticRoles = new LinkedHashSet<>();
    // find currently defined automatic roles
    Set<IdmRoleTreeNodeDto> newAutomaticRoles = getRoleTreeNodeService().getAutomaticRolesByTreeNode(treeNode.getId());
    if (CollectionUtils.isNotEmpty(newAutomaticRoles)) {
        automaticRoles.addAll(newAutomaticRoles.stream().map(IdmRoleTreeNodeDto::getId).collect(Collectors.toSet()));
    }
    // previously defined automatic roles
    Set<UUID> previousAutomaticRoles = event.getSetProperty(PROPERTY_PREVIOUS_AUTOMATIC_ROLES, UUID.class);
    if (CollectionUtils.isNotEmpty(previousAutomaticRoles)) {
        automaticRoles.addAll(previousAutomaticRoles);
    }
    // 
    if (CollectionUtils.isEmpty(automaticRoles)) {
        LOG.debug("Tree node [{}] was moved under new parent node [{}]. No automatic roles are affected.", treeNode.getId(), treeNode.getParent());
        // 
        return new DefaultEventResult<>(event, this);
    }
    // flag can be processed afterwards
    if (getBooleanProperty(AutomaticRoleManager.SKIP_RECALCULATION, event.getProperties())) {
        automaticRoles.forEach(automaticRole -> {
            LOG.debug("Automatic role [{}] recount is skipped after tree node [{}] was moved in tree structure. " + "State [AUTOMATIC_ROLE_SKIPPED] for automatic role will be created only.", automaticRole, treeNode.getId());
            // 
            IdmEntityStateDto state = new IdmEntityStateDto();
            state.setOwnerId(automaticRole);
            state.setOwnerType(entityStateManager.getOwnerType(IdmRoleTreeNodeDto.class));
            state.setResult(new OperationResultDto.Builder(OperationState.BLOCKED).setModel(new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_SKIPPED)).build());
            entityStateManager.saveState(null, state);
        });
        // 
        return new DefaultEventResult<>(event, this);
    }
    // 
    // process all affected automatic roles
    ProcessAutomaticRoleByTreeTaskExecutor automaticRoleTask = AutowireHelper.createBean(ProcessAutomaticRoleByTreeTaskExecutor.class);
    automaticRoleTask.setAutomaticRoles(Lists.newArrayList(automaticRoles));
    executeTask(event, automaticRoleTask);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IdmEntityStateDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto) ProcessAutomaticRoleByTreeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) UUID(java.util.UUID)

Example 2 with ProcessAutomaticRoleByTreeTaskExecutor

use of eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor in project CzechIdMng by bcvsolutions.

the class DefaultIdmTreeNodeServiceIntegrationTest method testAssignAutomaticRoleAfterNodeIsMovedWithDownRecursion.

@Test
public void testAssignAutomaticRoleAfterNodeIsMovedWithDownRecursion() {
    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().createContract(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 3 with ProcessAutomaticRoleByTreeTaskExecutor

use of eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor in project CzechIdMng by bcvsolutions.

the class DefaultIdmIdentityContractServiceIntegrationTest method saveAutomaticRole.

/**
 * Save automatic role with repository and manual create and wait for task
 * @param automaticRole
 * @return
 */
private IdmRoleTreeNodeDto saveAutomaticRole(IdmRoleTreeNodeDto automaticRole, boolean withLongRunningTask) {
    // default name
    automaticRole.setName("default");
    IdmRoleTreeNodeDto roleTreeNode = roleTreeNodeService.saveInternal(automaticRole);
    // 
    if (withLongRunningTask) {
        ProcessAutomaticRoleByTreeTaskExecutor task = new ProcessAutomaticRoleByTreeTaskExecutor();
        task.setAutomaticRoles(Lists.newArrayList(roleTreeNode.getId()));
        taskManager.executeSync(task);
    }
    // 
    return roleTreeNodeService.get(roleTreeNode.getId());
}
Also used : ProcessAutomaticRoleByTreeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)

Example 4 with ProcessAutomaticRoleByTreeTaskExecutor

use of eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor in project CzechIdMng by bcvsolutions.

the class DefaultIdmIdentityContractServiceIntegrationTest method testAcceptSimultaneousAutomaticRoleTask.

@Test(expected = AcceptedException.class)
public void testAcceptSimultaneousAutomaticRoleTask() {
    IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(getHelper().createRole(), getHelper().createTreeNode(), true);
    ProcessAutomaticRoleByTreeTaskExecutor taskExecutor = AutowireHelper.createBean(ProcessAutomaticRoleByTreeTaskExecutor.class);
    taskExecutor.setAutomaticRoles(Lists.newArrayList(automaticRole.getId()));
    // 
    IdmLongRunningTaskDto lrt = null;
    try {
        lrt = longRunningTaskManager.resolveLongRunningTask(taskExecutor, null, OperationState.RUNNING);
        lrt.setRunning(true);
        longRunningTaskService.save(lrt);
        // 
        taskExecutor = AutowireHelper.createBean(ProcessAutomaticRoleByTreeTaskExecutor.class);
        taskExecutor.setAutomaticRoles(Lists.newArrayList(automaticRole.getId()));
        // 
        longRunningTaskManager.execute(taskExecutor);
    } finally {
        lrt.setRunning(false);
        lrt = longRunningTaskService.save(lrt);
        // 
        longRunningTaskService.delete(lrt);
    }
}
Also used : ProcessAutomaticRoleByTreeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 5 with ProcessAutomaticRoleByTreeTaskExecutor

use of eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor 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)

Aggregations

IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)7 ProcessAutomaticRoleByTreeTaskExecutor (eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor)7 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)3 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)3 UUID (java.util.UUID)3 Test (org.junit.Test)3 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)2 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)2 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)2 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)2 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)1 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)1 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)1 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)1 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)1 LinkedHashSet (java.util.LinkedHashSet)1