Search in sources :

Example 51 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class AlarmsDashlet method addComponents.

/**
 * Adds the alarms components to a {@link com.vaadin.ui.AbstractOrderedLayout}
 *
 * @param component the component to add alarms to
 * @param alarms    the alarms list
 */
private void addComponents(AbstractOrderedLayout component, List<OnmsAlarm> alarms) {
    if (alarms.size() == 0) {
        Label label = new Label("No alarms found!");
        label.addStyleName("alerts-noalarms-font");
        component.addComponent(label);
    } else {
        for (OnmsAlarm onmsAlarm : alarms) {
            OnmsNode onmsNode = null;
            if (onmsAlarm.getNodeId() != null) {
                CriteriaBuilder nodeCb = new CriteriaBuilder(OnmsNode.class);
                nodeCb.eq("id", onmsAlarm.getNodeId());
                List<OnmsNode> nodes = m_nodeDao.findMatching(nodeCb.toCriteria());
                if (nodes.size() == 1) {
                    onmsNode = nodes.get(0);
                }
            }
            component.addComponent(createAlarmComponent(onmsAlarm, onmsNode));
            OnmsSeverity boostSeverity = OnmsSeverity.valueOf(getDashletSpec().getParameters().get("boostSeverity"));
            if (onmsAlarm.getSeverity().isGreaterThanOrEqual(boostSeverity)) {
                boosted = true;
            }
        }
    }
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsSeverity(org.opennms.netmgt.model.OnmsSeverity) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Label(com.vaadin.ui.Label)

Example 52 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class SummaryDashlet method countBySeverity.

/**
 * Searches for alarms with the given criterias and returns the number found.
 *
 * @param acknowledged search for acknowledged or unacknowledged alarms
 * @param age          the age of the alarms
 * @param onmsSeverity the {@link OnmsSeverity} to search for
 * @return number of alarms found
 */
public int countBySeverity(boolean acknowledged, long age, OnmsSeverity onmsSeverity) {
    CriteriaBuilder criteriaBuilder = new CriteriaBuilder(OnmsAlarm.class);
    if (acknowledged) {
        criteriaBuilder.isNotNull("alarmAckUser");
    } else {
        criteriaBuilder.isNull("alarmAckUser");
    }
    criteriaBuilder.eq("severity", onmsSeverity);
    criteriaBuilder.sql("EXTRACT(EPOCH FROM CURRENT_TIMESTAMP - lastEventTime) < ?", age, Type.LONG);
    return m_alarmDao.countMatching(criteriaBuilder.toCriteria());
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder)

Example 53 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class SummaryDashlet method countByUei.

/**
 * Searches for alarms with the given criterias and returns the number found.
 *
 * @param acknowledged search for acknowledged or unacknowledged alarms
 * @param age          the age of the alarms
 * @param uei          search for alarms with the specified uei
 * @return number of alarms found
 */
public int countByUei(boolean acknowledged, long age, String uei) {
    CriteriaBuilder criteriaBuilder = new CriteriaBuilder(OnmsAlarm.class);
    if (acknowledged) {
        criteriaBuilder.isNotNull("alarmAckUser");
    } else {
        criteriaBuilder.isNull("alarmAckUser");
    }
    criteriaBuilder.eq("uei", uei);
    criteriaBuilder.sql("EXTRACT(EPOCH FROM CURRENT_TIMESTAMP - lastEventTime) < ?", age, Type.LONG);
    return m_alarmDao.countMatching(criteriaBuilder.toCriteria());
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder)

Example 54 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class ApplicationRestService method getCriteriaBuilder.

@Override
protected CriteriaBuilder getCriteriaBuilder(UriInfo uriInfo) {
    final CriteriaBuilder builder = new CriteriaBuilder(OnmsApplication.class);
    // Order by application name by default
    builder.orderBy("name").asc();
    return builder;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder)

Example 55 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class IfServiceRestService method getCriteriaBuilder.

@Override
protected CriteriaBuilder getCriteriaBuilder(final UriInfo uriInfo) {
    final CriteriaBuilder builder = new CriteriaBuilder(getDaoClass());
    // 1st level JOINs
    builder.alias("ipInterface", Aliases.ipInterface.toString(), JoinType.LEFT_JOIN);
    builder.alias("serviceType", Aliases.serviceType.toString(), JoinType.LEFT_JOIN);
    // 2nd level JOINs
    builder.alias(Aliases.ipInterface.prop("node"), Aliases.node.toString(), JoinType.LEFT_JOIN);
    builder.alias(Aliases.ipInterface.prop("snmpInterface"), Aliases.snmpInterface.toString(), JoinType.LEFT_JOIN);
    // 3rd level JOINs
    builder.alias(Aliases.node.prop("assetRecord"), Aliases.assetRecord.toString(), JoinType.LEFT_JOIN);
    builder.alias(Aliases.node.prop("location"), Aliases.location.toString(), JoinType.LEFT_JOIN);
    // TODO: Only add this alias when filtering so that we can specify a join condition
    // builder.alias("node.categories", Aliases.category.toString(), JoinType.LEFT_JOIN);
    builder.orderBy("id");
    return builder;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder)

Aggregations

CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)155 Test (org.junit.Test)60 Criteria (org.opennms.core.criteria.Criteria)31 OnmsNode (org.opennms.netmgt.model.OnmsNode)25 Transactional (org.springframework.transaction.annotation.Transactional)23 Date (java.util.Date)20 GET (javax.ws.rs.GET)13 ArrayList (java.util.ArrayList)12 Produces (javax.ws.rs.Produces)12 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)11 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)11 InetSocketAddress (java.net.InetSocketAddress)9 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)7 HibernateDaoFactory (org.opennms.smoketest.utils.HibernateDaoFactory)7 OnmsMinion (org.opennms.netmgt.model.minion.OnmsMinion)6 RateLimiter (com.google.common.util.concurrent.RateLimiter)4 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)4 EventDao (org.opennms.netmgt.dao.api.EventDao)4 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)4 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)4