Search in sources :

Example 1 with MotechSchedulerJobRetrievalException

use of org.motechproject.scheduler.exception.MotechSchedulerJobRetrievalException in project motech by motech.

the class MotechSchedulerDatabaseServiceImpl method getScheduledJobDetailedInfo.

@Override
public JobDetailedInfo getScheduledJobDetailedInfo(JobBasicInfo jobBasicInfo) throws MotechSchedulerJobRetrievalException {
    JobDetailedInfo jobDetailedInfo = new JobDetailedInfo();
    List<EventInfo> eventInfos = new ArrayList<>();
    try {
        for (String groupName : scheduler.getJobGroupNames()) {
            for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) {
                if (jobKey.getName().equals(jobBasicInfo.getName())) {
                    EventInfo eventInfo = new EventInfo();
                    String subject;
                    Map<String, Object> parameters = scheduler.getJobDetail(jobKey).getJobDataMap().getWrappedMap();
                    Map<String, Object> metadata = (HashMap) parameters.get(SchedulerConstants.EVENT_METADATA);
                    parameters.remove(SchedulerConstants.EVENT_METADATA);
                    parameters.putAll(metadata);
                    eventInfo.setParameters(parameters);
                    if (eventInfo.getParameters().containsKey(SchedulerConstants.EVENT_TYPE_KEY_NAME)) {
                        subject = eventInfo.getParameters().get(SchedulerConstants.EVENT_TYPE_KEY_NAME).toString();
                        eventInfo.getParameters().remove(SchedulerConstants.EVENT_TYPE_KEY_NAME);
                    } else {
                        subject = jobKey.getName().substring(0, jobKey.getName().indexOf('-'));
                    }
                    eventInfo.setSubject(subject);
                    eventInfos.add(eventInfo);
                }
            }
        }
        jobDetailedInfo.setEventInfoList(eventInfos);
        return jobDetailedInfo;
    } catch (SchedulerException e) {
        throw new MotechSchedulerJobRetrievalException("Retrieval of detailed info for job " + jobBasicInfo.getName() + " failed.", e);
    }
}
Also used : JobDetailedInfo(org.motechproject.scheduler.contract.JobDetailedInfo) JobKey(org.quartz.JobKey) SchedulerException(org.quartz.SchedulerException) EventInfo(org.motechproject.scheduler.contract.EventInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MotechSchedulerJobRetrievalException(org.motechproject.scheduler.exception.MotechSchedulerJobRetrievalException)

Example 2 with MotechSchedulerJobRetrievalException

use of org.motechproject.scheduler.exception.MotechSchedulerJobRetrievalException in project motech by motech.

the class MotechSchedulerDatabaseServiceImpl method getScheduledJobsBasicInfo.

@Override
public List<JobBasicInfo> getScheduledJobsBasicInfo(JobsSearchSettings jobsSearchSettings) throws MotechSchedulerJobRetrievalException {
    List<JobBasicInfo> jobBasicInfos = new LinkedList<>();
    String query = getQuery(jobsSearchSettings);
    if (query == null) {
        return jobBasicInfos;
    }
    LOGGER.debug("Executing {}", query);
    List<String> columnNames = new LinkedList<>();
    columnNames.add(TRIGGER_NAME);
    columnNames.add(TRIGGER_GROUP);
    columnNames.add(JOB_DATA);
    List<List<Object>> objects;
    try {
        objects = executeQuery(query, columnNames);
        for (List<Object> row : objects) {
            JobKey jobKey = new JobKey(row.get(0).toString(), row.get(1).toString());
            Trigger trigger = scheduler.getTriggersOfJob(jobKey).get(0);
            String jobName = jobKey.getName();
            String jobGroup = jobKey.getGroup();
            String jobType = getJobType(jobKey);
            String activity = getJobActivity(trigger);
            String info = getJobInfo(trigger, jobType);
            String status = getJobStatus(trigger.getKey());
            String startDate = getStartDate(trigger);
            String nextFireDate = "";
            if (trigger.getNextFireTime() != null) {
                nextFireDate = DateTimeFormat.forPattern(DATE_FORMAT_PATTERN).print(trigger.getNextFireTime().getTime());
            }
            String endDate = getEndDate(trigger, jobType);
            boolean uiDefined = getUiDefined((byte[]) row.get(2));
            jobBasicInfos.add(new JobBasicInfo(activity, status, jobName, jobGroup, startDate, nextFireDate, endDate, jobType, info, uiDefined));
        }
        return jobBasicInfos;
    } catch (SQLException | SchedulerException | ClassNotFoundException | IOException e) {
        throw new MotechSchedulerJobRetrievalException("Retrieval of scheduled jobs failed.", e);
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) SQLException(java.sql.SQLException) IOException(java.io.IOException) LinkedList(java.util.LinkedList) MotechSchedulerJobRetrievalException(org.motechproject.scheduler.exception.MotechSchedulerJobRetrievalException) JobKey(org.quartz.JobKey) CalendarIntervalTrigger(org.quartz.CalendarIntervalTrigger) CronTrigger(org.quartz.CronTrigger) OperableTrigger(org.quartz.spi.OperableTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 3 with MotechSchedulerJobRetrievalException

use of org.motechproject.scheduler.exception.MotechSchedulerJobRetrievalException in project motech by motech.

the class MotechSchedulerDatabaseServiceImpl method countJobs.

@Override
public int countJobs(JobsSearchSettings jobsSearchSettings) throws MotechSchedulerJobRetrievalException {
    String query = buildJobsCountSqlQuery(jobsSearchSettings);
    int rowCount;
    try {
        rowCount = executeCountQuery(query);
        LOGGER.debug("Executing {}", query);
        return rowCount;
    } catch (SQLException e) {
        throw new MotechSchedulerJobRetrievalException("Jobs counting failed.", e);
    }
}
Also used : SQLException(java.sql.SQLException) MotechSchedulerJobRetrievalException(org.motechproject.scheduler.exception.MotechSchedulerJobRetrievalException)

Aggregations

MotechSchedulerJobRetrievalException (org.motechproject.scheduler.exception.MotechSchedulerJobRetrievalException)3 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 JobKey (org.quartz.JobKey)2 SchedulerException (org.quartz.SchedulerException)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 EventInfo (org.motechproject.scheduler.contract.EventInfo)1 JobBasicInfo (org.motechproject.scheduler.contract.JobBasicInfo)1 JobDetailedInfo (org.motechproject.scheduler.contract.JobDetailedInfo)1 CalendarIntervalTrigger (org.quartz.CalendarIntervalTrigger)1 CronTrigger (org.quartz.CronTrigger)1 SimpleTrigger (org.quartz.SimpleTrigger)1 Trigger (org.quartz.Trigger)1 OperableTrigger (org.quartz.spi.OperableTrigger)1