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 AccessPointRestService method getAccessPoints.
/**
* <p>
* getOutages
* </p>
*
* @return a {@link org.opennms.netmgt.model.OnmsOutageCollection} object.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Transactional
public OnmsAccessPointCollection getAccessPoints(@Context final UriInfo uriInfo) {
readLock();
try {
final CriteriaBuilder builder = new CriteriaBuilder(OnmsAccessPoint.class);
// TODO: Fix query filters - these don't seem to work outside of
// the opennms-webapp project
// applyQueryFilters(uriInfo.getQueryParameters(), builder);
final OnmsAccessPointCollection coll = new OnmsAccessPointCollection(m_accessPointDao.findAll());
// For getting totalCount
coll.setTotalCount(m_accessPointDao.countMatching(builder.count().toCriteria()));
return coll;
} finally {
readUnlock();
}
}
use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.
the class StatisticsReportsIT method hasReportLinkThatMatchDescription.
@Test
public void hasReportLinkThatMatchDescription() throws Exception {
Date startOfTest = new Date();
HibernateDaoFactory daoFactory = new HibernateDaoFactory(getPostgresService());
ResourceReferenceDao resourceReferenceDao = daoFactory.getDao(ResourceReferenceDaoHibernate.class);
StatisticsReportDao statisticsReportDao = daoFactory.getDao(StatisticsReportDaoHibernate.class);
StatisticsReport report = new StatisticsReport();
report.setName("Top10_Response_Hourly");
report.setDescription("Hourly Top 10 responses across all nodes");
report.setStartDate(new Date());
report.setEndDate(new Date());
report.setJobStartedDate(new Date());
report.setJobCompletedDate(new Date());
report.setPurgeDate(new Date());
ResourceReference resource = new ResourceReference();
resource.setResourceId("node1");
resourceReferenceDao.save(resource);
StatisticsReportData data = new StatisticsReportData();
data.setReport(report);
data.setResource(resource);
data.setValue(4.0);
report.addData(data);
statisticsReportDao.save(report);
await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(DaoUtils.findMatchingCallable(statisticsReportDao, new CriteriaBuilder(StatisticsReport.class).ge("startDate", startOfTest).toCriteria()), notNullValue());
m_driver.navigate().refresh();
assertNotNull(findElementByLink("Hourly Top 10 responses across all nodes"));
}
Aggregations