Search in sources :

Example 11 with CriteriaBuilder

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

the class AlarmDetailsDashlet method getAlarms.

/**
     * Returns the alarms defined by this dashlet.
     *
     * @return the list of alarms
     */
private List<OnmsAlarm> getAlarms() {
    final CriteriaBuilder alarmCb = new CriteriaBuilder(OnmsAlarm.class);
    alarmCb.alias("node", "node");
    alarmCb.alias("node.categories", "category");
    alarmCb.alias("lastEvent", "event");
    String criteria = getDashletSpec().getParameters().get("criteria");
    m_criteriaBuilderHelper.parseConfiguration(alarmCb, criteria);
    alarmCb.fetch("firstEvent", Fetch.FetchType.EAGER);
    alarmCb.fetch("lastEvent", Fetch.FetchType.EAGER);
    /**
         * due to restrictions in the criteria api it's quite hard
         * to use distinct and orderBy together, so I apply a workaround
         * to avoid alarmCb.distinct();
         */
    List<OnmsAlarm> onmsAlarmList = m_alarmDao.findMatching(alarmCb.toCriteria());
    Map<Integer, OnmsAlarm> onmsAlarmMap = new LinkedHashMap<>();
    for (OnmsAlarm onmsAlarm : onmsAlarmList) {
        if (!onmsAlarmMap.containsKey(onmsAlarm.getId())) {
            onmsAlarmMap.put(onmsAlarm.getId(), onmsAlarm);
        }
    }
    return Lists.newArrayList(onmsAlarmMap.values());
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) LinkedHashMap(java.util.LinkedHashMap)

Example 12 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 13 with CriteriaBuilder

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

the class AcknowledgmentRestService method getQueryFilters.

private static CriteriaBuilder getQueryFilters(MultivaluedMap<String, String> params) {
    final CriteriaBuilder builder = new CriteriaBuilder(OnmsAcknowledgment.class);
    applyQueryFilters(params, builder);
    builder.orderBy("ackTime").desc();
    return builder;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder)

Example 14 with CriteriaBuilder

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

the class AlarmRestService method updateAlarms.

/**
     * <p>
     * updateAlarms
     * </p>
     * 
     * @param formProperties
     *            a {@link org.opennms.web.rest.support.MultivaluedMapImpl} object.
     */
@PUT
@Transactional
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response updateAlarms(@Context final SecurityContext securityContext, final MultivaluedMapImpl formProperties) {
    writeLock();
    try {
        final String ackValue = formProperties.getFirst("ack");
        formProperties.remove("ack");
        final String escalateValue = formProperties.getFirst("escalate");
        formProperties.remove("escalate");
        final String clearValue = formProperties.getFirst("clear");
        formProperties.remove("clear");
        final CriteriaBuilder builder = getCriteriaBuilder(formProperties, false);
        builder.distinct();
        builder.limit(0);
        builder.offset(0);
        final String ackUser = formProperties.containsKey("ackUser") ? formProperties.getFirst("ackUser") : securityContext.getUserPrincipal().getName();
        formProperties.remove("ackUser");
        assertUserEditCredentials(securityContext, ackUser);
        final List<OnmsAlarm> alarms = m_alarmDao.findMatching(builder.toCriteria());
        for (final OnmsAlarm alarm : alarms) {
            final OnmsAcknowledgment acknowledgement = new OnmsAcknowledgment(alarm, ackUser);
            acknowledgement.setAckAction(AckAction.UNSPECIFIED);
            if (ackValue != null) {
                if (Boolean.parseBoolean(ackValue)) {
                    acknowledgement.setAckAction(AckAction.ACKNOWLEDGE);
                } else {
                    acknowledgement.setAckAction(AckAction.UNACKNOWLEDGE);
                }
            } else if (escalateValue != null) {
                if (Boolean.parseBoolean(escalateValue)) {
                    acknowledgement.setAckAction(AckAction.ESCALATE);
                }
            } else if (clearValue != null) {
                if (Boolean.parseBoolean(clearValue)) {
                    acknowledgement.setAckAction(AckAction.CLEAR);
                }
            } else {
                throw getException(Status.BAD_REQUEST, "Must supply one of the 'ack', 'escalate', or 'clear' parameters, set to either 'true' or 'false'.");
            }
            m_ackDao.processAck(acknowledgement);
        }
        return alarms == null || alarms.isEmpty() ? Response.notModified().build() : Response.noContent().build();
    } finally {
        writeUnlock();
    }
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with CriteriaBuilder

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

the class AlarmStatsRestService method getNewestAcknowledged.

protected OnmsAlarm getNewestAcknowledged(final OnmsSeverity severity) {
    final CriteriaBuilder builder = getCriteriaBuilder(severity);
    builder.orderBy("lastEventTime").desc();
    builder.orderBy("id").desc();
    builder.limit(1);
    final Criteria criteria = builder.toCriteria();
    LOG.debug("getNewestAcknowledged({}) criteria = {}", severity, criteria);
    return m_statisticsService.getAcknowledged(criteria);
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) Criteria(org.opennms.core.criteria.Criteria)

Aggregations

CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)128 Test (org.junit.Test)55 Criteria (org.opennms.core.criteria.Criteria)28 OnmsNode (org.opennms.netmgt.model.OnmsNode)21 Transactional (org.springframework.transaction.annotation.Transactional)20 Date (java.util.Date)18 GET (javax.ws.rs.GET)13 Produces (javax.ws.rs.Produces)12 InetSocketAddress (java.net.InetSocketAddress)8 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)8 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)8 ArrayList (java.util.ArrayList)7 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)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 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)4 ScanReport (org.opennms.netmgt.model.ScanReport)4 ScanReportRestService (org.opennms.web.rest.v2.ScanReportRestService)4 PUT (javax.ws.rs.PUT)3