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;
}
};
}
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();
};
}
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;
}
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());
}
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();
}
Aggregations