use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class AlarmStatsRestService method getStats.
protected AlarmStatistics getStats(final UriInfo uriInfo, final OnmsSeverity severity) {
final AlarmStatistics stats = new AlarmStatistics();
final CriteriaBuilder builder = getCriteriaBuilder(uriInfo.getQueryParameters(), false);
// note: this is just the *total count* criteria, so no ordering, and count everything
builder.count();
if (severity != null) {
builder.eq("severity", severity);
}
final Criteria criteria = builder.toCriteria();
LOG.debug("criteria = {}", criteria);
final int count = m_statisticsService.getTotalCount(criteria);
stats.setTotalCount(count);
stats.setAcknowledgedCount(m_statisticsService.getAcknowledgedCount(criteria));
stats.setNewestAcknowledged(getNewestAcknowledged(severity));
stats.setNewestUnacknowledged(getNewestUnacknowledged(severity));
stats.setOldestAcknowledged(getOldestAcknowledged(severity));
stats.setOldestUnacknowledged(getOldestUnacknowledged(severity));
return stats;
}
use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class AlarmStatsRestService method getCriteriaBuilder.
protected static CriteriaBuilder getCriteriaBuilder(final OnmsSeverity severity) {
final CriteriaBuilder builder = new CriteriaBuilder(OnmsAlarm.class);
if (severity != null) {
builder.eq("severity", severity);
}
builder.fetch("firstEvent", FetchType.EAGER);
builder.fetch("lastEvent", FetchType.EAGER);
builder.alias("node", "node", JoinType.LEFT_JOIN);
builder.alias("node.snmpInterfaces", "snmpInterface", JoinType.LEFT_JOIN);
builder.alias("node.ipInterfaces", "ipInterface", JoinType.LEFT_JOIN);
return builder;
}
use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class AlarmRestService method getAlarms.
/**
* <p>
* getAlarms
* </p>
*
* @return a {@link org.opennms.netmgt.model.OnmsAlarmCollection} object.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Transactional
public OnmsAlarmCollection getAlarms(@Context final SecurityContext securityContext, @Context final UriInfo uriInfo) {
assertUserReadCredentials(securityContext);
final CriteriaBuilder builder = getCriteriaBuilder(uriInfo.getQueryParameters(), false);
builder.distinct();
final OnmsAlarmCollection coll = new OnmsAlarmCollection(m_alarmDao.findMatching(builder.toCriteria()));
// For getting totalCount
coll.setTotalCount(m_alarmDao.countMatching(builder.count().toCriteria()));
return coll;
}
use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class AlarmRestServiceBase method getCriteriaBuilder.
protected CriteriaBuilder getCriteriaBuilder(final MultivaluedMap<String, String> params, final boolean stripOrdering) {
translateParameters(params);
final CriteriaBuilder cb = new CriteriaBuilder(OnmsAlarm.class);
cb.fetch("firstEvent", FetchType.EAGER);
cb.fetch("lastEvent", FetchType.EAGER);
cb.alias("node", "node", JoinType.LEFT_JOIN);
cb.alias("node.snmpInterfaces", "snmpInterface", JoinType.LEFT_JOIN);
cb.alias("node.ipInterfaces", "ipInterface", JoinType.LEFT_JOIN);
cb.alias("node.location", "location", JoinType.LEFT_JOIN);
if (params.containsKey("alarmId")) {
if (params.containsKey("id")) {
throw getException(Status.BAD_REQUEST, "Form parameters contain both the 'alarmId' and 'id' properties! Pick a side!");
}
params.put("id", params.remove("alarmId"));
}
applyQueryFilters(params, cb);
if (stripOrdering) {
cb.clearOrder();
cb.limit(DEFAULT_LIMIT);
cb.offset(0);
} else {
cb.orderBy("lastEventTime").desc();
}
cb.distinct();
return cb;
}
use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class NodeDaoIT method testCriteriaBuilderOrderBy.
@Test
@Transactional
public void testCriteriaBuilderOrderBy() {
CriteriaBuilder cb = new CriteriaBuilder(OnmsNode.class);
cb.alias("ipInterfaces", "ipInterface").distinct();
// TODO: Make this work but we need to put the fields into
// an aggregator function since node->ipInterfaces is a 1->M
// relationship.
//
//cb.orderBy("ipInterfaces.ipAddress").distinct();
Criteria criteria = cb.toCriteria();
System.out.println("Criteria: " + criteria.toString());
List<OnmsNode> nodes = m_nodeDao.findMatching(criteria);
nodes.stream().forEach(System.out::println);
assertEquals(6, nodes.size());
}
Aggregations