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;
}
});
}
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)));
}
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);
}
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;
}
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));
}
Aggregations