Search in sources :

Example 11 with Criteria

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

the class TrapIT method canReceiveTraps.

@Test
public void canReceiveTraps() throws Exception {
    Date startOfTest = new Date();
    final InetSocketAddress trapAddr = minionSystem.getServiceAddress(ContainerAlias.MINION, 1162, "udp");
    // Connect to the postgresql container
    InetSocketAddress pgsql = minionSystem.getServiceAddress(ContainerAlias.POSTGRES, 5432);
    HibernateDaoFactory daoFactory = new HibernateDaoFactory(pgsql);
    EventDao eventDao = daoFactory.getDao(EventDaoHibernate.class);
    // Parsing the message correctly relies on the customized syslogd-configuration.xml that is part of the OpenNMS image
    Criteria criteria = new CriteriaBuilder(OnmsEvent.class).eq("eventUei", "uei.opennms.org/generic/traps/SNMP_Warm_Start").ge("eventTime", startOfTest).toCriteria();
    // Send traps to the Minion listener until one makes it through
    await().atMost(5, MINUTES).pollInterval(30, SECONDS).pollDelay(0, SECONDS).until(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            sendTrap(trapAddr);
            try {
                await().atMost(30, SECONDS).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(eventDao, criteria), greaterThanOrEqualTo(1));
            } catch (final Exception e) {
                return false;
            }
            return true;
        }
    });
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) HibernateDaoFactory(org.opennms.smoketest.utils.HibernateDaoFactory) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) EventDao(org.opennms.netmgt.dao.api.EventDao) InetSocketAddress(java.net.InetSocketAddress) Criteria(org.opennms.core.criteria.Criteria) Date(java.util.Date) Test(org.junit.Test)

Example 12 with Criteria

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

the class LayoutDaoIT method verifyCRUD.

@Test
@Transactional
public void verifyCRUD() {
    // Nothing created yet
    Assert.assertEquals(0, layoutDao.countAll());
    Assert.assertEquals(0, layoutDao.countMatching(new Criteria(VertexPositionEntity.class)));
    // Create dummy
    LayoutEntity layout = new LayoutEntity();
    layout.setId("hash");
    layout.setCreated(new Date());
    layout.setCreator("mvrueden");
    layout.setUpdated(layout.getCreated());
    layout.setUpdator(layout.getCreator());
    layout.addVertexPosition(createVertexPosition("dummy", "1", 0, 0));
    layout.addVertexPosition(createVertexPosition("dummy", "2", 1, 1));
    // create and verify creation
    layoutDao.saveOrUpdate(layout);
    Assert.assertEquals(1, layoutDao.countAll());
    Assert.assertEquals(2, layoutDao.countMatching(new Criteria(VertexPositionEntity.class)));
    // Update
    // Remove Vertex
    layout.getVertexPositions().remove(0);
    layoutDao.update(layout);
    Assert.assertEquals(1, layoutDao.countAll());
    Assert.assertEquals(1, layoutDao.countMatching(new Criteria(VertexPositionEntity.class)));
    // Add Vertex
    layout.addVertexPosition(createVertexPosition("dummy", "3", 2, 2));
    layoutDao.update(layout);
    Assert.assertEquals(1, layoutDao.countAll());
    Assert.assertEquals(2, layoutDao.countMatching(new Criteria(VertexPositionEntity.class)));
    // Update layout
    layout.setUpdated(new Date());
    layout.setUpdator("ulf");
    Assert.assertEquals(1, layoutDao.countAll());
    Assert.assertEquals(2, layoutDao.countMatching(new Criteria(VertexPositionEntity.class)));
    // Delete
    layoutDao.delete(layout);
    Assert.assertEquals(0, layoutDao.countAll());
    Assert.assertEquals(0, layoutDao.countMatching(new Criteria(VertexPositionEntity.class)));
}
Also used : Criteria(org.opennms.core.criteria.Criteria) LayoutEntity(org.opennms.netmgt.topology.persistence.api.LayoutEntity) Date(java.util.Date) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with Criteria

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

the class AlarmStatsRestService method getNewestAcknowledged.

protected OnmsAlarm getNewestAcknowledged(final OnmsSeverity severity) {
    final CriteriaBuilder builder = getCriteriaBuilder(severity);
    builder.orderBy("lastEventTime").desc();
    builder.orderBy("id").desc();
    builder.limit(1);
    final Criteria criteria = builder.toCriteria();
    LOG.debug("getNewestAcknowledged({}) criteria = {}", severity, criteria);
    return m_statisticsService.getAcknowledged(criteria);
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) Criteria(org.opennms.core.criteria.Criteria)

Example 14 with Criteria

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

the class AlarmStatsRestService method getStats.

protected AlarmStatistics getStats(final UriInfo uriInfo, final OnmsSeverity severity) {
    final AlarmStatistics stats = new AlarmStatistics();
    final CriteriaBuilder builder = getCriteriaBuilder(uriInfo.getQueryParameters(), false);
    // note: this is just the *total count* criteria, so no ordering, and count everything
    builder.count();
    if (severity != null) {
        builder.eq("severity", severity);
    }
    final Criteria criteria = builder.toCriteria();
    LOG.debug("criteria = {}", criteria);
    final int count = m_statisticsService.getTotalCount(criteria);
    stats.setTotalCount(count);
    stats.setAcknowledgedCount(m_statisticsService.getAcknowledgedCount(criteria));
    stats.setNewestAcknowledged(getNewestAcknowledged(severity));
    stats.setNewestUnacknowledged(getNewestUnacknowledged(severity));
    stats.setOldestAcknowledged(getOldestAcknowledged(severity));
    stats.setOldestUnacknowledged(getOldestUnacknowledged(severity));
    return stats;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) Criteria(org.opennms.core.criteria.Criteria)

Example 15 with Criteria

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

the class BusinessServiceDaoIT method verifyDistinctObjectLoading.

@Test
@Transactional
public void verifyDistinctObjectLoading() {
    BusinessServiceEntity entity = new BusinessServiceEntityBuilder().name("Parent Web Servers").addReductionKey("TestReductionKeyA", new IdentityEntity()).addReductionKey("TestReductionKeyB", new IdentityEntity()).addReductionKey("TestReductionKeyC", new IdentityEntity()).reduceFunction(m_highestSeverity).toEntity();
    m_businessServiceDao.save(entity);
    m_businessServiceDao.flush();
    assertEquals(1, m_businessServiceDao.countAll());
    assertEquals(3, m_edgeDao.countAll());
    Criteria criteria = new CriteriaBuilder(BusinessServiceEntity.class).toCriteria();
    // verify that root entity is merged
    assertEquals(1, m_businessServiceDao.findMatching(criteria).size());
    // verify that countMatching also works
    assertEquals(1, m_businessServiceDao.countMatching(criteria));
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) Criteria(org.opennms.core.criteria.Criteria) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Criteria (org.opennms.core.criteria.Criteria)62 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)31 Test (org.junit.Test)16 EqRestriction (org.opennms.core.criteria.restrictions.EqRestriction)16 Date (java.util.Date)13 Alias (org.opennms.core.criteria.Alias)13 ArrayList (java.util.ArrayList)10 Order (org.opennms.core.criteria.Order)9 Transactional (org.springframework.transaction.annotation.Transactional)9 GET (javax.ws.rs.GET)8 PUT (javax.ws.rs.PUT)7 OnmsNode (org.opennms.netmgt.model.OnmsNode)7 POST (javax.ws.rs.POST)6 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)5 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)5 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)5 Produces (javax.ws.rs.Produces)4 EventDao (org.opennms.netmgt.dao.api.EventDao)4 ScanReport (org.opennms.netmgt.model.ScanReport)4 ScanReportRestService (org.opennms.web.rest.v2.ScanReportRestService)4