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);
}
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;
}
Aggregations