Search in sources :

Example 11 with Operand

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);
}
Also used : Percentage(com.dexels.navajo.document.types.Percentage) Operand(com.dexels.navajo.document.Operand)

Example 12 with Operand

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;
}
Also used : AdapterFieldDependency(com.dexels.navajo.mapping.compiler.meta.AdapterFieldDependency) Operand(com.dexels.navajo.document.Operand) ExtendDependency(com.dexels.navajo.mapping.compiler.meta.ExtendDependency) AdapterFieldDependency(com.dexels.navajo.mapping.compiler.meta.AdapterFieldDependency) IncludeDependency(com.dexels.navajo.mapping.compiler.meta.IncludeDependency) Dependency(com.dexels.navajo.script.api.Dependency) HashSet(java.util.HashSet)

Example 13 with Operand

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);
    }
}
Also used : Operand(com.dexels.navajo.document.Operand) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 14 with Operand

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;
}
Also used : ReactiveTransformerFactory(com.dexels.navajo.reactive.api.ReactiveTransformerFactory) ReactiveParseProblem(com.dexels.navajo.document.stream.ReactiveParseProblem) ReactiveParameters(com.dexels.navajo.reactive.api.ReactiveParameters) Operand(com.dexels.navajo.document.Operand) ArrayList(java.util.ArrayList) ReactiveSourceFactory(com.dexels.navajo.reactive.api.ReactiveSourceFactory) ReactiveMerger(com.dexels.navajo.reactive.api.ReactiveMerger)

Example 15 with Operand

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;
        }
    };
}
Also used : MappableTreeNode(com.dexels.navajo.script.api.MappableTreeNode) TipiLink(com.dexels.navajo.expression.api.TipiLink) Message(com.dexels.navajo.document.Message) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Optional(java.util.Optional) Selection(com.dexels.navajo.document.Selection) Operand(com.dexels.navajo.document.Operand) ContextExpression(com.dexels.navajo.expression.api.ContextExpression) Access(com.dexels.navajo.script.api.Access) Navajo(com.dexels.navajo.document.Navajo)

Aggregations

Operand (com.dexels.navajo.document.Operand)95 Test (org.junit.Test)57 Message (com.dexels.navajo.document.Message)22 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)20 Navajo (com.dexels.navajo.document.Navajo)20 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)15 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)14 ArrayList (java.util.ArrayList)12 Selection (com.dexels.navajo.document.Selection)11 Property (com.dexels.navajo.document.Property)10 FunctionInterface (com.dexels.navajo.expression.api.FunctionInterface)10 Access (com.dexels.navajo.script.api.Access)10 MappableTreeNode (com.dexels.navajo.script.api.MappableTreeNode)10 NavajoException (com.dexels.navajo.document.NavajoException)9 TipiLink (com.dexels.navajo.expression.api.TipiLink)9 Optional (java.util.Optional)9 FunctionDefinition (com.dexels.navajo.expression.api.FunctionDefinition)8 GiveLongTestFunction (com.dexels.navajo.expression.compiled.GiveLongTestFunction)6 SystemException (com.dexels.navajo.script.api.SystemException)6 List (java.util.List)6