Search in sources :

Example 56 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class NodeIpInterfacesRestService method getCriteriaBuilder.

@Override
protected CriteriaBuilder getCriteriaBuilder(final UriInfo uriInfo) {
    final CriteriaBuilder builder = new CriteriaBuilder(getDaoClass());
    // 1st level JOINs
    // TODO: Only add this alias when filtering so that we can specify a join condition
    builder.alias("monitoredServices", Aliases.monitoredService.toString(), JoinType.LEFT_JOIN);
    // 2nd level JOINs
    // TODO: Only add this alias when filtering so that we can specify a join condition
    builder.alias("monitoredService.serviceType", Aliases.serviceType.toString(), JoinType.LEFT_JOIN);
    // TODO: Remove this once the join conditions are in place
    builder.distinct();
    updateCriteria(uriInfo, builder);
    return builder;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder)

Example 57 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class NodeSnmpInterfacesRestService method getCriteriaBuilder.

@Override
protected CriteriaBuilder getCriteriaBuilder(final UriInfo uriInfo) {
    final CriteriaBuilder builder = new CriteriaBuilder(getDaoClass());
    updateCriteria(uriInfo, builder);
    return builder;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder)

Example 58 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class NotificationRestService method getCriteriaBuilder.

@Override
protected CriteriaBuilder getCriteriaBuilder(UriInfo uriInfo) {
    final CriteriaBuilder builder = new CriteriaBuilder(OnmsNotification.class, Aliases.notification.toString());
    // 1st level JOINs
    builder.alias("event", Aliases.event.toString(), JoinType.LEFT_JOIN);
    builder.alias("node", Aliases.node.toString(), JoinType.LEFT_JOIN);
    builder.alias("serviceType", Aliases.serviceType.toString(), JoinType.LEFT_JOIN);
    // 2nd level JOINs
    builder.alias(Aliases.event.prop("distPoller"), Aliases.distPoller.toString(), JoinType.LEFT_JOIN);
    builder.alias(Aliases.node.prop("assetRecord"), Aliases.assetRecord.toString(), JoinType.LEFT_JOIN);
    // Left joins on a toMany relationship need a join condition so that only one row is returned
    builder.alias(Aliases.node.prop("ipInterfaces"), Aliases.ipInterface.toString(), JoinType.LEFT_JOIN, Restrictions.or(Restrictions.eq(Aliases.ipInterface.prop("ipAddress"), Aliases.notification.prop("ipAddress")), Restrictions.isNull(Aliases.ipInterface.prop("ipAddress"))));
    builder.alias(Aliases.node.prop("location"), Aliases.location.toString(), JoinType.LEFT_JOIN);
    // Left joins on a toMany relationship need a join condition so that only one row is returned
    builder.alias(Aliases.node.prop("snmpInterfaces"), Aliases.snmpInterface.toString(), JoinType.LEFT_JOIN, Restrictions.or(Restrictions.eqProperty(Aliases.snmpInterface.prop("ifIndex"), Aliases.event.prop("ifIndex")), Restrictions.isNull(Aliases.snmpInterface.prop("ifIndex"))));
    // Order by ID by default
    builder.orderBy("notifyId").desc();
    return builder;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder)

Example 59 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class CriteriaBuilderSearchVisitorIT method testScanReportAndCondition.

@Test
public void testScanReportAndCondition() {
    CriteriaBuilder builder = new ScanReportRestService().getCriteriaBuilder(null);
    CriteriaBuilderSearchVisitor<ScanReport, ScanReport> visitor = new CriteriaBuilderSearchVisitor<>(builder, ScanReport.class);
    // Simulates /opennms/api/v2/scanreports?_s=applications%3D%3DLocal+Access;timestamp%3Dle%3D2016-02-01T15:07:14.340-0500&limit=20&offset=0&order=desc&orderBy=timestamp
    List<SearchCondition<ScanReport>> conditions = new ArrayList<SearchCondition<ScanReport>>();
    conditions.add(new PrimitiveSearchCondition<ScanReport>("applications", "blah", String.class, ConditionType.EQUALS, new ScanReport()));
    conditions.add(new PrimitiveSearchCondition<ScanReport>("timestamp", new Date(), Date.class, ConditionType.LESS_OR_EQUALS, new ScanReport()));
    SearchCondition<ScanReport> andCondition = new AndSearchCondition<ScanReport>(conditions);
    visitor.visit(andCondition);
    Criteria criteria = visitor.getQuery().toCriteria();
    System.out.println(criteria.toString());
    m_dao.countMatching(criteria);
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) ScanReport(org.opennms.netmgt.model.ScanReport) ArrayList(java.util.ArrayList) Criteria(org.opennms.core.criteria.Criteria) Date(java.util.Date) ScanReportRestService(org.opennms.web.rest.v2.ScanReportRestService) AndSearchCondition(org.apache.cxf.jaxrs.ext.search.AndSearchCondition) PrimitiveSearchCondition(org.apache.cxf.jaxrs.ext.search.PrimitiveSearchCondition) SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) AndSearchCondition(org.apache.cxf.jaxrs.ext.search.AndSearchCondition) Test(org.junit.Test)

Example 60 with CriteriaBuilder

use of org.opennms.core.criteria.CriteriaBuilder in project opennms by OpenNMS.

the class CriteriaBuilderSearchVisitorIT method testScanReportTwoConditions.

@Test
public void testScanReportTwoConditions() {
    CriteriaBuilder builder = new ScanReportRestService().getCriteriaBuilder(null);
    CriteriaBuilderSearchVisitor<ScanReport, ScanReport> visitor = new CriteriaBuilderSearchVisitor<>(builder, ScanReport.class);
    visitor.visit(new PrimitiveSearchCondition<ScanReport>("applications", "blah", String.class, ConditionType.EQUALS, new ScanReport()));
    visitor.visit(new PrimitiveSearchCondition<ScanReport>("timestamp", new Date(), Date.class, ConditionType.LESS_OR_EQUALS, new ScanReport()));
    Criteria criteria = visitor.getQuery().toCriteria();
    System.out.println(criteria.toString());
    m_dao.countMatching(criteria);
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) ScanReport(org.opennms.netmgt.model.ScanReport) Criteria(org.opennms.core.criteria.Criteria) Date(java.util.Date) ScanReportRestService(org.opennms.web.rest.v2.ScanReportRestService) 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