use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class IdentityRoleValidRequestSchedulerTest method createLotsOfValidRequests.
@Test
public void createLotsOfValidRequests() throws InterruptedException, ExecutionException {
IdmRoleDto role = createAndSaveRole();
createAndSaveRoleSystem(role, system);
IdmTreeTypeDto treeType = createAndSaveTreeType();
IdmTreeNodeDto treeNode = createAndSaveTreeNode(treeType);
LocalDate validFrom = new LocalDate();
// set plus days
validFrom = validFrom.plusDays(5);
// clear request, if any
List<IdmIdentityRoleValidRequestDto> list = identityRoleValidRequestService.findAllValid();
for (IdmIdentityRoleValidRequestDto request : list) {
identityRoleValidRequestService.delete(request);
}
List<IdmIdentityDto> identities = new ArrayList<>();
for (int index = 0; index < MAX_CREATE; index++) {
IdmIdentityDto identity = createAndSaveIdentity();
IdmIdentityContractDto identityContract = createAndSaveIdentityContract(identity, treeNode);
// provisioning is not executed, role isn't valid from now
createAndSaveIdentityRole(identityContract, role, null, validFrom);
identities.add(identity);
}
list = identityRoleValidRequestService.findAllValid();
assertEquals(0, list.size());
validFrom = validFrom.minusDays(15);
for (IdmIdentityDto identity : identities) {
List<IdmIdentityRole> roles = identityRoleRepository.findAllByIdentityContract_Identity_Id(identity.getId(), null);
assertEquals(1, roles.size());
IdmIdentityRole identityRole = roles.get(0);
identityRole.setValidFrom(validFrom);
identityRoleRepository.save(identityRole);
}
list = identityRoleValidRequestService.findAllValid();
assertEquals(MAX_CREATE, list.size());
IdentityRoleValidRequestTaskExecutor taskExecutor = new IdentityRoleValidRequestTaskExecutor();
LongRunningFutureTask<Boolean> futureTask = longRunningTaskManager.execute(taskExecutor);
assertEquals(true, futureTask.getFutureTask().get());
IdmLongRunningTaskDto longRunningTask = longRunningTaskService.get(taskExecutor.getLongRunningTaskId());
assertEquals(OperationState.EXECUTED, longRunningTask.getResult().getState());
list = identityRoleValidRequestService.findAllValid();
assertEquals(0, list.size());
for (IdmIdentityDto identity : identities) {
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setIdentityId(identity.getId());
List<AccIdentityAccountDto> accountsList = identityAccountService.find(filter, null).getContent();
assertEquals(false, accountsList.isEmpty());
assertEquals(1, accountsList.size());
}
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class DefaultProvisioningExecutorIntegrationTest method testAsynchronousSystem.
@Test
public void testAsynchronousSystem() {
SysSystemDto system = helper.createTestResourceSystem(true);
system.setQueue(true);
system = systemService.save(system);
//
// create test provisioning context
SysProvisioningOperationDto provisioningOperation = createProvisioningOperation(system, "firstname");
Map<ProvisioningAttributeDto, Object> accoutObject = provisioningOperation.getProvisioningContext().getAccountObject();
String uid = (String) accoutObject.get(getProvisioningAttribute(TestHelper.ATTRIBUTE_MAPPING_NAME));
//
// publish event
provisioningExecutor.execute(provisioningOperation);
// is necessary to get again operation from service
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setSystemEntity(provisioningOperation.getSystemEntity());
filter.setSystemId(system.getId());
SysProvisioningOperationDto operation = provisioningOperationService.find(filter, null).getContent().get(0);
assertEquals(OperationState.CREATED, operation.getResultState());
SysSystemEntityDto systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, uid);
assertTrue(systemEntity.isWish());
assertNull(helper.findResource(uid));
//
// execute LRT with incorrect setting - virtual at fist - expected no process
ProvisioningQueueTaskExecutor provisioningQueueExecutor = new ProvisioningQueueTaskExecutor();
provisioningQueueExecutor.setVirtual(true);
Boolean result = longRunningTaskManager.executeSync(provisioningQueueExecutor);
assertTrue(result);
IdmLongRunningTaskDto lrt = longRunningTaskManager.getLongRunningTask(provisioningQueueExecutor.getLongRunningTaskId());
assertEquals(0L, lrt.getCount().longValue());
systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, uid);
assertTrue(systemEntity.isWish());
assertNull(helper.findResource(uid));
//
// execute LRT with correct setting
provisioningQueueExecutor = new ProvisioningQueueTaskExecutor();
result = longRunningTaskManager.executeSync(provisioningQueueExecutor);
assertTrue(result);
lrt = longRunningTaskManager.getLongRunningTask(provisioningQueueExecutor);
assertEquals(1L, lrt.getCount().longValue());
systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, uid);
assertFalse(systemEntity.isWish());
assertNotNull(helper.findResource(uid));
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class ContractSynchronizationExecutor method executeHrProcess.
/**
* Start HR process. Find quartz task and LRT. If some LRT for this task type
* exists, then is used. If not exists, then is created new. Task is execute
* synchronously.
*
* @param log
* @param executor
* @return
*/
private SysSyncLogDto executeHrProcess(SysSyncLogDto log, SchedulableTaskExecutor<?> executor) {
@SuppressWarnings("unchecked") Class<? extends SchedulableTaskExecutor<?>> taskType = (Class<? extends SchedulableTaskExecutor<?>>) executor.getClass();
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
filter.setOperationState(OperationState.CREATED);
filter.setTaskType(taskType.getCanonicalName());
List<IdmLongRunningTaskDto> createdLrts = longRunningTaskService.find(filter, null).getContent();
IdmLongRunningTaskDto lrt = null;
String simpleName = taskType.getSimpleName();
if (createdLrts.isEmpty()) {
// We do not have LRT for this task, we will create him
Task processTask = findTask(taskType);
if (processTask == null) {
addToItemLog(log, MessageFormat.format("Warning - HR process [{0}] cannot be executed, because task for this type was not found!", simpleName));
log = synchronizationLogService.save(log);
return log;
}
IdmScheduledTaskDto scheduledTask = scheduledTaskService.findByQuartzTaskName(processTask.getId());
if (scheduledTask == null) {
addToItemLog(log, MessageFormat.format("Warning - HR process [{0}] cannot be executed, because scheduled task for this type was not found!", simpleName));
log = synchronizationLogService.save(log);
return log;
}
lrt = longRunningTaskService.create(scheduledTask, executor, configurationService.getInstanceId());
} else {
lrt = createdLrts.get(0);
}
if (lrt != null) {
log.addToLog(MessageFormat.format("After success sync have to be run HR task [{1}]. We start him (synchronously) now [{0}]. LRT ID: [{2}]", LocalDateTime.now(), simpleName, lrt.getId()));
log = synchronizationLogService.save(log);
executor.setLongRunningTaskId(lrt.getId());
longRunningTaskManager.executeSync(executor);
log.addToLog(MessageFormat.format("HR task [{1}] ended in [{0}].", LocalDateTime.now(), simpleName));
log = synchronizationLogService.save(log);
}
return log;
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class AbstractSchedulableStatefulExecutorUnitTest method testLogItemProcessed.
@Test
public void testLogItemProcessed() {
IdmLongRunningTaskDto lrt = new IdmLongRunningTaskDto();
lrt.setId(UUID.randomUUID());
when(itemService.saveInternal(any(IdmProcessedTaskItemDto.class))).then(AdditionalAnswers.returnsFirstArg());
when(longRunningTaskService.get(any(UUID.class))).thenReturn(lrt);
when(itemService.createLogItem(any(AbstractDto.class), any(OperationResult.class), any(IdmLongRunningTaskDto.class))).thenCallRealMethod();
//
IdmIdentityDto dto = getTestIdentityDto();
OperationResult opResult = new OperationResult.Builder(OperationState.EXCEPTION).build();
IdmProcessedTaskItemDto qItem = executor.logItemProcessed(dto, opResult);
//
assertEquals(lrt.getId(), qItem.getLongRunningTask());
assertEquals(opResult, qItem.getOperationResult());
assertEquals(dto.getClass().getCanonicalName(), qItem.getReferencedDtoType());
assertEquals(dto.getId(), qItem.getReferencedEntityId());
assertNull(qItem.getScheduledTaskQueueOwner());
//
verify(itemService, times(1)).saveInternal(any(IdmProcessedTaskItemDto.class));
verify(executor, times(1)).logItemProcessed(any(IdmIdentityDto.class), any(OperationResult.class));
verify(executor, times(1)).getLongRunningTaskId();
verify(longRunningTaskService, times(1)).get(any(UUID.class));
verify(itemService, times(1)).createLogItem(any(AbstractDto.class), any(OperationResult.class), any(IdmLongRunningTaskDto.class));
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class AbstractSchedulableStatefulExecutorUnitTest method testDontTouchProcessed.
@Test
public void testDontTouchProcessed() {
IdmLongRunningTaskDto lrt = new IdmLongRunningTaskDto();
IdmScheduledTaskDto scheduledTask = new IdmScheduledTaskDto();
scheduledTask.setId(UUID.randomUUID());
//
IdmIdentityDto dto1 = getTestIdentityDto();
IdmIdentityDto dto2 = getTestIdentityDto();
// stubs
doReturn(true).when(executor).isInProcessedQueue(any(IdmIdentityDto.class));
doReturn(Lists.newArrayList(dto1.getId(), dto2.getId())).when(executor).getProcessedItemRefsFromQueue();
doReturn(scheduledTask.getId()).when(executor).getScheduledTaskId();
// matchers
when(longRunningTaskService.get(any(UUID.class))).thenReturn(lrt);
when(executor.getItemsToProcess(any(Pageable.class))).thenReturn(new PageImpl<>(Lists.newArrayList(dto1, dto2))).thenReturn(new PageImpl<>(Lists.newArrayList()));
//
//
Boolean processingResult = executor.process();
assertTrue(processingResult);
//
//
verify(longRunningTaskService, times(2)).get(any(UUID.class));
//
verify(executor, times(1)).getItemsToProcess(any(Pageable.class));
verify(executor, times(1)).isInProcessedQueue(dto1);
verify(executor, times(1)).isInProcessedQueue(dto2);
verify(executor, times(1)).getProcessedItemRefsFromQueue();
verify(executor, never()).getScheduledTaskId();
verify(executor, never()).removeFromProcessedQueue(any(UUID.class));
verify(executor, never()).addToProcessedQueue(any(IdmIdentityDto.class), any(OperationResult.class));
verify(executor, never()).processItem(any(IdmIdentityDto.class));
verify(itemService, never()).saveInternal(any(IdmProcessedTaskItemDto.class));
verify(itemService, never()).deleteInternal(any(IdmProcessedTaskItemDto.class));
verify(itemService, never()).find(any(IdmProcessedTaskItemFilter.class), any(Pageable.class));
}
Aggregations