Search in sources :

Example 21 with OnmsCriteria

use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.

the class AbstractDaoHibernate method findMatching.

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
public List<T> findMatching(final OnmsCriteria onmsCrit) throws DataAccessException {
    //FIXME: why is this here?
    onmsCrit.resultsOfType(m_entityClass);
    final HibernateCallback<List<T>> callback = new HibernateCallback<List<T>>() {

        @Override
        public List<T> doInHibernate(final Session session) throws HibernateException, SQLException {
            final Criteria attachedCrit = onmsCrit.getDetachedCriteria().getExecutableCriteria(session);
            if (onmsCrit.getFirstResult() != null)
                attachedCrit.setFirstResult(onmsCrit.getFirstResult());
            if (onmsCrit.getMaxResults() != null)
                attachedCrit.setMaxResults(onmsCrit.getMaxResults());
            return (List<T>) attachedCrit.list();
        }
    };
    return getHibernateTemplate().execute(callback);
}
Also used : List(java.util.List) HibernateCallback(org.springframework.orm.hibernate3.HibernateCallback) Criteria(org.hibernate.Criteria) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria) Session(org.hibernate.Session)

Example 22 with OnmsCriteria

use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.

the class AbstractDaoHibernate method countMatching.

/** {@inheritDoc} */
public int countMatching(final OnmsCriteria onmsCrit) throws DataAccessException {
    final HibernateCallback<Integer> callback = new HibernateCallback<Integer>() {

        @Override
        public Integer doInHibernate(final Session session) throws HibernateException, SQLException {
            final Criteria attachedCrit = onmsCrit.getDetachedCriteria().getExecutableCriteria(session).setProjection(Projections.rowCount());
            Long retval = (Long) attachedCrit.uniqueResult();
            attachedCrit.setProjection(null);
            attachedCrit.setResultTransformer(Criteria.ROOT_ENTITY);
            return retval.intValue();
        }
    };
    Integer retval = getHibernateTemplate().execute(callback);
    return retval == null ? 0 : retval.intValue();
}
Also used : HibernateCallback(org.springframework.orm.hibernate3.HibernateCallback) Criteria(org.hibernate.Criteria) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria) Session(org.hibernate.Session)

Example 23 with OnmsCriteria

use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.

the class AlarmRepositoryHibernate method escalateAlarms.

/**
     * {@inheritDoc}
     */
@Transactional
@Override
public void escalateAlarms(int[] alarmIds, String user, Date timestamp) {
    OnmsCriteria criteria = new OnmsCriteria(OnmsAlarm.class);
    criteria.add(Restrictions.in("id", Arrays.asList(ArrayUtils.toObject(alarmIds))));
    List<OnmsAlarm> alarms = m_alarmDao.findMatching(criteria);
    Iterator<OnmsAlarm> alarmsIt = alarms.iterator();
    while (alarmsIt.hasNext()) {
        OnmsAlarm alarm = alarmsIt.next();
        OnmsAcknowledgment ack = new OnmsAcknowledgment(alarm, user);
        ack.setAckTime(timestamp);
        ack.setAckAction(AckAction.ESCALATE);
        m_ackDao.processAck(ack);
    }
}
Also used : OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with OnmsCriteria

use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.

the class AlarmRepositoryHibernate method acknowledgeAlarms.

@Transactional
public void acknowledgeAlarms(String user, Date timestamp, int[] alarmIds) {
    OnmsCriteria criteria = new OnmsCriteria(OnmsAlarm.class);
    criteria.add(Restrictions.in("id", Arrays.asList(ArrayUtils.toObject(alarmIds))));
    acknowledgeMatchingAlarms(user, timestamp, criteria);
}
Also used : OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with OnmsCriteria

use of org.opennms.netmgt.model.OnmsCriteria in project opennms by OpenNMS.

the class DefaultNodeListService method createNodeList.

/** {@inheritDoc} */
public NodeListModel createNodeList(NodeListCommand command, boolean sanitizeLabels) {
    Collection<OnmsNode> onmsNodes = null;
    /*
         * All search queries can be done solely with
         * criteria, so we build a common criteria object with common
         * restrictions and sort options.  Each specific search query
         * adds its own criteria restrictions (if any).
         * 
         * A set of booleans is maintained for aliases that might be
         * added in multiple places to ensure we don't add the same alias
         * multiple times.
         */
    OnmsCriteria criteria = new OnmsCriteria(OnmsNode.class, "node");
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    criteria.add(Restrictions.ne("node.type", "D"));
    // Add additional criteria based on the command object
    addCriteriaForCommand(criteria, command);
    criteria.addOrder(Order.asc("node.label"));
    onmsNodes = m_nodeDao.findMatching(criteria);
    if (command.getNodesWithDownAggregateStatus()) {
        AggregateStatus as = new AggregateStatus(onmsNodes);
        onmsNodes = as.getDownNodes();
    }
    if (sanitizeLabels) {
        for (OnmsNode node : onmsNodes) {
            node.setLabel(WebSecurityUtils.sanitizeString(node.getLabel()));
        }
    }
    return createModelForNodes(command, onmsNodes);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria) AggregateStatus(org.opennms.web.svclayer.model.AggregateStatus)

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