use of org.apache.commons.jexl3.JexlExpression in project dbeaver by serge-rider.
the class DBVUtils method executeExpression.
public static Object executeExpression(DBVEntityAttribute attribute, DBDAttributeBinding[] allAttributes, Object[] row) {
String exprString = attribute.getExpression();
if (CommonUtils.isEmpty(exprString)) {
return null;
}
JexlExpression expression = attribute.getParsedExpression();
if (expression == null) {
return null;
}
return evaluateDataExpression(allAttributes, row, expression, attribute.getName());
}
use of org.apache.commons.jexl3.JexlExpression in project dbeaver by serge-rider.
the class DBVUtils method evaluateDataExpression.
public static Object evaluateDataExpression(DBDAttributeBinding[] allAttributes, Object[] row, JexlExpression expression, String attributeName) {
Map<String, Object> nsList = getExpressionNamespaces();
JexlContext context = new JexlContext() {
@Override
public Object get(String s) {
Object ns = nsList.get(s);
if (ns != null) {
return ns;
}
if (s.equals(attributeName)) {
return null;
}
for (DBDAttributeBinding attr : allAttributes) {
if (s.equals(attr.getLabel())) {
return DBUtils.getAttributeValue(attr, allAttributes, row);
}
}
return null;
}
@Override
public void set(String s, Object o) {
}
@Override
public boolean has(String s) {
return get(s) != null;
}
};
try {
return expression.evaluate(context);
} catch (Exception e) {
return GeneralUtils.getExpressionParseMessage(e);
}
}
use of org.apache.commons.jexl3.JexlExpression in project dbeaver by dbeaver.
the class DBVUtils method evaluateDataExpression.
public static Object evaluateDataExpression(DBDAttributeBinding[] allAttributes, Object[] row, JexlExpression expression, String attributeName) {
Map<String, Object> nsList = getExpressionNamespaces();
JexlContext context = new JexlContext() {
@Override
public Object get(String s) {
Object ns = nsList.get(s);
if (ns != null) {
return ns;
}
if (s.equals(attributeName)) {
return null;
}
for (DBDAttributeBinding attr : allAttributes) {
if (s.equals(attr.getLabel())) {
return DBUtils.getAttributeValue(attr, allAttributes, row);
}
}
return null;
}
@Override
public void set(String s, Object o) {
}
@Override
public boolean has(String s) {
return get(s) != null;
}
};
try {
return expression.evaluate(context);
} catch (Exception e) {
return GeneralUtils.getExpressionParseMessage(e);
}
}
use of org.apache.commons.jexl3.JexlExpression in project dbeaver by dbeaver.
the class DBVUtils method executeExpression.
public static Object executeExpression(DBVEntityAttribute attribute, DBDAttributeBinding[] allAttributes, Object[] row) {
String exprString = attribute.getExpression();
if (CommonUtils.isEmpty(exprString)) {
return null;
}
JexlExpression expression = attribute.getParsedExpression();
if (expression == null) {
return null;
}
return evaluateDataExpression(allAttributes, row, expression, attribute.getName());
}
use of org.apache.commons.jexl3.JexlExpression in project nifi by apache.
the class ExtractCCDAAttributes method processElement.
/**
* Process elements children based on the parser mapping.
* Any String values are added to attributes
* For List, the processList method is called to iterate and process
* For an Object this method is called recursively
* While adding to the attributes the key is prefixed by parent
* @param parent parent key for this element, used as a prefix for attribute key
* @param element element to be processed
* @param attributes map of attributes to populate
* @return map of processed data, value can contain String or Map of Strings
*/
protected Map<String, Object> processElement(String parent, Object element, Map<String, String> attributes) {
final StopWatch stopWatch = new StopWatch(true);
Map<String, Object> map = new LinkedHashMap<String, Object>();
String name = element.getClass().getName();
// get JEXL mappings for this element
Map<String, String> jexlMap = processMap.get(name);
if (jexlMap == null) {
getLogger().warn("Missing mapping for element " + name);
return null;
}
for (Entry<String, String> entry : jexlMap.entrySet()) {
// evaluate JEXL for each child element
jexlCtx.set("element", element);
JexlExpression jexlExpr = jexl.createExpression(entry.getValue());
Object value = jexlExpr.evaluate(jexlCtx);
String key = entry.getKey();
String prefix = parent != null ? parent + "." + key : key;
addElement(map, prefix, key, value, attributes);
}
stopWatch.stop();
getLogger().debug("Processed {} in {}", new Object[] { name, stopWatch.getDuration(TimeUnit.MILLISECONDS) });
return map;
}
Aggregations