Search in sources :

Example 31 with Selection

use of com.dexels.navajo.document.Selection 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)

Example 32 with Selection

use of com.dexels.navajo.document.Selection in project navajo by Dexels.

the class BasePropertyImpl method isEqual.

@Override
public final boolean isEqual(Property p) {
    if (!getName().equals(p.getName())) {
        return false;
    }
    if ((this.getType() != null && p.getType() != null) && !this.getType().equals(p.getType())) {
        return false;
    }
    // Check for date properties.
    if (p.getType().equals(Property.DATE_PROPERTY)) {
        // If both values are null they're equal.
        if (p.getTypedValue() == null && this.getTypedValue() == null) {
            return true;
        }
        // If only one of them is null they're not equal.
        if (p.getTypedValue() == null || this.getTypedValue() == null) {
            return false;
        }
        java.util.Date myDate = (java.util.Date) getTypedValue();
        java.util.Date otherDate = (java.util.Date) p.getTypedValue();
        return dateFormat2.get().format(myDate).equals(dateFormat2.get().format(otherDate));
    } else // Check for selection properties.
    if (p.getType().equals(Property.SELECTION_PROPERTY)) {
        try {
            List<Selection> l = p.getAllSelectedSelections();
            List<Selection> me = this.getAllSelectedSelections();
            // equal.
            if (me.size() != l.size()) {
                return false;
            }
            for (int j = 0; j < l.size(); j++) {
                Selection other = l.get(j);
                boolean match = false;
                for (int k = 0; k < me.size(); k++) {
                    Selection mysel = me.get(k);
                    if (mysel.getValue().equals(other.getValue())) {
                        match = true;
                        k = me.size() + 1;
                    }
                }
                if (!match) {
                    return false;
                }
            }
            return true;
        } catch (Exception e) {
            logger.warn("Error: ", e);
            return false;
        }
    } else if (p.getType().equals(Property.BINARY_PROPERTY)) {
        // If both values are null they're equal.
        if (p.getTypedValue() == null && this.getTypedValue() == null) {
            return true;
        }
        // If only one of them is null they're not equal.
        if (p.getTypedValue() == null || this.getTypedValue() == null) {
            return false;
        }
        return ((Binary) this.getTypedValue()).isEqual((Binary) p.getTypedValue());
    } else // Else I am some other property.
    {
        // If both values are null they're equal.
        if (p.getValue() == null && this.getValue() == null) {
            return true;
        }
        // If only one of them is null they're not equal.
        if (p.getValue() == null || this.getValue() == null) {
            return false;
        }
        return p.getValue().equals(this.getValue());
    }
}
Also used : Date(java.util.Date) Selection(com.dexels.navajo.document.Selection) ArrayList(java.util.ArrayList) List(java.util.List) Binary(com.dexels.navajo.document.types.Binary) Date(java.util.Date) PropertyTypeException(com.dexels.navajo.document.PropertyTypeException) NavajoException(com.dexels.navajo.document.NavajoException) ParseException(java.text.ParseException) ExpressionChangedException(com.dexels.navajo.document.ExpressionChangedException) IOException(java.io.IOException)

Example 33 with Selection

use of com.dexels.navajo.document.Selection in project navajo by Dexels.

the class BasePropertyImpl method setSelected.

@Override
public final void setSelected(String value) {
    if (!"+".equals(getCardinality())) {
        ArrayList<Selection> al = getAllSelections();
        for (int i = 0; i < al.size(); i++) {
            BaseSelectionImpl s = (BaseSelectionImpl) al.get(i);
            s.setSelected(false);
        }
    }
    String oldSel = null;
    Selection sel = getSelected();
    if (sel != null) {
        oldSel = sel.getValue();
    }
    Selection s = getSelectionByValue(value);
    firePropertyChanged("selection", oldSel, value);
    s.setSelected(true);
}
Also used : Selection(com.dexels.navajo.document.Selection)

Example 34 with Selection

use of com.dexels.navajo.document.Selection in project navajo by Dexels.

the class BasePropertyImpl method setSelected.

@Override
public void setSelected(String[] s) {
    if (!getType().equals(SELECTION_PROPERTY)) {
        throw NavajoFactory.getInstance().createNavajoException("Setting selected of non-selection property!");
    }
    setAllSelected(false);
    for (int i = 0; i < s.length; i++) {
        Selection st = getSelectionByValue(s[i]);
        st.setSelected(true);
    }
}
Also used : Selection(com.dexels.navajo.document.Selection)

Example 35 with Selection

use of com.dexels.navajo.document.Selection in project navajo by Dexels.

the class BasePropertyImpl method updateExpressionSelections.

private void updateExpressionSelections(List<Selection> list) {
    removeAllSelections();
    for (int i = 0; i < list.size(); i++) {
        Selection s = list.get(i);
        Selection copy = NavajoFactory.getInstance().createSelection(getRootDoc(), s.getName(), s.getValue(), false);
        addSelection(copy);
    }
}
Also used : Selection(com.dexels.navajo.document.Selection)

Aggregations

Selection (com.dexels.navajo.document.Selection)78 Property (com.dexels.navajo.document.Property)36 Test (org.junit.Test)32 Message (com.dexels.navajo.document.Message)24 Navajo (com.dexels.navajo.document.Navajo)21 Access (com.dexels.navajo.script.api.Access)14 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)13 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)12 TipiLink (com.dexels.navajo.expression.api.TipiLink)12 MappableTreeNode (com.dexels.navajo.script.api.MappableTreeNode)12 ArrayList (java.util.ArrayList)12 Optional (java.util.Optional)12 Operand (com.dexels.navajo.document.Operand)11 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)11 List (java.util.List)8 NavajoException (com.dexels.navajo.document.NavajoException)6 UserException (com.dexels.navajo.script.api.UserException)4 Binary (com.dexels.navajo.document.types.Binary)3 FunctionClassification (com.dexels.navajo.expression.api.FunctionClassification)3 StringTokenizer (java.util.StringTokenizer)3