Search in sources :

Example 16 with GraphAttribute

use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.

the class GraphRecordStoreUtilities method copySpecifiedVertex.

/**
 * Copy the attribute values of a single graph vertex to a
 * {@link RecordStore}.
 *
 * @param graph A {@link GraphReadMethods} from which the RecordStore will
 * be created
 * @param recordStore A {@link RecordStore} to which the vertices will be
 * copied. If null, a new {@link RecordStore} will be created.
 * @param vxId The vertex id of the vertex being copied.
 * @param copiedId An array of {@link String} containing the id of the
 * vertex in the {@link RecordStore} in the zeroth position.
 * @return A {@link RecordStore} with the vertex copied to it. This will be
 * the supplied {@link RecordStore} if it was not null.
 */
public static RecordStore copySpecifiedVertex(final GraphReadMethods graph, RecordStore recordStore, final int vxId, final String[] copiedId) {
    if (recordStore == null) {
        recordStore = new GraphRecordStore();
    }
    final int attributeCount = graph.getAttributeCount(GraphElementType.VERTEX);
    final Attribute[] attributes = new Attribute[attributeCount];
    for (int a = 0; a < attributeCount; a++) {
        final int attributeId = graph.getAttribute(GraphElementType.VERTEX, a);
        attributes[a] = new GraphAttribute(graph, attributeId);
    }
    final StringBuilder sb = new StringBuilder();
    recordStore.add();
    for (Attribute attribute : attributes) {
        sb.setLength(0);
        sb.append(SOURCE).append(attribute.getName()).append("<").append(attribute.getAttributeType()).append(">");
        recordStore.set(sb.toString(), graph.getStringValue(attribute.getId(), vxId));
    }
    String copyId = "";
    for (int primarykeyAttr : graph.getPrimaryKey(GraphElementType.VERTEX)) {
        final String val = graph.getStringValue(primarykeyAttr, vxId);
        copyId += graph.getAttributeName(primarykeyAttr) + "<" + (StringUtils.defaultString(val)) + ">";
    }
    copiedId[0] = COPY + copyId;
    recordStore.set(SOURCE + ID, copiedId[0]);
    return recordStore;
}
Also used : Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute)

Example 17 with GraphAttribute

use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.

the class GraphRecordStoreUtilities method getVertices.

/**
 * Populate a new {@link RecordStore} with the attribute values of the
 * vertices from the specified graph. This method also offers the ability to
 * start collecting vertices from the specified offset value, and to limit
 * to a specified number of results - essentially allowing paginated
 * queries.
 *
 * @param graph A {@link GraphReadMethods} from which {@link RecordStore}
 * will be created.
 * @param selectedOnly A boolean value specifying whether or not to only
 * include selected graph elements in the {@link RecordStore}.
 * @param singletonsOnly Only include singleton vertices. This is useful
 * when building a RecordStore that reflects the graph structure.
 * @param disassociateIds If true, the ids of the graph elements in the
 * created {@link RecordStore} will be distinct from the ids of the graph
 * elements on the graph.
 * @param offset An array of integers, where the zeroth value represents the
 * vertex position from which to begin collection.
 * @param limit An integer value representing the maximum number of vertices
 * to collect.
 * @return A {@link RecordStore} representing the graph's vertices.
 */
public static GraphRecordStore getVertices(final GraphReadMethods graph, final boolean singletonsOnly, final boolean selectedOnly, final boolean disassociateIds, final int[] offset, final int limit) {
    final GraphRecordStore recordStore = new GraphRecordStore();
    final int attributeCount = graph.getAttributeCount(GraphElementType.VERTEX);
    final Attribute[] attributes = new Attribute[attributeCount];
    for (int a = 0; a < attributeCount; a++) {
        final int attributeId = graph.getAttribute(GraphElementType.VERTEX, a);
        attributes[a] = new GraphAttribute(graph, attributeId);
    }
    final int selected = graph.getAttribute(GraphElementType.VERTEX, SELECTED_ATTRIBUTE_NAME);
    final int vertexCount = graph.getVertexCount();
    boolean limitReached = false;
    for (int v = offset[0]; v < vertexCount; v++) {
        final int vxId = graph.getVertex(v);
        if ((!selectedOnly || graph.getBooleanValue(selected, vxId)) && (!singletonsOnly || graph.getVertexNeighbourCount(vxId) == 0)) {
            recordStore.add();
            for (final Attribute attribute : attributes) {
                final String type = attribute.getAttributeType();
                recordStore.set(SOURCE + attribute.getName() + "<" + type + ">", graph.getStringValue(attribute.getId(), vxId));
            }
            recordStore.set(SOURCE + ID, disassociateIds ? "id-" + vxId : String.valueOf(vxId));
            if (limit > 0 && recordStore.size() >= limit) {
                offset[0] = v + 1;
                limitReached = true;
                break;
            }
        }
    }
    if (!limitReached) {
        offset[0] = graph.getVertexCount();
    }
    return recordStore;
}
Also used : Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute)

Example 18 with GraphAttribute

use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.

the class GraphRecordStoreUtilities method getTransactions.

/**
 * Populate a new {@link RecordStore} with the attribute values of the
 * transactions and their endpoint vertices.
 *
 * @param graph A {@link GraphReadMethods} from which the RecordStore will
 * be created.
 * @param selectedOnly A boolean value specifying whether or not to only
 * include selected transactions in the {@link RecordStore}.
 * @param disassociateIds If true, the ids of the transactions in the
 * created {@link RecordStore} will be distinct from the ids of the
 * transactions on the graph.
 * @return A {@link RecordStore} representing the graph's transactions.
 */
public static GraphRecordStore getTransactions(final GraphReadMethods graph, final boolean selectedOnly, final boolean disassociateIds) {
    final GraphRecordStore recordStore = new GraphRecordStore();
    final int transactionAttributeCount = graph.getAttributeCount(GraphElementType.TRANSACTION);
    final Attribute[] transactionAttributes = new Attribute[transactionAttributeCount];
    for (int a = 0; a < transactionAttributeCount; a++) {
        final int attributeId = graph.getAttribute(GraphElementType.TRANSACTION, a);
        transactionAttributes[a] = new GraphAttribute(graph, attributeId);
    }
    final int vertexAttributeCount = graph.getAttributeCount(GraphElementType.VERTEX);
    final Attribute[] vertexAttributes = new Attribute[vertexAttributeCount];
    for (int a = 0; a < vertexAttributeCount; a++) {
        final int attributeId = graph.getAttribute(GraphElementType.VERTEX, a);
        vertexAttributes[a] = new GraphAttribute(graph, attributeId);
    }
    final int selected = graph.getAttribute(GraphElementType.TRANSACTION, SELECTED_ATTRIBUTE_NAME);
    final int transactionCount = graph.getTransactionCount();
    for (int t = 0; t < transactionCount; t++) {
        final int txId = graph.getTransaction(t);
        final int source = graph.getTransactionSourceVertex(txId);
        final int destination = graph.getTransactionDestinationVertex(txId);
        if (!selectedOnly || graph.getBooleanValue(selected, txId)) {
            recordStore.add();
            for (final Attribute transactionAttribute : transactionAttributes) {
                final String type = transactionAttribute.getAttributeType();
                recordStore.set(TRANSACTION + transactionAttribute.getName() + "<" + type + ">", graph.getStringValue(transactionAttribute.getId(), txId));
            }
            for (final Attribute vertexAttribute : vertexAttributes) {
                final String type = vertexAttribute.getAttributeType();
                recordStore.set(SOURCE + vertexAttribute.getName() + "<" + type + ">", graph.getStringValue(vertexAttribute.getId(), source));
                recordStore.set(DESTINATION + vertexAttribute.getName() + "<" + type + ">", graph.getStringValue(vertexAttribute.getId(), destination));
            }
            if (graph.getTransactionDirection(txId) == Graph.UNDIRECTED) {
                recordStore.set(TRANSACTION + DIRECTED_KEY, FALSE);
            }
            recordStore.set(TRANSACTION + ID, disassociateIds ? "id-" + txId : String.valueOf(txId));
            recordStore.set(SOURCE + ID, disassociateIds ? "id-" + source : String.valueOf(source));
            recordStore.set(DESTINATION + ID, disassociateIds ? "id-" + destination : String.valueOf(destination));
        }
    }
    return recordStore;
}
Also used : Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute)

Example 19 with GraphAttribute

use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.

the class GraphRecordStoreUtilities method copySelectedVertices.

/**
 * Puts all selected vertices in a {@link RecordStore} ready to be pasted
 * into another graph.
 * <p>
 * There are a few differences from {@link #getSelectedVertices} that are
 * specific to the requirement of copying to another graph:
 * <ul>
 * <li>Ids must not be valid graph ids otherwise they may clash with
 * elements on a destination graph</li>
 * <li>The keys for the attributes are suffixed with the attribute types as
 * the receiving graph may not have these attributes.</li>
 * <li>This method can be used when copying transactions to add 'ghost
 * vertices' to the {@link RecordStore}, that is vertices which are not
 * selected but where an incident transaction is. This allows selected
 * transaction to be pasted onto a destination graph if and only if the
 * endpoints which are not selected exist on that graph </li>
 * </ul>
 *
 * @param graph A {@link GraphReadMethods} from which the
 * {@link RecordStore} will be created.
 * @param recordStore A {@link RecordStore} to which the vertices will be
 * copied. If null, a new {@link RecordStore} will be created.
 * @param transactionEndPoints A {@link BitSet} containing ids of vertices
 * that are endpoints of selected transactions. When using this method to
 * purely copy vertices, this can be empty.
 * @return a {@link RecordStore} representing the selected vertices that can
 * be added to another graph. This will be the supplied {@link RecordStore}
 * if it was not null.
 */
public static RecordStore copySelectedVertices(final GraphReadMethods graph, RecordStore recordStore, final BitSet transactionEndPoints) {
    if (recordStore == null) {
        recordStore = new GraphRecordStore();
    }
    final int attributeCount = graph.getAttributeCount(GraphElementType.VERTEX);
    final Attribute[] attributes = new Attribute[attributeCount];
    for (int a = 0; a < attributeCount; a++) {
        final int attributeId = graph.getAttribute(GraphElementType.VERTEX, a);
        attributes[a] = new GraphAttribute(graph, attributeId);
    }
    final int selected = graph.getAttribute(GraphElementType.VERTEX, SELECTED_ATTRIBUTE_NAME);
    final int vertexCount = graph.getVertexCount();
    final StringBuilder sb = new StringBuilder();
    for (int position = 0; position < vertexCount; position++) {
        final int vxId = graph.getVertex(position);
        if (graph.getBooleanValue(selected, vxId) || transactionEndPoints.get(vxId)) {
            recordStore.add();
            for (Attribute attribute : attributes) {
                sb.setLength(0);
                sb.append(SOURCE).append(attribute.getName()).append("<").append(attribute.getAttributeType()).append(">");
                recordStore.set(sb.toString(), graph.getStringValue(attribute.getId(), vxId));
            }
            recordStore.set(SOURCE + ID, COPY + String.valueOf(vxId));
        }
        if (transactionEndPoints.get(vxId) && !graph.getBooleanValue(selected, vxId)) {
            // will be checked if it has a value to denote true.
            recordStore.set(SOURCE + GHOST, "");
        }
    }
    return recordStore;
}
Also used : Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute)

Example 20 with GraphAttribute

use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.

the class GraphRecordStoreUtilities method copyTransactionsToComposite.

/**
 * Takes transactions connected to the constituent of an expanded composite
 * and adds to a {@link RecordStore} copies of the corresponding
 * transactions connected instead to the composite itself. This is used when
 * a composite node is contracted.
 *
 * @param graph A {@link GraphReadMethods} from which the
 * {@link RecordStore} will be created.
 * @param recordStore The {@link RecordStore} to add the transactions to.
 * @param expandedVxId The vertex id of the composite constituent to copy
 * transactions from.
 * @param expandedId The id of the composite constituent to be used in the
 * {@link RecordStore}.
 * @param expandedIds The set of expandedIds.
 * @param toId The id of the composite node to be used in the
 * {@link RecordStore}.
 * @param uniqueIdAttr The id of uniqueId attribute for transactions. This
 * is required as the uniqueId attribute is used to hold information about
 * the original source and destination vertices of transactions connected to
 * composite nodes.
 */
public static void copyTransactionsToComposite(final GraphReadMethods graph, final RecordStore recordStore, final int expandedVxId, final String expandedId, final Set<Integer> expandedIds, final String toId, final Attribute uniqueIdAttr) {
    final int transactionAttributeCount = graph.getAttributeCount(GraphElementType.TRANSACTION);
    final Attribute[] transactionAttributes = new Attribute[transactionAttributeCount];
    for (int a = 0; a < transactionAttributeCount; a++) {
        final int attributeId = graph.getAttribute(GraphElementType.TRANSACTION, a);
        transactionAttributes[a] = new GraphAttribute(graph, attributeId);
    }
    final int transactionCount = graph.getVertexTransactionCount(expandedVxId);
    for (int t = 0; t < transactionCount; t++) {
        final int transaction = graph.getVertexTransaction(expandedVxId, t);
        final int source = graph.getTransactionSourceVertex(transaction);
        final int destination = graph.getTransactionDestinationVertex(transaction);
        // Don't add to a composite those transactions which are between two constituents of the composite!
        if (expandedIds.contains(source) && expandedIds.contains(destination)) {
            continue;
        }
        final CompositeTransactionId compositeTransactionId = CompositeTransactionId.fromString(graph.getStringValue(uniqueIdAttr.getId(), transaction));
        String sourceId = null;
        String destId = null;
        String uniqueId;
        if (expandedVxId == source) {
            destId = String.valueOf(destination);
            if (!compositeTransactionId.isSourceContracted() && compositeTransactionId.getOriginalSourceNode() != null) {
                sourceId = compositeTransactionId.getOriginalSourceNode();
                compositeTransactionId.setOriginalSourceNode(null);
                uniqueId = compositeTransactionId.toString();
            } else {
                sourceId = toId;
                compositeTransactionId.setSourceContracted(true);
                compositeTransactionId.setOriginalSourceNode(expandedId);
                uniqueId = compositeTransactionId.toString();
            }
        } else {
            sourceId = String.valueOf(source);
            if (!compositeTransactionId.isDestContracted() && compositeTransactionId.getOriginalDestinationNode() != null) {
                destId = compositeTransactionId.getOriginalDestinationNode();
                compositeTransactionId.setOriginalDestinationNode(null);
                uniqueId = compositeTransactionId.toString();
            } else {
                destId = toId;
                compositeTransactionId.setDestContracted(true);
                compositeTransactionId.setOriginalDestinationNode(expandedId);
                uniqueId = compositeTransactionId.toString();
            }
        }
        recordStore.add();
        for (Attribute transactionAttribute : transactionAttributes) {
            final String value = transactionAttribute.getName().equals(uniqueIdAttr.getName()) ? uniqueId : graph.getStringValue(transactionAttribute.getId(), transaction);
            recordStore.set(TRANSACTION + transactionAttribute.getName() + "<" + transactionAttribute.getAttributeType() + ">", value);
        }
        if (graph.getTransactionDirection(transaction) == Graph.UNDIRECTED) {
            recordStore.set(TRANSACTION + DIRECTED_KEY, FALSE);
        }
        recordStore.set(TRANSACTION + ID, COPY + String.format(NUMBER_STRING_STRING_FORMAT, transaction, sourceId, destId));
        recordStore.set(SOURCE + ID, sourceId);
        recordStore.set(DESTINATION + ID, destId);
    }
}
Also used : Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) CompositeTransactionId(au.gov.asd.tac.constellation.graph.utilities.CompositeTransactionId)

Aggregations

GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)65 Attribute (au.gov.asd.tac.constellation.graph.Attribute)45 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)25 ArrayList (java.util.ArrayList)25 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)19 HashMap (java.util.HashMap)16 Test (org.testng.annotations.Test)15 GraphNode (au.gov.asd.tac.constellation.graph.node.GraphNode)10 FindRule (au.gov.asd.tac.constellation.views.find.advanced.FindRule)9 Graph (au.gov.asd.tac.constellation.graph.Graph)8 AdvancedFindPlugin (au.gov.asd.tac.constellation.views.find.advanced.AdvancedFindPlugin)8 FindResult (au.gov.asd.tac.constellation.views.find.advanced.FindResult)8 TopComponent (org.openide.windows.TopComponent)8 TableColumn (javafx.scene.control.TableColumn)6 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)5 List (java.util.List)5 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)4 Column (au.gov.asd.tac.constellation.views.tableview.api.Column)4 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)3 GraphRecordStoreUtilities (au.gov.asd.tac.constellation.graph.processing.GraphRecordStoreUtilities)3