Search in sources :

Example 66 with CriteriaBuilder

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;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterfaceList(org.opennms.netmgt.model.OnmsIpInterfaceList) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 67 with CriteriaBuilder

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;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsSnmpInterfaceList(org.opennms.netmgt.model.OnmsSnmpInterfaceList) OnmsNode(org.opennms.netmgt.model.OnmsNode) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 68 with CriteriaBuilder

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()));
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) MultivaluedMapImpl(org.opennms.web.rest.support.MultivaluedMapImpl) OnmsOutageCollection(org.opennms.netmgt.model.OnmsOutageCollection) Date(java.util.Date) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Transactional(org.springframework.transaction.annotation.Transactional)

Example 69 with CriteriaBuilder

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();
    }
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsAccessPointCollection(org.opennms.netmgt.model.OnmsAccessPointCollection) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Transactional(org.springframework.transaction.annotation.Transactional)

Example 70 with CriteriaBuilder

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"));
}
Also used : StatisticsReportDao(org.opennms.netmgt.dao.api.StatisticsReportDao) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) HibernateDaoFactory(org.opennms.smoketest.utils.HibernateDaoFactory) StatisticsReport(org.opennms.netmgt.model.StatisticsReport) StatisticsReportData(org.opennms.netmgt.model.StatisticsReportData) ResourceReferenceDao(org.opennms.netmgt.dao.api.ResourceReferenceDao) ResourceReference(org.opennms.netmgt.model.ResourceReference) Date(java.util.Date) Test(org.junit.Test)

Aggregations

CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)155 Test (org.junit.Test)60 Criteria (org.opennms.core.criteria.Criteria)31 OnmsNode (org.opennms.netmgt.model.OnmsNode)25 Transactional (org.springframework.transaction.annotation.Transactional)23 Date (java.util.Date)20 GET (javax.ws.rs.GET)13 ArrayList (java.util.ArrayList)12 Produces (javax.ws.rs.Produces)12 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)11 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)11 InetSocketAddress (java.net.InetSocketAddress)9 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)7 HibernateDaoFactory (org.opennms.smoketest.utils.HibernateDaoFactory)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 EventDao (org.opennms.netmgt.dao.api.EventDao)4 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)4 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)4