use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.
the class DaoWebOutageRepository method getOnmsCriteria.
/*
* NOTE: Criteria building for Outages must included the following aliases"
*
* monitoredService as monitoredService
* monitoredService.ipInterface as ipInterface
* monitoredService.ipInterface.node as node
* monitoredService.serviceType as serviceType
*
*/
private OnmsCriteria getOnmsCriteria(final OutageCriteria outageCriteria) {
final OnmsCriteria criteria = new OnmsCriteria(OnmsOutage.class);
criteria.createAlias("serviceLostEvent.distPoller", "distPoller");
criteria.createAlias("monitoredService", "monitoredService");
criteria.createAlias("monitoredService.ipInterface", "ipInterface");
criteria.createAlias("monitoredService.ipInterface.node", "node");
criteria.createAlias("monitoredService.serviceType", "serviceType");
outageCriteria.visit(new OutageCriteriaVisitor<RuntimeException>() {
@Override
public void visitOutageType(OutageType ackType) throws RuntimeException {
if (ackType == OutageType.CURRENT) {
criteria.add(Restrictions.isNull("ifRegainedService"));
} else if (ackType == OutageType.RESOLVED) {
criteria.add(Restrictions.isNotNull("ifRegainedService"));
}
}
@Override
public void visitFilter(Filter filter) throws RuntimeException {
criteria.add(filter.getCriterion());
}
@Override
public void visitGroupBy() throws RuntimeException {
}
@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 FOREIGNSOURCE:
criteria.addOrder(Order.desc("node.foreignSource"));
break;
case NODE:
criteria.addOrder(Order.desc("node.label"));
break;
case INTERFACE:
criteria.addOrder(Order.desc("ipInterface.ipAddress"));
break;
case SERVICE:
criteria.addOrder(Order.desc("serviceType.name"));
break;
case IFLOSTSERVICE:
criteria.addOrder(Order.desc("ifLostService"));
break;
case IFREGAINEDSERVICE:
criteria.addOrder(Order.desc("ifRegainedService"));
break;
case ID:
criteria.addOrder(Order.desc("id"));
break;
case LOCATION:
criteria.addOrder(Order.desc("node.location"));
break;
case REVERSE_FOREIGNSOURCE:
criteria.addOrder(Order.asc("node.foreignSource"));
break;
case REVERSE_NODE:
criteria.addOrder(Order.asc("node.label"));
break;
case REVERSE_INTERFACE:
criteria.addOrder(Order.asc("ipInterface.ipAddress"));
break;
case REVERSE_SERVICE:
criteria.addOrder(Order.asc("serviceType.name"));
break;
case REVERSE_IFLOSTSERVICE:
criteria.addOrder(Order.asc("ifLostService"));
break;
case REVERSE_IFREGAINEDSERVICE:
criteria.addOrder(Order.asc("ifRegainedService"));
break;
case REVERSE_ID:
criteria.addOrder(Order.asc("id"));
break;
case REVERSE_LOCATION:
criteria.addOrder(Order.asc("node.location"));
break;
default:
throw new IllegalArgumentException("Unknown SortStyle: " + sortStyle);
}
}
});
return criteria;
}
use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.
the class NetworkElementFactory method getHostname.
/* (non-Javadoc)
* @see org.opennms.web.element.NetworkElementFactoryInterface#getHostname(java.lang.String)
*/
@Override
public String getHostname(String ipAddress) {
OnmsCriteria criteria = new OnmsCriteria(OnmsIpInterface.class);
criteria.add(Restrictions.eq("ipAddress", InetAddressUtils.addr(ipAddress)));
criteria.add(Restrictions.isNotNull("ipHostName"));
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
List<OnmsIpInterface> ipIfaces = m_ipInterfaceDao.findMatching(criteria);
if (ipIfaces.size() > 0) {
OnmsIpInterface iface = ipIfaces.get(0);
return iface.getIpHostName();
}
return null;
}
use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.
the class NetworkElementFactory method getAllNodes.
/* (non-Javadoc)
* @see org.opennms.web.element.NetworkElementFactoryInterface#getAllNodes()
*/
@Override
public List<OnmsNode> getAllNodes() {
OnmsCriteria criteria = new OnmsCriteria(OnmsNode.class);
criteria.add(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 NetworkElementFactory method getAllInterfaces.
/*
* Returns all interfaces, but only includes SNMP data if includeSNMP is true
* This may be useful for pages that don't need SNMP data and don't want to execute
* a sub-query per interface!
*
* @param includeSNMP a boolean.
* @return an array of {@link org.opennms.web.element.Interface} objects.
*/
/* (non-Javadoc)
* @see org.opennms.web.element.NetworkElementFactoryInterface#getAllInterfaces(boolean)
*/
@Override
public Interface[] getAllInterfaces(boolean includeSnmp) {
OnmsCriteria criteria = new OnmsCriteria(OnmsIpInterface.class);
criteria.createAlias("snmpInterface", "snmpInterface", OnmsCriteria.LEFT_JOIN);
if (!includeSnmp) {
return getInterfaceArray(m_ipInterfaceDao.findMatching(criteria));
} else {
return getInterfaceArrayWithSnmpData(m_ipInterfaceDao.findMatching(criteria));
}
}
use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.
the class NetworkElementFactory method getNodesWithIfAlias.
/* (non-Javadoc)
* @see org.opennms.web.element.NetworkElementFactoryInterface#getNodesWithIfAlias(java.lang.String)
*/
@Override
public List<OnmsNode> getNodesWithIfAlias(String ifAlias) {
OnmsCriteria criteria = new OnmsCriteria(OnmsNode.class);
criteria.createAlias("snmpInterfaces", "snmpIface");
criteria.add(Restrictions.ne("type", "D"));
criteria.add(Restrictions.ilike("snmpIface.ifAlias", ifAlias, MatchMode.ANYWHERE));
criteria.addOrder(Order.asc("label"));
return m_nodeDao.findMatching(criteria);
}
Aggregations