Search in sources :

Example 1 with TokenMgrError

use of com.netflix.metacat.common.server.partition.parser.TokenMgrError in project metacat by Netflix.

the class FilterPartition method evaluatePartitionExpression.

/**
     * Evaluates the given expression.
     * @param partitionExpression expression
     * @param name name
     * @param path partition uri path
     * @param batchid batch id
     * @param values map of values
     * @return true if the expression evaluates to true
     */
public boolean evaluatePartitionExpression(final String partitionExpression, final String name, final String path, final boolean batchid, final Map<String, String> values) {
    if (partitionExpression != null) {
        try {
            if (parser == null) {
                parser = new PartitionParser(new StringReader(partitionExpression));
            } else {
                parser.ReInit(new StringReader(partitionExpression));
            }
            context.clear();
            if (batchid) {
                PartitionUtil.getPartitionKeyValues(path, context);
            }
            PartitionUtil.getPartitionKeyValues(name, context);
            if (values != null) {
                context.putAll(values);
            }
            if (context.size() > 0) {
                return (Boolean) parser.filter().jjtAccept(new PartitionParserEval(context), null);
            } else {
                return false;
            }
        } catch (ParseException | TokenMgrError e) {
            throw new IllegalArgumentException(String.format("Invalid expression: %s", partitionExpression), e);
        } catch (IllegalArgumentException e) {
            throw e;
        } catch (Throwable t) {
            log.warn("Caught unexpected exception during evaluatePartitionExpression,", t);
            return false;
        }
    }
    return true;
}
Also used : PartitionParser(com.netflix.metacat.common.server.partition.parser.PartitionParser) StringReader(java.io.StringReader) TokenMgrError(com.netflix.metacat.common.server.partition.parser.TokenMgrError) PartitionParserEval(com.netflix.metacat.common.server.partition.visitor.PartitionParserEval) ParseException(com.netflix.metacat.common.server.partition.parser.ParseException)

Aggregations

ParseException (com.netflix.metacat.common.server.partition.parser.ParseException)1 PartitionParser (com.netflix.metacat.common.server.partition.parser.PartitionParser)1 TokenMgrError (com.netflix.metacat.common.server.partition.parser.TokenMgrError)1 PartitionParserEval (com.netflix.metacat.common.server.partition.visitor.PartitionParserEval)1 StringReader (java.io.StringReader)1