Search in sources :

Example 6 with ImmutableMessage

use of com.dexels.immutable.api.ImmutableMessage 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 7 with ImmutableMessage

use of com.dexels.immutable.api.ImmutableMessage in project navajo by Dexels.

the class HttpPushStreamTransformer method execute.

@Override
public FlowableTransformer<DataItem, DataItem> execute(StreamScriptContext context, Optional<ImmutableMessage> current, ImmutableMessage param) {
    ReactiveResolvedParameters resolved = parameters.resolve(context, current, param, metadata);
    String name = resolved.paramString("name");
    String id = resolved.paramString("id");
    String bucket = resolved.paramString("bucket");
    String type = resolved.optionalString("type").orElse("application/octetstream");
    return flow -> {
        Flowable<byte[]> in = flow.map(f -> f.data());
        return HttpResourceFactory.getInstance().getHttpResource(name).put(context.getTenant(), bucket, id, type, in).map(status -> ImmutableFactory.empty().with("code", status, Property.INTEGER_PROPERTY)).map(DataItem::of).toFlowable();
    };
}
Also used : ReactiveResolvedParameters(com.dexels.navajo.reactive.api.ReactiveResolvedParameters) ReactiveTransformer(com.dexels.navajo.reactive.api.ReactiveTransformer) ReactiveParameters(com.dexels.navajo.reactive.api.ReactiveParameters) DataItem(com.dexels.navajo.document.stream.DataItem) TransformerMetadata(com.dexels.navajo.reactive.api.TransformerMetadata) StreamScriptContext(com.dexels.navajo.document.stream.api.StreamScriptContext) ImmutableFactory(com.dexels.immutable.factory.ImmutableFactory) FlowableTransformer(io.reactivex.FlowableTransformer) HttpResourceFactory(com.dexels.navajo.resource.http.HttpResourceFactory) ReactiveResolvedParameters(com.dexels.navajo.reactive.api.ReactiveResolvedParameters) Flowable(io.reactivex.Flowable) Optional(java.util.Optional) Property(com.dexels.navajo.document.Property) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) DataItem(com.dexels.navajo.document.stream.DataItem) Flowable(io.reactivex.Flowable)

Example 8 with ImmutableMessage

use of com.dexels.immutable.api.ImmutableMessage in project navajo by Dexels.

the class JsonTmlConverterImpl method toMessage.

@Override
public Message toMessage(String messageName, ImmutableMessage message, Navajo rootNavajo) {
    Message cV = NavajoFactory.getInstance().createMessage(rootNavajo, messageName);
    for (String columnName : message.columnNames()) {
        String type = message.columnType(columnName);
        Object value = message.value(columnName).orElse(null);
        Property colProp = NavajoFactory.getInstance().createProperty(rootNavajo, columnName, type, null, 0, "", Property.DIR_OUT);
        switch(type) {
            case Property.CLOCKTIME_PROPERTY:
                if (value != null) {
                    ClockTime ct = new ClockTime((Date) value);
                    colProp.setAnyValue(ct);
                }
                colProp.setType(type);
                break;
            default:
                colProp.setAnyValue(value);
                colProp.setType(type);
                break;
        }
        cV.addProperty(colProp);
    }
    for (Entry<String, List<ImmutableMessage>> e : message.subMessageListMap().entrySet()) {
        Message subArrayMessage = NavajoFactory.getInstance().createMessage(rootNavajo, e.getKey(), Message.MSG_TYPE_ARRAY);
        cV.addMessage(subArrayMessage);
        for (ImmutableMessage elt : e.getValue()) {
            Message msgElt = toMessage(e.getKey(), elt, rootNavajo);
            subArrayMessage.addElement(msgElt);
        }
    }
    for (Entry<String, ImmutableMessage> e : message.subMessageMap().entrySet()) {
        Message msgElt = toMessage(e.getKey(), e.getValue(), rootNavajo);
        cV.addMessage(msgElt);
    }
    return cV;
}
Also used : Message(com.dexels.navajo.document.Message) ReplicationMessage(com.dexels.replication.api.ReplicationMessage) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) List(java.util.List) ClockTime(com.dexels.navajo.document.types.ClockTime) Property(com.dexels.navajo.document.Property)

Example 9 with ImmutableMessage

use of com.dexels.immutable.api.ImmutableMessage in project navajo by Dexels.

the class TestRun method testTimestamp.

@Test
public void testTimestamp() {
    ImmutableMessage msg = ReplicationFactory.getInstance().parseStream(getClass().getResourceAsStream("test3.json")).message();
    Navajo nn = JsonTmlFactory.getInstance().toFlatNavajo("Match", msg);
    Message match = nn.getMessage("Match");
    assertNotNull(match.getProperty("matchtime"));
    Property matchtime = match.getProperty("matchtime");
    assertEquals(Property.DATE_PROPERTY, matchtime.getType());
    Date matchtimeobj = (Date) matchtime.getTypedValue();
    Calendar cal = Calendar.getInstance();
    cal.setTime(matchtimeobj);
    assertEquals(1971, cal.get(Calendar.YEAR));
    assertEquals(12, cal.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, cal.get(Calendar.MINUTE));
    Property matchtime2 = match.getProperty("matchtime2");
    assertEquals(Property.CLOCKTIME_PROPERTY, matchtime2.getType());
}
Also used : Message(com.dexels.navajo.document.Message) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Calendar(java.util.Calendar) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property) Date(java.util.Date) Test(org.junit.Test)

Example 10 with ImmutableMessage

use of com.dexels.immutable.api.ImmutableMessage in project navajo by Dexels.

the class ExpressionTest method setup.

@Before
public void setup() {
    NavajoFactory.getInstance().setExpressionEvaluator(new CachedExpressionEvaluator());
    testDoc = NavajoFactory.getInstance().createNavajo();
    topMessage = NavajoFactory.getInstance().createMessage(testDoc, "MyTop");
    testDoc.addMessage(topMessage);
    Property pt = NavajoFactory.getInstance().createProperty(testDoc, "TopProp", "1", "", Property.DIR_IN);
    testSelection = NavajoFactory.getInstance().createSelection(testDoc, "option1", "value1", true);
    pt.addSelection(testSelection);
    topMessage.addProperty(pt);
    Message a = NavajoFactory.getInstance().createMessage(testDoc, "MyArrayMessage", "array");
    topMessage.addMessage(a);
    for (int i = 0; i < 5; i++) {
        Message a1 = NavajoFactory.getInstance().createMessage(testDoc, "MyArrayMessage");
        a.addMessage(a1);
        Property p = NavajoFactory.getInstance().createProperty(testDoc, "MyProp", "string", "noot" + i, 0, "", "in");
        a1.addProperty(p);
        Property p2 = NavajoFactory.getInstance().createProperty(testDoc, "MyProp2", "string", "aap" + i, 0, "", "in");
        a1.addProperty(p2);
    }
    Map<String, Object> values = new HashMap<>();
    Map<String, String> types = new HashMap<>();
    values.put("SomeString", "Tralala");
    types.put("SomeString", "string");
    values.put("SomeInteger", 3);
    types.put("SomeInteger", "integer");
    immutableMessage = ReplicationFactory.createReplicationMessage(Optional.empty(), Optional.empty(), Optional.empty(), null, 0, Operation.NONE, Collections.emptyList(), types, values, Collections.emptyMap(), Collections.emptyMap(), Optional.empty(), Optional.empty()).message();
    Map<String, Object> valueparams = new HashMap<>();
    Map<String, String> typeparams = new HashMap<>();
    valueparams.put("SomeString", "Tralala2");
    typeparams.put("SomeString", "string");
    valueparams.put("SomeInteger", 4);
    typeparams.put("SomeInteger", "integer");
    paramMessage = ReplicationFactory.createReplicationMessage(Optional.empty(), Optional.empty(), Optional.empty(), null, 0, Operation.NONE, Collections.emptyList(), typeparams, valueparams, Collections.emptyMap(), Collections.emptyMap(), Optional.empty(), Optional.empty()).message();
}
Also used : ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Message(com.dexels.navajo.document.Message) HashMap(java.util.HashMap) CachedExpressionEvaluator(com.dexels.navajo.parser.compiled.api.CachedExpressionEvaluator) Property(com.dexels.navajo.document.Property) Before(org.junit.Before)

Aggregations

ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)36 Message (com.dexels.navajo.document.Message)23 Navajo (com.dexels.navajo.document.Navajo)18 Operand (com.dexels.navajo.document.Operand)17 Optional (java.util.Optional)17 Selection (com.dexels.navajo.document.Selection)12 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)12 TipiLink (com.dexels.navajo.expression.api.TipiLink)12 Access (com.dexels.navajo.script.api.Access)12 MappableTreeNode (com.dexels.navajo.script.api.MappableTreeNode)12 Test (org.junit.Test)12 List (java.util.List)9 Property (com.dexels.navajo.document.Property)7 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)6 HashMap (java.util.HashMap)6 ImmutableFactory (com.dexels.immutable.factory.ImmutableFactory)5 ArrayList (java.util.ArrayList)5 DataItem (com.dexels.navajo.document.stream.DataItem)4 StreamScriptContext (com.dexels.navajo.document.stream.api.StreamScriptContext)4 ReactiveParameters (com.dexels.navajo.reactive.api.ReactiveParameters)4