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