Search in sources :

Example 81 with NotFoundException

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

the class SyncopeLogic method readTypeExtension.

@PreAuthorize("isAuthenticated()")
public TypeExtensionTO readTypeExtension(final String groupName) {
    Group group = groupDAO.findByName(groupName);
    if (group == null) {
        throw new NotFoundException("Group " + groupName);
    }
    Optional<? extends TypeExtension> typeExt = group.getTypeExtension(anyTypeDAO.findUser());
    if (!typeExt.isPresent()) {
        throw new NotFoundException("TypeExtension in " + groupName + " for users");
    }
    return groupDataBinder.getTypeExtensionTO(typeExt.get());
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 82 with NotFoundException

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

the class TaskLogic method updateSchedTask.

@PreAuthorize("hasRole('" + StandardEntitlement.TASK_UPDATE + "')")
public <T extends SchedTaskTO> T updateSchedTask(final TaskType type, final SchedTaskTO taskTO) {
    SchedTask task = taskDAO.find(taskTO.getKey());
    if (task == null) {
        throw new NotFoundException("Task " + taskTO.getKey());
    }
    TaskUtils taskUtils = taskUtilsFactory.getInstance(task);
    if (taskUtils.getType() != type) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRequest);
        sce.getElements().add("Found " + type + ", expected " + taskUtils.getType());
        throw sce;
    }
    binder.updateSchedTask(task, taskTO, taskUtils);
    task = taskDAO.save(task);
    try {
        jobManager.register(task, task.getStartAt(), confDAO.find("tasks.interruptMaxRetries", 1L));
    } catch (Exception e) {
        LOG.error("While registering quartz job for task " + task.getKey(), e);
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Scheduling);
        sce.getElements().add(e.getMessage());
        throw sce;
    }
    return binder.getTaskTO(task, taskUtils, false);
}
Also used : TaskUtils(org.apache.syncope.core.persistence.api.entity.task.TaskUtils) SchedTask(org.apache.syncope.core.persistence.api.entity.task.SchedTask) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) 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 83 with NotFoundException

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

the class TaskLogic method deleteExecution.

@PreAuthorize("hasRole('" + StandardEntitlement.TASK_DELETE + "')")
@Override
public ExecTO deleteExecution(final String execKey) {
    TaskExec taskExec = taskExecDAO.find(execKey);
    if (taskExec == null) {
        throw new NotFoundException("Task execution " + execKey);
    }
    ExecTO taskExecutionToDelete = binder.getExecTO(taskExec);
    taskExecDAO.delete(taskExec);
    return taskExecutionToDelete;
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) TaskExec(org.apache.syncope.core.persistence.api.entity.task.TaskExec) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 84 with NotFoundException

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

the class TaskLogic method getJob.

@PreAuthorize("hasRole('" + StandardEntitlement.TASK_READ + "')")
@Override
public JobTO getJob(final String key) {
    Task task = taskDAO.find(key);
    if (task == null) {
        throw new NotFoundException("Task " + key);
    }
    JobTO jobTO = null;
    try {
        jobTO = getJobTO(JobNamer.getJobKey(task));
    } catch (SchedulerException e) {
        LOG.error("Problems while retrieving scheduled job {}", JobNamer.getJobKey(task), e);
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Scheduling);
        sce.getElements().add(e.getMessage());
        throw sce;
    }
    if (jobTO == null) {
        throw new NotFoundException("Job for task " + key);
    }
    return jobTO;
}
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) SchedulerException(org.quartz.SchedulerException) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) JobTO(org.apache.syncope.common.lib.to.JobTO) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 85 with NotFoundException

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

the class TaskLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.TASK_DELETE + "')")
public <T extends TaskTO> T delete(final TaskType type, final String key) {
    Task task = taskDAO.find(key);
    if (task == null) {
        throw new NotFoundException("Task " + key);
    }
    TaskUtils taskUtils = taskUtilsFactory.getInstance(task);
    if (type != null && taskUtils.getType() != type) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRequest);
        sce.getElements().add("Found " + type + ", expected " + taskUtils.getType());
        throw sce;
    }
    T taskToDelete = binder.getTaskTO(task, taskUtils, true);
    if (TaskType.SCHEDULED == taskUtils.getType() || TaskType.PULL == taskUtils.getType() || TaskType.PUSH == taskUtils.getType()) {
        jobManager.unregister(task);
    }
    taskDAO.delete(task);
    return taskToDelete;
}
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) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) 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