Search in sources :

Example 16 with TMLExpressionException

use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.

the class DecryptString method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    String result = null;
    String key = (String) getOperand(0);
    String message = (String) getOperand(1);
    try {
        Security s = new Security(key);
        result = s.decrypt(message);
    } catch (Exception e) {
        throw new TMLExpressionException(e.getMessage(), e);
    }
    return result;
}
Also used : Security(com.dexels.navajo.functions.security.Security) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 17 with TMLExpressionException

use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.

the class Exists method evaluate.

@Override
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    /**
     *@todo Implement this com.dexels.navajo.parser.FunctionInterface abstract method
     */
    Message arrayMessage = null;
    String messagePath = null;
    if (getOperand(0) instanceof Message) {
        arrayMessage = (Message) getOperand(0);
    } else {
        messagePath = (String) getOperand(0);
    }
    String expression = (String) getOperand(1);
    String filter = null;
    if (getOperands().size() > 2) {
        filter = (String) getOperand(2);
    }
    Message parent = getCurrentMessage();
    Navajo doc = getNavajo();
    // try {
    try {
        List<Message> arrayMsg = null;
        if (arrayMessage != null) {
            arrayMsg = arrayMessage.getAllMessages();
        } else {
            arrayMsg = (parent != null ? parent.getMessages(messagePath) : doc.getMessages(messagePath));
        }
        if (arrayMsg == null) {
            throw new TMLExpressionException(this, "Empty or non existing array message: " + messagePath);
        }
        for (int i = 0; i < arrayMsg.size(); i++) {
            Message current = arrayMsg.get(i);
            try {
                boolean evaluate = (filter != null ? Condition.evaluate(filter, doc, null, current, getAccess()) : true);
                if (evaluate) {
                    Operand result = Expression.evaluate(expression, doc, null, current);
                    if (result == null) {
                        throw new TMLExpressionException(this, "Error evaluating expression: " + expression + " in message: " + current.getFullMessageName());
                    }
                    if (result.value == null) {
                        throw new TMLExpressionException(this, "Error evaluating expression: " + expression + " in message: " + current.getFullMessageName());
                    }
                    String res2 = "" + result.value;
                    Operand result2 = Expression.evaluate(res2, doc, null, current);
                    if (result2 == null) {
                        throw new TMLExpressionException(this, "Error evaluating expression: " + res2 + " in message: " + current.getFullMessageName());
                    }
                    if (result2.value == null) {
                        throw new TMLExpressionException(this, "Error evaluating expression: " + res2 + " in message: " + current.getFullMessageName());
                    }
                    boolean res = ((Boolean) result2.value).booleanValue();
                    if (res) {
                        return Boolean.TRUE;
                    }
                }
            } catch (SystemException ex) {
                logger.error("Error: ", ex);
            }
        }
    } catch (NavajoException ex) {
        throw new TMLExpressionException(this, "Error evaluating message path");
    }
    return Boolean.FALSE;
}
Also used : Message(com.dexels.navajo.document.Message) SystemException(com.dexels.navajo.script.api.SystemException) Operand(com.dexels.navajo.document.Operand) NavajoException(com.dexels.navajo.document.NavajoException) Navajo(com.dexels.navajo.document.Navajo) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 18 with TMLExpressionException

use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.

the class ExistsSelectionValue method evaluate.

@Override
@SuppressWarnings("unchecked")
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    if (getOperands().size() != 2) {
        throw new TMLExpressionException(this, "Invalid function call, need two parameters");
    }
    Object o = getOperand(0);
    if (o == null) {
        throw new TMLExpressionException(this, "Invalid function call in ExistsSelectionValue: First parameter null");
    }
    Object v = getOperand(1);
    if (v == null) {
        throw new TMLExpressionException(this, "Invalid function call in ExistsSelectionValue: Second parameter null");
    }
    if (!(v instanceof String)) {
        throw new TMLExpressionException(this, "Invalid function call in ExistsSelectionValue: Second parameter not a string");
    }
    if (o instanceof Property) {
        Property p = (Property) o;
        try {
            Selection s = p.getSelectionByValue((String) v);
            return !s.getValue().equals(Selection.DUMMY_ELEMENT);
        } catch (NavajoException ne) {
            throw new TMLExpressionException(this, "Invalid function call in ExistsSelectionValue: First parameter not a selection property");
        }
    }
    if (!(o instanceof List)) {
        throw new TMLExpressionException(this, "Invalid function call in ExistsSelectionValue: First parameter not a selection property");
    }
    List<Selection> l = (List<Selection>) o;
    for (Selection selection : l) {
        if (v.equals(selection.getValue())) {
            return true;
        }
    }
    return false;
}
Also used : Selection(com.dexels.navajo.document.Selection) NavajoException(com.dexels.navajo.document.NavajoException) List(java.util.List) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Property(com.dexels.navajo.document.Property)

Example 19 with TMLExpressionException

use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.

the class GetSelectedValues method evaluate.

@Override
@SuppressWarnings("unchecked")
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    if (getOperands().size() > 2) {
        throw new TMLExpressionException(this, "Invalid function call, need one or two parameters");
    }
    Object o = operand(0).value;
    if (o == null) {
        throw new TMLExpressionException(this, "Invalid function call in GetSelectedValues: Parameter null");
    }
    boolean outputAsStringList = false;
    if (getOperands().size() > 1) {
        outputAsStringList = getBooleanOperand(1);
    }
    List<Object> values = new ArrayList<Object>();
    if (o instanceof Property) {
        Property p = (Property) o;
        if (p.getSelected() != null) {
            if (p.getAllSelectedSelections().size() > 0) {
                values.add(p.getAllSelectedSelections());
            }
        }
    } else if (o instanceof String) {
        values.add(o);
    } else {
        if (!(o instanceof List)) {
            throw new TMLExpressionException(this, "Invalid function call in GetSelectedValues: Not a selection property");
        }
        if (((List<Object>) o).size() != 0) {
            List<Object> l = (List<Object>) o;
            if (outputAsStringList) {
                for (Object selection : l) {
                    values.add(selection.toString());
                }
            } else {
                values.add(l);
            }
        }
    }
    // Outputtype...
    if (outputAsStringList && values.size() != 0) {
        String output = "";
        for (Object item : values) {
            output += item.toString() + ";";
        }
        return output;
    } else {
        return values;
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Property(com.dexels.navajo.document.Property)

Example 20 with TMLExpressionException

use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.

the class GetUrlTime method evaluate.

@Override
public final Object evaluate() throws TMLExpressionException {
    // input (ArrayList, Object).
    if (this.getOperands().size() != 1)
        throw new TMLExpressionException("GetUrlTime(String) expected");
    Object a = this.getOperands().get(0);
    if (a == null) {
        return null;
    }
    if (!(a instanceof String))
        throw new TMLExpressionException("GetUrlTime(String) expected");
    URL u;
    try {
        u = new URL((String) a);
    } catch (MalformedURLException e) {
        throw new TMLExpressionException("CheckUrl: bad url: " + a);
    }
    return getUrlTime(u);
}
Also used : MalformedURLException(java.net.MalformedURLException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) URL(java.net.URL)

Aggregations

TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)129 Message (com.dexels.navajo.document.Message)26 Navajo (com.dexels.navajo.document.Navajo)26 Binary (com.dexels.navajo.document.types.Binary)23 Property (com.dexels.navajo.document.Property)17 ArrayList (java.util.ArrayList)16 Operand (com.dexels.navajo.document.Operand)15 List (java.util.List)13 NavajoException (com.dexels.navajo.document.NavajoException)12 IOException (java.io.IOException)12 Selection (com.dexels.navajo.document.Selection)11 Access (com.dexels.navajo.script.api.Access)10 Calendar (java.util.Calendar)10 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)9 Test (org.junit.Test)9 Money (com.dexels.navajo.document.types.Money)8 SystemException (com.dexels.navajo.script.api.SystemException)8 StringTokenizer (java.util.StringTokenizer)8 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)7 ClockTime (com.dexels.navajo.document.types.ClockTime)7