use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.
the class NetworkElementFactory method getNodesWithService.
/* (non-Javadoc)
* @see org.opennms.web.element.NetworkElementFactoryInterface#getNodesWithService(int)
*/
@Override
public List<OnmsNode> getNodesWithService(int serviceId) {
OnmsCriteria criteria = new OnmsCriteria(OnmsNode.class);
criteria.createAlias("assetRecord", "assetRecord");
criteria.createAlias("ipInterfaces", "iface");
criteria.createAlias("iface.monitoredServices", "svc");
criteria.createAlias("svc.serviceType", "svcType").add(Restrictions.eq("svcType.id", serviceId));
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
return m_nodeDao.findMatching(criteria);
}
use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.
the class NetworkElementFactory method getNodesLike.
/* (non-Javadoc)
* @see org.opennms.web.element.NetworkElementFactoryInterface#getNodesLike(java.lang.String)
*/
@Override
public List<OnmsNode> getNodesLike(String nodeLabel) {
OnmsCriteria criteria = new OnmsCriteria(OnmsNode.class);
criteria.createAlias("assetRecord", "assetRecord");
criteria.add(Restrictions.and(Restrictions.ilike("label", nodeLabel, MatchMode.ANYWHERE), Restrictions.or(Restrictions.isNull("type"), Restrictions.ne("type", "D"))));
criteria.addOrder(Order.asc("label"));
return m_nodeDao.findMatching(criteria);
}
use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.
the class OutageDaoIT method getMonitoredService.
private OnmsMonitoredService getMonitoredService(OnmsIpInterface ipInterface, OnmsServiceType serviceType) {
final OnmsCriteria criteria = new OnmsCriteria(OnmsMonitoredService.class).add(Restrictions.eq("ipInterface", ipInterface)).add(Restrictions.eq("serviceType", serviceType));
final List<OnmsMonitoredService> services = m_monitoredServiceDao.findMatching(criteria);
OnmsMonitoredService monitoredService;
if (services.size() > 0) {
monitoredService = services.get(0);
} else {
monitoredService = new OnmsMonitoredService(ipInterface, serviceType);
}
m_monitoredServiceDao.save(monitoredService);
return monitoredService;
}
use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.
the class AlarmUtil method getOnmsCriteria.
public static OnmsCriteria getOnmsCriteria(final AlarmCriteria alarmCriteria) {
final OnmsCriteria criteria = new OnmsCriteria(OnmsAlarm.class);
criteria.createAlias("node", "node", OnmsCriteria.LEFT_JOIN);
criteria.createAlias("distPoller", "distPoller", OnmsCriteria.LEFT_JOIN);
criteria.createAlias("lastEvent", "lastEvent", OnmsCriteria.LEFT_JOIN);
criteria.createAlias("serviceType", "serviceType", OnmsCriteria.LEFT_JOIN);
alarmCriteria.visit(new AlarmCriteriaVisitor<RuntimeException>() {
@Override
public void visitAckType(AcknowledgeType ackType) throws RuntimeException {
if (ackType == AcknowledgeType.ACKNOWLEDGED) {
criteria.add(Restrictions.isNotNull("alarmAckUser"));
} else if (ackType == AcknowledgeType.UNACKNOWLEDGED) {
criteria.add(Restrictions.isNull("alarmAckUser"));
}
}
@Override
public void visitFilter(Filter filter) throws RuntimeException {
criteria.add(filter.getCriterion());
}
@Override
public void visitLimit(int limit, int offset) throws RuntimeException {
criteria.setMaxResults(limit);
criteria.setFirstResult(offset);
}
@Override
public void visitSortStyle(SortStyle sortStyle) throws RuntimeException {
switch(sortStyle) {
case COUNT:
criteria.addOrder(Order.desc("counter"));
break;
case FIRSTEVENTTIME:
criteria.addOrder(Order.desc("firstEventTime"));
break;
case ID:
criteria.addOrder(Order.desc("id"));
break;
case INTERFACE:
criteria.addOrder(Order.desc("ipAddr"));
break;
case LASTEVENTTIME:
criteria.addOrder(Order.desc("lastEventTime"));
break;
case NODE:
criteria.addOrder(Order.desc("node.label"));
break;
case POLLER:
criteria.addOrder(Order.desc("distPoller"));
break;
case SERVICE:
criteria.addOrder(Order.desc("serviceType.name"));
break;
case SEVERITY:
criteria.addOrder(Order.desc("severity"));
break;
case ACKUSER:
criteria.addOrder(Order.asc("alarmAckUser"));
break;
case REVERSE_COUNT:
criteria.addOrder(Order.asc("counter"));
break;
case REVERSE_FIRSTEVENTTIME:
criteria.addOrder(Order.asc("firstEventTime"));
break;
case REVERSE_ID:
criteria.addOrder(Order.asc("id"));
break;
case REVERSE_INTERFACE:
criteria.addOrder(Order.asc("ipAddr"));
break;
case REVERSE_LASTEVENTTIME:
criteria.addOrder(Order.asc("lastEventTime"));
break;
case REVERSE_NODE:
criteria.addOrder(Order.asc("node.label"));
break;
case REVERSE_POLLER:
criteria.addOrder(Order.asc("distPoller"));
break;
case REVERSE_SERVICE:
criteria.addOrder(Order.asc("serviceType.name"));
break;
case REVERSE_SEVERITY:
criteria.addOrder(Order.asc("severity"));
break;
case REVERSE_ACKUSER:
criteria.addOrder(Order.desc("alarmAckUser"));
break;
default:
break;
}
}
});
return criteria;
}
use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.
the class InsSession method getEventsByCriteria.
private void getEventsByCriteria() {
LOG.debug("clearing events");
clearEvents();
final BeanFactoryReference bf = BeanUtils.getBeanFactory("daoContext");
final EventDao eventDao = BeanUtils.getBean(bf, "eventDao", EventDao.class);
final TransactionTemplate transTemplate = BeanUtils.getBean(bf, "transactionTemplate", TransactionTemplate.class);
try {
transTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
LOG.debug("Entering transaction call back: selection with criteria: {}", criteriaRestriction);
final OnmsCriteria criteria = new OnmsCriteria(OnmsEvent.class);
criteria.add(Restrictions.sqlRestriction(criteriaRestriction));
final List<OnmsEvent> events = eventDao.findMatching(criteria);
LOG.info("Found {} event(s) with criteria: {}", events.size(), criteriaRestriction);
for (final OnmsEvent onmsEvent : events) {
final Event xmlEvent = getXMLEvent(onmsEvent);
if (xmlEvent != null)
addEvent(xmlEvent);
}
}
});
} catch (final RuntimeException e) {
LOG.error("Error while getting events.", e);
}
}
Aggregations