Search in sources :

Example 31 with Attribute

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

the class GraphRecordStoreUtilities method copyTransactionsBetweenVertices.

/**
 * Take transactions between two constituents of an expanded composite and
 * add to a {@link RecordStore} copies of these transactions. This is used
 * when a composite node is contracted so that these transactions can be *
 * added back when it is expanded.
 *
 * @param graph A {@link GraphReadMethods} from which the
 * {@link RecordStore} will be created.
 * @param recordStore The {@link RecordStore} to add the transactions to.
 * @param fromVxId The vertex id of the first composite constituent.
 * @param toVxId The vertex id of the second composite constituent.
 * @param fromId The id of the first composite constituent to be used in the
 * {@link RecordStore}.
 * @param toId The id of the first composite constituent to be used in the
 * {@link RecordStore}.
 */
public static void copyTransactionsBetweenVertices(final GraphReadMethods graph, final RecordStore recordStore, final int fromVxId, final int toVxId, final String fromId, final String toId) {
    final int transactionAttributeCount = graph.getAttributeCount(GraphElementType.TRANSACTION);
    final Attribute[] transactionAttributes = new Attribute[transactionAttributeCount];
    for (int a = 0; a < transactionAttributeCount; a++) {
        int attributeId = graph.getAttribute(GraphElementType.TRANSACTION, a);
        transactionAttributes[a] = new GraphAttribute(graph, attributeId);
    }
    final int lxId = graph.getLink(fromVxId, toVxId);
    if (lxId != Graph.NOT_FOUND) {
        final int transactionCount = graph.getLinkTransactionCount(lxId);
        for (int t = 0; t < transactionCount; t++) {
            final int transaction = graph.getLinkTransaction(lxId, t);
            final int source = graph.getTransactionSourceVertex(transaction);
            final String sourceId = source == fromVxId ? fromId : toId;
            final String destId = source == fromVxId ? toId : fromId;
            recordStore.add();
            for (Attribute transactionAttribute : transactionAttributes) {
                final String value = 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)

Example 32 with Attribute

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

the class CopyGraphUtilities method copyGraphToGraph.

/**
 * Adapted from CopySelectedElementsPlugin.makeGraph
 *
 * @param original - the Graph to copy elements from
 * @param graph - the Graph to copy elements to
 * @param copyAll - whether to copy all elements or just the selected ones
 */
public static void copyGraphToGraph(final GraphReadMethods original, final GraphWriteMethods graph, final boolean copyAll) {
    final int vertexSelected = original.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.SELECTED.getName());
    final int transactionSelected = original.getAttribute(GraphElementType.TRANSACTION, VisualConcept.TransactionAttribute.SELECTED.getName());
    final int[] attributeTranslation = new int[original.getAttributeCapacity()];
    // Copy the attributes.
    for (final GraphElementType type : GraphElementType.values()) {
        final int attributeCount = original.getAttributeCount(type);
        for (int attributePosition = 0; attributePosition < attributeCount; attributePosition++) {
            int originalAttributeId = original.getAttribute(type, attributePosition);
            final Attribute attribute = new GraphAttribute(original, originalAttributeId);
            int newAttributeId = graph.getAttribute(type, attribute.getName());
            if (newAttributeId == Graph.NOT_FOUND) {
                newAttributeId = graph.addAttribute(type, attribute.getAttributeType(), attribute.getName(), attribute.getDescription(), attribute.getDefaultValue(), null);
            }
            attributeTranslation[originalAttributeId] = newAttributeId;
            if (type == GraphElementType.GRAPH) {
                graph.setObjectValue(newAttributeId, 0, original.getObjectValue(originalAttributeId, 0));
            }
        }
    }
    // Copy the vertices.
    final int[] vertexTranslation = new int[original.getVertexCapacity()];
    for (int position = 0; position < original.getVertexCount(); position++) {
        final int originalVertex = original.getVertex(position);
        if (copyAll || vertexSelected == Graph.NOT_FOUND || original.getBooleanValue(vertexSelected, originalVertex)) {
            final int newVertex = graph.addVertex();
            vertexTranslation[originalVertex] = newVertex;
            for (int attributePosition = 0; attributePosition < original.getAttributeCount(GraphElementType.VERTEX); attributePosition++) {
                final int originalAttributeId = original.getAttribute(GraphElementType.VERTEX, attributePosition);
                final int newAttributeId = attributeTranslation[originalAttributeId];
                graph.setObjectValue(newAttributeId, newVertex, original.getObjectValue(originalAttributeId, originalVertex));
            }
        }
    }
    // Copy the transactions.
    final int[] edgeTranslation = new int[original.getEdgeCapacity()];
    final int[] linkTranslation = new int[original.getLinkCapacity()];
    for (int position = 0; position < original.getTransactionCount(); position++) {
        final int originalTransaction = original.getTransaction(position);
        if (!copyAll && ((transactionSelected != Graph.NOT_FOUND && !original.getBooleanValue(transactionSelected, originalTransaction)) || (vertexSelected != Graph.NOT_FOUND && (!original.getBooleanValue(vertexSelected, original.getTransactionSourceVertex(originalTransaction)) || !original.getBooleanValue(vertexSelected, original.getTransactionDestinationVertex(originalTransaction)))))) {
            continue;
        }
        final int sourceVertex = vertexTranslation[original.getTransactionSourceVertex(originalTransaction)];
        final int destinationVertex = vertexTranslation[original.getTransactionDestinationVertex(originalTransaction)];
        final boolean directed = original.getTransactionDirection(originalTransaction) < 2;
        final int newTransaction = graph.addTransaction(sourceVertex, destinationVertex, directed);
        // add the edge translations
        final int originalEdge = original.getTransactionEdge(originalTransaction);
        final int newEdge = graph.getTransactionEdge(newTransaction);
        edgeTranslation[originalEdge] = newEdge;
        // add the link translations
        final int originalLink = original.getTransactionLink(originalTransaction);
        final int newLink = graph.getTransactionLink(newTransaction);
        linkTranslation[originalLink] = newLink;
        for (int attributePosition = 0; attributePosition < original.getAttributeCount(GraphElementType.TRANSACTION); attributePosition++) {
            final int originalAttributeId = original.getAttribute(GraphElementType.TRANSACTION, attributePosition);
            final int newAttributeId = attributeTranslation[originalAttributeId];
            graph.setObjectValue(newAttributeId, newTransaction, original.getObjectValue(originalAttributeId, originalTransaction));
        }
    }
    // Copy the edges
    for (int position = 0; position < original.getEdgeCount(); position++) {
        final int originalEdge = original.getEdge(position);
        if (!copyAll && ((transactionSelected != Graph.NOT_FOUND && !original.getBooleanValue(transactionSelected, originalEdge)) || (vertexSelected != Graph.NOT_FOUND && (!original.getBooleanValue(vertexSelected, original.getEdgeSourceVertex(originalEdge)) || !original.getBooleanValue(vertexSelected, original.getEdgeDestinationVertex(originalEdge)))))) {
            continue;
        }
        for (int attributePosition = 0; attributePosition < original.getAttributeCount(GraphElementType.EDGE); attributePosition++) {
            final int originalAttributeId = original.getAttribute(GraphElementType.EDGE, attributePosition);
            final int newAttributeId = attributeTranslation[originalAttributeId];
            graph.setObjectValue(newAttributeId, edgeTranslation[originalEdge], original.getObjectValue(originalAttributeId, originalEdge));
        }
    }
    // Copy the links
    for (int position = 0; position < original.getLinkCount(); position++) {
        final int originalLink = original.getLink(position);
        if (!copyAll && ((transactionSelected != Graph.NOT_FOUND && !original.getBooleanValue(transactionSelected, originalLink)) || (vertexSelected != Graph.NOT_FOUND && (!original.getBooleanValue(vertexSelected, original.getEdgeSourceVertex(originalLink)) || !original.getBooleanValue(vertexSelected, original.getEdgeDestinationVertex(originalLink)))))) {
            continue;
        }
        for (int attributePosition = 0; attributePosition < original.getAttributeCount(GraphElementType.LINK); attributePosition++) {
            final int originalAttributeId = original.getAttribute(GraphElementType.LINK, attributePosition);
            final int newAttributeId = attributeTranslation[originalAttributeId];
            graph.setObjectValue(newAttributeId, linkTranslation[originalLink], original.getObjectValue(originalAttributeId, originalLink));
        }
    }
}
Also used : GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType)

Example 33 with Attribute

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

the class CopyGraphUtilities method copyGraphTypeElements.

/**
 * Copy a graph attribute and its values to a new graph
 *
 * @param original Original graph
 * @param graph New graph
 */
public static void copyGraphTypeElements(final GraphReadMethods original, final GraphWriteMethods graph) {
    final int attributeCount = original.getAttributeCount(GraphElementType.GRAPH);
    for (int attributePosition = 0; attributePosition < attributeCount; attributePosition++) {
        int originalAttributeId = original.getAttribute(GraphElementType.GRAPH, attributePosition);
        final Attribute attribute = new GraphAttribute(original, originalAttributeId);
        int newAttributeId = graph.getAttribute(GraphElementType.GRAPH, attribute.getName());
        if (newAttributeId == Graph.NOT_FOUND) {
            newAttributeId = graph.addAttribute(GraphElementType.GRAPH, attribute.getAttributeType(), attribute.getName(), attribute.getDescription(), attribute.getDefaultValue(), null);
        }
        graph.setObjectValue(newAttributeId, 0, original.getObjectValue(originalAttributeId, 0));
    }
}
Also used : GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute)

Example 34 with Attribute

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

the class ImportController method updateAutoAddedAttributes.

/**
 * Get the attributes that will automatically be added to the attribute
 * list.
 *
 * @param elementType
 * @param attributes
 * @param rg
 */
private void updateAutoAddedAttributes(final GraphElementType elementType, final Map<String, Attribute> attributes, final GraphReadMethods rg, final boolean showSchemaAttributes) {
    attributes.clear();
    // Add attributes from the graph
    int attributeCount = rg.getAttributeCount(elementType);
    for (int i = 0; i < attributeCount; i++) {
        int attributeId = rg.getAttribute(elementType, i);
        Attribute attribute = new GraphAttribute(rg, attributeId);
        attributes.put(attribute.getName(), attribute);
    }
    // Add attributes from the schema
    if (showSchemaAttributes && rg.getSchema() != null) {
        final SchemaFactory factory = rg.getSchema().getFactory();
        for (final SchemaAttribute sattr : factory.getRegisteredAttributes(elementType).values()) {
            final Attribute attribute = new GraphAttribute(elementType, sattr.getAttributeType(), sattr.getName(), sattr.getDescription());
            if (!attributes.containsKey(attribute.getName())) {
                attributes.put(attribute.getName(), attribute);
            }
        }
    }
    // Add pseudo-attributes
    if (elementType == GraphElementType.TRANSACTION) {
        final Attribute attribute = new GraphAttribute(elementType, BooleanAttributeDescription.ATTRIBUTE_NAME, DIRECTED, "Is this transaction directed?");
        attributes.put(attribute.getName(), attribute);
    }
    // Add primary keys
    for (int key : rg.getPrimaryKey(elementType)) {
        keys.add(key);
    }
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) Attribute(au.gov.asd.tac.constellation.graph.Attribute) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)

Example 35 with Attribute

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

the class ImportController method updateDisplayedAttributes.

public void updateDisplayedAttributes() {
    if (configurationPane != null) {
        displayedVertexAttributes = createDisplayedAttributes(autoAddedVertexAttributes, manuallyAddedVertexAttributes);
        displayedTransactionAttributes = createDisplayedAttributes(autoAddedTransactionAttributes, manuallyAddedTransactionAttributes);
        for (Attribute attribute : configurationPane.getAllocatedAttributes()) {
            if (attribute.getElementType() == GraphElementType.VERTEX) {
                if (!displayedVertexAttributes.containsKey(attribute.getName())) {
                    Attribute newAttribute = new NewAttribute(attribute);
                    displayedVertexAttributes.put(newAttribute.getName(), newAttribute);
                }
            } else {
                if (!displayedTransactionAttributes.containsKey(attribute.getName())) {
                    Attribute newAttribute = new NewAttribute(attribute);
                    displayedTransactionAttributes.put(newAttribute.getName(), newAttribute);
                }
            }
        }
        configurationPane.setDisplayedAttributes(displayedVertexAttributes, displayedTransactionAttributes, keys);
    }
}
Also used : Attribute(au.gov.asd.tac.constellation.graph.Attribute) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute)

Aggregations

Attribute (au.gov.asd.tac.constellation.graph.Attribute)94 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)55 ArrayList (java.util.ArrayList)30 Test (org.testng.annotations.Test)23 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)18 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)15 TableViewState (au.gov.asd.tac.constellation.views.tableview.state.TableViewState)13 Graph (au.gov.asd.tac.constellation.graph.Graph)12 BasicFindReplaceParameters (au.gov.asd.tac.constellation.views.find2.utilities.BasicFindReplaceParameters)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 ObservableList (javafx.collections.ObservableList)8 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)7 Column (au.gov.asd.tac.constellation.views.tableview.api.Column)7 TableColumn (javafx.scene.control.TableColumn)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)6 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)5 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)5 Tuple (au.gov.asd.tac.constellation.utilities.datastructure.Tuple)5 JsonFactory (com.fasterxml.jackson.core.JsonFactory)5