use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto 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);
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testSkipAndAssignAutomaticRoleOnPositionAfterChange.
@Test
public void testSkipAndAssignAutomaticRoleOnPositionAfterChange() {
IdmTreeNodeDto otherNode = getHelper().createTreeNode();
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
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmContractPositionDto position = getHelper().createContractPosition(getHelper().getPrimeContract(identity), otherNode);
// no role should be assigned now
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
position.setWorkPosition(node.getId());
EntityEvent<IdmContractPositionDto> event = new ContractPositionEvent(ContractPositionEventType.UPDATE, position);
event.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
position = contractPositionService.publish(event).getContent();
UUID positionId = position.getId();
IdmEntityStateFilter filter = new IdmEntityStateFilter();
filter.setStates(Lists.newArrayList(OperationState.BLOCKED));
filter.setResultCode(CoreResultCode.AUTOMATIC_ROLE_SKIPPED.getCode());
filter.setOwnerType(entityStateManager.getOwnerType(IdmContractPositionDto.class));
List<IdmEntityStateDto> skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertTrue(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(positionId)));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
// recount skipped automatic roles
longRunningTaskManager.execute(new ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor());
skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertFalse(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(automaticRole.getId())));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method prepareAutomaticRoles.
/**
*/
private void prepareAutomaticRoles() {
// prepare automatic roles
automaticRoleA = new IdmRoleTreeNodeDto();
automaticRoleA.setRecursionType(RecursionType.DOWN);
automaticRoleA.setRole(roleA.getId());
automaticRoleA.setTreeNode(nodeA.getId());
automaticRoleA = saveAutomaticRole(automaticRoleA, false);
automaticRoleD = new IdmRoleTreeNodeDto();
automaticRoleD.setRecursionType(RecursionType.DOWN);
automaticRoleD.setRole(roleB.getId());
automaticRoleD.setTreeNode(nodeD.getId());
automaticRoleD = saveAutomaticRole(automaticRoleD, false);
automaticRoleF = new IdmRoleTreeNodeDto();
automaticRoleF.setRecursionType(RecursionType.UP);
automaticRoleF.setRole(roleC.getId());
automaticRoleF.setTreeNode(nodeF.getId());
automaticRoleF = saveAutomaticRole(automaticRoleF, false);
automaticRoleE = new IdmRoleTreeNodeDto();
automaticRoleE.setRecursionType(RecursionType.NO);
automaticRoleE.setRole(roleD.getId());
automaticRoleE.setTreeNode(nodeE.getId());
automaticRoleE = saveAutomaticRole(automaticRoleE, false);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testFindAutomaticRoleWithRecursionDown.
@Test
public void testFindAutomaticRoleWithRecursionDown() {
// prepare
automaticRoleA = new IdmRoleTreeNodeDto();
automaticRoleA.setRecursionType(RecursionType.DOWN);
automaticRoleA.setRole(roleA.getId());
automaticRoleA.setTreeNode(nodeD.getId());
automaticRoleA = saveAutomaticRole(automaticRoleA, false);
//
// test
Set<IdmRoleTreeNodeDto> automaticRoles = roleTreeNodeService.getAutomaticRolesByTreeNode(nodeD.getId());
assertEquals(1, automaticRoles.size());
assertEquals(roleA.getId(), automaticRoles.iterator().next().getRole());
assertTrue(roleTreeNodeService.getAutomaticRolesByTreeNode(nodeB.getId()).isEmpty());
automaticRoles = roleTreeNodeService.getAutomaticRolesByTreeNode(nodeF.getId());
assertEquals(1, automaticRoles.size());
assertEquals(roleA.getId(), automaticRoles.iterator().next().getRole());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.
the class TreeSyncTest method testTreeWithAutomaticRoles.
@Test
public void testTreeWithAutomaticRoles() {
IdmTreeTypeDto treeType = getHelper().createTreeType();
//
// create synchronization
AbstractSysSyncConfigDto syncConfigCustom = this.getBean().doCreateSyncConfig(treeType.getCode(), true);
Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom));
// We want to sync all account under that node!
IdmTreeNodeDto treeNodeExistedNode = helper.createTreeNode(treeType, null);
syncConfigCustom.setRootsFilterScript("if(account){ def parentValue = account.getAttributeByName(\"" + helper.getSchemaColumnName("PARENT") + "\").getValue();" + " if(parentValue == null || parentValue.isEmpty()){" + " account.getAttributeByName(\"" + helper.getSchemaColumnName("PARENT") + "\").setValues([\"" + treeNodeExistedNode.getId() + "\"]); return Boolean.TRUE;}}" + " \nreturn Boolean.FALSE;");
syncConfigService.save(syncConfigCustom);
//
helper.startSynchronization(syncConfigCustom);
//
SysSyncLogFilter logFilter = new SysSyncLogFilter();
logFilter.setSynchronizationConfigId(syncConfigCustom.getId());
List<SysSyncLogDto> logs = syncLogService.find(logFilter, null).getContent();
Assert.assertEquals(1, logs.size());
SysSyncLogDto log = logs.get(0);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
//
helper.checkSyncLog(syncConfigCustom, SynchronizationActionType.CREATE_ENTITY, 6, OperationResultType.SUCCESS);
//
// prepare contracts
IdmTreeNodeFilter nodeFilter = new IdmTreeNodeFilter();
nodeFilter.setTreeTypeId(treeType.getId());
nodeFilter.setCode("112");
List<IdmTreeNodeDto> results = treeNodeService.find(nodeFilter, null).getContent();
IdmTreeNodeDto parentNode = results.get(0);
nodeFilter.setCode("1111");
// parent will be set by synchronization
IdmTreeNodeDto node = treeNodeService.find(nodeFilter, null).getContent().get(0);
// 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());
//
// change tree structure and synchronize
this.getBean().changeParent("1111", "112");
helper.startSynchronization(syncConfigCustom);
log = helper.checkSyncLog(syncConfigCustom, SynchronizationActionType.UPDATE_ENTITY, 6, OperationResultType.SUCCESS);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
}
Aggregations