Search in sources :

Example 11 with TMLExpressionException

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

the class Switch method testWithNotEnoughParameters.

@Test
public void testWithNotEnoughParameters() throws Exception {
    FunctionInterface fi = fff.getInstance(cl, "Switch");
    fi.reset();
    Navajo n = createTestNavajo();
    fi.setInMessage(n);
    fi.insertOperand(Expression.evaluate("[/Single/Vuur]", n));
    fi.insertIntegerOperand(20);
    fi.insertIntegerOperand(-20);
    try {
        Object result = fi.evaluate();
    } catch (TMLExpressionException tmle) {
        assertTrue(tmle.getMessage().indexOf("Not enough") != -1);
    }
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) Navajo(com.dexels.navajo.document.Navajo) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Test(org.junit.Test)

Example 12 with TMLExpressionException

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

the class Switch method testWithOnlyPropertyParameter.

@Test
public void testWithOnlyPropertyParameter() throws Exception {
    FunctionInterface fi = fff.getInstance(cl, "Switch");
    fi.reset();
    Navajo n = createTestNavajo();
    fi.setInMessage(n);
    fi.insertOperand(Expression.evaluate("[/Single/Vuur]", n));
    try {
        Object result = fi.evaluate();
    } catch (TMLExpressionException tmle) {
        assertTrue(tmle.getMessage().indexOf("Not enough") != -1);
    }
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) Navajo(com.dexels.navajo.document.Navajo) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Test(org.junit.Test)

Example 13 with TMLExpressionException

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

the class Zip method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    if (getOperands().size() != 2) {
        return new TMLExpressionException(this, "Wrong number of arguments");
    }
    if (!(getOperand(0) instanceof Binary)) {
        return new TMLExpressionException(this, "Binary content expected");
    }
    if (!(getOperand(1) instanceof String)) {
        return new TMLExpressionException(this, "String expected");
    }
    Binary i = (Binary) getOperand(0);
    String f = (String) getOperand(1);
    File tempFile = null;
    try {
        tempFile = File.createTempFile("zip_function", "navajo");
        System.err.println("Created tempfile: " + tempFile.getAbsolutePath());
        FileOutputStream fos = new FileOutputStream(tempFile);
        // ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ZipOutputStream zo = new ZipOutputStream(fos);
        ZipEntry entry = new ZipEntry(f);
        zo.putNextEntry(entry);
        // zo.write( i.getData() );
        i.write(zo, false);
        fos.flush();
        zo.closeEntry();
        zo.close();
        // byte [] result = baos.toByteArray();
        fos.close();
        Binary b = new Binary(tempFile, false);
        return b;
    } catch (Exception e) {
        throw new TMLExpressionException(this, e.getMessage(), e);
    } finally {
        if (tempFile != null) {
            tempFile.delete();
        }
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) Binary(com.dexels.navajo.document.types.Binary) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) File(java.io.File) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 14 with TMLExpressionException

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

the class TestCompiledExpression method parseIntAddition.

@Test
public void parseIntAddition() throws ParseException, TMLExpressionException {
    List<String> problems = new ArrayList<>();
    String expression = "1+1";
    ContextExpression ss = ExpressionCache.getInstance().parse(problems, expression, fn -> FunctionClassification.DEFAULT);
    ContextExpression ss2 = ExpressionCache.getInstance().parse(problems, expression, fn -> FunctionClassification.DEFAULT);
    if (!problems.isEmpty()) {
        throw new TMLExpressionException(problems, expression);
    }
    Assert.assertEquals(2, ss.apply().value);
    Assert.assertEquals(2, ss2.apply().value);
    Assert.assertTrue(ss.isLiteral());
    Assert.assertTrue(ss2.isLiteral());
}
Also used : ContextExpression(com.dexels.navajo.expression.api.ContextExpression) ArrayList(java.util.ArrayList) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Test(org.junit.Test)

Example 15 with TMLExpressionException

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

the class TestCompiledExpression method testParseTmlConditionalComplex.

@Test
@Ignore
public void testParseTmlConditionalComplex() throws ParseException, TMLExpressionException {
    String expression = "{request@.:!?[/NewMemberFunction/FromUnion]} AND {response@.:!?[/ExistingClubFunction/PersonId]}";
    StringReader sr = new StringReader(expression);
    CompiledParser cp = new CompiledParser(sr);
    cp.Expression();
    List<String> problems = new ArrayList<>();
    ContextExpression ss = cp.getJJTree().rootNode().interpretToLambda(problems, sr.toString(), fn -> FunctionClassification.DEFAULT, name -> Optional.empty());
    if (!problems.isEmpty()) {
        throw new TMLExpressionException(problems, expression);
    }
    ss.apply();
}
Also used : ContextExpression(com.dexels.navajo.expression.api.ContextExpression) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Ignore(org.junit.Ignore) Test(org.junit.Test)

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