Search in sources :

Example 1 with SchedulerHelper

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();
    }
}
Also used : SchedulerHelper(org.jaffa.modules.scheduler.services.SchedulerHelper) ScheduledTask(org.jaffa.modules.scheduler.services.ScheduledTask) UOW(org.jaffa.persistence.UOW) TaskFinderOutDto(org.jaffa.modules.scheduler.components.taskfinder.dto.TaskFinderOutDto) LinkedList(java.util.LinkedList) FrameworkException(org.jaffa.exceptions.FrameworkException) TaskFinderOutRowDto(org.jaffa.modules.scheduler.components.taskfinder.dto.TaskFinderOutRowDto)

Aggregations

LinkedList (java.util.LinkedList)1 FrameworkException (org.jaffa.exceptions.FrameworkException)1 TaskFinderOutDto (org.jaffa.modules.scheduler.components.taskfinder.dto.TaskFinderOutDto)1 TaskFinderOutRowDto (org.jaffa.modules.scheduler.components.taskfinder.dto.TaskFinderOutRowDto)1 ScheduledTask (org.jaffa.modules.scheduler.services.ScheduledTask)1 SchedulerHelper (org.jaffa.modules.scheduler.services.SchedulerHelper)1 UOW (org.jaffa.persistence.UOW)1