public void visit(SearchCondition<T> sc) { PrimitiveStatement statement = sc.getStatement(); if (statement != null) { if (statement.getProperty() != null) { queryStack.peek().add(buildSimpleQuery(sc.getConditionType(), statement.getProperty(), statement.getValue())); } } else { queryStack.push(new ArrayList<>()); for (SearchCondition<T> condition : sc.getSearchConditions()) { condition.accept(this); } boolean orCondition = sc.getConditionType() == ConditionType.OR; List<Filter> queries = queryStack.pop(); queryStack.peek().add(createCompositeQuery(queries, orCondition)); } }
public boolean isMet(T pojo) { for (SearchCondition<T> sc : conditions) { if (!sc.isMet(pojo)) { return false; } } return true; }
private List<LogRecord> filterRecords(List<LogRecord> list, SearchCondition<LogRecord> theSearch) { return theSearch == null ? list : theSearch.findAll(list); }
public void visit(SearchCondition<T> sc) { if (builder == null) { builder = em.getCriteriaBuilder(); cq = builder.createQuery(queryClass); root = cq.from(tClass); predStack.push(new ArrayList<>()); } if (sc.getStatement() != null) { predStack.peek().add(buildPredicate(sc.getStatement())); } else { predStack.push(new ArrayList<>()); for (SearchCondition<T> condition : sc.getSearchConditions()) { condition.accept(this); } List<Predicate> predsList = predStack.pop(); Predicate[] preds = predsList.toArray(new Predicate[0]); Predicate newPred; if (sc instanceof OrSearchCondition) { newPred = builder.or(preds); } else { newPred = builder.and(preds); } predStack.peek().add(newPred); } }
public static <T> String toSQL(SearchCondition<T> sc, String table, String... columns) { SQLPrinterVisitor<T> visitor = new SQLPrinterVisitor<>(table, columns); sc.accept(visitor); return visitor.getQuery(); }
private static List<SearchClause> getCompoundSearchClauses(final SearchCondition<SearchBean> sc) { List<SearchClause> clauses = new ArrayList<>(); for (SearchCondition<SearchBean> searchCondition : sc.getSearchConditions()) { if (searchCondition.getStatement() == null) { clauses.addAll(getCompoundSearchClauses(searchCondition)); } else { SearchClause clause = getPrimitiveSearchClause(searchCondition); if (sc.getConditionType() == ConditionType.AND) { clause.setOperator(SearchClause.Operator.AND); } if (sc.getConditionType() == ConditionType.OR) { clause.setOperator(SearchClause.Operator.OR); } clauses.add(clause); } } return clauses; }
@Override public PrimitiveStatement getStatement() { if (scts.size() == 1) { return scts.get(0).getStatement(); } return null; }
@SuppressWarnings("ConvertToStringSwitch") private SearchCond visitPrimitive(final SearchCondition<SearchBean> sc) { String name = getRealPropertyName(sc.getStatement().getProperty()); Optional<SpecialAttr> specialAttrName = SpecialAttr.fromString(name); URLDecoder.decode(sc.getStatement().getValue().toString(), StandardCharsets.UTF_8), false). replaceAll("\\\\_", "_"); attributeCond.setExpression(value); ConditionType ct = sc.getConditionType(); if (sc instanceof SyncopeFiqlSearchCondition && sc.getConditionType() == ConditionType.CUSTOM) { SyncopeFiqlSearchCondition<SearchBean> sfsc = (SyncopeFiqlSearchCondition<SearchBean>) sc; if (SyncopeFiqlParser.IEQ.equals(sfsc.getOperator())) { attributeCond.setExpression(null); } else if (value.indexOf('%') == -1) { attributeCond.setType(sc.getConditionType() == ConditionType.CUSTOM ? AttributeCond.Type.IEQ : AttributeCond.Type.EQ); } else { attributeCond.setType(sc.getConditionType() == ConditionType.CUSTOM ? AttributeCond.Type.ILIKE : AttributeCond.Type.LIKE);
private static SearchClause getPrimitiveSearchClause(final SearchCondition<SearchBean> sc) { SearchClause clause = new SearchClause(); String property = sc.getCondition().getKeySet().iterator().next(); clause.setProperty(property); String value = sc.getCondition().get(property).replace("%252C", ",").replace("%253B", ";"); clause.setValue(value); LOG.debug("Condition: " + sc.getCondition()); ConditionType ct = sc.getConditionType(); if (sc instanceof SyncopeFiqlSearchCondition && sc.getConditionType() == ConditionType.CUSTOM) { SyncopeFiqlSearchCondition<SearchBean> sfsc = (SyncopeFiqlSearchCondition<SearchBean>) sc; if (SyncopeFiqlParser.IEQ.equals(sfsc.getOperator())) {
public void visit(SearchCondition<T> sc) { if (builder == null) { builder = em.getCriteriaBuilder(); cq = builder.createQuery(queryClass); root = cq.from(tClass); predStack.push(new ArrayList<>()); } if (sc.getStatement() != null) { predStack.peek().add(buildPredicate(sc.getStatement())); } else { predStack.push(new ArrayList<>()); for (SearchCondition<T> condition : sc.getSearchConditions()) { condition.accept(this); } List<Predicate> predsList = predStack.pop(); Predicate[] preds = predsList.toArray(new Predicate[0]); Predicate newPred; if (sc instanceof OrSearchCondition) { newPred = builder.or(preds); } else { newPred = builder.and(preds); } predStack.peek().add(newPred); } }
public static <T> String toSQL(SearchCondition<T> sc, String table, String... columns) { SQLPrinterVisitor<T> visitor = new SQLPrinterVisitor<>(table, columns); sc.accept(visitor); return visitor.getQuery(); }
private SearchCond visitCompount(final SearchCondition<SearchBean> sc) { List<SearchCond> searchConds = new ArrayList<>(); sc.getSearchConditions().forEach(searchCondition -> { searchConds.add(searchCondition.getStatement() == null ? visitCompount(searchCondition) : visitPrimitive(searchCondition)); }); SearchCond compound; switch (sc.getConditionType()) { case AND: compound = SearchCond.getAndCond(searchConds); break; case OR: compound = SearchCond.getOrCond(searchConds); break; default: throw new IllegalArgumentException( String.format("Condition type %s is not supported", sc.getConditionType().name())); } return compound; }
public PrimitiveStatement getStatement() { if (scts.size() == 1) { return scts.get(0).getStatement(); } else { return null; } }
public void visit(SearchCondition<T> sc) { PrimitiveStatement statement = sc.getStatement(); if (statement != null) { if (statement.getProperty() != null) { queryStack.peek().add(buildSimpleQuery(sc.getConditionType(), statement.getProperty(), statement.getValue())); } } else { queryStack.push(new ArrayList<Query>()); for (SearchCondition<T> condition : sc.getSearchConditions()) { condition.accept(this); } boolean orCondition = sc.getConditionType() == ConditionType.OR; List<Query> queries = queryStack.pop(); queryStack.peek().add(createCompositeQuery(queries, orCondition)); } }
public void visit(SearchCondition<T> sc) { if (builder == null) { builder = em.getCriteriaBuilder(); cq = builder.createQuery(queryClass); root = cq.from(tClass); predStack.push(new ArrayList<Predicate>()); } if (sc.getStatement() != null) { predStack.peek().add(buildPredicate(sc.getStatement())); } else { predStack.push(new ArrayList<Predicate>()); for (SearchCondition<T> condition : sc.getSearchConditions()) { condition.accept(this); } List<Predicate> predsList = predStack.pop(); Predicate[] preds = predsList.toArray(new Predicate[predsList.size()]); Predicate newPred; if (sc instanceof OrSearchCondition) { newPred = builder.or(preds); } else { newPred = builder.and(preds); } predStack.peek().add(newPred); } }
public static <T> String toSQL(SearchCondition<T> sc, String table, String... columns) { SQLPrinterVisitor<T> visitor = new SQLPrinterVisitor<T>(table, columns); sc.accept(visitor); return visitor.getQuery(); }
@Override public PrimitiveStatement getStatement() { if (scts.size() == 1) { return scts.get(0).getStatement(); } return null; }
public boolean isMet(T pojo) { for (SearchCondition<T> sc : conditions) { if (!sc.isMet(pojo)) { return false; } } return true; }
@GET @Path("/books/{search}/chapter/{chapter}") @Produces("application/xml") public Chapter getChapterFromSelectedBook(@Context SearchContext searchContext, @PathParam("search") String expression, @PathParam("chapter") int chapter) { SearchCondition<Book> sc = searchContext.getCondition(expression, Book.class); if (sc == null) { throw new WebApplicationException(404); } List<Book> found = sc.findAll(books.values()); if (found.size() != 1) { throw new WebApplicationException(404); } Book selectedBook = found.get(0); return selectedBook.getChapter(chapter); }
public void visit(SearchCondition<T> sc) { PrimitiveStatement statement = sc.getStatement(); if (statement != null) { if (statement.getProperty() != null) { queryStack.peek().add(buildSimpleQuery(sc.getConditionType(), statement.getProperty(), statement.getValue())); } } else { queryStack.push(new ArrayList<>()); for (SearchCondition<T> condition : sc.getSearchConditions()) { condition.accept(this); } boolean orCondition = sc.getConditionType() == ConditionType.OR; List<Filter> queries = queryStack.pop(); queryStack.peek().add(createCompositeQuery(queries, orCondition)); } }