All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.securegraph.accumulo.EdgeMaker Maven / Gradle / Ivy

The newest version!
package org.securegraph.accumulo;

import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Value;
import org.apache.hadoop.io.Text;
import org.securegraph.Authorizations;
import org.securegraph.Edge;
import org.securegraph.SecureGraphException;

import java.util.Iterator;
import java.util.Map;

public class EdgeMaker extends ElementMaker {
    private static final String VISIBILITY_SIGNAL = AccumuloEdge.CF_SIGNAL.toString();
    private final AccumuloGraph graph;
    private String inVertexId;
    private String outVertexId;
    private String label;
    private long timestamp;

    public EdgeMaker(AccumuloGraph graph, Iterator> row, Authorizations authorizations) {
        super(graph, row, authorizations);
        this.graph = graph;
    }

    @Override
    protected void processColumn(Key key, Value value) {
        Text columnFamily = key.getColumnFamily();
        Text columnQualifier = key.getColumnQualifier();

        if (AccumuloEdge.CF_SIGNAL.compareTo(columnFamily) == 0) {
            this.label = columnQualifier.toString();
            this.timestamp = key.getTimestamp();
            return;
        }

        if (AccumuloEdge.CF_IN_VERTEX.compareTo(columnFamily) == 0) {
            this.inVertexId = columnQualifier.toString();
            return;
        }

        if (AccumuloEdge.CF_OUT_VERTEX.compareTo(columnFamily) == 0) {
            this.outVertexId = columnQualifier.toString();
        }
    }

    @Override
    protected String getIdFromRowKey(String rowKey) {
        if (rowKey.startsWith(AccumuloConstants.EDGE_ROW_KEY_PREFIX)) {
            return rowKey.substring(AccumuloConstants.EDGE_ROW_KEY_PREFIX.length());
        }
        throw new SecureGraphException("Invalid row key for edge: " + rowKey);
    }

    @Override
    protected String getVisibilitySignal() {
        return VISIBILITY_SIGNAL;
    }

    @Override
    protected Edge makeElement(boolean includeHidden) {
        return new AccumuloEdge(
                this.graph,
                this.getId(),
                this.outVertexId,
                this.inVertexId,
                this.label,
                null,
                this.getVisibility(),
                this.getProperties(includeHidden),
                null,
                this.getHiddenVisibilities(),
                this.getAuthorizations(),
                this.timestamp
        );
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy