Search in sources :

Example 86 with NotFoundException

use of org.apache.syncope.core.persistence.api.dao.NotFoundException 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)

Example 87 with NotFoundException

use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.

the class TaskLogic method deleteExecutions.

@PreAuthorize("hasRole('" + StandardEntitlement.TASK_DELETE + "')")
@Override
public BulkActionResult deleteExecutions(final String key, final Date startedBefore, final Date startedAfter, final Date endedBefore, final Date endedAfter) {
    Task task = taskDAO.find(key);
    if (task == null) {
        throw new NotFoundException("Task " + key);
    }
    BulkActionResult result = new BulkActionResult();
    taskExecDAO.findAll(task, startedBefore, startedAfter, endedBefore, endedAfter).forEach(exec -> {
        try {
            taskExecDAO.delete(exec);
            result.getResults().put(String.valueOf(exec.getKey()), BulkActionResult.Status.SUCCESS);
        } catch (Exception e) {
            LOG.error("Error deleting execution {} of task {}", exec.getKey(), key, e);
            result.getResults().put(String.valueOf(exec.getKey()), BulkActionResult.Status.FAILURE);
        }
    });
    return result;
}
Also used : 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) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) 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)

Example 88 with NotFoundException

use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.

the class TaskLogic method actionJob.

@PreAuthorize("hasRole('" + StandardEntitlement.TASK_EXECUTE + "')")
@Override
public void actionJob(final String key, final JobAction action) {
    Task task = taskDAO.find(key);
    if (task == null) {
        throw new NotFoundException("Task " + key);
    }
    doActionJob(JobNamer.getJobKey(task), action);
}
Also used : 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) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 89 with NotFoundException

use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.

the class AnyTypeClassLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.ANYTYPECLASS_DELETE + "')")
public AnyTypeClassTO delete(final String key) {
    AnyTypeClass anyTypeClass = anyTypeClassDAO.find(key);
    if (anyTypeClass == null) {
        LOG.error("Could not find anyTypeClass '" + key + "'");
        throw new NotFoundException(key);
    }
    AnyTypeClassTO deleted = binder.getAnyTypeClassTO(anyTypeClass);
    anyTypeClassDAO.delete(key);
    return deleted;
}
Also used : NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 90 with NotFoundException

use of org.apache.syncope.core.persistence.api.dao.NotFoundException in project syncope by apache.

the class AnyTypeLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.ANYTYPE_DELETE + "')")
public AnyTypeTO delete(final String key) {
    AnyType anyType = anyTypeDAO.find(key);
    if (anyType == null) {
        LOG.error("Could not find anyType '" + key + "'");
        throw new NotFoundException(key);
    }
    Integer anyObjects = anyObjectDAO.countByType().get(anyType);
    if (anyObjects != null && anyObjects > 0) {
        LOG.error("{} AnyObject instances found for {}, aborting", anyObjects, anyType);
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidAnyType);
        sce.getElements().add("AnyObject instances found for " + key);
        throw sce;
    }
    try {
        return binder.delete(anyType);
    } catch (IllegalArgumentException e) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRequest);
        sce.getElements().add(e.getMessage());
        throw sce;
    }
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)110 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)87 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)41 Transactional (org.springframework.transaction.annotation.Transactional)21 Date (java.util.Date)12 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)10 SchedulerException (org.quartz.SchedulerException)10 ArrayList (java.util.ArrayList)8 List (java.util.List)8 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)8 Report (org.apache.syncope.core.persistence.api.entity.Report)8 SchedTask (org.apache.syncope.core.persistence.api.entity.task.SchedTask)8 User (org.apache.syncope.core.persistence.api.entity.user.User)8 HashMap (java.util.HashMap)7 Collectors (java.util.stream.Collectors)7 Pair (org.apache.commons.lang3.tuple.Pair)7 ExecTO (org.apache.syncope.common.lib.to.ExecTO)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 StringUtils (org.apache.commons.lang3.StringUtils)6 DuplicateException (org.apache.syncope.core.persistence.api.dao.DuplicateException)6