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();
}
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);
}
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]);
}
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));
}
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);
}
Aggregations