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;
}
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;
}
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);
}
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;
}
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;
}
}
Aggregations