Search in sources :

Example 1 with TaskNotRecoverableException

use of eu.bcvsolutions.idm.core.scheduler.exception.TaskNotRecoverableException in project CzechIdMng by bcvsolutions.

the class DefaultLongRunningTaskManager method recover.

@Override
@Transactional
public LongRunningFutureTask<?> recover(UUID longRunningTaskId) {
    LOG.info("Processing task [{}] again", longRunningTaskId);
    // 
    IdmLongRunningTaskDto task = service.get(longRunningTaskId);
    if (task == null) {
        throw new EntityNotFoundException(IdmLongRunningTask.class, longRunningTaskId);
    }
    if (task.isRunning() || OperationState.RUNNING == task.getResultState()) {
        throw new ResultCodeException(CoreResultCode.LONG_RUNNING_TASK_IS_RUNNING, ImmutableMap.of("taskId", task.getId()));
    }
    if (!task.isRecoverable()) {
        throw new TaskNotRecoverableException(CoreResultCode.LONG_RUNNING_TASK_NOT_RECOVERABLE, task);
    }
    // 
    // clean previous state and create new LRT instance
    DtoUtils.clearAuditFields(task);
    // clear previous transaction context
    task.getTaskProperties().remove(LongRunningTaskExecutor.PARAMETER_TRANSACTION_CONTEXT);
    // new record
    task.setId(null);
    // clear state
    task.clearState();
    // prevent to execute created task redundantly by asynchronous job
    task.setResult(new OperationResult(OperationState.RUNNING));
    // persist new task
    task = service.save(task);
    // 
    LongRunningTaskExecutor<?> taskExecutor = createTaskExecutor(task);
    if (taskExecutor == null) {
        return null;
    }
    return execute(taskExecutor);
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) TaskNotRecoverableException(eu.bcvsolutions.idm.core.scheduler.exception.TaskNotRecoverableException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)1 EntityNotFoundException (eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)1 TaskNotRecoverableException (eu.bcvsolutions.idm.core.scheduler.exception.TaskNotRecoverableException)1 Transactional (org.springframework.transaction.annotation.Transactional)1