use of org.motechproject.scheduler.contract.JobDetailedInfo 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);
}
}
use of org.motechproject.scheduler.contract.JobDetailedInfo in project motech by motech.
the class MotechSchedulerDatabaseServiceImplBundleIT method shouldGetScheduledJobDetailedInfo.
@Test
public void shouldGetScheduledJobDetailedInfo() throws SchedulerException, SQLException {
try {
fakeNow(newDateTime(CURRENT_YEAR + 6, 7, 15, 10, 0, 0));
JobDetailedInfo jobDetailedInfo = null;
Map<String, Object> params = new HashMap<>();
params.put(MotechSchedulerService.JOB_ID_KEY, "job_id_2");
params.put("param1", "value1");
params.put("param2", "value2");
schedulerService.scheduleRunOnceJob(new RunOnceSchedulableJob(new MotechEvent("test_event_2", params), newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0)));
JobsSearchSettings jobsSearchSettings = getGridSettings(0, 10, "name", "asc");
for (JobBasicInfo job : databaseService.getScheduledJobsBasicInfo(jobsSearchSettings)) {
if (job.getName().equals("test_event_2-job_id_2-runonce")) {
jobDetailedInfo = databaseService.getScheduledJobDetailedInfo(job);
}
}
assertNotNull(jobDetailedInfo);
assertEquals("test_event_2", jobDetailedInfo.getEventInfoList().get(0).getSubject());
assertEquals(4, jobDetailedInfo.getEventInfoList().get(0).getParameters().size());
} finally {
stopFakingTime();
}
}
Aggregations