Search in sources :

Example 1 with HttpResource

use of com.dexels.navajo.resource.http.HttpResource in project navajo by Dexels.

the class GetBinaryFromStore method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    String resource = (String) getOperand(0);
    if (resource == null) {
        throw new TMLExpressionException("No resource defined in GetBinaryFromStore");
    }
    String bucket = (String) getOperand(1);
    if (bucket == null) {
        throw new TMLExpressionException("No bucket defined in GetBinaryFromStore");
    }
    Object idObj = getOperand(2);
    String id = null;
    if (idObj instanceof String) {
        id = (String) idObj;
    } else {
        id = idObj.toString();
    }
    if (id == null) {
        throw new TMLExpressionException("No id defined in GetBinaryFromStore");
    }
    Integer expiration = (Integer) super.getOperand(3);
    if (expiration == null) {
        throw new TMLExpressionException("No expiration defined in GetBinaryFromStore");
    }
    Access access = this.getAccess();
    String tenant = access.getTenant();
    HttpResourceFactory instance = HttpResourceFactory.getInstance();
    if (instance == null) {
        throw new TMLExpressionException("No HttpResourceFactory found in GetBinaryFromStore");
    }
    HttpResource httpResource = instance.getHttpResource(resource);
    if (httpResource == null) {
        throw new TMLExpressionException("HttpResource: " + resource + " not found in GetBinaryFromStore");
    }
    return httpResource.expiringURL(tenant, bucket, id, expiration);
}
Also used : HttpResourceFactory(com.dexels.navajo.resource.http.HttpResourceFactory) HttpResource(com.dexels.navajo.resource.http.HttpResource) Access(com.dexels.navajo.script.api.Access) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 2 with HttpResource

use of com.dexels.navajo.resource.http.HttpResource in project navajo by Dexels.

the class ExistsBinaryInStore method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    String resource = (String) super.getOperand(0);
    if (resource == null) {
        throw new TMLExpressionException("No resource defined in ExistsBinaryInStore");
    }
    String bucket = (String) super.getOperand(1);
    if (bucket == null) {
        throw new TMLExpressionException("No bucket defined in ExistsBinaryInStore");
    }
    String id = (String) super.getOperand(2);
    if (id == null) {
        throw new TMLExpressionException("No id defined in ExistsBinaryInStore");
    }
    Access access = this.getAccess();
    if (access == null) {
        throw new TMLExpressionException("No access defined in ExistsBinaryInStore");
    }
    String tenant = access.getTenant();
    if (tenant == null) {
        throw new TMLExpressionException("No tenant defined in ExistsBinaryInStore");
    }
    HttpResourceFactory instance = HttpResourceFactory.getInstance();
    if (instance == null) {
        throw new TMLExpressionException("No HttpResourceFactory found in ExistsBinaryInStore");
    }
    HttpResource httpResource = instance.getHttpResource(resource);
    if (httpResource == null) {
        throw new TMLExpressionException("HttpResource: " + resource + " found in ExistsBinaryInStore");
    }
    return httpResource.head(tenant, bucket, id).blockingGet().status() < 400;
}
Also used : HttpResourceFactory(com.dexels.navajo.resource.http.HttpResourceFactory) HttpResource(com.dexels.navajo.resource.http.HttpResource) Access(com.dexels.navajo.script.api.Access) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 3 with HttpResource

use of com.dexels.navajo.resource.http.HttpResource in project navajo by Dexels.

the class StoreBinary method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    String resource = (String) super.getOperand(0);
    if (resource == null) {
        throw new TMLExpressionException("No resource defined in PutBinary");
    }
    String bucket = (String) super.getOperand(1);
    if (bucket == null) {
        throw new TMLExpressionException("No bucket defined in PutBinary");
    }
    Binary binary = (Binary) super.getOperand(2);
    if (binary == null) {
        throw new TMLExpressionException("No binary defined in PutBinary");
    }
    Access access = this.getAccess();
    if (access == null) {
        throw new TMLExpressionException("No access defined in PutBinary");
    }
    String tenant = access.getTenant();
    if (tenant == null) {
        throw new TMLExpressionException("No tenant defined in PutBinary");
    }
    HttpResourceFactory instance = HttpResourceFactory.getInstance();
    if (instance == null) {
        throw new TMLExpressionException("No HttpResourceFactory found in PutBinary");
    }
    HttpResource httpResource = instance.getHttpResource(resource);
    if (httpResource == null) {
        throw new TMLExpressionException("HttpResource: " + resource + " found in PutBinary");
    }
    return httpResource.put(tenant, bucket, binary.getHexDigest(), binary).blockingGet().status();
}
Also used : HttpResourceFactory(com.dexels.navajo.resource.http.HttpResourceFactory) HttpResource(com.dexels.navajo.resource.http.HttpResource) Access(com.dexels.navajo.script.api.Access) Binary(com.dexels.navajo.document.types.Binary) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 4 with HttpResource

use of com.dexels.navajo.resource.http.HttpResource in project navajo by Dexels.

the class DeleteBinary method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    String resource = (String) super.getOperand(0);
    if (resource == null) {
        throw new TMLExpressionException("No resource defined in DeleteBinary");
    }
    String bucket = (String) super.getOperand(1);
    if (bucket == null) {
        throw new TMLExpressionException("No bucket defined in DeleteBinary");
    }
    String id = (String) super.getOperand(2);
    if (id == null) {
        throw new TMLExpressionException("No id defined in GetBinary");
    }
    Access access = this.getAccess();
    if (access == null) {
        throw new TMLExpressionException("No access defined in DeleteBinary");
    }
    String tenant = access.getTenant();
    if (tenant == null) {
        throw new TMLExpressionException("No tenant defined in DeleteBinary");
    }
    HttpResourceFactory instance = HttpResourceFactory.getInstance();
    if (instance == null) {
        throw new TMLExpressionException("No HttpResourceFactory found in DeleteBinary");
    }
    HttpResource httpResource = instance.getHttpResource(resource);
    if (httpResource == null) {
        throw new TMLExpressionException("HttpResource: " + resource + " found in DeleteBinary");
    }
    return httpResource.delete(tenant, bucket, id).blockingGet().status();
}
Also used : HttpResourceFactory(com.dexels.navajo.resource.http.HttpResourceFactory) HttpResource(com.dexels.navajo.resource.http.HttpResource) Access(com.dexels.navajo.script.api.Access) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 5 with HttpResource

use of com.dexels.navajo.resource.http.HttpResource 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

HttpResource (com.dexels.navajo.resource.http.HttpResource)5 HttpResourceFactory (com.dexels.navajo.resource.http.HttpResourceFactory)5 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)4 Access (com.dexels.navajo.script.api.Access)4 Binary (com.dexels.navajo.document.types.Binary)2 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)1 ImmutableFactory (com.dexels.immutable.factory.ImmutableFactory)1 DataItem (com.dexels.navajo.document.stream.DataItem)1 StreamScriptContext (com.dexels.navajo.document.stream.api.StreamScriptContext)1 ReactiveParameters (com.dexels.navajo.reactive.api.ReactiveParameters)1 ReactiveResolvedParameters (com.dexels.navajo.reactive.api.ReactiveResolvedParameters)1 ReactiveTransformer (com.dexels.navajo.reactive.api.ReactiveTransformer)1 TransformerMetadata (com.dexels.navajo.reactive.api.TransformerMetadata)1 FlowableTransformer (io.reactivex.FlowableTransformer)1 Schedulers (io.reactivex.schedulers.Schedulers)1 Optional (java.util.Optional)1