コード例 #1
0
  /**
   * In the absence of DAOs and ORMs this creates an Event object from the persisted record.
   *
   * @param eventid a int.
   * @return a populated Event object
   */
  public Event getEvent(final int eventid) {
    // don't switch using event builder since this event is read from the database
    final Event event = new Event();
    Querier querier =
        new Querier(
            m_dataSource,
            "select * from events where eventid = ?",
            new RowProcessor() {

              public void processRow(ResultSet rs) throws SQLException {
                event.setDbid(rs.getInt("eventid"));
                event.setUei(rs.getString("eventuei"));
                event.setNodeid(rs.getLong("nodeid"));
                event.setTime(rs.getString("eventtime"));
                event.setHost(rs.getString("eventhost"));
                event.setInterface(rs.getString("ipaddr"));
                event.setSnmphost(rs.getString("eventsnmphost"));
                event.setService(getServiceName(rs.getInt("serviceid")));
                event.setCreationTime(rs.getString("eventcreatetime"));
                event.setSeverity(rs.getString("eventseverity"));
                event.setPathoutage(rs.getString("eventpathoutage"));
                Tticket tticket = new Tticket();
                tticket.setContent(rs.getString("eventtticket"));
                tticket.setState(rs.getString("eventtticketstate"));
                event.setTticket(tticket);
                event.setSource(rs.getString("eventsource"));
              }

              private String getServiceName(int serviceid) {
                SingleResultQuerier querier =
                    new SingleResultQuerier(
                        m_dataSource, "select servicename from service where serviceid = ?");
                return (String) querier.getResult();
              }
            });
    querier.execute(eventid);
    return event;
  }
コード例 #2
0
 /**
  * forEachUserNotification
  *
  * @param notifId a int.
  * @param rp a {@link org.opennms.netmgt.utils.RowProcessor} object.
  */
 public void forEachUserNotification(final int notifId, final RowProcessor rp) {
   final Querier querier =
       new Querier(
           m_dataSource, "select * from usersNotified where notifyId = ? order by notifytime", rp);
   querier.execute(notifId);
 }
コード例 #3
0
  /**
   * rebuildParameterMap
   *
   * @param notifId a int.
   * @param resolutionPrefix a {@link java.lang.String} object.
   * @param skipNumericPrefix a boolean.
   * @return a {@link java.util.Map} object.
   * @throws java.lang.Exception if any.
   */
  public Map<String, String> rebuildParameterMap(
      final int notifId, final String resolutionPrefix, final boolean skipNumericPrefix)
      throws Exception {
    final Map<String, String> parmMap = new HashMap<String, String>();
    Querier querier =
        new Querier(
            m_dataSource,
            "select notifications.*, service.* from notifications left outer join service on notifications.serviceID = service.serviceID  where notifyId = ?") {
          public void processRow(ResultSet rs) throws SQLException {

            /*
             * Note, getString on results is valid for any SQL data type except the new SQL types:
             *    Blog, Clob, Array, Struct, Ref
             * of which we have none in this table so this row processor is using getString
             * to correctly align with annotated types in the map.
             */
            parmMap.put(
                NotificationManager.PARAM_TEXT_MSG,
                BroadcastEventProcessor.expandNotifParms(
                        resolutionPrefix,
                        Collections.singletonMap("noticeid", String.valueOf(notifId)))
                    + rs.getString("textMsg"));
            if (skipNumericPrefix) {
              parmMap.put(NotificationManager.PARAM_NUM_MSG, rs.getString("numericMsg"));
            } else {
              parmMap.put(
                  NotificationManager.PARAM_NUM_MSG,
                  BroadcastEventProcessor.expandNotifParms(
                          resolutionPrefix,
                          Collections.singletonMap("noticeid", String.valueOf(notifId)))
                      + rs.getString("numericMsg"));
            }
            parmMap.put(
                NotificationManager.PARAM_SUBJECT,
                BroadcastEventProcessor.expandNotifParms(
                        resolutionPrefix,
                        Collections.singletonMap("noticeid", String.valueOf(notifId)))
                    + rs.getString("subject"));
            parmMap.put(NotificationManager.PARAM_NODE, rs.getString("nodeID"));
            parmMap.put(NotificationManager.PARAM_INTERFACE, rs.getString("interfaceID"));
            parmMap.put(NotificationManager.PARAM_SERVICE, rs.getString("serviceName"));
            parmMap.put("noticeid", rs.getString("notifyID"));
            parmMap.put("eventID", rs.getString("eventID"));
            parmMap.put("eventUEI", rs.getString("eventUEI"));

            Notification notification = null;
            try {
              notification = getNotification(rs.getObject("notifConfigName").toString());
            } catch (MarshalException e) {
            } catch (ValidationException e) {
            } catch (IOException e) {
            }

            if (notification != null) {
              addNotificationParams(parmMap, notification);
            }
          }
        };
    querier.execute(notifId);
    return parmMap;
  }