@PreAuthorize("hasRole('TASK_UPDATE')")
@RequestMapping(method = RequestMethod.POST, value = "/update/sched")
public TaskTO updateSched(@RequestBody final SchedTaskTO taskTO) {
LOG.debug("Task update called with parameter {}", taskTO);
SchedTask task = taskDAO.find(taskTO.getId());
if (task == null) {
throw new NotFoundException("Task " + taskTO.getId());
}
TaskUtil taskUtil = getTaskUtil(task);
SyncopeClientCompositeErrorException scce = new SyncopeClientCompositeErrorException(HttpStatus.BAD_REQUEST);
binder.updateSchedTask(task, taskTO, taskUtil);
task = taskDAO.save(task);
try {
jobInstanceLoader.registerJob(task, task.getJobClassName(), task.getCronExpression());
} catch (Exception e) {
LOG.error("While registering quartz job for task " + task.getId(), e);
SyncopeClientException sce = new SyncopeClientException(SyncopeClientExceptionType.Scheduling);
sce.addElement(e.getMessage());
scce.addException(sce);
throw scce;
}
auditManager.audit(Category.task, TaskSubCategory.update, Result.success,
"Successfully udpated task: " + task.getId() + "/" + taskUtil);
return binder.getTaskTO(task, taskUtil);
}