@Override public void onClick(final AjaxRequestTarget target, final T ignore) { SchedTaskDirectoryPanel.this.getTogglePanel().close(target); startAt.setExecutionDetail(model.getObject().getKey(), model.getObject().getName(), target); startAt.toggle(target, true); } }, ActionLink.ActionType.EXECUTE, StandardEntitlement.TASK_EXECUTE);
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final ProvisioningTaskTO other = (ProvisioningTaskTO) obj; return new EqualsBuilder(). appendSuper(super.equals(obj)). append(resource, other.resource). append(performCreate, other.performCreate). append(performUpdate, other.performUpdate). append(performDelete, other.performDelete). append(syncStatus, other.syncStatus). append(unmatchingRule, other.unmatchingRule). append(matchingRule, other.matchingRule). append(actions, other.actions). build(); } }
@Override public int hashCode() { return new HashCodeBuilder(). appendSuper(super.hashCode()). append(resource). append(performCreate). append(performUpdate). append(performDelete). append(syncStatus). append(unmatchingRule). append(matchingRule). append(actions). build(); }
@Override public void updateSchedTask(final SchedTask task, 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())); } if (StringUtils.isBlank(taskTO.getName())) { SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing); sce.getElements().add("name"); throw sce; } task.setName(taskTO.getName()); task.setDescription(taskTO.getDescription()); task.setCronExpression(taskTO.getCronExpression()); task.setActive(taskTO.isActive()); if (task instanceof ProvisioningTask) { fill((ProvisioningTask) task, (ProvisioningTaskTO) taskTO); } }
private void fill(final SchedTaskTO schedTaskTO, final SchedTask schedTask) { schedTaskTO.setName(schedTask.getName()); schedTaskTO.setDescription(schedTask.getDescription()); schedTaskTO.setStart(schedTask.getStartAt()); schedTaskTO.setCronExpression(schedTask.getCronExpression()); schedTaskTO.setActive(schedTask.isActive()); schedTaskTO.setLastExec(schedTaskTO.getStart()); String triggerName = JobNamer.getTriggerName(JobNamer.getJobKey(schedTask).getName()); try { Trigger trigger = scheduler.getScheduler().getTrigger(new TriggerKey(triggerName, Scheduler.DEFAULT_GROUP)); if (trigger != null) { schedTaskTO.setLastExec(trigger.getPreviousFireTime()); schedTaskTO.setNextExec(trigger.getNextFireTime()); } } catch (SchedulerException e) { LOG.warn("While trying to get to " + triggerName, e); } if (schedTaskTO instanceof ProvisioningTaskTO && schedTask instanceof ProvisioningTask) { ProvisioningTaskTO provisioningTaskTO = (ProvisioningTaskTO) schedTaskTO; ProvisioningTask provisioningTask = (ProvisioningTask) schedTask; provisioningTaskTO.setResource(provisioningTask.getResource().getKey()); provisioningTaskTO.getActions().addAll( provisioningTask.getActions().stream().map(Entity::getKey).collect(Collectors.toList())); provisioningTaskTO.setPerformCreate(provisioningTask.isPerformCreate()); provisioningTaskTO.setPerformUpdate(provisioningTask.isPerformUpdate()); provisioningTaskTO.setPerformDelete(provisioningTask.isPerformDelete()); provisioningTaskTO.setSyncStatus(provisioningTask.isSyncStatus()); } }
@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; }
@Override protected Serializable onApplyInternal(final SchedTaskTO modelObject) { if (modelObject instanceof PushTaskTO && wrapper != null) { wrapper.fillFilterConditions(); } modelObject.setCronExpression(crontabPanel.getCronExpression()); if (modelObject.getKey() == null) { taskRestClient.create(type, modelObject); } else { taskRestClient.update(type, modelObject); } return modelObject; }
@Override public Response create(final TaskType type, final SchedTaskTO taskTO) { SchedTaskTO createdTask; if (taskTO != null) { createdTask = logic.createSchedTask(type, taskTO); } else { throw new BadRequestException(); } URI location = uriInfo.getAbsolutePathBuilder().path(createdTask.getKey()).build(); return Response.created(location). header(RESTHeaders.RESOURCE_KEY, createdTask.getKey()). build(); }
@Override public void onClick(final AjaxRequestTarget target, final T ignore) { SchedTaskDirectoryPanel.this.getTogglePanel().close(target); send(SchedTaskDirectoryPanel.this, Broadcast.EXACT, new AjaxWizard.EditItemActionEvent<>( restClient.readTask(taskType, model.getObject().getKey()), target).setResourceModel( new StringResourceModel("inner.task.edit", SchedTaskDirectoryPanel.this, Model.of(Pair.of( ActionLink.ActionType.EDIT, model.getObject()))))); } }, ActionLink.ActionType.EDIT, StandardEntitlement.TASK_UPDATE);
@Override public void onClick(final AjaxRequestTarget target, final T ignore) { try { restClient.delete(taskType, taskTO.getKey()); SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED)); target.add(container); SchedTaskDirectoryPanel.this.getTogglePanel().close(target); } catch (SyncopeClientException e) { SyncopeConsoleSession.get().error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage()); LOG.error("While deleting propagation task {}", taskTO.getKey(), e); } ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target); } }, ActionLink.ActionType.DELETE, StandardEntitlement.TASK_DELETE, true);
@Override public int hashCode() { return new HashCodeBuilder(). appendSuper(super.hashCode()). append(resource). append(performCreate). append(performUpdate). append(performDelete). append(syncStatus). append(unmatchingRule). append(matchingRule). append(actions). build(); }
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final ProvisioningTaskTO other = (ProvisioningTaskTO) obj; return new EqualsBuilder(). appendSuper(super.equals(obj)). append(resource, other.resource). append(performCreate, other.performCreate). append(performUpdate, other.performUpdate). append(performDelete, other.performDelete). append(syncStatus, other.syncStatus). append(unmatchingRule, other.unmatchingRule). append(matchingRule, other.matchingRule). append(actions, other.actions). build(); } }
@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); }