use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.
the class AbstractDaoRestService method deleteMany.
@DELETE
public Response deleteMany(@Context final UriInfo uriInfo, @Context final SearchContext searchContext) {
writeLock();
try {
Criteria crit = getCriteria(uriInfo, searchContext);
final List<T> objects = getDao().findMatching(crit);
if (objects == null || objects.size() == 0) {
return Response.status(Status.NOT_FOUND).build();
}
for (T object : objects) {
LOG.debug("delete: deleting object {}", object);
getDao().delete(object);
}
return Response.noContent().build();
} finally {
writeUnlock();
}
}
use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.
the class AlarmDaoIT method testSortOnNodeLabel.
@Test
@Transactional
public void testSortOnNodeLabel() {
Criteria criteria = new Criteria(OnmsAlarm.class);
criteria.setAliases(Arrays.asList(new Alias[] { new Alias("node", "node", JoinType.LEFT_JOIN) }));
criteria.setOrders(Arrays.asList(new Order[] { Order.asc("node.label") }));
m_alarmDao.findMatching(criteria);
}
use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.
the class OnmsVaadinContainer method getCriteria.
/**
* Creates a {@link Criteria} object to get data from database.
* If considerPaging is set Limit and offset values are added as restriction.
* @param page
* @param doOrder
* @return
*/
protected Criteria getCriteria(Page page, boolean doOrder) {
Criteria tmpCriteria = new Criteria(getItemClass());
for (Restriction eachRestriction : m_restrictions) {
tmpCriteria.addRestriction(eachRestriction);
}
if (doOrder) {
tmpCriteria.setOrders(m_orders);
}
if (page != null) {
tmpCriteria.setOffset(page.offset);
tmpCriteria.setLimit(page.length);
}
addAdditionalCriteriaOptions(tmpCriteria, page, doOrder);
LOG.debug("query criteria: {}", tmpCriteria);
return tmpCriteria;
}
use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.
the class AlarmDaoIT method testSave.
@Test
@Transactional
public void testSave() {
OnmsEvent event = new OnmsEvent();
event.setEventLog("Y");
event.setEventDisplay("Y");
event.setEventCreateTime(new Date());
event.setDistPoller(m_distPollerDao.whoami());
event.setEventTime(new Date());
event.setEventSeverity(OnmsSeverity.CRITICAL.getId());
event.setEventUei("uei://org/opennms/test/EventDaoTest");
event.setEventSource("test");
m_eventDao.save(event);
OnmsNode node = m_nodeDao.findAll().iterator().next();
OnmsAlarm alarm = new OnmsAlarm();
alarm.setNode(node);
alarm.setUei(event.getEventUei());
alarm.setSeverityId(event.getEventSeverity());
alarm.setFirstEventTime(event.getEventTime());
alarm.setLastEvent(event);
alarm.setCounter(1);
alarm.setDistPoller(m_distPollerDao.whoami());
m_alarmDao.save(alarm);
// It works we're so smart! hehe
OnmsAlarm newAlarm = m_alarmDao.load(alarm.getId());
assertEquals("uei://org/opennms/test/EventDaoTest", newAlarm.getUei());
assertEquals(alarm.getLastEvent().getId(), newAlarm.getLastEvent().getId());
Collection<OnmsAlarm> alarms;
Criteria criteria = new Criteria(OnmsAlarm.class);
criteria.addRestriction(new EqRestriction("node.id", node.getId()));
alarms = m_alarmDao.findMatching(criteria);
assertEquals(1, alarms.size());
newAlarm = alarms.iterator().next();
assertEquals("uei://org/opennms/test/EventDaoTest", newAlarm.getUei());
assertEquals(alarm.getLastEvent().getId(), newAlarm.getLastEvent().getId());
}
use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.
the class MockFilterDao method getActiveIPAddressList.
@Override
public List<InetAddress> getActiveIPAddressList(final String rule) throws FilterParseException {
LOG.debug("rule = {}", rule);
final List<InetAddress> addrs = new ArrayList<>();
if (rule.equals("IPADDR != '0.0.0.0'")) {
Assert.notNull(m_ipInterfaceDao);
final CriteriaBuilder builder = new CriteriaBuilder(OnmsIpInterface.class);
builder.ne("ipAddress", "0.0.0.0");
builder.ne("isManaged", "D");
builder.distinct();
final Criteria criteria = builder.toCriteria();
for (final OnmsIpInterface iface : m_ipInterfaceDao.findMatching(criteria)) {
addrs.add(iface.getIpAddress());
}
return addrs;
}
throw new UnsupportedOperationException("Not yet implemented!");
}
Aggregations