Search in sources :

Example 1 with TriggerRetrievalException

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);
    }
}
Also used : TriggerRetrievalException(org.motechproject.tasks.exception.TriggerRetrievalException) JobDataMap(org.quartz.JobDataMap) SQLException(java.sql.SQLException) Statement(java.sql.Statement) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) ObjectInputStream(java.io.ObjectInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) IOException(java.io.IOException) EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) ByteArrayInputStream(java.io.ByteArrayInputStream) ResultSet(java.sql.ResultSet) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with TriggerRetrievalException

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);
    }
}
Also used : TriggerRetrievalException(org.motechproject.tasks.exception.TriggerRetrievalException) JobDataMap(org.quartz.JobDataMap) SQLException(java.sql.SQLException) Statement(java.sql.Statement) ObjectInputStream(java.io.ObjectInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) IOException(java.io.IOException) EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) ByteArrayInputStream(java.io.ByteArrayInputStream) ResultSet(java.sql.ResultSet) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Statement (java.sql.Statement)2 ArrayList (java.util.ArrayList)2 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)2 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)2 TriggerRetrievalException (org.motechproject.tasks.exception.TriggerRetrievalException)2 JobDataMap (org.quartz.JobDataMap)2