Search in sources :

Example 6 with NotificationTask

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);
}
Also used : NotificationTask(org.apache.syncope.core.persistence.api.entity.task.NotificationTask)

Example 7 with NotificationTask

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;
}
Also used : TaskUtils(org.apache.syncope.core.persistence.api.entity.task.TaskUtils) NotificationTask(org.apache.syncope.core.persistence.api.entity.task.NotificationTask) SchedTask(org.apache.syncope.core.persistence.api.entity.task.SchedTask) Task(org.apache.syncope.core.persistence.api.entity.task.Task) JobDataMap(org.quartz.JobDataMap) ExecTO(org.apache.syncope.common.lib.to.ExecTO) TaskExec(org.apache.syncope.core.persistence.api.entity.task.TaskExec) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Date(java.util.Date) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) SchedulerException(org.quartz.SchedulerException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

NotificationTask (org.apache.syncope.core.persistence.api.entity.task.NotificationTask)7 TaskExec (org.apache.syncope.core.persistence.api.entity.task.TaskExec)3 ArrayList (java.util.ArrayList)2 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)2 ExecTO (org.apache.syncope.common.lib.to.ExecTO)2 UserTO (org.apache.syncope.common.lib.to.UserTO)2 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)2 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)2 User (org.apache.syncope.core.persistence.api.entity.user.User)2 ParseException (java.text.ParseException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Pair (org.apache.commons.lang3.tuple.Pair)1 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)1 GroupTO (org.apache.syncope.common.lib.to.GroupTO)1 NotificationTaskTO (org.apache.syncope.common.lib.to.NotificationTaskTO)1