Search in sources :

Example 1 with EventInfo

use of org.motechproject.scheduler.contract.EventInfo 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)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 EventInfo (org.motechproject.scheduler.contract.EventInfo)1 JobDetailedInfo (org.motechproject.scheduler.contract.JobDetailedInfo)1 MotechSchedulerJobRetrievalException (org.motechproject.scheduler.exception.MotechSchedulerJobRetrievalException)1 JobKey (org.quartz.JobKey)1 SchedulerException (org.quartz.SchedulerException)1