use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.
the class NoticeFactory method canDisplayEvent.
/**
* This method determines the log status of an event associated with a
* notification
*
* @param eventId
* the unique id of the event from the notice
* @return true if the event is display, false if log only
*/
public static boolean canDisplayEvent(int eventId) {
boolean display = false;
final DBUtils d = new DBUtils(NoticeFactory.class);
try {
Connection connection = DataSourceFactory.getInstance().getConnection();
d.watch(connection);
PreparedStatement statement = connection.prepareStatement("SELECT eventDisplay FROM events WHERE eventid=?");
d.watch(statement);
statement.setInt(1, eventId);
ResultSet results = statement.executeQuery();
d.watch(results);
results.next();
String status = results.getString(1);
if (status.equals("Y")) {
display = true;
}
} catch (SQLException e) {
LOG.error("Error getting event display status: {}", e.getMessage(), e);
} finally {
d.cleanUp();
}
return display;
}
use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.
the class NoticeFactory method getNoticesForInterface.
/**
* Return all notices (optionally only unacknowledged notices) sorted by id
* for the given interface.
*
* @param nodeId a int.
* @param ipAddress a {@link java.lang.String} object.
* @param includeAcknowledged a boolean.
* @return an array of {@link org.opennms.web.notification.Notification} objects.
* @throws java.sql.SQLException if any.
*/
public static Notification[] getNoticesForInterface(int nodeId, String ipAddress, boolean includeAcknowledged, ServletContext servletContext) throws SQLException {
if (ipAddress == null) {
throw new IllegalArgumentException("Cannot take null parameters.");
}
Notification[] notices = null;
final DBUtils d = new DBUtils(NoticeFactory.class);
try {
Connection conn = DataSourceFactory.getInstance().getConnection();
d.watch(conn);
final StringBuilder select = new StringBuilder("SELECT * FROM NOTIFICATIONS WHERE NODEID=? AND INTERFACEID=?");
if (!includeAcknowledged) {
select.append(" AND RESPONDTIME IS NULL");
}
select.append(" ORDER BY NOTIFYID DESC");
PreparedStatement stmt = conn.prepareStatement(select.toString());
d.watch(stmt);
stmt.setInt(1, nodeId);
stmt.setString(2, ipAddress);
ResultSet rs = stmt.executeQuery();
d.watch(rs);
notices = rs2Notices(rs, servletContext);
} finally {
d.cleanUp();
}
return notices;
}
use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.
the class NoticeFactory method getNotice.
/**
* Return a specific notice.
*
* @param noticeId a int.
* @return a {@link org.opennms.web.notification.Notification} object.
* @throws java.sql.SQLException if any.
*/
public static Notification getNotice(int noticeId, ServletContext servletContext) throws SQLException {
Notification notice = null;
DBUtils d = new DBUtils(NoticeFactory.class);
try {
Connection conn = DataSourceFactory.getInstance().getConnection();
d.watch(conn);
PreparedStatement stmt = conn.prepareStatement("SELECT * FROM NOTIFICATION WHERE NOTIFYID=?");
d.watch(stmt);
stmt.setInt(1, noticeId);
ResultSet rs = stmt.executeQuery();
d.watch(rs);
Notification[] notices = rs2Notices(rs, servletContext);
// what do I do if this actually returns more than one service?
if (notices.length > 0) {
notice = notices[0];
}
} finally {
d.cleanUp();
}
return notice;
}
use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.
the class NoticeFactory method getNoticeCount.
/**
* Count the number of notices for a given acknowledgement type.
*
* @param ackType a {@link org.opennms.web.notification.AcknowledgeType} object.
* @param filters an array of org$opennms$web$filter$Filter objects.
* @return a int.
* @throws java.sql.SQLException if any.
*/
public static int getNoticeCount(AcknowledgeType ackType, Filter[] filters) throws SQLException {
if (ackType == null || filters == null) {
throw new IllegalArgumentException("Cannot take null parameters.");
}
int noticeCount = 0;
final DBUtils d = new DBUtils(NoticeFactory.class);
try {
Connection conn = DataSourceFactory.getInstance().getConnection();
d.watch(conn);
final StringBuilder select = new StringBuilder("SELECT COUNT(NOTIFYID) AS NOTICECOUNT FROM NOTIFICATIONS WHERE");
select.append(ackType.getAcknowledgeTypeClause());
for (Filter filter : filters) {
select.append(" AND");
select.append(filter.getParamSql());
}
PreparedStatement stmt = conn.prepareStatement(select.toString());
d.watch(stmt);
int parameterIndex = 1;
for (Filter filter : filters) {
parameterIndex += filter.bindParam(stmt, parameterIndex);
}
ResultSet rs = stmt.executeQuery();
d.watch(rs);
if (rs.next()) {
noticeCount = rs.getInt("NOTICECOUNT");
}
} finally {
d.cleanUp();
}
return noticeCount;
}
use of org.opennms.core.utils.DBUtils in project opennms by OpenNMS.
the class NoticeFactory method getNoticesForService.
/**
* Return all notices (optionally only unacknowledged notices) sorted by id
* for the given service type, regardless of what node or interface they
* belong to.
*
* @param serviceId a int.
* @param includeAcknowledged a boolean.
* @return an array of {@link org.opennms.web.notification.Notification} objects.
* @throws java.sql.SQLException if any.
*/
public static Notification[] getNoticesForService(int serviceId, boolean includeAcknowledged, ServletContext servletContext) throws SQLException {
Notification[] notices = null;
DBUtils d = new DBUtils(NoticeFactory.class);
try {
Connection conn = DataSourceFactory.getInstance().getConnection();
d.watch(conn);
final StringBuilder select = new StringBuilder("SELECT * FROM NOTIFICATION WHERE SERVICEID=?");
if (!includeAcknowledged) {
select.append(" AND RESPONDTIME IS NULL");
}
select.append(" ORDER BY NOTIFIYID DESC");
PreparedStatement stmt = conn.prepareStatement(select.toString());
d.watch(stmt);
stmt.setInt(1, serviceId);
ResultSet rs = stmt.executeQuery();
d.watch(rs);
notices = rs2Notices(rs, servletContext);
} finally {
d.cleanUp();
}
return notices;
}
Aggregations