Search in sources :

Example 11 with GraphRecordStore

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

the class CompareGraphPluginNGTest method testReadWithDuplicateGraphScenarioInReverse.

// @Test(expectedExceptions = DuplicateKeyException.class)
@Test
public void testReadWithDuplicateGraphScenarioInReverse() throws InterruptedException {
    int vx0, vx1, vx2, tx0, tx1;
    int identifierAttribute, vertexTypeAttribute, uniqueIdAttribute, transactionTypeAttribute, transactionDateTimeAttribute;
    final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
    final StoreGraph originalGraph = new StoreGraph(schema);
    identifierAttribute = VisualConcept.VertexAttribute.IDENTIFIER.ensure(originalGraph);
    vertexTypeAttribute = AnalyticConcept.VertexAttribute.TYPE.ensure(originalGraph);
    uniqueIdAttribute = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(originalGraph);
    transactionTypeAttribute = AnalyticConcept.TransactionAttribute.TYPE.ensure(originalGraph);
    transactionDateTimeAttribute = TemporalConcept.TransactionAttribute.DATETIME.ensure(originalGraph);
    originalGraph.setPrimaryKey(GraphElementType.VERTEX, identifierAttribute, vertexTypeAttribute);
    originalGraph.setPrimaryKey(GraphElementType.TRANSACTION, uniqueIdAttribute, transactionTypeAttribute, transactionDateTimeAttribute);
    originalGraph.validateKeys();
    vx0 = originalGraph.addVertex();
    vx1 = originalGraph.addVertex();
    vx2 = originalGraph.addVertex();
    tx0 = originalGraph.addTransaction(vx0, vx1, true);
    tx1 = originalGraph.addTransaction(vx1, vx2, true);
    originalGraph.setStringValue(identifierAttribute, vx0, "Vertex #0");
    originalGraph.setStringValue(identifierAttribute, vx1, "Vertex #1");
    // mimic creating nodes on visual schema which will create a DuplicateKeyException - i.e. this is a known issue
    originalGraph.setStringValue(identifierAttribute, vx2, "Vertex #2");
    originalGraph.setStringValue(vertexTypeAttribute, vx0, "Unknown");
    originalGraph.setStringValue(vertexTypeAttribute, vx1, "Unknown");
    originalGraph.setStringValue(vertexTypeAttribute, vx2, "Unknown");
    Graph compareGraph;
    GraphRecordStore compareAll;
    try {
        final Plugin copyGraphPlugin = PluginRegistry.get(InteractiveGraphPluginRegistry.COPY_TO_NEW_GRAPH);
        final PluginParameters copyGraphParams = copyGraphPlugin.createParameters();
        PluginExecution.withPlugin(copyGraphPlugin).withParameters(copyGraphParams).executeNow((GraphReadMethods) originalGraph);
        compareGraph = (Graph) copyGraphParams.getParameters().get(CopyToNewGraphPlugin.NEW_GRAPH_OUTPUT_PARAMETER_ID).getObjectValue();
    } catch (PluginException ex) {
        compareGraph = null;
        Assert.fail(ex.getLocalizedMessage());
    }
    final WritableGraph wg = compareGraph.getWritableGraph("remove a node", true);
    try {
        Assert.assertEquals(wg.getVertexCount(), 3);
        wg.removeVertex(vx1);
        Assert.assertEquals(wg.getVertexCount(), 2);
    } finally {
        wg.commit();
    }
    final ReadableGraph rg = compareGraph.getReadableGraph();
    try {
        compareAll = GraphRecordStoreUtilities.getAll(rg, false, true);
    } finally {
        rg.release();
    }
    final GraphRecordStore originalAll = GraphRecordStoreUtilities.getAll(originalGraph, false, true);
    Set<String> vertexPrimaryKeys = null;
    Set<String> transactionPrimaryKeys = null;
    final ReadableGraph rg2 = compareGraph.getReadableGraph();
    try {
        vertexPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(rg2, GraphElementType.VERTEX);
        transactionPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(rg2, GraphElementType.TRANSACTION);
    } finally {
        rg2.release();
    }
    final List<String> ignoreVertexAttributes = new ArrayList<>();
    final List<String> ignoreTransactionAttributes = new ArrayList<>();
    ignoreVertexAttributes.add("[id]");
    ignoreTransactionAttributes.add("[id]");
    // debug
    System.out.println("originalAll ==>\n" + originalAll.toStringVerbose());
    System.out.println("compareAll ==>\n" + compareAll.toStringVerbose());
    final CompareGraphPlugin instance = new CompareGraphPlugin();
    Graph finalGraph = null;
    GraphRecordStore changes = new GraphRecordStore();
    try {
        changes = instance.compareGraphs("", compareAll, originalAll, vertexPrimaryKeys, transactionPrimaryKeys, ignoreVertexAttributes, ignoreTransactionAttributes, ADDED_COLOUR, REMOVED_COLOUR, CHANGED_COLOUR, UNCHANGED_COLOUR);
        System.out.println("changes ==>\n" + changes.toStringVerbose());
        // assertEquals(changes.size(), 3);
        finalGraph = instance.createComparisonGraph(compareGraph, changes);
    } catch (InterruptedException | PluginException ex) {
        Assert.fail(ex.getLocalizedMessage());
    }
    // }
    try {
        SaveGraphUtilities.saveGraphToTemporaryDirectory(originalGraph, "originalGraph");
        SaveGraphUtilities.saveGraphToTemporaryDirectory(compareGraph, "compareGraph", true);
        SaveGraphUtilities.saveGraphToTemporaryDirectory(finalGraph, "finalGraph", true);
    } catch (IOException | InterruptedException ex) {
        Assert.fail(ex.getLocalizedMessage());
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) CopyToNewGraphPlugin(au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToNewGraphPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Example 12 with GraphRecordStore

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

the class CompareGraphPluginNGTest method testReadWithDuplicateGraphScenario.

@Test
public void testReadWithDuplicateGraphScenario() throws InterruptedException {
    int vx0, vx1, vx2, tx0, tx1;
    int identifierAttribute, typeAttribute, uniqueIdAttribute;
    final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
    final StoreGraph originalGraph = new StoreGraph(schema);
    identifierAttribute = VisualConcept.VertexAttribute.IDENTIFIER.ensure(originalGraph);
    // typeAttribute = AnalyticConcept.VertexAttribute.TYPE.ensure(originalGraph);
    uniqueIdAttribute = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(originalGraph);
    originalGraph.setPrimaryKey(GraphElementType.VERTEX, identifierAttribute);
    originalGraph.setPrimaryKey(GraphElementType.TRANSACTION, uniqueIdAttribute);
    vx0 = originalGraph.addVertex();
    vx1 = originalGraph.addVertex();
    vx2 = originalGraph.addVertex();
    tx0 = originalGraph.addTransaction(vx0, vx1, true);
    tx1 = originalGraph.addTransaction(vx1, vx2, true);
    originalGraph.setStringValue(identifierAttribute, vx0, "vx0");
    originalGraph.setStringValue(identifierAttribute, vx1, "vx1");
    originalGraph.setStringValue(identifierAttribute, vx2, "vx2");
    Graph compareGraph;
    GraphRecordStore compareAll;
    try {
        final Plugin copyGraphPlugin = PluginRegistry.get(InteractiveGraphPluginRegistry.COPY_TO_NEW_GRAPH);
        final PluginParameters copyParams = copyGraphPlugin.createParameters();
        copyParams.getParameters().get(CopyToNewGraphPlugin.COPY_ALL_PARAMETER_ID).setBooleanValue(true);
        PluginExecution.withPlugin(copyGraphPlugin).withParameters(copyParams).executeNow((GraphReadMethods) originalGraph);
        compareGraph = (Graph) copyParams.getParameters().get(CopyToNewGraphPlugin.NEW_GRAPH_OUTPUT_PARAMETER_ID).getObjectValue();
    } catch (PluginException ex) {
        compareGraph = null;
        Assert.fail(ex.getLocalizedMessage());
    }
    final WritableGraph wg = compareGraph.getWritableGraph("remove a node", true);
    try {
        Assert.assertEquals(wg.getVertexCount(), 3);
        Assert.assertEquals(wg.getTransactionCount(), 2);
        wg.removeVertex(vx1);
        Assert.assertEquals(wg.getVertexCount(), 2);
        Assert.assertEquals(wg.getTransactionCount(), 0);
    } finally {
        wg.commit();
    }
    ReadableGraph rg = compareGraph.getReadableGraph();
    try {
        compareAll = GraphRecordStoreUtilities.getAll(rg, false, true);
    } finally {
        rg.release();
    }
    final GraphRecordStore originalAll = GraphRecordStoreUtilities.getAll(originalGraph, false, true);
    final Set<String> vertexPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(originalGraph, GraphElementType.VERTEX);
    final Set<String> transactionPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(originalGraph, GraphElementType.TRANSACTION);
    final List<String> ignoreVertexAttributes = new ArrayList<>();
    final List<String> ignoreTransactionAttributes = new ArrayList<>();
    ignoreVertexAttributes.add("[id]");
    ignoreTransactionAttributes.add("[id]");
    // debug
    System.out.println("originalAll ==>\n" + originalAll.toStringVerbose());
    System.out.println("compareAll ==>\n" + compareAll.toStringVerbose());
    final CompareGraphPlugin instance = new CompareGraphPlugin();
    Graph finalGraph = null;
    GraphRecordStore changes = new GraphRecordStore();
    try {
        changes = instance.compareGraphs("", originalAll, compareAll, vertexPrimaryKeys, transactionPrimaryKeys, ignoreVertexAttributes, ignoreTransactionAttributes, ADDED_COLOUR, REMOVED_COLOUR, CHANGED_COLOUR, UNCHANGED_COLOUR);
        System.out.println("changes ==>\n" + changes.toStringVerbose());
        assertEquals(changes.size(), 5);
        finalGraph = instance.createComparisonGraph(new DualGraph(originalGraph, true), changes);
    } catch (InterruptedException | PluginException ex) {
        Assert.fail(ex.getLocalizedMessage());
    }
    changes.reset();
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER), "vx0");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.UNCHANGED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER), "vx1");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.REMOVED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER), "vx2");
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.UNCHANGED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER), "vx0");
    assertEquals(changes.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.IDENTIFIER), "vx1");
    assertEquals(changes.get(GraphRecordStoreUtilities.TRANSACTION + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.REMOVED);
    changes.next();
    assertEquals(changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER), "vx1");
    assertEquals(changes.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.IDENTIFIER), "vx2");
    assertEquals(changes.get(GraphRecordStoreUtilities.TRANSACTION + CompareGraphPlugin.COMPARE_ATTRIBUTE), CompareGraphPlugin.REMOVED);
    rg = finalGraph.getReadableGraph();
    try {
        int vxCount = rg.getVertexCount();
        int txCount = rg.getTransactionCount();
        assertEquals(vxCount, 3);
        assertEquals(txCount, 2);
    } finally {
        rg.release();
    }
    try {
        SaveGraphUtilities.saveGraphToTemporaryDirectory(originalGraph, "originalGraph");
        SaveGraphUtilities.saveGraphToTemporaryDirectory(compareGraph, "compareGraph", true);
        SaveGraphUtilities.saveGraphToTemporaryDirectory(finalGraph, "finalGraph", true);
    } catch (IOException | InterruptedException ex) {
        Assert.fail(ex.getLocalizedMessage());
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) CopyToNewGraphPlugin(au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToNewGraphPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) Test(org.testng.annotations.Test)

Example 13 with GraphRecordStore

use of au.gov.asd.tac.constellation.graph.processing.GraphRecordStore 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 14 with GraphRecordStore

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

the class AddRecordStore method callService.

@Override
public void callService(final PluginParameters parameters, final InputStream in, final OutputStream out) throws IOException {
    final String graphId = parameters.getStringValue(GRAPH_ID_PARAMETER_ID);
    final boolean completeWithSchema = parameters.getBooleanValue(COMPLETE_PARAMETER_ID);
    final String arrange = parameters.getStringValue(ARRANGE_PARAMETER_ID);
    final boolean resetView = parameters.getBooleanValue(RESET_PARAMETER_ID);
    final RecordStore rs = new GraphRecordStore();
    final ObjectMapper mapper = new ObjectMapper();
    final JsonNode json = mapper.readTree(in);
    final Graph graph = graphId == null ? RestUtilities.getActiveGraph() : GraphNode.getGraph(graphId);
    if (graph == null) {
        throw new RestServiceException(HTTP_UNPROCESSABLE_ENTITY, "No graph with id " + graphId);
    }
    // (We ignore the index array.)
    if (!json.hasNonNull(COLUMNS) || !json.get(COLUMNS).isArray()) {
        throw new RestServiceException("Could not find columns object containing column names");
    }
    if (!json.hasNonNull("data") || !json.get("data").isArray()) {
        throw new RestServiceException("Could not find data object containing data rows");
    }
    final ArrayNode columns = (ArrayNode) json.get(COLUMNS);
    final String[] headers = new String[columns.size()];
    for (int i = 0; i < headers.length; i++) {
        headers[i] = columns.get(i).asText();
    }
    final ArrayNode data = (ArrayNode) json.get("data");
    for (final Iterator<JsonNode> i = data.elements(); i.hasNext(); ) {
        final ArrayNode jrow = (ArrayNode) i.next();
        rs.add();
        boolean txFound = false;
        boolean txSourceFound = false;
        for (int ix = 0; ix < headers.length; ix++) {
            final String h = headers[ix];
            final JsonNode jn = jrow.get(ix);
            if (!jn.isNull()) {
                if (jn.getNodeType() == JsonNodeType.ARRAY) {
                    rs.set(h, RestServiceUtilities.toList((ArrayNode) jn));
                } else {
                    rs.set(h, jn.asText());
                }
            }
            txFound |= h.startsWith(GraphRecordStoreUtilities.TRANSACTION);
            txSourceFound |= TX_SOURCE.equals(h);
        }
        if (txFound && !txSourceFound) {
            rs.set(TX_SOURCE, API_SOURCE);
        }
    }
    addToGraph(graph, rs, completeWithSchema, arrange, resetView);
}
Also used : RestServiceException(au.gov.asd.tac.constellation.webserver.restapi.RestServiceException) Graph(au.gov.asd.tac.constellation.graph.Graph) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 15 with GraphRecordStore

use of au.gov.asd.tac.constellation.graph.processing.GraphRecordStore 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)47 Test (org.testng.annotations.Test)33 ArrayList (java.util.ArrayList)24 RecordStore (au.gov.asd.tac.constellation.graph.processing.RecordStore)19 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)19 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)15 Graph (au.gov.asd.tac.constellation.graph.Graph)12 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)11 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)10 HashSet (java.util.HashSet)10 DefaultPluginInteraction (au.gov.asd.tac.constellation.graph.node.plugins.DefaultPluginInteraction)9 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)8 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)8 HashMap (java.util.HashMap)8 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)7 Schema (au.gov.asd.tac.constellation.graph.schema.Schema)7 IOException (java.io.IOException)5 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)3 TextPluginInteraction (au.gov.asd.tac.constellation.plugins.text.TextPluginInteraction)3 File (java.io.File)3