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);
}
Aggregations