use of com.dexels.navajo.document.stream.api.StreamScriptContext in project navajo by Dexels.
the class ASTPipeDefinition method transformerElements.
@SuppressWarnings("unchecked")
private List<Object> transformerElements(List<String> problems, String originalExpression, Function<String, FunctionClassification> functionClassifier, Function<String, Optional<Node>> mapResolver) {
int count = jjtGetNumChildren();
List<Object> pipeElements = new ArrayList<>();
for (int i = (partial ? 0 : 1); i < count; i++) {
ContextExpression interpretToLambda = jjtGetChild(i).interpretToLambda(problems, originalExpression, functionClassifier, mapResolver);
Object result = interpretToLambda.apply().value;
if (result instanceof Function) {
Function<StreamScriptContext, Function<DataItem, DataItem>> merger = (Function<StreamScriptContext, Function<DataItem, DataItem>>) result;
pipeElements.add(merger);
} else if (result instanceof ReactiveTransformer) {
ReactiveTransformer transformer = (ReactiveTransformer) result;
pipeElements.add(transformer);
} else {
logger.warn("huh? {}", result);
// something weird
}
}
return pipeElements;
}
use of com.dexels.navajo.document.stream.api.StreamScriptContext 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.navajo.document.stream.api.StreamScriptContext in project navajo by Dexels.
the class CallRemoteSource method execute.
@Override
public Flowable<DataItem> execute(StreamScriptContext context, Optional<ImmutableMessage> current, ImmutableMessage param) {
ReactiveResolvedParameters resolved = params.resolve(context, current, ImmutableFactory.empty(), metadata);
String server = resolved.paramString("server");
String username = resolved.paramString("username");
String password = resolved.paramString("password");
final String service = resolved.paramString("service");
Flowable<NavajoStreamEvent> flow = client.callWithBodyToStream(server, e -> e.header("X-Navajo-Username", username).header("X-Navajo-Password", password).header("X-Navajo-Service", service).method(HttpMethod.POST), Flowable.<NavajoStreamEvent>empty().compose(StreamDocument.inNavajo(service, Optional.of(username), Optional.of(password))).lift(StreamDocument.serialize()), "text/xml").lift(XML.parseFlowable(10)).concatMap(e -> e).lift(StreamDocument.parse()).concatMap(e -> e).filter(e -> e.type() != NavajoStreamEvent.NavajoEventTypes.NAVAJO_STARTED && e.type() != NavajoStreamEvent.NavajoEventTypes.NAVAJO_DONE);
Flowable<DataItem> fw = Flowable.just(DataItem.ofEventStream(flow));
return fw;
}
use of com.dexels.navajo.document.stream.api.StreamScriptContext in project navajo by Dexels.
the class CallRemoteTransformer method execute.
@Override
public FlowableTransformer<DataItem, DataItem> execute(StreamScriptContext context, Optional<ImmutableMessage> current, ImmutableMessage param) {
ReactiveResolvedParameters resolved = parameters.resolve(context, current, param, metadata);
String server = resolved.paramString("server");
String username = resolved.paramString("username");
String password = resolved.paramString("password");
final String service = resolved.paramString("service");
return flow -> {
Flowable<NavajoStreamEvent> result = client.callWithBodyToStream(server, e -> e.header("X-Navajo-Username", username).header("X-Navajo-Password", password).header("X-Navajo-Service", service), flow.map(di -> di.eventStream()).concatMap(e -> e).lift(StreamDocument.serialize()), "text/xml").lift(XML.parseFlowable(10)).concatMap(e -> e).lift(StreamDocument.parse()).concatMap(e -> e).filter(e -> e.type() != NavajoStreamEvent.NavajoEventTypes.NAVAJO_STARTED && e.type() != NavajoStreamEvent.NavajoEventTypes.NAVAJO_DONE);
return Flowable.just(DataItem.ofEventStream(result));
};
}
use of com.dexels.navajo.document.stream.api.StreamScriptContext in project navajo by Dexels.
the class HttpPushTransformer 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");
int parallel = resolved.optionalInteger("parallel").orElse(1);
HttpResource res = HttpResourceFactory.getInstance().getHttpResource(name);
return flow -> {
if (res == null) {
throw new NullPointerException("Missing http resource: " + name);
}
return flow.map(f -> f.message()).observeOn(Schedulers.io()).map(msg -> {
ReactiveResolvedParameters resInMsg = parameters.resolve(context, Optional.of(msg), ImmutableFactory.empty(), metadata);
String id = resInMsg.paramString("id");
String bucket = resInMsg.paramString("bucket");
String property = resInMsg.paramString("property");
Binary bin = (Binary) msg.columnValue(property);
return res.put(context.getTenant(), bucket, id, bin).map(e -> e.toMessage()).toFlowable();
}).flatMap(f -> f, parallel).map(DataItem::of);
};
}
Aggregations