19 package org.turro.indicator;
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.List;
25 import org.turro.string.Strings;
26 import org.turro.elephant.db.WhereClause;
34 private String table, entityRoot, relatedRoot, pathField,
35 relatedField, aggregate, filterEntity;
36 private boolean matchingPath;
38 private final List<String> joins =
new ArrayList<>();
39 private final List<String> conditions =
new ArrayList<>();
40 private final Map<String, Object> namedValues =
new HashMap<>();
47 this.entityRoot = entityRoot;
52 this.relatedRoot = entityRoot;
57 this.pathField = pathField;
62 this.relatedField = pathField;
67 this.matchingPath =
true;
72 this.aggregate = aggregate;
77 this.filterEntity = filterEntity;
82 this.variable = variable;
92 conditions.add(condition);
97 namedValues.put(name, value);
102 if(Strings.isBlank(relatedRoot)) {
111 wc.
addClause(
"select new org.turro.ranking.GenericRanking(");
112 wc.
addClause(pathField +
", '" + variable.
getName() +
"', " + aggregate +
")");
114 for(String join : joins) {
117 if(!Strings.isBlank(filterEntity)) {
118 wc.
addClause(
"where " + pathField +
" like concat(:entity, '%')");
121 wc.
addClause(
"where " + pathField +
" like concat('/', :root, '/%')");
124 for(String condition : conditions) {
127 namedValues.keySet().forEach(k -> wc.
addNamedValue(k, namedValues.get(k)));
129 wc.
addClause(
"having " + aggregate +
" <> 0");
135 wc.
addClause(
"select new org.turro.matching.GenericMatching(");
136 String relatedConcat = matchingPath ? relatedField :
137 "concat('/" + relatedRoot +
"/'," + relatedField +
")";
138 wc.
addClause(pathField +
", " + relatedConcat +
", '" + variable.
getName() +
"', " + aggregate +
")");
140 for(String join : joins) {
143 if(!Strings.isBlank(filterEntity)) {
144 wc.
addClause(
"where " + pathField +
" like concat(:entity, '%')");
147 wc.
addClause(
"where " + pathField +
" like concat('/', :root, '/%')");
150 wc.
addClause(
"and " + relatedConcat +
" like concat('/', :rroot, '/%')");
152 for(String condition : conditions) {
155 namedValues.keySet().forEach(k -> wc.
addNamedValue(k, namedValues.get(k)));
156 wc.
addClause(
"group by " + pathField +
"," + relatedConcat);
157 wc.
addClause(
"having " + aggregate +
" <> 0");
void addClause(String clause)
void addNamedValue(String name, Object value)
PreprocessClause setMatchingField(String pathField)
PreprocessClause addCondition(String condition)
PreprocessClause setFilter(String filterEntity)
PreprocessClause setVariable(IndicatorVariable variable)
PreprocessClause setMatchingIsPath()
PreprocessClause addJoin(String join)
WhereClause getRankingClause()
PreprocessClause setMatchingRoot(String entityRoot)
PreprocessClause addNamedValue(String name, Object value)
PreprocessClause setAggregate(String aggregate)
PreprocessClause setRankingRoot(String entityRoot)
WhereClause getMatchingClause()
static PreprocessClause load(String table)
PreprocessClause setRankingField(String pathField)