Search in sources :

Example 26 with IdmLongRunningTaskDto

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

the class DefaultIdmLongRunningTaskServiceTest method textFilterTest.

@Test
public void textFilterTest() {
    IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
    String expectedResult = "TEST_SUCCESS_04_M";
    String type1 = "Type00001";
    String type2 = "Type00002";
    // set tasks
    LongRunningTaskExecutor<String> taskExecutor = new TestSimpleLongRunningTaskExecutor(expectedResult);
    assertNull(taskExecutor.getLongRunningTaskId());
    manager.executeSync(taskExecutor);
    IdmLongRunningTaskDto task1 = idmLongRunningTaskService.get(taskExecutor.getLongRunningTaskId());
    task1.setTaskType(type1);
    idmLongRunningTaskService.save(task1);
    LongRunningTaskExecutor<String> taskExecutor2 = new TestSimpleLongRunningTaskExecutor(expectedResult);
    assertNull(taskExecutor2.getLongRunningTaskId());
    manager.executeSync(taskExecutor2);
    IdmLongRunningTaskDto task2 = idmLongRunningTaskService.get(taskExecutor2.getLongRunningTaskId());
    task2.setTaskType(type1);
    idmLongRunningTaskService.save(task2);
    LongRunningTaskExecutor<String> taskExecutor3 = new TestSimpleLongRunningTaskExecutor(expectedResult);
    assertNull(taskExecutor3.getLongRunningTaskId());
    manager.executeSync(taskExecutor3);
    IdmLongRunningTaskDto task3 = idmLongRunningTaskService.get(taskExecutor3.getLongRunningTaskId());
    task3.setTaskType(type2);
    idmLongRunningTaskService.save(task3);
    LongRunningTaskExecutor<String> taskExecutor4 = new TestSimpleLongRunningTaskExecutor(expectedResult);
    assertNull(taskExecutor4.getLongRunningTaskId());
    manager.executeSync(taskExecutor4);
    IdmLongRunningTaskDto task4 = idmLongRunningTaskService.get(taskExecutor4.getLongRunningTaskId());
    task4.setTaskDescription(type1);
    idmLongRunningTaskService.save(task4);
    // set filter
    filter.setText(type1);
    Page<IdmLongRunningTaskDto> result = idmLongRunningTaskService.find(filter, null);
    assertEquals("Wrong Text Type", 3, result.getTotalElements());
    assertEquals("Wrong Text Type", true, result.getContent().contains(task4));
    assertEquals("Wrong Text Description", 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 27 with IdmLongRunningTaskDto

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

the class DefaultIdmLongRunningTaskServiceTest method statefulFilterTest.

@Test
public void statefulFilterTest() {
    IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
    String expectedResult = "TEST_SUCCESS_01_M";
    // set tasks
    LongRunningTaskExecutor<String> taskExecutor = new TestSimpleLongRunningTaskExecutor(expectedResult);
    assertNull(taskExecutor.getLongRunningTaskId());
    manager.executeSync(taskExecutor);
    IdmLongRunningTaskDto task1 = idmLongRunningTaskService.get(taskExecutor.getLongRunningTaskId());
    task1.setStateful(false);
    idmLongRunningTaskService.save(task1);
    // 
    LongRunningTaskExecutor<String> taskExecutor2 = new TestSimpleLongRunningTaskExecutor(expectedResult);
    assertNull(taskExecutor2.getLongRunningTaskId());
    manager.executeSync(taskExecutor2);
    idmLongRunningTaskService.get(taskExecutor2.getLongRunningTaskId());
    // 
    LongRunningTaskExecutor<String> taskExecutor3 = new TestSimpleLongRunningTaskExecutor(expectedResult);
    assertNull(taskExecutor3.getLongRunningTaskId());
    manager.executeSync(taskExecutor3);
    idmLongRunningTaskService.get(taskExecutor3.getLongRunningTaskId());
    // set filter
    filter.setTaskType(task1.getTaskType());
    filter.setStateful(true);
    Page<IdmLongRunningTaskDto> result = idmLongRunningTaskService.find(filter, null);
    assertEquals("Wrong StateFul true", 2, result.getTotalElements());
    filter.setStateful(false);
    result = idmLongRunningTaskService.find(filter, null);
    assertEquals("Wrong StateFul false", 1, result.getTotalElements());
}
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 28 with IdmLongRunningTaskDto

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

the class DefaultIdmLongRunningTaskServiceTest method datesFilterTest.

@Test
public void datesFilterTest() {
    IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
    String expectedResult = "TEST_SUCCESS_05_M";
    // set tasks
    LongRunningTaskExecutor<String> taskExecutor = new TestSimpleLongRunningTaskExecutor(expectedResult);
    assertNull(taskExecutor.getLongRunningTaskId());
    manager.executeSync(taskExecutor);
    IdmLongRunningTaskDto task1 = idmLongRunningTaskService.get(taskExecutor.getLongRunningTaskId());
    LongRunningTaskExecutor<String> taskExecutor2 = new TestSimpleLongRunningTaskExecutor(expectedResult);
    assertNull(taskExecutor2.getLongRunningTaskId());
    manager.executeSync(taskExecutor2);
    IdmLongRunningTaskDto task2 = idmLongRunningTaskService.get(taskExecutor2.getLongRunningTaskId());
    task2.setCreated(task1.getCreated());
    idmLongRunningTaskService.save(task2);
    filter.setFrom(task1.getCreated());
    Page<IdmLongRunningTaskDto> result = idmLongRunningTaskService.find(filter, null);
    assertEquals("Wrong From Date", 2, result.getTotalElements());
    filter.setTill(task1.getModified());
    result = idmLongRunningTaskService.find(filter, null);
    assertEquals("Wrong Till Date", 2, result.getTotalElements());
}
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 29 with IdmLongRunningTaskDto

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

the class LongRunningTaskEndProcessor method process.

@Override
public EventResult<IdmLongRunningTaskDto> process(EntityEvent<IdmLongRunningTaskDto> event) {
    IdmLongRunningTaskDto task = event.getContent();
    // end task
    task.setRunning(false);
    // and persist state
    service.save(task);
    event.setContent(task);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Example 30 with IdmLongRunningTaskDto

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

the class DefaultLongRunningTaskManager method executeSync.

@Override
@Transactional
public <V> V executeSync(LongRunningTaskExecutor<V> taskExecutor) {
    // autowire task properties
    AutowireHelper.autowire(taskExecutor);
    // persist LRT
    IdmLongRunningTaskDto task = persistTask(taskExecutor);
    // 
    markTaskAsRunning(getValidTask(taskExecutor));
    // 
    LOG.debug("Execute task [{}] synchronously", task.getId());
    // execute
    try {
        return taskExecutor.call();
    } catch (Exception ex) {
        throw new ResultCodeException(CoreResultCode.LONG_RUNNING_TASK_FAILED, ImmutableMap.of("taskId", task.getId(), "taskType", task.getTaskType(), "instanceId", task.getInstanceId()), ex);
    } finally {
        LOG.debug("Executing task [{}] synchronously ended", task.getId());
    }
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)56 Test (org.junit.Test)32 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)29 IdmScheduledTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto)14 IdmProcessedTaskItemDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto)13 IdmLongRunningTaskFilter (eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter)13 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)11 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)10 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)9 Transactional (org.springframework.transaction.annotation.Transactional)7 LocalDate (org.joda.time.LocalDate)6 LongRunningFutureTask (eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask)5 IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)4 Task (eu.bcvsolutions.idm.core.scheduler.api.dto.Task)4 UUID (java.util.UUID)4 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)3 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)3 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)3 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)3 ResultModel (eu.bcvsolutions.idm.core.api.dto.ResultModel)3