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);
}
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();
}
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);
}
}
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);
}
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);
}
Aggregations