use of org.jaffa.modules.scheduler.services.SchedulerHelper in project jaffa-framework by jaffa-projects.
the class TaskFinderTx method find.
/**
* Searches for Task objects.
* @param taskType taskType of tasks that should be returned.
* @throws FrameworkException in case any internal error occurs.
* @throws ApplicationExceptions Indicates application error(s).
* @return The search results.
*/
public TaskFinderOutDto find(String taskType) throws FrameworkException, ApplicationExceptions {
UOW uow = null;
try {
if (log.isDebugEnabled())
log.debug("Retrieving all scheduled tasks");
uow = new UOW();
SchedulerHelper sh = SchedulerHelperFactory.instance();
TaskFinderOutDto output = new TaskFinderOutDto();
output.setSchedulerStatus(sh.getSchedulerStatus());
if (output.getSchedulerStatus() == SchedulerHelper.SchedulerStatusEnumeration.STOPPED) {
if (log.isDebugEnabled())
log.debug("The Scheduler has been shutdown. The Task list cannot be obtained");
} else {
ScheduledTask[] tasks = null;
if (SecurityManager.checkFunctionAccess("Jaffa.Scheduler.Task.InquiryAll"))
tasks = sh.getTasks(null, taskType != null ? taskType : null);
else
tasks = sh.getTasks(org.jaffa.security.SecurityManager.getPrincipal().getName(), taskType != null ? taskType : null);
if (tasks != null) {
Collection<TaskFinderOutRowDto> rows = new LinkedList<TaskFinderOutRowDto>();
for (ScheduledTask task : tasks) {
if (SchedulerBrowser.hasBrowseTaskAccess(task)) {
TaskFinderOutRowDto row = new TaskFinderOutRowDto(task);
if (row.getFailedTaskCount() != null && row.getFailedTaskCount() > 0)
row.setLastError(findLastError(uow, task.getScheduledTaskId()));
row.setHasAdminTaskAccess(SchedulerBrowser.hasAdminTaskAccess(task.getTaskType()));
rows.add(row);
}
}
output.setRows(rows.toArray(new TaskFinderOutRowDto[rows.size()]));
}
}
if (log.isDebugEnabled())
log.debug("Output: " + output);
return output;
} catch (Exception e) {
throw ExceptionHelper.throwAFR(e);
} finally {
if (uow != null)
uow.rollback();
}
}
Aggregations