19 package org.turro.indicator;
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.stream.Collectors;
24 import java.util.stream.Stream;
25 import org.turro.elephant.db.SQLHelper;
26 import org.turro.elephant.db.WhereClause;
27 import org.turro.entities.Entities;
28 import org.turro.jpa.Dao;
29 import org.turro.matching.GenericSiblings;
30 import org.turro.matching.ProcessMatching;
31 import org.turro.ranking.ProcessRanking;
39 protected List<IndicatorVariable>
variables =
new ArrayList<>();
40 protected String
root, relatedRoot;
88 if(variable !=
null)
variables.add(variable);
93 return variables.stream().filter(v ->
root.equals(v.getRoot())).collect(Collectors.toList());
103 return getVariables().stream().filter(v -> name.equals(v.getName())).findAny().get();
108 return variables.stream().filter(v -> v.permits(
root) && v.getType().isRanking()).collect(Collectors.toList());
113 return variables.stream().filter(v -> v.permits(
root) && v.getType().isMatching()).collect(Collectors.toList());
128 String v[] = indicator.split(
"\\s*\\.\\s*");
132 wc.
addClause(
"select new org.turro.indicator.IndicatorResult(sum(ranking), count(ranking))");
134 wc.
addClause(
"select new org.turro.indicator.IndicatorResult(sum(matching), count(matching))");
137 wc.
addClause(
"where entityPath like :entityPath");
140 wc.
addClause(
"and relatedPath like :relatedPath");
141 wc.
addNamedValue(
"relatedPath", convertPathToLike(v[index++], relatedRoot));
143 wc.
addClause(
"and concept like :indicator");
144 wc.
addNamedValue(
"indicator", convertIndicatorToLike(v[index]));
177 private String convertPathToLike(String value, String
root) {
178 if(value.matches(
"\\/[a-z\\-\\*\\?]+\\/[0-9a-zA-Z\\*\\?]+")) {
181 return "/" +
root +
"/" + SQLHelper.convertToLike(value);
185 private String convertIndicatorToLike(String value) {
186 if(
"final".equals(value)) {
189 return SQLHelper.convertToLike(value);
216 throw new UnsupportedOperationException(
"Not supported yet.");
221 throw new UnsupportedOperationException(
"Not supported yet.");
241 return this.root.equals(
root);
static String convertToLike(String value)
void addClause(String clause)
void addNamedValue(String name, Object value)
static IElephantEntity getController(String path)
void preprocess(IndicatorVariable variable, IPreprocessor preprocessor, String entityRoot, String relatedRoot)
String getPath(Object entity)
boolean itsMine(IndicatorVariable variable)
void addVariable(String name, VariableType type)
Stream< GenericSiblings > getSiblingPaths(String entityPath)
List< IndicatorVariable > getAllMatchingVariables(String root)
List< IndicatorVariable > getVariables()
void addVariable(String name, VariableType type, String avoid)
void postprocess(IndicatorVariable variable, IPreprocessor postprocessor, String entityRoot, String relatedRoot)
abstract void processMatchingVariable(Dao dao, IPreprocessor preprocessor, IndicatorVariable variable, String entityRoot, String relatedRoot)
Stream< String > getEntityPaths(String root)
IndicatorResult readIndicator(String storeClass, String indicator)
void addVariable(String name, boolean preprocess, VariableType type, String avoid)
abstract void processRankingVariable(Dao dao, IPreprocessor preprocessor, IndicatorVariable variable, String entityRoot)
void postprocessRankingVariable(Dao dao, IPreprocessor postprocessor, IndicatorVariable variable, String entityRoot)
abstract void initExternalVariables()
double getValue(IndicatorVariable variable, Object entity)
void addVariable(String name, boolean preprocess, VariableType type)
void addVariable(String name, boolean preprocess, VariableType type, boolean reversed)
List< IndicatorVariable > getAllVariables()
boolean itsMine(String root)
void postprocessMatchingVariable(Dao dao, IPreprocessor postprocessor, IndicatorVariable variable, String entityRoot, String relatedRoot)
List< IndicatorVariable > getAllRankingVariables(String root)
List< IndicatorVariable > variables
double getValue(IndicatorVariable variable, Object entity, String relatedPath)
IndicatorVariable getVariable(String name)
void addExternalVariable(String root, String name)
abstract void initVariables()
void addVariable(String name, VariableType type, boolean reversed)
static IElephantIndicator getIndicator(String root)
static IndicatorVariable getVariable(String root, String name)
Object getSingleResultOrNull(SqlClause sc)
void preprocess(IndicatorVariable variable, IPreprocessor preprocessor, String entityRoot, String relatedRoot)