Search in sources :

Example 81 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class AlarmStatisticsServiceTest method testCountBySeverity.

@Test
public void testCountBySeverity() {
    final CriteriaBuilder cb = new CriteriaBuilder(OnmsAlarm.class);
    cb.ge("severity", OnmsSeverity.NORMAL);
    cb.fetch("firstEvent", FetchType.EAGER);
    cb.fetch("lastEvent", FetchType.EAGER);
    cb.alias("node", "node", JoinType.LEFT_JOIN);
    cb.alias("node.snmpInterfaces", "snmpInterface", JoinType.LEFT_JOIN);
    cb.alias("node.ipInterfaces", "ipInterface", JoinType.LEFT_JOIN);
    cb.distinct();
    final int count = m_statisticsService.getTotalCount(cb.toCriteria());
    assertEquals(1, count);
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) Test(org.junit.Test)

Example 82 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class AlarmStatisticsServiceTest method testCount.

@Test
public void testCount() {
    final CriteriaBuilder cb = new CriteriaBuilder(OnmsAlarm.class);
    cb.fetch("firstEvent", FetchType.EAGER);
    cb.fetch("lastEvent", FetchType.EAGER);
    cb.alias("node", "node", JoinType.LEFT_JOIN);
    cb.alias("node.snmpInterfaces", "snmpInterface", JoinType.LEFT_JOIN);
    cb.alias("node.ipInterfaces", "ipInterface", JoinType.LEFT_JOIN);
    cb.distinct();
    final int count = m_statisticsService.getTotalCount(cb.toCriteria());
    assertEquals(1, count);
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) Test(org.junit.Test)

Example 83 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class AbstractBusinessServiceRestServiceIT method findEntityByName.

private BusinessServiceEntity findEntityByName(String name) {
    Criteria criteria = new CriteriaBuilder(BusinessServiceEntity.class).eq("name", name).toCriteria();
    List<BusinessServiceEntity> matching = m_businessServiceDao.findMatching(criteria);
    if (matching.isEmpty()) {
        throw new NoSuchElementException("Did not find business service with name '" + name + "'.");
    }
    return matching.get(0);
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) Criteria(org.opennms.core.criteria.Criteria) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) NoSuchElementException(java.util.NoSuchElementException)

Example 84 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class DefaultPollContext method getPollableNodes.

@Override
public List<OnmsIpInterface> getPollableNodes() {
    CriteriaBuilder builder = new CriteriaBuilder(OnmsIpInterface.class);
    builder.eq("isSnmpPrimary", PrimaryType.PRIMARY).eq("isManaged", "M");
    return getIpInterfaceDao().findMatching(builder.toCriteria());
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder)

Example 85 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class DefaultPollContext method getPollableNodesByIp.

@Override
public List<OnmsIpInterface> getPollableNodesByIp(String ipaddr) {
    CriteriaBuilder builder = new CriteriaBuilder(OnmsIpInterface.class);
    builder.eq("ipAddress", InetAddressUtils.addr(ipaddr)).eq("isSnmpPrimary", PrimaryType.PRIMARY).eq("isManaged", "M");
    return getIpInterfaceDao().findMatching(builder.toCriteria());
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder)

Aggregations

CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)155 Test (org.junit.Test)60 Criteria (org.opennms.core.criteria.Criteria)31 OnmsNode (org.opennms.netmgt.model.OnmsNode)25 Transactional (org.springframework.transaction.annotation.Transactional)23 Date (java.util.Date)20 GET (javax.ws.rs.GET)13 ArrayList (java.util.ArrayList)12 Produces (javax.ws.rs.Produces)12 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)11 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)11 InetSocketAddress (java.net.InetSocketAddress)9 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)7 HibernateDaoFactory (org.opennms.smoketest.utils.HibernateDaoFactory)7 OnmsMinion (org.opennms.netmgt.model.minion.OnmsMinion)6 RateLimiter (com.google.common.util.concurrent.RateLimiter)4 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)4 EventDao (org.opennms.netmgt.dao.api.EventDao)4 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)4 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)4