Search in sources :

Example 1 with HttpResourceFactory

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

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

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

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

Aggregations

TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)4 HttpResource (com.dexels.navajo.resource.http.HttpResource)4 HttpResourceFactory (com.dexels.navajo.resource.http.HttpResourceFactory)4 Access (com.dexels.navajo.script.api.Access)4 Binary (com.dexels.navajo.document.types.Binary)1