Search in sources :

Example 26 with OnmsCriteria

use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.

the class DefaultNodeListService method addCriteriaForIpLike.

private static void addCriteriaForIpLike(OnmsCriteria criteria, String iplike) {
    OnmsCriteria ipInterface = criteria.createCriteria("node.ipInterfaces", "ipInterface");
    ipInterface.add(Restrictions.ne("isManaged", "D"));
    ipInterface.add(OnmsRestrictions.ipLike(iplike));
}
Also used : OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria)

Example 27 with OnmsCriteria

use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.

the class DefaultRtcService method createServiceCriteria.

/**
     * <p>Create a {@link OnmsCriteria} that will select {@link OnmsMonitoredService} objects.</p>
     * 
     * <p>CAUTION: This criteria must contain a JOIN alias to the node table called 'node' so that the
     * {@link org.opennms.dashboard.server.CriteriaAddingVisitor.addCriteriaForCategories(OnmsCriteria, String...)}
     * function can add a category-based restriction on matching node IDs to the criteria.</p>
     *
     * @return a {@link org.opennms.netmgt.model.OnmsCriteria} object.
     */
@Override
public OnmsCriteria createServiceCriteria() {
    OnmsCriteria serviceCriteria = new OnmsCriteria(OnmsMonitoredService.class, "monitoredService");
    serviceCriteria.add(Restrictions.eq("monitoredService.status", "A"));
    serviceCriteria.createAlias("ipInterface", "ipInterface", OnmsCriteria.INNER_JOIN);
    serviceCriteria.add(Restrictions.ne("ipInterface.isManaged", "D"));
    // Required for {@link org.opennms.dashboard.server.CriteriaAddingVisitor.addCriteriaForCategories(OnmsCriteria, String...)}
    // to work properly.
    serviceCriteria.createAlias("ipInterface.node", "node", OnmsCriteria.INNER_JOIN);
    serviceCriteria.add(Restrictions.ne("node.type", "D"));
    serviceCriteria.createAlias("serviceType", "serviceType", OnmsCriteria.INNER_JOIN);
    serviceCriteria.createAlias("currentOutages", "currentOutages", OnmsCriteria.INNER_JOIN);
    return serviceCriteria;
}
Also used : OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria)

Example 28 with OnmsCriteria

use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.

the class HibernateCriteriaConverterIT method testNodeQuery.

@Test
@JUnitTemporaryDatabase
public void testNodeQuery() throws Exception {
    List<OnmsNode> nodes;
    // first, try with OnmsCriteria
    final OnmsCriteria crit = new OnmsCriteria(OnmsNode.class);
    crit.add(org.hibernate.criterion.Restrictions.isNotNull("id"));
    nodes = m_nodeDao.findMatching(crit);
    assertEquals(6, nodes.size());
    // then the same with the builder
    final CriteriaBuilder cb = new CriteriaBuilder(OnmsNode.class);
    cb.isNotNull("id");
    nodes = m_nodeDao.findMatching(cb.toCriteria());
    assertEquals(6, nodes.size());
    cb.eq("label", "node1").join("ipInterfaces", "ipInterface").eq("ipInterface.ipAddress", "192.168.1.1");
    nodes = m_nodeDao.findMatching(cb.toCriteria());
    assertEquals(1, nodes.size());
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 29 with OnmsCriteria

use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.

the class DefaultRtcService method createOutageCriteria.

/**
     * <p>Create a {@link OnmsCriteria} that will select {@link OnmsOutage} objects.</p>
     * 
     * <p>CAUTION: This criteria must contain a JOIN alias to the node table called 'node' so that the
     * {@link org.opennms.dashboard.server.CriteriaAddingVisitor.addCriteriaForCategories(OnmsCriteria, String...)}
     * function can add a category-based restriction on matching node IDs to the criteria.</p>
     *
     * @return a {@link org.opennms.netmgt.model.OnmsCriteria} object.
     */
@Override
public OnmsCriteria createOutageCriteria() {
    OnmsCriteria outageCriteria = new OnmsCriteria(OnmsOutage.class, "outage");
    outageCriteria.createAlias("monitoredService", "monitoredService", OnmsCriteria.INNER_JOIN);
    outageCriteria.add(Restrictions.eq("monitoredService.status", "A"));
    outageCriteria.createAlias("monitoredService.ipInterface", "ipInterface", OnmsCriteria.INNER_JOIN);
    outageCriteria.add(Restrictions.ne("ipInterface.isManaged", "D"));
    // Required for {@link org.opennms.dashboard.server.CriteriaAddingVisitor.addCriteriaForCategories(OnmsCriteria, String...)}
    // to work properly.
    outageCriteria.createAlias("monitoredService.ipInterface.node", "node", OnmsCriteria.INNER_JOIN);
    outageCriteria.add(Restrictions.ne("node.type", "D"));
    return outageCriteria;
}
Also used : OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria)

Example 30 with OnmsCriteria

use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.

the class DefaultRtcService method getNodeList.

/**
     * <p>getNodeList</p>
     *
     * @return a {@link org.opennms.web.svclayer.model.RtcNodeModel} object.
     */
@Override
public RtcNodeModel getNodeList() {
    OnmsCriteria serviceCriteria = createServiceCriteria();
    OnmsCriteria outageCriteria = createOutageCriteria();
    return getNodeListForCriteria(serviceCriteria, outageCriteria);
}
Also used : OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria)

Aggregations

OnmsCriteria (org.opennms.netmgt.model.OnmsCriteria)51 Transactional (org.springframework.transaction.annotation.Transactional)8 Filter (org.opennms.web.filter.Filter)7 Test (org.junit.Test)6 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)6 OnmsNode (org.opennms.netmgt.model.OnmsNode)5 ArrayList (java.util.ArrayList)4 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)4 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)3 AlarmCriteria (org.opennms.web.alarm.filter.AlarmCriteria)3 Date (java.util.Date)2 List (java.util.List)2 Criteria (org.hibernate.Criteria)2 Session (org.hibernate.Session)2 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)2 OnmsAcknowledgment (org.opennms.netmgt.model.OnmsAcknowledgment)2 AcknowledgedByFilter (org.opennms.web.alarm.filter.AcknowledgedByFilter)2 SeverityFilter (org.opennms.web.alarm.filter.SeverityFilter)2 HibernateCallback (org.springframework.orm.hibernate3.HibernateCallback)2 SyndContent (com.sun.syndication.feed.synd.SyndContent)1