Search in sources :

Example 6 with OnmsCriteria

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

Example 7 with OnmsCriteria

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

Example 8 with OnmsCriteria

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

Example 9 with OnmsCriteria

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;
}
Also used : NegativeExactUEIFilter(org.opennms.web.alarm.filter.NegativeExactUEIFilter) IPAddrLikeFilter(org.opennms.web.alarm.filter.IPAddrLikeFilter) ExactUEIFilter(org.opennms.web.alarm.filter.ExactUEIFilter) NegativeLocationFilter(org.opennms.web.alarm.filter.NegativeLocationFilter) NegativeServiceFilter(org.opennms.web.alarm.filter.NegativeServiceFilter) LogMessageMatchesAnyFilter(org.opennms.web.alarm.filter.LogMessageMatchesAnyFilter) NegativeInterfaceFilter(org.opennms.web.alarm.filter.NegativeInterfaceFilter) AfterLastEventTimeFilter(org.opennms.web.alarm.filter.AfterLastEventTimeFilter) NegativeEventParmLikeFilter(org.opennms.web.alarm.filter.NegativeEventParmLikeFilter) NegativeSeverityFilter(org.opennms.web.alarm.filter.NegativeSeverityFilter) LogMessageSubstringFilter(org.opennms.web.alarm.filter.LogMessageSubstringFilter) NegativePartialUEIFilter(org.opennms.web.alarm.filter.NegativePartialUEIFilter) ServiceFilter(org.opennms.web.alarm.filter.ServiceFilter) AfterFirstEventTimeFilter(org.opennms.web.alarm.filter.AfterFirstEventTimeFilter) NegativeNodeFilter(org.opennms.web.alarm.filter.NegativeNodeFilter) EventParmLikeFilter(org.opennms.web.alarm.filter.EventParmLikeFilter) InterfaceFilter(org.opennms.web.alarm.filter.InterfaceFilter) SeverityFilter(org.opennms.web.alarm.filter.SeverityFilter) Filter(org.opennms.web.filter.Filter) NegativeAcknowledgedByFilter(org.opennms.web.alarm.filter.NegativeAcknowledgedByFilter) PartialUEIFilter(org.opennms.web.alarm.filter.PartialUEIFilter) NegativeNodeLocationFilter(org.opennms.web.alarm.filter.NegativeNodeLocationFilter) NodeFilter(org.opennms.web.alarm.filter.NodeFilter) NodeLocationFilter(org.opennms.web.alarm.filter.NodeLocationFilter) NodeNameLikeFilter(org.opennms.web.alarm.filter.NodeNameLikeFilter) BeforeLastEventTimeFilter(org.opennms.web.alarm.filter.BeforeLastEventTimeFilter) AcknowledgedByFilter(org.opennms.web.alarm.filter.AcknowledgedByFilter) LocationFilter(org.opennms.web.alarm.filter.LocationFilter) BeforeFirstEventTimeFilter(org.opennms.web.alarm.filter.BeforeFirstEventTimeFilter) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria)

Example 10 with OnmsCriteria

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);
    }
}
Also used : BeanFactoryReference(org.springframework.beans.factory.access.BeanFactoryReference) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) EventDao(org.opennms.netmgt.dao.api.EventDao) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Event(org.opennms.netmgt.xml.event.Event) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria) ArrayList(java.util.ArrayList) List(java.util.List) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

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