use of org.motechproject.tasks.exception.TriggerRetrievalException in project motech by motech.
the class SchedulerChannelProvider method getTriggers.
@Override
public List<TriggerEvent> getTriggers(int page, int pageSize) {
try (Connection conn = DBConnectionManager.getInstance().getConnection(sqlProperties.getProperty(DATA_SOURCE));
Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery(buildGetTriggersQuery(page, pageSize));
List<TriggerEvent> triggers = new ArrayList<>();
while (rs.next()) {
try (InputStream is = new ByteArrayInputStream(rs.getBytes(JOB_DATA));
ObjectInputStream ois = new ObjectInputStream(is)) {
JobDataMap dataMap = (JobDataMap) ois.readObject();
List<EventParameter> parameters = new ArrayList<>();
parameters.add(new EventParameter("scheduler.jobId", MotechSchedulerService.JOB_ID_KEY));
triggers.add(new TriggerEvent("Job: " + rs.getString(JOB_NAME), rs.getString(JOB_NAME), rs.getString(JOB_DESCRIPTION), parameters, dataMap.getString(SchedulerConstants.EVENT_TYPE_KEY_NAME)));
}
}
return triggers;
} catch (SQLException | IOException | ClassNotFoundException e) {
throw new TriggerRetrievalException("Couldn't retrieve triggers for Scheduler channel", e);
}
}
use of org.motechproject.tasks.exception.TriggerRetrievalException in project motech by motech.
the class SchedulerChannelProvider method getTrigger.
@Override
public TriggerEvent getTrigger(TaskTriggerInformation info) {
try (Connection conn = DBConnectionManager.getInstance().getConnection(sqlProperties.getProperty(DATA_SOURCE));
Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery(buildGetTriggerQuery(info.getSubject()));
if (rs.next()) {
try (InputStream is = new ByteArrayInputStream(rs.getBytes(JOB_DATA));
ObjectInputStream ois = new ObjectInputStream(is)) {
JobDataMap dataMap = (JobDataMap) ois.readObject();
List<EventParameter> parameters = new ArrayList<>();
parameters.add(new EventParameter("scheduler.jobId", MotechSchedulerService.JOB_ID_KEY));
return new TriggerEvent("Job: " + rs.getString(JOB_NAME), rs.getString(JOB_NAME), rs.getString(JOB_DESCRIPTION), parameters, dataMap.getString(SchedulerConstants.EVENT_TYPE_KEY_NAME));
}
}
return null;
} catch (SQLException | IOException | ClassNotFoundException e) {
throw new TriggerRetrievalException("Couldn't retrieve triggers for Scheduler channel", e);
}
}
Aggregations