Search in sources :

Example 1 with JobDetailedInfo

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

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();
    }
}
Also used : JobDetailedInfo(org.motechproject.scheduler.contract.JobDetailedInfo) HashMap(java.util.HashMap) JobBasicInfo(org.motechproject.scheduler.contract.JobBasicInfo) MotechEvent(org.motechproject.event.MotechEvent) JobsSearchSettings(org.motechproject.scheduler.contract.JobsSearchSettings) RunOnceSchedulableJob(org.motechproject.scheduler.contract.RunOnceSchedulableJob) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)2 JobDetailedInfo (org.motechproject.scheduler.contract.JobDetailedInfo)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 MotechEvent (org.motechproject.event.MotechEvent)1 EventInfo (org.motechproject.scheduler.contract.EventInfo)1 JobBasicInfo (org.motechproject.scheduler.contract.JobBasicInfo)1 JobsSearchSettings (org.motechproject.scheduler.contract.JobsSearchSettings)1 RunOnceSchedulableJob (org.motechproject.scheduler.contract.RunOnceSchedulableJob)1 MotechSchedulerJobRetrievalException (org.motechproject.scheduler.exception.MotechSchedulerJobRetrievalException)1 JobKey (org.quartz.JobKey)1 SchedulerException (org.quartz.SchedulerException)1