use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.
the class ApplicationSearchProvider method query.
@Override
public List<SearchResult> query(SearchQuery searchQuery, GraphContainer container) {
LOG.info("ApplicationServiceSearchProvider->query: called with search query: '{}'", searchQuery);
List<SearchResult> results = Lists.newArrayList();
String queryString = searchQuery.getQueryString();
CriteriaBuilder bldr = new CriteriaBuilder(OnmsApplication.class);
if (queryString != null && queryString.length() > 0) {
bldr.ilike("name", String.format("%%%s%%", queryString));
}
bldr.orderBy("name", true);
bldr.limit(10);
Criteria dbQueryCriteria = bldr.toCriteria();
for (OnmsApplication application : applicationDao.findMatching(dbQueryCriteria)) {
final ApplicationVertex applicationVertex = new ApplicationVertex(application);
SearchResult searchResult = new SearchResult(applicationVertex, true, false);
results.add(searchResult);
}
LOG.info("ApplicationServiceSearchProvider->query: found {} results: {}", results.size(), results);
return results;
}
use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.
the class EnLinkdElementFactory method convertFromModel.
@Transactional
@SuppressWarnings("deprecation")
private LldpLinkNode convertFromModel(int nodeid, LldpLink link) {
LldpLinkNode linknode = new LldpLinkNode();
linknode.setLldpPortString(getPortString(link.getLldpPortId(), link.getLldpPortIdSubType()));
linknode.setLldpPortDescr(link.getLldpPortDescr());
linknode.setLldpPortUrl(getSnmpInterfaceUrl(Integer.valueOf(nodeid), link.getLldpPortIfindex()));
linknode.setLldpRemSysName(link.getLldpRemSysname());
linknode.setLldpRemPortString(getPortString(link.getLldpRemPortId(), link.getLldpRemPortIdSubType()));
linknode.setLldpRemPortDescr(link.getLldpRemPortDescr());
linknode.setLldpCreateTime(Util.formatDateToUIString(link.getLldpLinkCreateTime()));
linknode.setLldpLastPollTime(Util.formatDateToUIString(link.getLldpLinkLastPollTime()));
OnmsNode remNode = null;
List<LldpElement> lldpremelements = m_lldpElementDao.findByChassisId(link.getLldpRemChassisId(), link.getLldpRemChassisIdSubType());
if (lldpremelements.size() == 1) {
remNode = lldpremelements.get(0).getNode();
} else if (lldpremelements.size() > 1) {
linknode.setLldpRemChassisIdString(getChassisIdString("Found " + lldpremelements.size() + " nodes for", link.getLldpRemChassisId(), link.getLldpRemChassisIdSubType()));
return linknode;
} else {
final Criteria criteria = new Criteria(OnmsNode.class).addRestriction(new EqRestriction("sysName", link.getLldpRemSysname()));
List<OnmsNode> nodes = m_nodeDao.findMatching(criteria);
if (nodes.size() == 1)
remNode = nodes.get(0);
}
if (remNode != null) {
linknode.setLldpRemChassisIdString(getChassisIdString(remNode.getLabel(), link.getLldpRemChassisId(), link.getLldpRemChassisIdSubType()));
linknode.setLldpRemChassisIdUrl(getNodeUrl(remNode.getId()));
if (link.getLldpRemPortIdSubType() == LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL) {
try {
Integer remIfIndex = Integer.getInteger(link.getLldpRemPortId());
linknode.setLldpRemPortUrl(getSnmpInterfaceUrl(Integer.valueOf(remNode.getId()), remIfIndex));
} catch (Exception e) {
}
}
} else {
linknode.setLldpRemChassisIdString(getChassisIdString(link.getLldpRemChassisId(), link.getLldpRemChassisIdSubType()));
}
return linknode;
}
use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.
the class AlarmLifecycleEventsIT method canGenerateAlarmDeletedLifecycleEvents.
@Test
public void canGenerateAlarmDeletedLifecycleEvents() {
// Expect an alarmCreated event
m_eventMgr.getEventAnticipator().resetAnticipated();
m_eventMgr.getEventAnticipator().anticipateEvent(new EventBuilder(EventConstants.ALARM_CREATED_UEI, "alarmd").getEvent());
m_eventMgr.getEventAnticipator().setDiscardUnanticipated(true);
// Send a nodeDown
sendNodeDownEvent(1);
// Wait until we've received the alarmCreated event
await().until(allAnticipatedEventsWereReceived());
// Expect an alarmCreated and a alarmCleared event
m_eventMgr.getEventAnticipator().resetAnticipated();
m_eventMgr.getEventAnticipator().anticipateEvent(new EventBuilder(EventConstants.ALARM_CREATED_UEI, "alarmd").getEvent());
m_eventMgr.getEventAnticipator().anticipateEvent(new EventBuilder(EventConstants.ALARM_CLEARED_UEI, "alarmd").getEvent());
m_eventMgr.getEventAnticipator().setDiscardUnanticipated(true);
// Send a nodeUp
sendNodeUpEvent(1);
// Wait until we've received the alarmCreated and alarmCleared events
// We need to wait for the cosmicClear automation, which currently runs every 30 seconds
await().atMost(1, MINUTES).until(allAnticipatedEventsWereReceived());
// Expect an alarmDeleted event
m_eventMgr.getEventAnticipator().anticipateEvent(new EventBuilder(EventConstants.ALARM_DELETED_EVENT_UEI, "alarmd").getEvent());
m_eventMgr.getEventAnticipator().setDiscardUnanticipated(true);
// We need to wait for the cleanUp automation, which currently runs every 60 seconds
// but it will only trigger then 'lastautomationtime' and 'lasteventtime' < "5 minutes ago"
// so we cheat a little and update the timestamps ourselves instead of waiting
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
Criteria criteria = new Criteria(OnmsAlarm.class);
criteria.addRestriction(new EqRestriction("node.id", 1));
criteria.addRestriction(new EqRestriction("uei", EventConstants.NODE_DOWN_EVENT_UEI));
for (OnmsAlarm alarm : m_alarmDao.findMatching(criteria)) {
LocalDateTime tenMinutesAgo = LocalDateTime.now().minusMinutes(10);
Date then = Date.from(tenMinutesAgo.toInstant(ZoneOffset.UTC));
alarm.setLastAutomationTime(then);
alarm.setLastEventTime(then);
m_alarmDao.save(alarm);
}
m_alarmDao.flush();
}
});
// Wait until we've received the alarmDeleted event
await().atMost(2, MINUTES).until(allAnticipatedEventsWereReceived());
}
use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.
the class BeanWrapperVisitorTest method testNot.
@Test
public void testNot() {
final Criteria criteria = new CriteriaBuilder(TestBean.class).not().eq("string", "I am a string.").toCriteria();
LOG.debug("criteria = {}", criteria);
criteria.visit(m_visitor);
assertEquals(0, m_visitor.getMatches().size());
}
use of org.opennms.core.criteria.Criteria in project opennms by OpenNMS.
the class DefaultPollingContext method getInterfaceList.
protected OnmsIpInterfaceList getInterfaceList() {
StringBuffer filterRules = new StringBuffer(getPackage().getEffectiveFilter());
List<InetAddress> ipList = FilterDaoFactory.getInstance().getActiveIPAddressList(filterRules.toString());
OnmsIpInterfaceList ifaces = new OnmsIpInterfaceList();
// Only poll the primary interface
final Criteria criteria = new Criteria(OnmsIpInterface.class);
criteria.addRestriction(new EqRestriction("isSnmpPrimary", PrimaryType.PRIMARY));
List<OnmsIpInterface> allValidIfaces = getIpInterfaceDao().findMatching(criteria);
for (OnmsIpInterface iface : allValidIfaces) {
if (ipList.contains(iface.getIpAddress())) {
ifaces.add(iface);
}
}
return ifaces;
}
Aggregations