Search in sources :

Example 86 with Navajo

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

the class Dispatcher method generateScheduledMessage.

private final Navajo generateScheduledMessage(Header h, String taskId, boolean rejected) {
    try {
        Navajo outMessage = NavajoFactory.getInstance().createNavajo();
        Header hnew = NavajoFactory.getInstance().createHeader(outMessage, h.getRPCName(), h.getRPCUser(), "", -1);
        if (!rejected) {
            hnew.setSchedule(taskId);
        } else {
            Message msg = NavajoFactory.getInstance().createMessage(outMessage, "Warning");
            outMessage.addMessage(msg);
            Property prop = NavajoFactory.getInstance().createProperty(outMessage, "Status", Property.STRING_PROPERTY, "TimeExpired", 32, "Created by generateScheduledMessage", Property.DIR_OUT);
            msg.addProperty(prop);
        }
        outMessage.addHeader(hnew);
        return outMessage;
    } catch (Exception e) {
        logger.error("Error: ", e);
        return null;
    }
}
Also used : Header(com.dexels.navajo.document.Header) Message(com.dexels.navajo.document.Message) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property) FatalException(com.dexels.navajo.script.api.FatalException) NavajoException(com.dexels.navajo.document.NavajoException) AuthorizationException(com.dexels.navajo.script.api.AuthorizationException) UserException(com.dexels.navajo.script.api.UserException) TriggerException(com.dexels.navajo.server.enterprise.scheduler.TriggerException) IOException(java.io.IOException) SystemException(com.dexels.navajo.script.api.SystemException)

Example 87 with Navajo

use of com.dexels.navajo.document.Navajo 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 88 with Navajo

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

the class TestGatherEvents method testMethods.

@Test
public void testMethods() throws IOException {
    try (InputStream is = TestGatherEvents.class.getResourceAsStream("tml_events.xml")) {
        Navajo n = NavajoFactory.getInstance().createNavajo(is);
        // List<NavajoStreamEvent> l =  NavajoDomStreamer.feed(n).toList().blockingGet();
        long l = Single.just(n).compose(StreamDocument.domStreamTransformer()).toObservable().concatMap(e -> e).toFlowable(BackpressureStrategy.BUFFER).compose(StreamDocument.eventsToImmutable(Optional.empty())).doOnNext(e -> ImmutableFactory.createParser().describe(e)).count().blockingGet();
        Assert.assertEquals(10, l);
    }
}
Also used : NavajoFactory(com.dexels.navajo.document.NavajoFactory) BackpressureStrategy(io.reactivex.BackpressureStrategy) Optional(java.util.Optional) IOException(java.io.IOException) Test(org.junit.Test) StreamDocument(com.dexels.navajo.document.stream.StreamDocument) Assert(org.junit.Assert) Single(io.reactivex.Single) Navajo(com.dexels.navajo.document.Navajo) InputStream(java.io.InputStream) ImmutableFactory(com.dexels.immutable.factory.ImmutableFactory) InputStream(java.io.InputStream) Navajo(com.dexels.navajo.document.Navajo) Test(org.junit.Test)

Example 89 with Navajo

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

the class BaseMessageImpl method copy.

@Override
public final Message copy() {
    Navajo empty = NavajoFactory.getInstance().createNavajo();
    Message result = copy(empty);
    empty.addMessage(result);
    return result;
}
Also used : Message(com.dexels.navajo.document.Message) Navajo(com.dexels.navajo.document.Navajo)

Example 90 with Navajo

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

the class JSONTMLImpl method parse.

private Navajo parse(JsonParser jp) throws Exception {
    Navajo n = NavajoFactory.getInstance().createNavajo();
    Message parent = NavajoFactory.getInstance().createMessage(n, (topLevelMessageName != null ? topLevelMessageName : "Request"));
    boolean first = true;
    while (jp.nextToken() != null) {
        if (first) {
            n.addMessage(parent);
            first = false;
        }
        parse(n, parent, jp);
    }
    return n;
}
Also used : Message(com.dexels.navajo.document.Message) Navajo(com.dexels.navajo.document.Navajo)

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