@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; }
@PreAuthorize("hasRole('" + StandardEntitlement.TASK_READ + "')") @Transactional(readOnly = true) public <T extends TaskTO> T read(final TaskType type, final String key, final boolean details) { 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; } return binder.getTaskTO(task, taskUtilsFactory.getInstance(task), details); }
@Override public String buildRefDesc(final Task task) { return taskUtilsFactory.getInstance(task).getType().name() + " " + "Task " + task.getKey() + " " + (task instanceof SchedTask ? SchedTask.class.cast(task).getName() : task instanceof PropagationTask ? PropagationTask.class.cast(task).getConnObjectKey() : StringUtils.EMPTY); }
@PreAuthorize("hasRole('" + StandardEntitlement.TASK_CREATE + "')") public <T extends SchedTaskTO> T createSchedTask(final TaskType type, final T taskTO) { TaskUtils taskUtils = taskUtilsFactory.getInstance(taskTO); if (taskUtils.getType() != type) { SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRequest); sce.getElements().add("Found " + type + ", expected " + taskUtils.getType()); throw sce; } SchedTask task = binder.createSchedTask(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); }
@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); }
@Override public SchedTask createSchedTask(final SchedTaskTO taskTO, final TaskUtils taskUtils) { Class<? extends TaskTO> taskTOClass = taskUtils.taskTOClass(); if (taskTOClass == null || !taskTOClass.equals(taskTO.getClass())) { throw new IllegalArgumentException(String.format("Expected %s, found %s", taskTOClass, taskTO.getClass())); } SchedTask task = taskUtils.newTask(); task.setStartAt(taskTO.getStartAt()); task.setCronExpression(taskTO.getCronExpression()); task.setName(taskTO.getName()); task.setDescription(taskTO.getDescription()); task.setActive(taskTO.isActive()); if (taskUtils.getType() == TaskType.SCHEDULED) { Implementation implementation = implementationDAO.find(taskTO.getJobDelegate()); if (implementation == null) { throw new NotFoundException("Implementation " + taskTO.getJobDelegate()); } task.setJobDelegate(implementation); } else if (taskTO instanceof ProvisioningTaskTO) { ProvisioningTaskTO provisioningTaskTO = (ProvisioningTaskTO) taskTO; ExternalResource resource = resourceDAO.find(provisioningTaskTO.getResource()); if (resource == null) { throw new NotFoundException("Resource " + provisioningTaskTO.getResource()); } ((ProvisioningTask) task).setResource(resource); fill((ProvisioningTask) task, provisioningTaskTO); } return task; }
switch (taskUtil.getType()) { case PROPAGATION: PropagationTaskTO taskTO = binder.<PropagationTaskTO>getTaskTO(task, taskUtil, false);
switch (taskUtils.getType()) { case PROPAGATION: PropagationTask propagationTask = (PropagationTask) task;