Search in sources :

Example 76 with TMLExpressionException

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

the class CallService method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    Operand result = null;
    String serviceName = getStringOperand(0);
    String expression = getOperands().size() == 1 ? null : getStringOperand(1);
    if (getNavajo() == null) {
        throw new TMLExpressionException("No Navajo Request object available.");
    }
    if (getOperands().size() > 2) {
        throw new TMLExpressionException("Invalid number of parameters.");
    }
    try {
        Navajo response = getNavajo().getNavajo(serviceName);
        if (response == null) {
            DispatcherInterface dispatcher = DispatcherFactory.getInstance();
            Navajo input = getNavajo().copy();
            input.getHeader().setRPCName(serviceName);
            response = dispatcher.handle(input, this.getAccess().getTenant(), true);
            getNavajo().addNavajo(serviceName, response);
        }
        if (expression == null) {
            Binary bbb = new Binary();
            OutputStream os = bbb.getOutputStream();
            response.write(os);
            os.flush();
            os.close();
            return bbb;
        } else {
            result = Expression.evaluate(expression, response);
        }
    } catch (Exception ex) {
        logger.error("Error: ", ex);
    }
    if (result != null) {
        return result.value;
    } else {
        return null;
    }
}
Also used : DispatcherInterface(com.dexels.navajo.server.DispatcherInterface) Operand(com.dexels.navajo.document.Operand) OutputStream(java.io.OutputStream) Navajo(com.dexels.navajo.document.Navajo) Binary(com.dexels.navajo.document.types.Binary) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 77 with TMLExpressionException

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

the class Base64Encode method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    Object o = operand(0).value;
    String data = null;
    if (o instanceof Binary) {
        Binary b = (Binary) o;
        data = Base64.getEncoder().encodeToString(b.getData());
    } else if (o instanceof String) {
        data = Base64.getEncoder().encodeToString(((String) o).getBytes(StandardCharsets.UTF_8));
    } else if (o instanceof Property && ((Property) o).getType() == Property.BINARY_PROPERTY) {
        data = ((Property) o).getValue();
    } else {
        throw new TMLExpressionException("Can not Base64Encode null data");
    }
    return data;
}
Also used : Binary(com.dexels.navajo.document.types.Binary) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Property(com.dexels.navajo.document.Property)

Example 78 with TMLExpressionException

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

the class GetSelectedName method evaluate.

@Override
@SuppressWarnings("unchecked")
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    if (getOperands().size() != 1) {
        throw new TMLExpressionException(this, "Invalid function call, need one parameter");
    }
    Object o = operand(0).value;
    if (o == null) {
        throw new TMLExpressionException(this, "Invalid function call in GetSelectedName: Parameter null");
    }
    if (o instanceof Property) {
        Property p = (Property) o;
        if (p.getSelected() != null) {
            return (p.getAllSelectedSelections().size() > 0 ? p.getSelected().getName() : null);
        } else {
            return null;
        }
    }
    if (!(o instanceof List)) {
        throw new TMLExpressionException(this, "Invalid function call in GetSelectedName: Not a selection property, but (" + o.getClass() + ")");
    }
    List<Selection> l = (List<Selection>) o;
    for (Selection selection : l) {
        if (selection.isSelected()) {
            return selection.getName();
        }
    }
    return null;
}
Also used : Selection(com.dexels.navajo.document.Selection) List(java.util.List) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Property(com.dexels.navajo.document.Property)

Example 79 with TMLExpressionException

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

the class GetUrlModificationTime method evaluate.

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

Example 80 with TMLExpressionException

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

the class GetValue method evaluate.

@Override
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    if (getOperands().size() != 1) {
        throw new TMLExpressionException(this, "Invalid function call, need one parameter");
    }
    Object o = getOperand(0);
    if (o == null) {
        throw new TMLExpressionException(this, "Invalid function call in GetSelectedValue: Parameter null");
    }
    if (!(o instanceof Property)) {
        throw new TMLExpressionException(this, "Invalid function call in GetValue: Not a  property, this is a: " + o.getClass() + " and it goes like this:  " + o);
    }
    Property p = (Property) o;
    return p.getTypedValue();
}
Also used : TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Property(com.dexels.navajo.document.Property)

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