Search in sources :

Example 6 with Node

use of org.apache.accumulo.core.security.ColumnVisibility.Node in project incubator-rya by apache.

the class DocumentVisibilityUtil method nodeToBooleanString.

public static String nodeToBooleanString(final Node node, final byte[] expression) throws DocumentVisibilityConversionException {
    boolean isFirst = true;
    final StringBuilder sb = new StringBuilder();
    if (node.getType() == NodeType.TERM) {
        final String data = getTermNodeData(node, expression);
        sb.append(data);
    }
    if (node.getType() == NodeType.AND) {
        sb.append("(");
    }
    for (final Node child : node.getChildren()) {
        if (isFirst) {
            isFirst = false;
        } else {
            if (node.getType() == NodeType.OR) {
                sb.append("|");
            } else if (node.getType() == NodeType.AND) {
                sb.append("&");
            }
        }
        switch(child.getType()) {
            case EMPTY:
                sb.append("");
                break;
            case TERM:
                final String data = getTermNodeData(child, expression);
                sb.append(data);
                break;
            case OR:
                sb.append("(");
                sb.append(nodeToBooleanString(child, expression));
                sb.append(")");
                break;
            case AND:
                sb.append(nodeToBooleanString(child, expression));
                break;
            default:
                throw new DocumentVisibilityConversionException("Unknown type: " + child.getType());
        }
    }
    if (node.getType() == NodeType.AND) {
        sb.append(")");
    }
    return sb.toString();
}
Also used : Node(org.apache.accumulo.core.security.ColumnVisibility.Node)

Example 7 with Node

use of org.apache.accumulo.core.security.ColumnVisibility.Node in project incubator-rya by apache.

the class DisjunctiveNormalFormConverterTest method testTruthTableNullNode.

/**
 * Test truth table with a {@code null} {@link Node}.
 */
@Test(expected = NullPointerException.class)
public void testTruthTableNullNode() {
    final Node node = null;
    final byte[] expression = new DocumentVisibility("A").getExpression();
    DisjunctiveNormalFormConverter.createTruthTableInputs(node, expression);
}
Also used : Node(org.apache.accumulo.core.security.ColumnVisibility.Node) DocumentVisibility(org.apache.rya.mongodb.document.visibility.DocumentVisibility) Test(org.junit.Test)

Example 8 with Node

use of org.apache.accumulo.core.security.ColumnVisibility.Node in project incubator-rya by apache.

the class DocumentVisibilityUtil method toMultidimensionalArray.

/**
 * Converts a {@link Node} and its corresponding expression into a
 * multidimensional array representation of the boolean expression.
 * @param node the {@link Node}. (not {@code null})
 * @param expression the expression byte array.
 * @return the multidimensional array representation of the boolean
 * expression.
 * @throws DocumentVisibilityConversionException
 */
public static Object[] toMultidimensionalArray(final Node node, final byte[] expression) throws DocumentVisibilityConversionException {
    checkNotNull(node);
    final List<Object> array = new ArrayList<>();
    if (node.getChildren().isEmpty() && node.getType() == NodeType.TERM) {
        final String data = getTermNodeData(node, expression);
        array.add(data);
    }
    log.trace("Children size: " + node.getChildren().size() + " Type: " + node.getType());
    for (final Node child : node.getChildren()) {
        switch(child.getType()) {
            case EMPTY:
            case TERM:
                String data;
                if (child.getType() == NodeType.TERM) {
                    data = getTermNodeData(child, expression);
                } else {
                    data = "";
                }
                if (node.getType() == NodeType.OR) {
                    array.add(Lists.newArrayList(data).toArray(new Object[0]));
                } else {
                    array.add(data);
                }
                break;
            case OR:
            case AND:
                array.add(toMultidimensionalArray(child, expression));
                break;
            default:
                throw new DocumentVisibilityConversionException("Unknown type: " + child.getType());
        }
    }
    return array.toArray(new Object[0]);
}
Also used : Node(org.apache.accumulo.core.security.ColumnVisibility.Node) ArrayList(java.util.ArrayList)

Example 9 with Node

use of org.apache.accumulo.core.security.ColumnVisibility.Node in project incubator-rya by apache.

the class DisjunctiveNormalFormConverter method findNodeTerms.

/**
 * Searches a node for all unique terms in its expression and returns them.
 * Duplicates are not included.
 * @param node the {@link Node}.
 * @return an unmodifiable {@link List} of string terms without duplicates.
 */
public static List<String> findNodeTerms(final Node node, final byte[] expression) {
    final Set<String> terms = new LinkedHashSet<>();
    if (node.getType() == NodeType.TERM) {
        final String data = DocumentVisibilityUtil.getTermNodeData(node, expression);
        terms.add(data);
    }
    for (final Node child : node.getChildren()) {
        switch(node.getType()) {
            case AND:
            case OR:
                terms.addAll(findNodeTerms(child, expression));
                break;
            default:
                break;
        }
    }
    return Collections.unmodifiableList(Lists.newArrayList(terms));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Node(org.apache.accumulo.core.security.ColumnVisibility.Node)

Example 10 with Node

use of org.apache.accumulo.core.security.ColumnVisibility.Node in project accumulo by apache.

the class ColumnVisibilityTest method testParseTreeWithMoreParentheses.

@Test
public void testParseTreeWithMoreParentheses() {
    Node node = parse("(W)|(U&V)");
    assertNode(node, NodeType.OR, 0, 9);
    assertNode(node.getChildren().get(0), NodeType.TERM, 1, 2);
    assertNode(node.getChildren().get(1), NodeType.AND, 5, 8);
    assertNode(node.getChildren().get(1).children.get(0), NodeType.TERM, 5, 6);
    assertNode(node.getChildren().get(1).children.get(1), NodeType.TERM, 7, 8);
}
Also used : Node(org.apache.accumulo.core.security.ColumnVisibility.Node) Test(org.junit.Test)

Aggregations

Node (org.apache.accumulo.core.security.ColumnVisibility.Node)12 Test (org.junit.Test)9 DocumentVisibility (org.apache.rya.mongodb.document.visibility.DocumentVisibility)2 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 NodeComparator (org.apache.accumulo.core.security.ColumnVisibility.NodeComparator)1