use of eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessSkippedAutomaticRoleByTreeTaskExecutor in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeNodeServiceIntegrationTest method testSkipAndAssignAutomaticRoleAfterNodeIsMovedWithUpRecursion.
@Test
public void testSkipAndAssignAutomaticRoleAfterNodeIsMovedWithUpRecursion() {
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().createContract(identity, parentNode);
// no role should be assigned now
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
node.setParent(parentNode.getId());
EntityEvent<IdmTreeNodeDto> event = new TreeNodeEvent(TreeNodeEventType.UPDATE, node);
event.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
node = service.publish(event).getContent();
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
// recount skipped automatic roles
longRunningTaskManager.execute(new ProcessSkippedAutomaticRoleByTreeTaskExecutor());
//
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())));
}
use of eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessSkippedAutomaticRoleByTreeTaskExecutor in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeNodeServiceIntegrationTest method testSkipAndAssignAutomaticRoleOnPositionAfterNodeIsMovedWithUpRecursion.
@Test
public void testSkipAndAssignAutomaticRoleOnPositionAfterNodeIsMovedWithUpRecursion() {
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());
EntityEvent<IdmTreeNodeDto> event = new TreeNodeEvent(TreeNodeEventType.UPDATE, node);
event.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
node = service.publish(event).getContent();
IdmEntityStateFilter filter = new IdmEntityStateFilter();
filter.setStates(Lists.newArrayList(OperationState.BLOCKED));
filter.setResultCode(CoreResultCode.AUTOMATIC_ROLE_SKIPPED.getCode());
filter.setOwnerType(entityStateManager.getOwnerType(IdmRoleTreeNodeDto.class));
List<IdmEntityStateDto> skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertTrue(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(automaticRole.getId())));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
// recount skipped automatic roles
longRunningTaskManager.execute(new ProcessSkippedAutomaticRoleByTreeTaskExecutor());
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());
//
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())));
}
use of eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessSkippedAutomaticRoleByTreeTaskExecutor in project CzechIdMng by bcvsolutions.
the class TreeSynchronizationExecutor method executeAutomaticRoleRecalculation.
/**
* Start automatic roles recalculation synchronously.
*
* @param log
* @return
* @since 10.4.0
*/
private SysSyncLogDto executeAutomaticRoleRecalculation(SysSyncLogDto log) {
log.addToLog(MessageFormat.format("After success sync have to recount automatic roles (by tree structure). We start recount automatic roles by tree structure (synchronously) now [{0}].", ZonedDateTime.now()));
Boolean executed = longRunningTaskManager.executeSync(new ProcessSkippedAutomaticRoleByTreeTaskExecutor());
if (BooleanUtils.isTrue(executed)) {
log.addToLog(MessageFormat.format("Recalculation automatic role by tree structure ended in [{0}].", ZonedDateTime.now()));
} else if (executed == null) {
log.addToLog(MessageFormat.format("Recalculation of automatic roles by tree structure ended in [{0}], role requests will be processed asynchronously.", ZonedDateTime.now()));
} else {
addToItemLog(log, "Warning - recalculation automatic role by attribute is not executed correctly.");
}
return synchronizationLogService.save(log);
}
use of eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessSkippedAutomaticRoleByTreeTaskExecutor 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());
}
use of eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessSkippedAutomaticRoleByTreeTaskExecutor in project CzechIdMng by bcvsolutions.
the class DefaultIdmTreeNodeServiceIntegrationTest method testRecountAutomaticRoleWithMissingContent.
@Test
public void testRecountAutomaticRoleWithMissingContent() {
// create state with missing content
IdmEntityStateDto state = new IdmEntityStateDto();
UUID ownerId = UUID.randomUUID();
state.setOwnerId(ownerId);
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);
//
state = new IdmEntityStateDto();
state.setOwnerId(ownerId);
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);
//
// recount skipped automatic roles
LongRunningFutureTask<Boolean> executor = longRunningTaskManager.execute(new ProcessSkippedAutomaticRoleByTreeTaskExecutor());
IdmLongRunningTaskDto longRunningTask = longRunningTaskManager.getLongRunningTask(executor);
Assert.assertTrue(longRunningTask.getWarningItemCount() > 0);
}
Aggregations