Search in sources :

Example 1 with Type

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;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) Restriction(org.opennms.core.criteria.restrictions.Restriction) OnmsResourceType(org.opennms.netmgt.model.OnmsResourceType) Type(org.opennms.core.criteria.restrictions.SqlRestriction.Type) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) ArrayList(java.util.ArrayList) Criteria(org.opennms.core.criteria.Criteria) OnmsNotification(org.opennms.netmgt.model.OnmsNotification)

Example 2 with Type

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;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) Type(org.opennms.core.criteria.restrictions.SqlRestriction.Type) JoinType(org.opennms.core.criteria.Alias.JoinType) BridgeDot1dBaseType(org.opennms.netmgt.model.BridgeElement.BridgeDot1dBaseType) CiscoNetworkProtocolType(org.opennms.netmgt.model.CdpLink.CiscoNetworkProtocolType) LldpChassisIdSubType(org.opennms.core.utils.LldpUtils.LldpChassisIdSubType) LldpPortIdSubType(org.opennms.core.utils.LldpUtils.LldpPortIdSubType) IsisISAdjNeighSysType(org.opennms.netmgt.model.IsIsLink.IsisISAdjNeighSysType) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface)

Aggregations

CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)2 Type (org.opennms.core.criteria.restrictions.SqlRestriction.Type)2 ArrayList (java.util.ArrayList)1 JoinType (org.opennms.core.criteria.Alias.JoinType)1 Criteria (org.opennms.core.criteria.Criteria)1 Restriction (org.opennms.core.criteria.restrictions.Restriction)1 LldpChassisIdSubType (org.opennms.core.utils.LldpUtils.LldpChassisIdSubType)1 LldpPortIdSubType (org.opennms.core.utils.LldpUtils.LldpPortIdSubType)1 BridgeDot1dBaseType (org.opennms.netmgt.model.BridgeElement.BridgeDot1dBaseType)1 CiscoNetworkProtocolType (org.opennms.netmgt.model.CdpLink.CiscoNetworkProtocolType)1 IsisISAdjNeighSysType (org.opennms.netmgt.model.IsIsLink.IsisISAdjNeighSysType)1 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)1 OnmsNotification (org.opennms.netmgt.model.OnmsNotification)1 OnmsResourceType (org.opennms.netmgt.model.OnmsResourceType)1 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)1