Search in sources :

Example 11 with OnmsCriteria

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;
}
Also used : Filter(org.opennms.web.filter.Filter) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria)

Example 12 with OnmsCriteria

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;
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria)

Example 13 with OnmsCriteria

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);
}
Also used : OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria)

Example 14 with OnmsCriteria

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));
    }
}
Also used : OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria)

Example 15 with OnmsCriteria

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);
}
Also used : OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria)

Aggregations

OnmsCriteria (org.opennms.netmgt.model.OnmsCriteria)51 Transactional (org.springframework.transaction.annotation.Transactional)8 Filter (org.opennms.web.filter.Filter)7 Test (org.junit.Test)6 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)6 OnmsNode (org.opennms.netmgt.model.OnmsNode)5 ArrayList (java.util.ArrayList)4 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)4 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)3 AlarmCriteria (org.opennms.web.alarm.filter.AlarmCriteria)3 Date (java.util.Date)2 List (java.util.List)2 Criteria (org.hibernate.Criteria)2 Session (org.hibernate.Session)2 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)2 OnmsAcknowledgment (org.opennms.netmgt.model.OnmsAcknowledgment)2 AcknowledgedByFilter (org.opennms.web.alarm.filter.AcknowledgedByFilter)2 SeverityFilter (org.opennms.web.alarm.filter.SeverityFilter)2 HibernateCallback (org.springframework.orm.hibernate3.HibernateCallback)2 SyndContent (com.sun.syndication.feed.synd.SyndContent)1