use of org.apache.syncope.core.persistence.api.entity.task.NotificationTask in project syncope by apache.
the class NotificationManagerImpl method setTaskExecuted.
@Override
public void setTaskExecuted(final String taskKey, final boolean executed) {
NotificationTask task = taskDAO.find(taskKey);
task.setExecuted(executed);
taskDAO.save(task);
}
use of org.apache.syncope.core.persistence.api.entity.task.NotificationTask in project syncope by apache.
the class TaskLogic method execute.
@PreAuthorize("hasRole('" + StandardEntitlement.TASK_EXECUTE + "')")
@Override
public ExecTO execute(final String key, final Date startAt, final boolean dryRun) {
Task task = taskDAO.find(key);
if (task == null) {
throw new NotFoundException("Task " + key);
}
if (startAt != null && startAt.before(new Date())) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Scheduling);
sce.getElements().add("Cannot schedule in the past");
throw sce;
}
TaskUtils taskUtil = taskUtilsFactory.getInstance(task);
ExecTO result = null;
switch(taskUtil.getType()) {
case PROPAGATION:
TaskExec propExec = taskExecutor.execute((PropagationTaskTO) binder.getTaskTO(task, taskUtil, false));
result = binder.getExecTO(propExec);
break;
case NOTIFICATION:
TaskExec notExec = notificationJobDelegate.executeSingle((NotificationTask) task);
result = binder.getExecTO(notExec);
break;
case SCHEDULED:
case PULL:
case PUSH:
if (!((SchedTask) task).isActive()) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Scheduling);
sce.getElements().add("Task " + key + " is not active");
throw sce;
}
try {
Map<String, Object> jobDataMap = jobManager.register((SchedTask) task, startAt, confDAO.find("tasks.interruptMaxRetries", 1L));
jobDataMap.put(TaskJob.DRY_RUN_JOBDETAIL_KEY, dryRun);
if (startAt == null) {
scheduler.getScheduler().triggerJob(JobNamer.getJobKey(task), new JobDataMap(jobDataMap));
}
} catch (Exception e) {
LOG.error("While executing task {}", task, e);
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Scheduling);
sce.getElements().add(e.getMessage());
throw sce;
}
result = new ExecTO();
result.setJobType(JobType.TASK);
result.setRefKey(task.getKey());
result.setRefDesc(binder.buildRefDesc(task));
result.setStart(new Date());
result.setStatus("JOB_FIRED");
result.setMessage("Job fired; waiting for results...");
break;
default:
}
return result;
}
Aggregations