use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.
the class DaoWebNotificationRepository method getOnmsCriteria.
/**
* TODO: Convert this function to use {@link Criteria} instead.
*/
private static final OnmsCriteria getOnmsCriteria(final NotificationCriteria notificationCriteria) {
final OnmsCriteria criteria = new OnmsCriteria(OnmsNotification.class);
criteria.createAlias("node", "node", OnmsCriteria.LEFT_JOIN);
criteria.createAlias("serviceType", "serviceType", OnmsCriteria.LEFT_JOIN);
criteria.createAlias("event", "event", OnmsCriteria.LEFT_JOIN);
criteria.createAlias("event.distPoller", "distPoller", OnmsCriteria.LEFT_JOIN);
notificationCriteria.visit(new NotificationCriteriaVisitor<RuntimeException>() {
@Override
public void visitAckType(AcknowledgeType ackType) throws RuntimeException {
if (ackType == AcknowledgeType.ACKNOWLEDGED) {
criteria.add(Restrictions.isNotNull("answeredBy"));
} else if (ackType == AcknowledgeType.UNACKNOWLEDGED) {
criteria.add(Restrictions.isNull("answeredBy"));
}
// AcknowledgeType.BOTH just adds no restriction
}
@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 LOCATION:
criteria.addOrder(Order.desc("event.distPoller.location"));
break;
case RESPONDER:
criteria.addOrder(Order.desc("answeredBy"));
break;
case PAGETIME:
criteria.addOrder(Order.desc("pageTime"));
break;
case RESPONDTIME:
criteria.addOrder(Order.desc("respondTime"));
break;
case NODE:
criteria.addOrder(Order.desc("node.label"));
break;
case NODE_LOCATION:
criteria.addOrder(Order.desc("node.location.locationName"));
break;
case INTERFACE:
criteria.addOrder(Order.desc("ipAddress"));
break;
case SERVICE:
criteria.addOrder(Order.desc("serviceType.name"));
break;
case ID:
criteria.addOrder(Order.desc("notifyId"));
break;
case SEVERITY:
criteria.addOrder(Order.desc("event.eventSeverity"));
break;
case REVERSE_LOCATION:
criteria.addOrder(Order.desc("event.distPoller.location"));
break;
case REVERSE_RESPONDER:
criteria.addOrder(Order.asc("answeredBy"));
break;
case REVERSE_PAGETIME:
criteria.addOrder(Order.asc("pageTime"));
break;
case REVERSE_RESPONDTIME:
criteria.addOrder(Order.asc("respondTime"));
break;
case REVERSE_NODE:
criteria.addOrder(Order.asc("node.label"));
break;
case REVERSE_NODE_LOCATION:
criteria.addOrder(Order.asc("node.location.locationName"));
break;
case REVERSE_INTERFACE:
criteria.addOrder(Order.asc("ipAddress"));
break;
case REVERSE_SERVICE:
criteria.addOrder(Order.asc("serviceType.name"));
break;
case REVERSE_ID:
criteria.addOrder(Order.asc("notifyId"));
break;
case REVERSE_SEVERITY:
criteria.addOrder(Order.asc("event.eventSeverity"));
break;
}
}
});
return criteria;
}
use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.
the class NetworkElementFactory method getNodeIdsWithIpLike.
/* (non-Javadoc)
* @see org.opennms.web.element.NetworkElementFactoryInterface#getNodeIdsWithIpLike(java.lang.String)
*/
@Override
public List<Integer> getNodeIdsWithIpLike(String iplike) {
if (iplike == null) {
throw new IllegalArgumentException("Cannot take null parameters.");
}
OnmsCriteria nodeCrit = new OnmsCriteria(OnmsNode.class);
nodeCrit.createCriteria("ipInterfaces", "iface").add(OnmsRestrictions.ipLike(iplike));
nodeCrit.add(Restrictions.ne("type", "D"));
nodeCrit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
List<Integer> nodeIds = new ArrayList<>();
List<OnmsNode> nodes = m_nodeDao.findMatching(nodeCrit);
for (OnmsNode node : nodes) {
nodeIds.add(node.getId());
}
return nodeIds;
}
use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.
the class NetworkElementFactory method getInterface.
/* (non-Javadoc)
* @see org.opennms.web.element.NetworkElementFactoryInterface#getInterface(int, java.lang.String)
*/
@Override
public Interface getInterface(int nodeId, String ipAddress) {
OnmsCriteria criteria = new OnmsCriteria(OnmsIpInterface.class);
criteria.createAlias("node", "node");
criteria.add(Restrictions.eq("node.id", nodeId));
criteria.add(Restrictions.eq("ipAddress", InetAddressUtils.addr(ipAddress)));
criteria.setFetchMode("snmpInterface", FetchMode.JOIN);
List<OnmsIpInterface> ifaces = m_ipInterfaceDao.findMatching(criteria);
return ifaces.size() > 0 ? new Interface(ifaces.get(0)) : null;
}
use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.
the class DaoWebEventRepository method getOnmsCriteria.
private OnmsCriteria getOnmsCriteria(final EventCriteria eventCriteria) {
final OnmsCriteria criteria = new OnmsCriteria(OnmsEvent.class);
criteria.createAlias("alarm", "alarm", OnmsCriteria.LEFT_JOIN);
criteria.createAlias("node", "node", OnmsCriteria.LEFT_JOIN);
criteria.createAlias("serviceType", "serviceType", OnmsCriteria.LEFT_JOIN);
criteria.createAlias("distPoller", "distPoller", OnmsCriteria.LEFT_JOIN);
criteria.add(new EventDisplayFilter("Y").getCriterion());
eventCriteria.visit(new EventCriteriaVisitor<RuntimeException>() {
@Override
public void visitAckType(AcknowledgeType ackType) throws RuntimeException {
if (ackType == AcknowledgeType.ACKNOWLEDGED) {
criteria.add(Restrictions.isNotNull("eventAckUser"));
} else if (ackType == AcknowledgeType.UNACKNOWLEDGED) {
criteria.add(Restrictions.isNull("eventAckUser"));
}
}
@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 ID:
criteria.addOrder(Order.desc("id"));
break;
case INTERFACE:
criteria.addOrder(Order.desc("ipAddr"));
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("eventSeverity"));
break;
case TIME:
criteria.addOrder(Order.desc("eventTime"));
break;
case LOCATION:
criteria.addOrder(Order.desc("distPoller.location"));
break;
case SYSTEMID:
criteria.addOrder(Order.desc("distPoller.id"));
break;
case REVERSE_ID:
criteria.addOrder(Order.asc("id"));
break;
case REVERSE_INTERFACE:
criteria.addOrder(Order.asc("ipAddr"));
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.desc("serviceType.name"));
break;
case REVERSE_SEVERITY:
criteria.addOrder(Order.asc("eventSeverity"));
break;
case REVERSE_TIME:
criteria.addOrder(Order.asc("eventTime"));
break;
case REVERSE_LOCATION:
criteria.addOrder(Order.asc("distPoller.location"));
break;
case REVERSE_SYSTEMID:
criteria.addOrder(Order.asc("distPoller.id"));
break;
}
}
});
return criteria;
}
use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.
the class HibernateCriteriaConverterIT method testNodeQuery.
@Test
@JUnitTemporaryDatabase
public void testNodeQuery() throws Exception {
List<OnmsNode> nodes;
// first, try with OnmsCriteria
final OnmsCriteria crit = new OnmsCriteria(OnmsNode.class);
crit.add(org.hibernate.criterion.Restrictions.isNotNull("id"));
nodes = m_nodeDao.findMatching(crit);
assertEquals(6, nodes.size());
// then the same with the builder
final CriteriaBuilder cb = new CriteriaBuilder(OnmsNode.class);
cb.isNotNull("id");
nodes = m_nodeDao.findMatching(cb.toCriteria());
assertEquals(6, nodes.size());
cb.eq("label", "node1").join("ipInterfaces", "ipInterface").eq("ipInterface.ipAddress", "192.168.1.1");
nodes = m_nodeDao.findMatching(cb.toCriteria());
assertEquals(1, nodes.size());
}
Aggregations