use of org.motechproject.scheduler.exception.MotechSchedulerJobRetrievalException 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.exception.MotechSchedulerJobRetrievalException in project motech by motech.
the class MotechSchedulerDatabaseServiceImpl method getScheduledJobsBasicInfo.
@Override
public List<JobBasicInfo> getScheduledJobsBasicInfo(JobsSearchSettings jobsSearchSettings) throws MotechSchedulerJobRetrievalException {
List<JobBasicInfo> jobBasicInfos = new LinkedList<>();
String query = getQuery(jobsSearchSettings);
if (query == null) {
return jobBasicInfos;
}
LOGGER.debug("Executing {}", query);
List<String> columnNames = new LinkedList<>();
columnNames.add(TRIGGER_NAME);
columnNames.add(TRIGGER_GROUP);
columnNames.add(JOB_DATA);
List<List<Object>> objects;
try {
objects = executeQuery(query, columnNames);
for (List<Object> row : objects) {
JobKey jobKey = new JobKey(row.get(0).toString(), row.get(1).toString());
Trigger trigger = scheduler.getTriggersOfJob(jobKey).get(0);
String jobName = jobKey.getName();
String jobGroup = jobKey.getGroup();
String jobType = getJobType(jobKey);
String activity = getJobActivity(trigger);
String info = getJobInfo(trigger, jobType);
String status = getJobStatus(trigger.getKey());
String startDate = getStartDate(trigger);
String nextFireDate = "";
if (trigger.getNextFireTime() != null) {
nextFireDate = DateTimeFormat.forPattern(DATE_FORMAT_PATTERN).print(trigger.getNextFireTime().getTime());
}
String endDate = getEndDate(trigger, jobType);
boolean uiDefined = getUiDefined((byte[]) row.get(2));
jobBasicInfos.add(new JobBasicInfo(activity, status, jobName, jobGroup, startDate, nextFireDate, endDate, jobType, info, uiDefined));
}
return jobBasicInfos;
} catch (SQLException | SchedulerException | ClassNotFoundException | IOException e) {
throw new MotechSchedulerJobRetrievalException("Retrieval of scheduled jobs failed.", e);
}
}
use of org.motechproject.scheduler.exception.MotechSchedulerJobRetrievalException in project motech by motech.
the class MotechSchedulerDatabaseServiceImpl method countJobs.
@Override
public int countJobs(JobsSearchSettings jobsSearchSettings) throws MotechSchedulerJobRetrievalException {
String query = buildJobsCountSqlQuery(jobsSearchSettings);
int rowCount;
try {
rowCount = executeCountQuery(query);
LOGGER.debug("Executing {}", query);
return rowCount;
} catch (SQLException e) {
throw new MotechSchedulerJobRetrievalException("Jobs counting failed.", e);
}
}
Aggregations