use of org.motechproject.scheduler.contract.SchedulableJob in project motech by motech.
the class SchedulableJobBuilder method buildJob.
/**
* Builds a job based on the given key, data map and trigger.
*
* @param key the job key
* @param dataMap the job data map
* @param trigger the job trigger
* @return the created job
* @throws SchedulerException when there were problems while building job
*/
public static SchedulableJob buildJob(JobKey key, JobDataMap dataMap, Trigger trigger) throws SchedulerException {
SchedulableJob job;
Map<String, Object> params = dataMap.getWrappedMap();
Map<String, Object> metadata = (Map<String, Object>) params.get(EVENT_METADATA);
params.remove(EVENT_METADATA);
params.putAll(metadata);
JobDataMap map = new JobDataMap(params);
switch(getJobType(key, map)) {
case CRON:
job = buildCronSchedulableJob(trigger, map);
break;
case REPEATING:
job = buildRepeatingSchedulableJob(trigger, map);
break;
case REPEATING_PERIOD:
job = buildRepeatingPeriodSchedulableJob(trigger, map);
break;
case DAY_OF_WEEK:
job = buildDayOfWeekSchedulableJob(trigger, map);
break;
case RUN_ONCE:
job = buildRunOnceSchedulableJob();
break;
default:
throw new MotechSchedulerException(String.format("Unknown job type: \n %s\n %s", key.getName(), key.getGroup()));
}
job.setMotechEvent(new MotechEvent(dataMap.getString(EVENT_TYPE_KEY_NAME), map.getWrappedMap()));
job.setUiDefined(map.getBoolean(UI_DEFINED));
job.setStartDate(new DateTime(trigger.getStartTime()));
return job;
}
Aggregations