Search in sources :

Example 31 with IdmLongRunningTaskFilter

use of eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter in project CzechIdMng by bcvsolutions.

the class DefaultIdmLongRunningTaskServiceTest method operationStateFilterTest.

@Test
public void operationStateFilterTest() {
    IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
    String expectedResult = "TEST_SUCCESS_06_M";
    // set tasks
    LongRunningTaskExecutor<String> taskExecutor = new TestSimpleLongRunningTaskExecutor(expectedResult);
    assertNull(taskExecutor.getLongRunningTaskId());
    manager.executeSync(taskExecutor);
    IdmLongRunningTaskDto task1 = idmLongRunningTaskService.get(taskExecutor.getLongRunningTaskId());
    // set filter
    filter.setOperationState(task1.getResultState());
    Page<IdmLongRunningTaskDto> result = idmLongRunningTaskService.find(filter, null);
    assertEquals("Wrong operationState id", true, result.getContent().contains(task1));
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 32 with IdmLongRunningTaskFilter

use of eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter in project CzechIdMng by bcvsolutions.

the class DefaultSchedulerManagerIntegrationTest method testDependentTaskNoExecutionAfterInitiatorFails.

@Test
public void testDependentTaskNoExecutionAfterInitiatorFails() throws Exception {
    helper.setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, false);
    try {
        LongRunningTaskExecuteDependentProcessor processor = context.getBean(LongRunningTaskExecuteDependentProcessor.class);
        // 
        IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
        filter.setOperationState(OperationState.CREATED);
        filter.setTaskType(TestSchedulableTask.class.getCanonicalName());
        filter.setFrom(new DateTime());
        List<IdmLongRunningTaskDto> createdLrts = longRunningTaskService.find(filter, null).getContent();
        Assert.assertEquals(0L, createdLrts.size());
        // 
        Task task = createTask("dependent-task-initiator");
        DependentTaskTrigger trigger = new DependentTaskTrigger();
        trigger.setInitiatorTaskId(task.getId());
        // 
        // initiator = dependent task => circular execution
        manager.createTrigger(task.getId(), trigger);
        manager.runTask(task.getId());
        helper.waitForResult(getContinueFunction());
        createdLrts = longRunningTaskService.find(filter, null).getContent();
        Assert.assertEquals(1L, createdLrts.size());
        IdmLongRunningTaskDto lrt = createdLrts.get(0);
        lrt.setResult(new OperationResult(OperationState.EXCEPTION));
        // not executed
        EventResult<IdmLongRunningTaskDto> result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
        Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
        lrt.setResult(new OperationResult(OperationState.BLOCKED));
        result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
        Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
        lrt.setResult(new OperationResult(OperationState.NOT_EXECUTED));
        result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
        Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
        lrt.setResult(new OperationResult(OperationState.CANCELED));
        result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
        Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
        lrt.setResult(new OperationResult(OperationState.CREATED));
        result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
        Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
        lrt.setResult(new OperationResult(OperationState.RUNNING));
        result = processor.process(new LongRunningTaskEvent(LongRunningTaskEventType.END, lrt));
        Assert.assertEquals(OperationState.NOT_EXECUTED, result.getResults().get(0).getState());
        // 
        longRunningTaskManager.cancel(lrt.getId());
        // 
        longRunningTaskService.find(filter, null).getContent();
        // cancel - clean up
        Assert.assertEquals(0L, longRunningTaskService.find(filter, null).getTotalElements());
    } finally {
        helper.setConfigurationValue(SchedulerConfiguration.PROPERTY_TASK_ASYNCHRONOUS_ENABLED, true);
    }
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) FutureTask(java.util.concurrent.FutureTask) Task(eu.bcvsolutions.idm.core.scheduler.api.dto.Task) LongRunningFutureTask(eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask) LongRunningTaskExecuteDependentProcessor(eu.bcvsolutions.idm.core.scheduler.event.processor.LongRunningTaskExecuteDependentProcessor) DependentTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.DependentTaskTrigger) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) LongRunningTaskEvent(eu.bcvsolutions.idm.core.scheduler.api.event.LongRunningTaskEvent) DateTime(org.joda.time.DateTime) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 33 with IdmLongRunningTaskFilter

use of eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter in project CzechIdMng by bcvsolutions.

the class IdentityUsernameExportBulkActionTest method processBulkAction.

@Test
public void processBulkAction() throws IOException {
    IdmBulkActionDto exampleAction = findBulkAction(IdmIdentity.class, IdentityUsernameExportBulkAction.BULK_ACTION_NAME);
    assertNotNull(exampleAction);
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmIdentityDto identity2 = getHelper().createIdentity();
    IdmIdentityDto identity3 = getHelper().createIdentity();
    exampleAction.setIdentifiers(Sets.newHashSet(identity.getId(), identity2.getId(), identity3.getId()));
    IdmBulkActionDto processAction = bulkActionManager.processAction(exampleAction);
    assertNotNull(processAction.getLongRunningTaskId());
    IdmLongRunningTaskFilter context = new IdmLongRunningTaskFilter();
    context.setIncludeItemCounts(true);
    IdmLongRunningTaskDto longRunningTask = longRunningTaskService.get(processAction.getLongRunningTaskId(), context);
    assertEquals(Long.valueOf(3), longRunningTask.getCount());
    assertEquals(Long.valueOf(3), longRunningTask.getSuccessItemCount());
    assertEquals(Long.valueOf(0), longRunningTask.getFailedItemCount());
    assertEquals(Long.valueOf(0), longRunningTask.getWarningItemCount());
    OperationResult result = longRunningTask.getResult();
    ResultModel model = result.getModel();
    assertNotNull(model);
    assertEquals(206, model.getStatusCode());
    assertEquals(CoreResultCode.LONG_RUNNING_TASK_PARTITIAL_DOWNLOAD.getCode(), model.getStatusEnum());
    UUID fromString = attachmentManager.getAttachments(longRunningTask, null).getContent().get(0).getId();
    assertNotNull(fromString);
    IdmAttachmentDto attachmentDto = attachmentManager.get(fromString);
    assertNotNull(attachmentDto);
    assertEquals(longRunningTask.getId(), attachmentDto.getOwnerId());
    IdmAttachmentDto attachmentForLongRunningTask = longRunningTaskManager.getAttachment(longRunningTask.getId(), attachmentDto.getId());
    assertNotNull(attachmentForLongRunningTask);
    assertEquals(attachmentDto.getId(), attachmentForLongRunningTask.getId());
    InputStream is = attachmentManager.getAttachmentData(attachmentDto.getId());
    try {
        String string = IOUtils.toString(is);
        assertTrue(string.contains(identity.getUsername()));
        assertTrue(string.contains(identity2.getUsername()));
        assertTrue(string.contains(identity3.getUsername()));
        assertTrue(string.contains(IdmIdentity_.username.getName().toUpperCase()));
        assertTrue(string.contains(IdmIdentity_.externalCode.getName().toUpperCase()));
        assertTrue(string.contains(IdmIdentity_.state.getName().toUpperCase()));
    } finally {
        IOUtils.closeQuietly(is);
    }
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) InputStream(java.io.InputStream) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 34 with IdmLongRunningTaskFilter

use of eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter in project CzechIdMng by bcvsolutions.

the class DefaultTestHelper method createRoleComposition.

@Override
public IdmRoleCompositionDto createRoleComposition(IdmRoleDto superior, IdmRoleDto sub) {
    IdmRoleCompositionDto roleComposition = new IdmRoleCompositionDto();
    roleComposition.setSuperior(superior.getId());
    roleComposition.setSub(sub.getId());
    // create role composition
    roleComposition = roleCompositionService.save(roleComposition);
    // wait for role composition is completely processed
    UUID transactionId = roleComposition.getTransactionId();
    // 
    waitForResult(res -> {
        IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
        filter.setOperationStates(Lists.newArrayList(OperationState.CREATED, OperationState.RUNNING));
        filter.setTransactionId(transactionId);
        // 
        List<IdmLongRunningTaskDto> tasks = taskManager.findLongRunningTasks(filter, null).getContent();
        // use this to debug, if needed ...
        tasks.forEach(task -> {
            System.out.println("Task: " + task.getTaskType() + ", " + task.getResultState() + ", TID: " + transactionId + " ~ " + task.getTransactionId());
        });
        // 
        return !tasks.isEmpty();
    }, 500, // ~ 40s max
    80);
    // 
    return roleComposition;
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) UUID(java.util.UUID)

Example 35 with IdmLongRunningTaskFilter

use of eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter in project CzechIdMng by bcvsolutions.

the class IdentityLogExampleBulkActionTest method processBulkAction.

@Test
public void processBulkAction() {
    IdmBulkActionDto exampleAction = findBulkAction(IdmIdentity.class, IdentityLogExampleBulkAction.BULK_ACTION_NAME);
    assertNotNull(exampleAction);
    Assert.assertEquals(NotificationLevel.INFO, exampleAction.getLevel());
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmIdentityDto identity2 = getHelper().createIdentity();
    IdmIdentityDto identity3 = getHelper().createIdentity();
    exampleAction.setIdentifiers(Sets.newHashSet(identity.getId(), identity2.getId(), identity3.getId()));
    IdmBulkActionDto processAction = bulkActionManager.processAction(exampleAction);
    assertNotNull(processAction.getLongRunningTaskId());
    IdmLongRunningTaskFilter context = new IdmLongRunningTaskFilter();
    context.setIncludeItemCounts(true);
    IdmLongRunningTaskDto longRunningTask = longRunningTaskService.get(processAction.getLongRunningTaskId(), context);
    assertEquals(Long.valueOf(3), longRunningTask.getCount());
    assertEquals(Long.valueOf(3), longRunningTask.getSuccessItemCount());
    assertEquals(Long.valueOf(0), longRunningTask.getFailedItemCount());
    assertEquals(Long.valueOf(0), longRunningTask.getWarningItemCount());
    List<IdmProcessedTaskItemDto> items = getItemsForLrt(longRunningTask);
    assertEquals(3, items.size());
    boolean identitySuccess = false;
    boolean identitySuccess2 = false;
    boolean identitySuccess3 = false;
    for (IdmProcessedTaskItemDto item : items) {
        if (item.getOperationResult().getState() != OperationState.EXECUTED) {
            fail("Identity " + item.getReferencedEntityId() + ", failed.");
        }
        if (item.getReferencedEntityId().equals(identity.getId())) {
            identitySuccess = true;
        }
        if (item.getReferencedEntityId().equals(identity2.getId())) {
            identitySuccess2 = true;
        }
        if (item.getReferencedEntityId().equals(identity3.getId())) {
            identitySuccess3 = true;
        }
    }
    assertTrue(identitySuccess);
    assertTrue(identitySuccess2);
    assertTrue(identitySuccess3);
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Aggregations

IdmLongRunningTaskFilter (eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter)54 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)41 Test (org.junit.Test)31 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)21 UUID (java.util.UUID)18 Transactional (org.springframework.transaction.annotation.Transactional)11 AbstractBulkActionTest (eu.bcvsolutions.idm.test.api.AbstractBulkActionTest)9 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)8 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)8 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)8 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)8 List (java.util.List)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8 LongRunningFutureTask (eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask)7 Assert (org.junit.Assert)7 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)6 IdmBulkActionDto (eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto)5 EventConfiguration (eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration)5 AutomaticRoleAttributeRuleComparison (eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleComparison)5 AutomaticRoleAttributeRuleType (eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType)5