use of org.opennms.core.criteria.restrictions.SqlRestriction.Type in project opennms by OpenNMS.
the class DefaultSurveillanceViewService method getNotificationsWithCriterias.
/**
* Returns a list of notifications for a given list of nodes.
*
* @param rowCategories the row catgories
* @param colCategories the column categories
* @param customSeverity the custom severity mapping for notifications
* @param severity the severity for these nodes
* @param criterias the restrictions to use
* @return the list of notifications
*/
private List<OnmsNotification> getNotificationsWithCriterias(final Set<OnmsCategory> rowCategories, final Set<OnmsCategory> colCategories, final Map<OnmsNotification, String> customSeverity, final String severity, final Restriction... criterias) {
CriteriaBuilder criteriaBuilder = new CriteriaBuilder(OnmsNotification.class);
criteriaBuilder.alias("node", "node");
final List<String> parameters = new ArrayList<>(rowCategories.stream().map(OnmsCategory::getName).collect(Collectors.toList()));
parameters.addAll(colCategories.stream().map(OnmsCategory::getName).collect(Collectors.toList()));
final Type[] types = new Type[parameters.size()];
Arrays.fill(types, Type.STRING);
// Restrict on OnmsNotification.nodeId
criteriaBuilder.sql(createQuery("{alias}.nodeId", rowCategories, colCategories), parameters.toArray(new String[parameters.size()]), types);
criteriaBuilder.ne("node.type", "D");
criteriaBuilder.orderBy("pageTime", false);
Criteria myCriteria = criteriaBuilder.toCriteria();
for (Restriction criteria : criterias) {
myCriteria.addRestriction(criteria);
}
List<OnmsNotification> notifications = m_notificationDao.findMatching(myCriteria);
for (OnmsNotification onmsNotification : notifications) {
customSeverity.put(onmsNotification, severity);
}
return notifications;
}
use of org.opennms.core.criteria.restrictions.SqlRestriction.Type in project opennms by OpenNMS.
the class EnLinkdElementFactory method getFromCdpCacheDevicePort.
private OnmsSnmpInterface getFromCdpCacheDevicePort(Integer nodeid, String cdpCacheDevicePort) {
final CriteriaBuilder builder = new CriteriaBuilder(OnmsSnmpInterface.class);
builder.alias("node", "node", JoinType.LEFT_JOIN);
builder.sql("snmpifalias = ? OR snmpifname = ? OR snmpifdescr = ?", new Object[] { cdpCacheDevicePort, cdpCacheDevicePort, cdpCacheDevicePort }, new Type[] { Type.STRING, Type.STRING, Type.STRING }).eq("node.id", nodeid);
final List<OnmsSnmpInterface> nodes = m_snmpInterfaceDao.findMatching(builder.toCriteria());
if (nodes.size() == 1)
return nodes.get(0);
return null;
}
Aggregations