Search in sources :

Example 1 with ReactiveResolvedParameters

use of com.dexels.navajo.reactive.api.ReactiveResolvedParameters 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 2 with ReactiveResolvedParameters

use of com.dexels.navajo.reactive.api.ReactiveResolvedParameters 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;
}
Also used : ReactiveResolvedParameters(com.dexels.navajo.reactive.api.ReactiveResolvedParameters) Type(com.dexels.navajo.document.stream.DataItem.Type) ReactiveParameters(com.dexels.navajo.reactive.api.ReactiveParameters) DataItem(com.dexels.navajo.document.stream.DataItem) StreamScriptContext(com.dexels.navajo.document.stream.api.StreamScriptContext) ImmutableFactory(com.dexels.immutable.factory.ImmutableFactory) SourceMetadata(com.dexels.navajo.reactive.api.SourceMetadata) HttpMethod(org.eclipse.jetty.http.HttpMethod) NavajoStreamEvent(com.dexels.navajo.document.stream.events.NavajoStreamEvent) ReactiveResolvedParameters(com.dexels.navajo.reactive.api.ReactiveResolvedParameters) Flowable(io.reactivex.Flowable) Optional(java.util.Optional) XML(com.dexels.navajo.document.stream.xml.XML) JettyClient(com.dexels.navajo.client.stream.jetty.JettyClient) StreamDocument(com.dexels.navajo.document.stream.StreamDocument) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) ReactiveSource(com.dexels.navajo.reactive.api.ReactiveSource) DataItem(com.dexels.navajo.document.stream.DataItem) NavajoStreamEvent(com.dexels.navajo.document.stream.events.NavajoStreamEvent)

Example 3 with ReactiveResolvedParameters

use of com.dexels.navajo.reactive.api.ReactiveResolvedParameters 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));
    };
}
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) FlowableTransformer(io.reactivex.FlowableTransformer) NavajoStreamEvent(com.dexels.navajo.document.stream.events.NavajoStreamEvent) ReactiveResolvedParameters(com.dexels.navajo.reactive.api.ReactiveResolvedParameters) Flowable(io.reactivex.Flowable) Optional(java.util.Optional) XML(com.dexels.navajo.document.stream.xml.XML) JettyClient(com.dexels.navajo.client.stream.jetty.JettyClient) StreamDocument(com.dexels.navajo.document.stream.StreamDocument) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Flowable(io.reactivex.Flowable)

Example 4 with ReactiveResolvedParameters

use of com.dexels.navajo.reactive.api.ReactiveResolvedParameters 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);
    };
}
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) Optional(java.util.Optional) Schedulers(io.reactivex.schedulers.Schedulers) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Binary(com.dexels.navajo.document.types.Binary) HttpResource(com.dexels.navajo.resource.http.HttpResource) HttpResource(com.dexels.navajo.resource.http.HttpResource) Binary(com.dexels.navajo.document.types.Binary)

Aggregations

ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)4 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 ReactiveResolvedParameters (com.dexels.navajo.reactive.api.ReactiveResolvedParameters)4 Optional (java.util.Optional)4 ImmutableFactory (com.dexels.immutable.factory.ImmutableFactory)3 ReactiveTransformer (com.dexels.navajo.reactive.api.ReactiveTransformer)3 TransformerMetadata (com.dexels.navajo.reactive.api.TransformerMetadata)3 Flowable (io.reactivex.Flowable)3 FlowableTransformer (io.reactivex.FlowableTransformer)3 JettyClient (com.dexels.navajo.client.stream.jetty.JettyClient)2 StreamDocument (com.dexels.navajo.document.stream.StreamDocument)2 NavajoStreamEvent (com.dexels.navajo.document.stream.events.NavajoStreamEvent)2 XML (com.dexels.navajo.document.stream.xml.XML)2 HttpResourceFactory (com.dexels.navajo.resource.http.HttpResourceFactory)2 Property (com.dexels.navajo.document.Property)1 Type (com.dexels.navajo.document.stream.DataItem.Type)1 Binary (com.dexels.navajo.document.types.Binary)1 ReactiveSource (com.dexels.navajo.reactive.api.ReactiveSource)1