Search in sources :

Example 21 with Navajo

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

the class StandardFunctionsTest method testGetInitials.

@Test
public void testGetInitials() {
    FunctionInterface fi = fff.getInstance(cl, "GetInitials");
    Navajo doc = createTestNavajo();
    fi.setInMessage(doc);
    fi.reset();
    fi.insertStringOperand("aap noot mies");
    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(String.class, o.getClass());
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) Navajo(com.dexels.navajo.document.Navajo) Test(org.junit.Test)

Example 22 with Navajo

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

the class StandardFunctionsTest method testSumExpressions.

@Test
public void testSumExpressions() {
    FunctionInterface fi = fff.getInstance(cl, "SumExpressions");
    Navajo doc = createTestNavajo();
    fi.setInMessage(doc);
    fi.reset();
    fi.insertStringOperand("Aap");
    fi.insertStringOperand("[Noot]+10");
    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(Integer.class, o.getClass());
    assertEquals("20", o.toString());
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) Navajo(com.dexels.navajo.document.Navajo) Test(org.junit.Test)

Example 23 with Navajo

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

the class SetValueCommand method execute.

@Override
public JsonNode execute(ArticleRuntime runtime, ArticleContext context, Map<String, String> parameters, XMLElement xmlElement) throws APIException {
    String service = parameters.get("service");
    if (service == null) {
        throw new APIException("Article problem in " + runtime.getArticleName() + ". setvalue requires a service, which is not supplied.", null, APIErrorCode.InternalError);
    }
    String element = parameters.get("element");
    if (element == null) {
        throw new APIException("Article problem in " + runtime.getArticleName() + ". setvalue requires a element, which is not supplied.", null, APIErrorCode.InternalError);
    }
    Navajo n = runtime.getNavajo(service);
    if (n == null) {
        throw new APIException("Article problem in " + runtime.getArticleName() + ". Requested service: " + service + " is not loaded.", null, APIErrorCode.InternalError);
    }
    Property p = n.getProperty(element);
    if (p == null) {
        throw new APIException("Article problem in " + runtime.getArticleName() + ". Requested element: " + element + " in service " + service + " is not found.", null, APIErrorCode.InternalError);
    }
    String value = parameters.get("value");
    if (value == null) {
        throw new APIException("Article problem in " + runtime.getArticleName() + ". setvalue requires a value, which is not supplied.", null, APIErrorCode.InternalError);
    }
    if (value.startsWith("@")) {
        String resolved = runtime.resolveArgument(value);
        if (resolved != null) {
            p.setValue(resolved);
        }
    } else if (value.startsWith("$")) {
        p.setAnyValue(runtime.resolveScope(value));
    } else {
        p.setValue(value);
    }
    return null;
}
Also used : APIException(com.dexels.navajo.article.APIException) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property)

Example 24 with Navajo

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

the class TableCommand method execute.

@Override
public JsonNode execute(ArticleRuntime runtime, ArticleContext context, Map<String, String> parameters, XMLElement element) throws APIException {
    String service = parameters.get("service");
    if (service == null) {
        throw new APIException("No service parameter supplied for table. We need to know which navajo you want to use.", null, APIErrorCode.InternalError);
    }
    Navajo navajo = runtime.getNavajo(service);
    if (navajo == null) {
        throw new APIException("Navajo: " + service + " was not found in the current runtime.", null, APIErrorCode.InternalError);
    }
    String path = parameters.get("path");
    if (path == null) {
        throw new APIException("No path parameter supplied. Which message do you want to listen to.", null, APIErrorCode.InternalError);
    }
    Message message = navajo.getMessage(path);
    if (message == null) {
        throw new APIException("Message: " + path + " not found", null, APIErrorCode.InternalError);
    }
    runtime.setMimeType("application/json; charset=utf-8");
    ArrayNode nodes = runtime.getObjectMapper().createArrayNode();
    for (Message data : message.getElements()) {
        ObjectNode node = runtime.getObjectMapper().createObjectNode();
        for (XMLElement XMLElement : element.getChildren()) {
            final String id = XMLElement.getStringAttribute("id");
            final String type = XMLElement.getStringAttribute("type");
            final String target = XMLElement.getStringAttribute("target");
            if (target != null) {
                // A target is a link, they do not have navajo value.
                node.put(id, resolveTarget(target, runtime, data));
            } else {
                // We default back to the id for the propertyName if not explicit set.
                final String propertyName = XMLElement.getStringAttribute("propertyName", id);
                Property property = data.getProperty(propertyName);
                APIValue.setValueOnNodeForType(node, id, type, property, runtime);
            }
        }
        nodes.add(node);
    }
    return nodes;
}
Also used : APIException(com.dexels.navajo.article.APIException) Message(com.dexels.navajo.document.Message) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Navajo(com.dexels.navajo.document.Navajo) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement) Property(com.dexels.navajo.document.Property)

Example 25 with Navajo

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

the class ITAsyncClient method testAsync.

@Test
@Ignore
public void testAsync() throws Exception {
    final ManualAsyncClient ac = new AsyncClientImpl();
    String service = "club/InitUpdateClub";
    System.err.println(TestConfig.NAVAJO_TEST_SERVER.getValue());
    ac.setServer(TestConfig.NAVAJO_TEST_SERVER.getValue());
    ac.setUsername(TestConfig.NAVAJO_TEST_USER.getValue());
    ac.setPassword(TestConfig.NAVAJO_TEST_PASS.getValue());
    Navajo input = NavajoFactory.getInstance().createNavajo();
    final NavajoResponseHandler showOutput = new NavajoResponseHandler() {

        @Override
        public void onResponse(Navajo n) {
            logger.info("Navajo finished!");
            try {
                StringWriter sw = new StringWriter();
                n.write(sw);
                logger.info("Response2 : {}", sw);
            } catch (NavajoException e) {
                logger.error("Error: ", e);
            }
        }

        @Override
        public void onFail(Throwable t) {
            logger.error("whoops: ", t);
        }

        @Override
        public Throwable getCaughtException() {
            return null;
        }
    };
    for (int i = 0; i < 10; i++) {
        ac.callService(input, service, showOutput);
        logger.info("Exchange sent");
    }
    Thread.sleep(10000);
}
Also used : ManualAsyncClient(com.dexels.navajo.client.async.ManualAsyncClient) StringWriter(java.io.StringWriter) NavajoException(com.dexels.navajo.document.NavajoException) NavajoResponseHandler(com.dexels.navajo.client.NavajoResponseHandler) Navajo(com.dexels.navajo.document.Navajo) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Navajo (com.dexels.navajo.document.Navajo)258 Message (com.dexels.navajo.document.Message)131 Test (org.junit.Test)109 Property (com.dexels.navajo.document.Property)86 NavajoException (com.dexels.navajo.document.NavajoException)31 Access (com.dexels.navajo.script.api.Access)30 IOException (java.io.IOException)28 StringWriter (java.io.StringWriter)27 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)26 FunctionInterface (com.dexels.navajo.expression.api.FunctionInterface)25 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)22 Selection (com.dexels.navajo.document.Selection)22 Header (com.dexels.navajo.document.Header)20 Operand (com.dexels.navajo.document.Operand)20 InputStream (java.io.InputStream)17 UserException (com.dexels.navajo.script.api.UserException)16 Optional (java.util.Optional)16 FatalException (com.dexels.navajo.script.api.FatalException)14 SystemException (com.dexels.navajo.script.api.SystemException)14 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)13