Search in sources :

Example 1 with SharedStoreInterface

use of com.dexels.navajo.sharedstore.SharedStoreInterface in project navajo by Dexels.

the class GetBinary method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    if (getOperands().size() != 1) {
        throw new TMLExpressionException(this, "Invalid number of operands");
    }
    if (!(getOperand(0) instanceof String)) {
        throw new TMLExpressionException(this, "Invalid operand: " + getOperand(0));
    }
    Binary b = null;
    String id = (String) getOperand(0);
    SharedStoreInterface mss = SharedStoreFactory.getInstance();
    try {
        InputStream is = mss.getStream(PARENT_LOCATION, id);
        b = new Binary(is);
        is.close();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new TMLExpressionException(this, e.getMessage());
    }
    return b;
}
Also used : InputStream(java.io.InputStream) SharedStoreInterface(com.dexels.navajo.sharedstore.SharedStoreInterface) Binary(com.dexels.navajo.document.types.Binary) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 2 with SharedStoreInterface

use of com.dexels.navajo.sharedstore.SharedStoreInterface in project navajo by Dexels.

the class StoreBinary method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    if (getOperands().size() != 2) {
        throw new TMLExpressionException(this, "Invalid number of operands");
    }
    if (!(getOperand(0) instanceof String)) {
        throw new TMLExpressionException(this, "Invalid operand: " + getOperand(0));
    }
    if (!(getOperand(1) instanceof Binary)) {
        throw new TMLExpressionException(this, "Invalid operand: " + getOperand(1));
    }
    String id = (String) getOperand(0);
    Binary n = (Binary) getOperand(1);
    SharedStoreInterface mss = SharedStoreFactory.getInstance();
    try {
        OutputStream os = mss.getOutputStream(getAccess().getTenant(), GetBinary.PARENT_LOCATION, id, false);
        n.write(os);
        os.close();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new TMLExpressionException(this, e.getMessage());
    }
    return id;
}
Also used : OutputStream(java.io.OutputStream) SharedStoreInterface(com.dexels.navajo.sharedstore.SharedStoreInterface) Binary(com.dexels.navajo.document.types.Binary) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Aggregations

Binary (com.dexels.navajo.document.types.Binary)2 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)2 SharedStoreInterface (com.dexels.navajo.sharedstore.SharedStoreInterface)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1