Search in sources :

Example 36 with ImmutableMessage

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