Search in sources :

Example 61 with Criteria

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

the class CriteriaBuilderSearchVisitorIT method testScanReportTwoConditionsWithIsNull.

@Test
public void testScanReportTwoConditionsWithIsNull() {
    CriteriaBuilder builder = new ScanReportRestService().getCriteriaBuilder(null);
    CriteriaBuilderSearchVisitor<ScanReport, ScanReport> visitor = new CriteriaBuilderSearchVisitor<>(builder, ScanReport.class);
    visitor.visit(new PrimitiveSearchCondition<ScanReport>("applications", CriteriaBuilderSearchVisitor.NULL_VALUE, 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)

Example 62 with Criteria

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

the class NodeRestService method getNodes.

/**
 * <p>getNodes</p>
 *
 * @return a {@link org.opennms.netmgt.model.OnmsNodeList} object.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
public OnmsNodeList getNodes(@Context final UriInfo uriInfo) {
    final MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
    final String type = params.getFirst("type");
    final CriteriaBuilder builder = getCriteriaBuilder(params);
    Criteria crit = null;
    if (params.size() == 1 && params.getFirst("nodeId") != null && params.getFirst("nodeId").contains(",")) {
        // we've been specifically asked for a list of nodes by ID
        final List<Integer> nodeIds = new ArrayList<>();
        for (final String id : params.getFirst("nodeId").split(",")) {
            nodeIds.add(Integer.valueOf(id));
        }
        crit = filterForNodeIds(builder, nodeIds).toCriteria();
    } else if (params.getFirst("filterRule") != null) {
        final Set<Integer> filteredNodeIds = m_filterDao.getNodeMap(params.getFirst("filterRule")).keySet();
        if (filteredNodeIds.size() < 1) {
            // The "in" criteria fails if the list of node ids is empty
            final OnmsNodeList coll = new OnmsNodeList(Collections.emptyList());
            coll.setTotalCount(0);
            return coll;
        }
        // Apply the criteria without the filter rule
        params.remove("filterRule");
        final CriteriaBuilder filterRuleCriteriaBuilder = getCriteriaBuilder(params);
        crit = filterForNodeIds(filterRuleCriteriaBuilder, filteredNodeIds).toCriteria();
    } else {
        applyQueryFilters(params, builder);
        builder.orderBy("label").asc();
        crit = builder.toCriteria();
        if (type == null) {
            final List<Restriction> restrictions = new ArrayList<Restriction>(crit.getRestrictions());
            restrictions.add(Restrictions.ne("type", "D"));
            crit.setRestrictions(restrictions);
        }
    }
    final OnmsNodeList coll = new OnmsNodeList(m_nodeDao.findMatching(crit));
    crit.setLimit(null);
    crit.setOffset(null);
    crit.setOrders(new ArrayList<Order>());
    coll.setTotalCount(m_nodeDao.countMatching(crit));
    return coll;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) Order(org.opennms.core.criteria.Order) Set(java.util.Set) OnmsNodeList(org.opennms.netmgt.model.OnmsNodeList) ArrayList(java.util.ArrayList) Criteria(org.opennms.core.criteria.Criteria) Restriction(org.opennms.core.criteria.restrictions.Restriction) List(java.util.List) OnmsNodeList(org.opennms.netmgt.model.OnmsNodeList) ArrayList(java.util.ArrayList) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Criteria (org.opennms.core.criteria.Criteria)62 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)31 Test (org.junit.Test)16 EqRestriction (org.opennms.core.criteria.restrictions.EqRestriction)16 Date (java.util.Date)13 Alias (org.opennms.core.criteria.Alias)13 ArrayList (java.util.ArrayList)10 Order (org.opennms.core.criteria.Order)9 Transactional (org.springframework.transaction.annotation.Transactional)9 GET (javax.ws.rs.GET)8 PUT (javax.ws.rs.PUT)7 OnmsNode (org.opennms.netmgt.model.OnmsNode)7 POST (javax.ws.rs.POST)6 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)5 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)5 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)5 Produces (javax.ws.rs.Produces)4 EventDao (org.opennms.netmgt.dao.api.EventDao)4 ScanReport (org.opennms.netmgt.model.ScanReport)4 ScanReportRestService (org.opennms.web.rest.v2.ScanReportRestService)4