use of eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testAutomaticRolesRemovalAfterContractEnds.
@Test
public void testAutomaticRolesRemovalAfterContractEnds() {
// automatic roles by tree structure
prepareAutomaticRoles();
// automatic role by attribute on contract
String autoPosition = getHelper().createName();
IdmRoleDto autoAttributeRole = getHelper().createRole();
IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(autoAttributeRole.getId());
getHelper().createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT, IdmIdentityContract_.position.getName(), null, autoPosition);
//
// prepare identity, contract, direct roles and automatic roles
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = service.getPrimeContract(identity.getId());
contract.setIdentity(identity.getId());
contract.setValidFrom(LocalDate.now().minusDays(1));
contract.setValidTill(LocalDate.now().plusMonths(1));
contract.setWorkPosition(nodeD.getId());
contract.setMain(true);
contract.setDescription("test-node-d");
contract.setPosition(autoPosition);
contract = service.save(contract);
UUID contractId = contract.getId();
IdmRoleDto directRole = getHelper().createRole();
getHelper().createIdentityRole(contract, directRole);
//
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
Assert.assertEquals(5, identityRoles.size());
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleA.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleB.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleC.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return directRole.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return autoAttributeRole.getId().equals(ir.getRole());
}));
//
try {
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, true);
//
// end contract - all roles should be removed, after asynchronous role request ends
contract.setValidTill(LocalDate.now().minusDays(1));
contract = service.save(contract);
//
Assert.assertFalse(contract.isValidNowOrInFuture());
//
getHelper().waitForResult(res -> {
return !identityRoleService.findAllByContract(contractId).isEmpty();
}, 300, Integer.MAX_VALUE);
getHelper().waitForResult(res -> {
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
filter.setRunning(Boolean.TRUE);
//
return taskManager.findLongRunningTasks(filter, null).getTotalElements() != 0;
});
//
identityRoles = identityRoleService.findAllByContract(contract.getId());
Assert.assertTrue(identityRoles.isEmpty());
//
service.delete(contract);
} finally {
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
}
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter in project CzechIdMng by bcvsolutions.
the class IdentityInitUniformPasswordProcessor method conditional.
@Override
public boolean conditional(EntityEvent<IdmIdentityDto> event) {
UUID identityId = event.getContent().getId();
UUID transactionId = event.getContent().getTransactionId();
if (identityId == null || transactionId == null) {
return false;
}
IdmLongRunningTaskFilter longRunningTaskFilter = new IdmLongRunningTaskFilter();
longRunningTaskFilter.setTransactionId(transactionId);
longRunningTaskFilter.setRunning(Boolean.TRUE);
// TODO: Check only for contract sync?
longRunningTaskFilter.setTaskType(SynchronizationSchedulableTaskExecutor.class.getCanonicalName());
long count = longRunningTaskService.count(longRunningTaskFilter);
return super.conditional(event) && count > 0;
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter in project CzechIdMng by bcvsolutions.
the class LongRunningTaskCancelBulkActionIntegrationTest method testProcessBulkActionByFilter.
@Test
public void testProcessBulkActionByFilter() {
List<IdmLongRunningTaskDto> tasks = createTasks(5);
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
filter.setId(tasks.get(2).getId());
List<IdmLongRunningTaskDto> checkEvents = service.find(filter, null).getContent();
Assert.assertEquals(1, checkEvents.size());
IdmBulkActionDto bulkAction = findBulkAction(IdmLongRunningTask.class, LongRunningTaskCancelBulkAction.NAME);
bulkAction.setTransformedFilter(filter);
bulkAction.setFilter(toMap(filter));
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
checkResultLrt(processAction, 1l, null, null);
Assert.assertEquals(OperationState.CANCELED, service.get(tasks.get(2)).getResultState());
Assert.assertEquals(OperationState.RUNNING, service.get(tasks.get(1)).getResultState());
Assert.assertEquals(OperationState.RUNNING, service.get(tasks.get(3)).getResultState());
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter in project CzechIdMng by bcvsolutions.
the class AbstractSchedulableStatefulExecutorIntegrationTest method getContext.
/**
* LRT with loaded counters.
*
* @return
*/
private IdmLongRunningTaskFilter getContext() {
IdmLongRunningTaskFilter context = new IdmLongRunningTaskFilter();
context.setIncludeItemCounts(true);
//
return context;
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter in project CzechIdMng by bcvsolutions.
the class LongRunningTaskDeleteBulkActionIntegrationTest method testPreventDeleteItself.
@Test
public void testPreventDeleteItself() {
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
filter.setTaskType(LongRunningTaskDeleteBulkAction.class.getCanonicalName());
//
IdmBulkActionDto bulkAction = findBulkAction(IdmLongRunningTask.class, LongRunningTaskDeleteBulkAction.NAME);
bulkAction.setTransformedFilter(filter);
bulkAction.setFilter(toMap(filter));
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
checkResultLrt(processAction, null, 0L, 0L);
Assert.assertEquals(OperationState.EXECUTED, service.get(bulkAction.getLongRunningTaskId()).getResultState());
}
Aggregations