use of com.dexels.navajo.document.Operand in project navajo by Dexels.
the class ToPercentage method main.
public static void main(String[] args) throws Exception {
java.util.Locale.setDefault(new java.util.Locale("nl", "NL"));
// Tests.
ToPercentage tm = new ToPercentage();
tm.reset();
tm.insertFloatOperand(Double.valueOf(1.5));
System.out.println("result = " + ((Percentage) tm.evaluate()).formattedString());
// Using expressions.
String expression = "ToPercentage(1024.50) + 500 - 5.7 + ToPercentage(1)/2";
Operand o = Expression.evaluate(expression, null);
System.out.println("o = " + o.value);
System.out.println("type = " + o.type);
}
use of com.dexels.navajo.document.Operand in project navajo by Dexels.
the class ScriptCompiler method processDependencies.
private Set<String> processDependencies(List<Dependency> dependencies) {
Set<String> dependentResources = new HashSet<>();
for (Dependency d : dependencies) {
if ("resource".equals(d.getType()) && (d instanceof AdapterFieldDependency)) {
final AdapterFieldDependency adapterFieldDep = (AdapterFieldDependency) d;
logger.info("ID: {}. It's an aadapter field. with multiple: {} type {}", adapterFieldDep.getId(), adapterFieldDep.hasMultipleDependencies(), adapterFieldDep.getClass());
Operand op = expressionEvaluator.evaluate(adapterFieldDep.getId(), null, Optional.empty(), Optional.empty());
if (op != null && op.value instanceof String) {
logger.debug("Succeeded evaluation of id: {}", ((String) op.value));
dependentResources.add((String) op.value);
}
logger.info("Resource dependency detected: {} type: {} dependency id: {}", d.getClass().getName(), d.getType(), d.getId());
Dependency[] subs = adapterFieldDep.getMultipleDependencies();
if (subs != null) {
for (Dependency dependency : subs) {
logger.info("Nested dependency detected: {}, type {}", dependency.getClass().getName(), dependency.getType());
}
}
}
}
return dependentResources;
}
use of com.dexels.navajo.document.Operand in project navajo by Dexels.
the class Parameters method store.
public void store(String name, String value, String type, String condition, Navajo doc) throws SystemException {
if (!this.isValueStored(name).equals(""))
return;
// First check condition.
boolean eval = false;
try {
if (condition.trim().equals(""))
eval = true;
else
eval = Condition.evaluate(condition, doc, null);
} catch (TMLExpressionException ce) {
eval = false;
}
// If condition succeeds evaluate parameter expression.
if (eval) {
Parameter p = new Parameter();
p.name = name;
try {
Operand op = Expression.evaluate(value, doc, null, null, null, null, null, null);
p.value = op.value;
} catch (TMLExpressionException tmle) {
// throw new SystemException(SystemException.PARSE_ERROR, "Invalid parameter expression: " + value + "\n"+tmle.getMessage());
}
p.type = type;
p.condition = condition;
super.put(name, p);
}
}
use of com.dexels.navajo.document.Operand in project navajo by Dexels.
the class ReactiveParseItem method materializeReactive.
private Operand materializeReactive() {
switch(type) {
case REACTIVE_SOURCE:
ReactiveSourceFactory sourceFactory = Reactive.finderInstance().getSourceFactory(name);
if (sourceFactory == null) {
throw new ReactiveParseException("No source found named: " + name);
}
return new Operand(sourceFactory.build(ReactiveParameters.of(sourceFactory, namedParams, unnamedParams)), Reactive.ReactiveItemType.REACTIVE_MAPPER.toString());
case REACTIVE_HEADER:
break;
case REACTIVE_MAPPER:
ReactiveMerger mergerFactory = Reactive.finderInstance().getMergerFactory(name);
ReactiveParameters mergeParameters = ReactiveParameters.of(mergerFactory, namedParams, unnamedParams);
return new Operand(mergerFactory.execute(mergeParameters), Reactive.ReactiveItemType.REACTIVE_MAPPER.toString());
case REACTIVE_TRANSFORMER:
ReactiveTransformerFactory transformerFactory = Reactive.finderInstance().getTransformerFactory(name);
List<ReactiveParseProblem> problems = new ArrayList<>();
ReactiveParameters transParameters = ReactiveParameters.of(transformerFactory, namedParams, unnamedParams);
// TODO problems?
return new Operand(transformerFactory.build(problems, transParameters), Reactive.ReactiveItemType.REACTIVE_MAPPER.toString());
default:
break;
}
// TODO rather throw something
return null;
}
use of com.dexels.navajo.document.Operand in project navajo by Dexels.
the class SimpleNode method lazyBiFunction.
public ContextExpression lazyBiFunction(List<String> problems, String expression, BinaryOperator<Operand> func, BiFunction<Optional<String>, Optional<String>, Boolean> acceptTypes, BiFunction<Optional<String>, Optional<String>, Optional<String>> returnTypeResolver, Function<String, FunctionClassification> functionClassifier, Function<String, Optional<Node>> mapResolver) {
ContextExpression expA = jjtGetChild(0).interpretToLambda(problems, expression, functionClassifier, mapResolver);
ContextExpression expB = jjtGetChild(1).interpretToLambda(problems, expression, functionClassifier, mapResolver);
Optional<String> aType = expA.returnType();
Optional<String> bType = expB.returnType();
boolean inputTypesValid = acceptTypes.apply(aType, bType);
if (!inputTypesValid) {
problems.add("Invalid input types in node: " + aType.orElse("unknown") + " and " + bType.orElse("unknown") + " in node type: " + this.getClass());
}
Optional<String> returnType = returnTypeResolver.apply(aType, bType);
return new ContextExpression() {
@Override
public Operand apply(Navajo doc, Message parentMsg, Message parentParamMsg, Selection parentSel, MappableTreeNode mapNode, TipiLink tipiLink, Access access, Optional<ImmutableMessage> immutableMessage, Optional<ImmutableMessage> paramMessage) {
Operand a = expA.apply(doc, parentMsg, parentParamMsg, parentSel, mapNode, tipiLink, access, immutableMessage, paramMessage);
Operand b = expB.apply(doc, parentMsg, parentParamMsg, parentSel, mapNode, tipiLink, access, immutableMessage, paramMessage);
return func.apply(a, b);
}
@Override
public boolean isLiteral() {
return expA.isLiteral() && expB.isLiteral();
}
@Override
public Optional<String> returnType() {
return returnType;
}
@Override
public String expression() {
return expression;
}
};
}
Aggregations