use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class OnmsIpInterfaceResource method getIpInterfaces.
/**
* <p>getIpInterfaces</p>
*
* @param nodeCriteria a {@link java.lang.String} object.
* @return a {@link org.opennms.netmgt.model.OnmsIpInterfaceList} object.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public OnmsIpInterfaceList getIpInterfaces(@Context final UriInfo uriInfo, @PathParam("nodeCriteria") final String nodeCriteria) {
LOG.debug("getIpInterfaces: reading interfaces for node {}", nodeCriteria);
final OnmsNode node = m_nodeDao.get(nodeCriteria);
final MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
final CriteriaBuilder builder = new CriteriaBuilder(OnmsIpInterface.class);
builder.alias("monitoredServices.serviceType", "serviceType", JoinType.LEFT_JOIN);
builder.ne("isManaged", "D");
builder.limit(20);
applyQueryFilters(params, builder);
builder.alias("node", "node");
builder.eq("node.id", node.getId());
final OnmsIpInterfaceList interfaceList = new OnmsIpInterfaceList(m_ipInterfaceDao.findMatching(builder.toCriteria()));
interfaceList.setTotalCount(m_ipInterfaceDao.countMatching(builder.count().toCriteria()));
return interfaceList;
}
use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class OnmsSnmpInterfaceResource method getSnmpInterfaces.
/**
* <p>getSnmpInterfaces</p>
*
* @param nodeCriteria a {@link java.lang.String} object.
* @return a {@link org.opennms.netmgt.model.OnmsSnmpInterfaceList} object.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public OnmsSnmpInterfaceList getSnmpInterfaces(@Context final UriInfo uriInfo, @PathParam("nodeCriteria") final String nodeCriteria) {
final OnmsNode node = m_nodeDao.get(nodeCriteria);
final MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
final CriteriaBuilder builder = new CriteriaBuilder(OnmsSnmpInterface.class);
builder.ne("collect", "D");
builder.limit(20);
applyQueryFilters(params, builder);
builder.eq("node.id", node.getId());
final OnmsSnmpInterfaceList snmpList = new OnmsSnmpInterfaceList(m_snmpInterfaceDao.findMatching(builder.toCriteria()));
snmpList.setTotalCount(m_snmpInterfaceDao.countMatching(builder.count().toCriteria()));
return snmpList;
}
use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class OutageRestService method forNodeId.
/**
* <p>forNodeId</p>
*
* @param nodeId a int.
* @param dateRange a long.
* @param startTs a java.lang.Long.
* @param endTs a java.lang.Long.
* @return a {@link org.opennms.netmgt.model.OnmsOutageCollection} object.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Transactional
@Path("forNode/{nodeId}")
public OnmsOutageCollection forNodeId(@Context final UriInfo uriInfo, @PathParam("nodeId") final int nodeId, @DefaultValue("604800000") @QueryParam("dateRange") final long dateRange, @QueryParam("start") final Long startTs, @QueryParam("end") final Long endTs) {
final CriteriaBuilder builder = new CriteriaBuilder(OnmsOutage.class);
builder.eq("node.id", nodeId);
builder.alias("monitoredService", "monitoredService");
builder.alias("monitoredService.ipInterface", "ipInterface");
builder.alias("monitoredService.ipInterface.node", "node");
builder.alias("monitoredService.serviceType", "serviceType");
final MultivaluedMap<String, String> params = new MultivaluedMapImpl();
params.putAll(uriInfo.getQueryParameters());
LOG.debug("Processing outages for node {} using {}", nodeId, params);
if (startTs != null && endTs != null) {
params.remove("start");
params.remove("end");
final Date start = new Date(startTs);
final Date end = new Date(endTs);
LOG.debug("Getting all outages from {} to {} for node {}", start, end, nodeId);
builder.or(Restrictions.isNull("ifRegainedService"), Restrictions.and(Restrictions.gt("ifLostService", start), Restrictions.lt("ifLostService", end)));
} else {
params.remove("dateRange");
final Date start = new Date(System.currentTimeMillis() - dateRange);
LOG.debug("Getting all outgae from {} to current date for node {}", start, nodeId);
builder.or(Restrictions.isNull("ifRegainedService"), Restrictions.gt("ifLostService", start));
}
applyQueryFilters(params, builder);
builder.orderBy("id").desc();
return new OnmsOutageCollection(m_outageDao.findMatching(builder.toCriteria()));
}
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);
return m_alarmDao.countMatching(criteriaBuilder.toCriteria());
}
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);
return m_alarmDao.countMatching(criteriaBuilder.toCriteria());
}
Aggregations