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