@Test public void testSearchSysCpuLoad() throws Exception { UISearchQuery uiSearchQuery = new UISearchQuery("health.sysCpuLoad < 0.99", null, 2, 0); Collection<NodeInfo> nodeInfos = filterApi.listNodes(nodeStorage, uiSearchQuery); assertNotNull(nodeInfos); assertEquals(nodeInfos.size(), 2); nodeInfos.forEach(n -> assertTrue(n.getHealth().getSysCpuLoad() < 0.99)); }
public <T> Collection<T> listNodes(Collection<T> collection, UISearchQuery searchQuery) { final String criteria = searchQuery.getCriterias(); final List<UISearchQuery.SearchOrder> orders = firstNonNull(searchQuery.getOrders(), Collections.emptyList()); Comparator<T> comparing = (t1, t2) -> 0; for (UISearchQuery.SearchOrder order : orders) { comparing = comparing.thenComparing((nodeInfo1, nodeInfo2) -> { Object value1 = getValue(nodeInfo1, order.getField()); Object value2 = getValue(nodeInfo2, order.getField()); Comparable v1 = value1 instanceof Comparable ? (Comparable) value1 : null; Comparable v2 = value2 instanceof Comparable ? (Comparable) value2 : null; @SuppressWarnings("unchecked") int result = Comparables.compare(v1, v2); return order.getOrder() == ASC ? result : -result; }); } final List<Criterion<T>> criterions = new ArrayList<>(); if (StringUtils.hasText(criteria)) { criterions.add(fromPredicate(w -> { try { SpelExpression expr = parser.parseRaw(criteria); return (Boolean) expr.getValue(w); } catch (Exception e) { log.error("error during parsing '" + criteria + "', '" + w + "'", e); return false; } })); } criterions.add(topN(comparing, searchQuery.getPage() * searchQuery.getSize(), searchQuery.getSize())); final Criterion<T> compositeCriteria = criterions.stream().reduce(c -> c, (c1, c2) -> (s -> c2.apply(c1.apply(s)))); return compositeCriteria.apply(collection.stream()).collect(Collectors.toList()); }
FilterApi { public <T> Collection<T> listNodes(Collection<T> collection, UISearchQuery searchQuery) { final String criteria = searchQuery.getCriterias(); final List<UISearchQuery.SearchOrder> orders = firstNonNull(searchQuery.getOrders(), Collections.emptyList()); Comparator<T> comparing = (t1, t2) -> 0; for (UISearchQuery.SearchOrder order : orders) { comparing = comparing.thenComparing((nodeInfo1, nodeInfo2) -> { Object value1 = getValue(nodeInfo1, order.getField()); Object value2 = getValue(nodeInfo2, order.getField()); Comparable v1 = value1 instanceof Comparable ? (Comparable) value1 : null; Comparable v2 = value2 instanceof Comparable ? (Comparable) value2 : null; @SuppressWarnings("unchecked") int result = Comparables.compare(v1, v2); return order.getOrder() == ASC ? result : -result; }); } final List<Criterion<T>> criterions = new ArrayList<>(); if (StringUtils.hasText(criteria)) { criterions.add(fromPredicate(w -> { try { SpelExpression expr = parser.parseRaw(criteria); return (Boolean) expr.getValue(w); } catch (Exception e) { log.error("error during parsing '" + criteria + "', '" + w + "'", e); return false; } })); } criterions.add(topN(comparing, searchQuery.getPage() * searchQuery.getSize(), searchQuery.getSize())); final Criterion<T> compositeCriteria = criterions.stream().reduce(c -> c, (c1, c2) -> (s -> c2.apply(c1.apply(s)))); return compositeCriteria.apply(collection.stream()).collect(Collectors.toList()); } }
FilterApi { public <T> Collection<T> listNodes(Collection<T> collection, UISearchQuery searchQuery) { final String criteria = searchQuery.getCriterias(); final List<UISearchQuery.SearchOrder> orders = firstNonNull(searchQuery.getOrders(), Collections.emptyList()); Comparator<T> comparing = (t1, t2) -> 0; for (UISearchQuery.SearchOrder order : orders) { comparing = comparing.thenComparing((nodeInfo1, nodeInfo2) -> { Object value1 = getValue(nodeInfo1, order.getField()); Object value2 = getValue(nodeInfo2, order.getField()); Comparable v1 = value1 instanceof Comparable ? (Comparable) value1 : null; Comparable v2 = value2 instanceof Comparable ? (Comparable) value2 : null; @SuppressWarnings("unchecked") int result = Comparables.compare(v1, v2); return order.getOrder() == ASC ? result : -result; }); } final List<Criterion<T>> criterions = new ArrayList<>(); if (StringUtils.hasText(criteria)) { criterions.add(fromPredicate(w -> { try { SpelExpression expr = parser.parseRaw(criteria); return (Boolean) expr.getValue(w); } catch (Exception e) { log.error("error during parsing '" + criteria + "', '" + w + "'", e); return false; } })); } criterions.add(topN(comparing, searchQuery.getPage() * searchQuery.getSize(), searchQuery.getSize())); final Criterion<T> compositeCriteria = criterions.stream().reduce(c -> c, (c1, c2) -> (s -> c2.apply(c1.apply(s)))); return compositeCriteria.apply(collection.stream()).collect(Collectors.toList()); }  }
FilterApi { public <T> Collection<T> listNodes(Collection<T> collection, UISearchQuery searchQuery) { final String criteria = searchQuery.getCriterias(); final List<UISearchQuery.SearchOrder> orders = firstNonNull(searchQuery.getOrders(), Collections.emptyList()); Comparator<T> comparing = (t1, t2) -> 0; for (UISearchQuery.SearchOrder order : orders) { comparing = comparing.thenComparing((nodeInfo1, nodeInfo2) -> { Object value1 = getValue(nodeInfo1, order.getField()); Object value2 = getValue(nodeInfo2, order.getField()); Comparable v1 = value1 instanceof Comparable ? (Comparable) value1 : null; Comparable v2 = value2 instanceof Comparable ? (Comparable) value2 : null; @SuppressWarnings("unchecked") int result = Comparables.compare(v1, v2); return order.getOrder() == ASC ? result : -result; }); } final List<Criterion<T>> criterions = new ArrayList<>(); if (StringUtils.hasText(criteria)) { criterions.add(fromPredicate(w -> { try { SpelExpression expr = parser.parseRaw(criteria); return (Boolean) expr.getValue(w); } catch (Exception e) { log.error("error during parsing '" + criteria + "', '" + w + "'", e); return false; } })); } criterions.add(topN(comparing, searchQuery.getPage() * searchQuery.getSize(), searchQuery.getSize())); final Criterion<T> compositeCriteria = criterions.stream().reduce(c -> c, (c1, c2) -> (s -> c2.apply(c1.apply(s)))); return compositeCriteria.apply(collection.stream()).collect(Collectors.toList()); }  Collection<T> listNodes(Collection<T> collection, UISearchQuery searchQuery); }
FilterApi { public <T> Collection<T> listNodes(Collection<T> collection, UISearchQuery searchQuery) { final String criteria = searchQuery.getCriterias(); final List<UISearchQuery.SearchOrder> orders = firstNonNull(searchQuery.getOrders(), Collections.emptyList()); Comparator<T> comparing = (t1, t2) -> 0; for (UISearchQuery.SearchOrder order : orders) { comparing = comparing.thenComparing((nodeInfo1, nodeInfo2) -> { Object value1 = getValue(nodeInfo1, order.getField()); Object value2 = getValue(nodeInfo2, order.getField()); Comparable v1 = value1 instanceof Comparable ? (Comparable) value1 : null; Comparable v2 = value2 instanceof Comparable ? (Comparable) value2 : null; @SuppressWarnings("unchecked") int result = Comparables.compare(v1, v2); return order.getOrder() == ASC ? result : -result; }); } final List<Criterion<T>> criterions = new ArrayList<>(); if (StringUtils.hasText(criteria)) { criterions.add(fromPredicate(w -> { try { SpelExpression expr = parser.parseRaw(criteria); return (Boolean) expr.getValue(w); } catch (Exception e) { log.error("error during parsing '" + criteria + "', '" + w + "'", e); return false; } })); } criterions.add(topN(comparing, searchQuery.getPage() * searchQuery.getSize(), searchQuery.getSize())); final Criterion<T> compositeCriteria = criterions.stream().reduce(c -> c, (c1, c2) -> (s -> c2.apply(c1.apply(s)))); return compositeCriteria.apply(collection.stream()).collect(Collectors.toList()); }  Collection<T> listNodes(Collection<T> collection, UISearchQuery searchQuery);  }