[ 
https://issues.apache.org/jira/browse/RYA-119?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15703519#comment-15703519
 ] 

ASF GitHub Bot commented on RYA-119:
------------------------------------

Github user isper3at commented on a diff in the pull request:

    https://github.com/apache/incubator-rya/pull/124#discussion_r89901044
  
    --- Diff: 
dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/document/util/DocumentVisibilityUtil.java
 ---
    @@ -0,0 +1,316 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.rya.mongodb.document.util;
    +
    +import static com.google.common.base.Preconditions.checkNotNull;
    +
    +import java.util.ArrayList;
    +import java.util.List;
    +
    +import org.apache.log4j.Logger;
    +import org.apache.rya.mongodb.MongoDbRdfConstants;
    +import org.apache.rya.mongodb.document.visibility.Authorizations;
    +import org.apache.rya.mongodb.document.visibility.ByteSequence;
    +import org.apache.rya.mongodb.document.visibility.DocumentVisibility;
    +import org.apache.rya.mongodb.document.visibility.DocumentVisibility.Node;
    +import 
org.apache.rya.mongodb.document.visibility.DocumentVisibility.NodeType;
    +import org.apache.rya.mongodb.document.visibility.VisibilityEvaluator;
    +import org.apache.rya.mongodb.document.visibility.VisibilityParseException;
    +
    +import com.google.common.base.Charsets;
    +import com.google.common.collect.Lists;
    +import com.mongodb.BasicDBList;
    +
    +/**
    + * Utility methods for converting boolean expressions between an Accumulo 
column
    + * visibility string style and a multidimensional array that can be used
    + * in MongoDB expressions.
    + */
    +public final class DocumentVisibilityUtil {
    +    private static final Logger log = 
Logger.getLogger(DocumentVisibilityUtil.class);
    +
    +    /**
    +     * Private constructor to prevent instantiation.
    +     */
    +    private DocumentVisibilityUtil() {
    +    }
    +
    +    /**
    +     * Converts a boolean string expression into a multidimensional
    +     * array representation of the boolean expression.
    +     * @param booleanString the boolean string expression.
    +     * @return the multidimensional array representation of the boolean
    +     * expression.
    +     */
    +    public static Object[] toMultidimensionalArray(final String 
booleanString) {
    +        final DocumentVisibility dv = new 
DocumentVisibility(booleanString);
    +        return toMultidimensionalArray(dv);
    +    }
    +
    +    /**
    +     * Converts a {@link DocumentVisibility} object into a multidimensional
    +     * array representation of the boolean expression.
    +     * @param dv the {@link DocumentVisibility}. (not {@code null})
    +     * @return the multidimensional array representation of the boolean
    +     * expression.
    +     */
    +    public static Object[] toMultidimensionalArray(final 
DocumentVisibility dv) {
    +        checkNotNull(dv);
    +        final byte[] expression = dv.flatten();
    +        final DocumentVisibility flattenedDv = 
DisjunctiveNormalFormConverter.createDnfDocumentVisibility(expression);
    +        final Object[] result = 
toMultidimensionalArray(flattenedDv.getParseTree(), expression);
    +        return result;
    +    }
    +
    +    /**
    +     * 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.
    +     */
    +    public static Object[] toMultidimensionalArray(final Node node, final 
byte[] expression) {
    +        checkNotNull(node);
    +        final List<Object> array = new ArrayList<>();
    +
    +        if (node.getChildren().isEmpty() && node.getType() == 
NodeType.TERM) {
    +            final String data = getTermNodeData(node);
    +            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);
    +                    } 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:
    +                    break;
    +            }
    +        }
    +
    +        return array.toArray(new Object[0]);
    +    }
    +
    +    public static String nodeToBooleanString(final Node node) {
    +        boolean isFirst = true;
    +        final StringBuilder sb = new StringBuilder();
    +        if (node.getType() == NodeType.TERM) {
    +            final String data = getTermNodeData(node);
    +            sb.append(data);
    +        }
    +        if (node.getType() == NodeType.AND) {
    +            sb.append("(");
    +        }
    +        for (final Node child : node.getChildren()) {
    --- End diff --
    
    do you have to worry about children's children?


> Add visibility support to MongoDB
> ---------------------------------
>
>                 Key: RYA-119
>                 URL: https://issues.apache.org/jira/browse/RYA-119
>             Project: Rya
>          Issue Type: Improvement
>          Components: dao
>    Affects Versions: 3.2.10
>            Reporter: Andrew Smith
>            Assignee: Eric White
>
> Currently, when querying mongo, visibility is ignored.  Need to add support 
> for visibility when querying mongo.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to