Search in sources :

Example 1 with ExpandedCompositeNodeState

use of au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ExpandedCompositeNodeState in project constellation by constellation-app.

the class CreateCompositeFromSelectionPlugin method edit.

@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    final int selectedAttr = VisualConcept.VertexAttribute.SELECTED.get(graph);
    if (selectedAttr != Graph.NOT_FOUND) {
        final Set<Integer> selectedVerts = new HashSet<>();
        for (int i = 0; i < graph.getVertexCount(); i++) {
            final int vxId = graph.getVertex(i);
            if (graph.getBooleanValue(selectedAttr, vxId)) {
                selectedVerts.add(vxId);
            }
        }
        if (selectedVerts.size() > 1) {
            final int compositeStateAttr = AnalyticConcept.VertexAttribute.COMPOSITE_STATE.ensure(graph);
            final int uniqueIdAttr = VisualConcept.TransactionAttribute.IDENTIFIER.get(graph);
            final int identifierAttr = VisualConcept.VertexAttribute.IDENTIFIER.get(graph);
            // We first destroy any composites which are selected or expanded and have constituents selected.
            // For any composites, we also add any expanded ids and remove the destroyed composite id from the list of selected ids.
            final Set<Integer> addedVerts = new HashSet<>();
            final Set<Integer> removedVerts = new HashSet<>();
            selectedVerts.forEach(id -> {
                final List<Integer> resultingVerts = CompositeUtilities.destroyComposite(graph, compositeStateAttr, uniqueIdAttr, id);
                if (!resultingVerts.isEmpty()) {
                    removedVerts.add(id);
                    addedVerts.addAll(resultingVerts);
                }
            });
            // NOTE:: Remove before adding, because of id reuse!
            selectedVerts.removeAll(removedVerts);
            selectedVerts.addAll(addedVerts);
            final String compositeIdentifier = String.format("%s + %d more...", graph.getStringValue(identifierAttr, selectedVerts.iterator().next()), selectedVerts.size() - 1);
            String copyId = "";
            for (int primarykeyAttr : graph.getPrimaryKey(GraphElementType.VERTEX)) {
                final String val = graph.getStringValue(primarykeyAttr, selectedVerts.iterator().next());
                copyId += graph.getAttributeName(primarykeyAttr) + "<" + StringUtils.defaultString(val) + ">";
            }
            final String compositeId = copyId;
            // Make a record store representing the new composite that is about to be added
            RecordStore newCompositeStore = new GraphRecordStore();
            newCompositeStore.add();
            newCompositeStore.set(GraphRecordStoreUtilities.SOURCE + GraphRecordStoreUtilities.ID, compositeId);
            newCompositeStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER, compositeIdentifier);
            newCompositeStore.set(GraphRecordStoreUtilities.SOURCE + AnalyticConcept.VertexAttribute.TYPE, SchemaVertexTypeUtilities.getDefaultType());
            // Construct and set an expanded composite node state for each of the nodes that will constitute the composite.
            selectedVerts.forEach(id -> {
                ExpandedCompositeNodeState expandedState = new ExpandedCompositeNodeState(newCompositeStore, compositeId, true, selectedVerts.size());
                graph.setObjectValue(compositeStateAttr, id, new CompositeNodeState(id, expandedState));
            });
            // Create the composite by calling contract on the first node's expanded composite state.
            ((CompositeNodeState) graph.getObjectValue(compositeStateAttr, selectedVerts.iterator().next())).expandedState.contract(graph);
        }
    }
    PluginExecution.withPlugin(VisualSchemaPluginRegistry.COMPLETE_SCHEMA).executeNow(graph);
}
Also used : CompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.CompositeNodeState) ExpandedCompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ExpandedCompositeNodeState) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) ExpandedCompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ExpandedCompositeNodeState) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) HashSet(java.util.HashSet)

Example 2 with ExpandedCompositeNodeState

use of au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ExpandedCompositeNodeState in project constellation by constellation-app.

the class CompositeUtilities method makeComposite.

/**
 * Make a composite node by specifying a lead node id and a set of the
 * comprising node id's
 *
 * @param graph The graph
 * @param comprisingIds A Set of the comprising node id's to be composited
 * @param leaderId The lead node id to contain the composited nodes
 */
public static void makeComposite(final GraphWriteMethods graph, final Set<Integer> comprisingIds, final int leaderId) {
    final int compositeStateAttr = AnalyticConcept.VertexAttribute.COMPOSITE_STATE.ensure(graph);
    final int uniqueIdAttr = VisualConcept.TransactionAttribute.IDENTIFIER.get(graph);
    // We first destroy any composites or composite constituents about to be composited.
    // For any composites, we also add any expanded ids and remove the destroyed composite id from the list of selected ids.
    final Set<Integer> addedVerts = new HashSet<>();
    final Set<Integer> removedVerts = new HashSet<>();
    comprisingIds.forEach(vxId -> {
        final List<Integer> resultingVerts = CompositeUtilities.destroyComposite(graph, compositeStateAttr, uniqueIdAttr, vxId);
        if (!resultingVerts.isEmpty()) {
            removedVerts.add(vxId);
            addedVerts.addAll(resultingVerts);
        }
    });
    // NOTE:: Remove before adding, because of id reuse!
    comprisingIds.removeAll(removedVerts);
    comprisingIds.addAll(addedVerts);
    // Make a record store representing the new composite that is about to be added
    final String[] compositeId = new String[1];
    final RecordStore newCompositeStore = new GraphRecordStore();
    GraphRecordStoreUtilities.copySpecifiedVertex(graph, newCompositeStore, leaderId, compositeId);
    // Construct and set an expanded composite node state for each of the nodes that will constitute the composite.
    comprisingIds.forEach(vxId -> {
        final ExpandedCompositeNodeState expandedState = new ExpandedCompositeNodeState(newCompositeStore, compositeId[0], true, comprisingIds.size());
        graph.setObjectValue(compositeStateAttr, vxId, new CompositeNodeState(vxId, expandedState));
    });
    // Create the composite by calling contract on the first node's expanded composite state.
    ((CompositeNodeState) graph.getObjectValue(compositeStateAttr, comprisingIds.iterator().next())).expandedState.contract(graph);
}
Also used : CompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.CompositeNodeState) ExpandedCompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ExpandedCompositeNodeState) ContractedCompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ContractedCompositeNodeState) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) ExpandedCompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ExpandedCompositeNodeState) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) HashSet(java.util.HashSet)

Aggregations

GraphRecordStore (au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)2 RecordStore (au.gov.asd.tac.constellation.graph.processing.RecordStore)2 CompositeNodeState (au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.CompositeNodeState)2 ExpandedCompositeNodeState (au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ExpandedCompositeNodeState)2 HashSet (java.util.HashSet)2 ContractedCompositeNodeState (au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ContractedCompositeNodeState)1