Search in sources :

Example 26 with GraphRecordStore

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

the class TSVDropperNGTest method testTSVDropperToGraphPlugin.

@Test
public void testTSVDropperToGraphPlugin() throws InterruptedException, PluginException {
    final PluginInteraction interaction = mock(PluginInteraction.class);
    final PluginParameters parameters = mock(PluginParameters.class);
    final StoreGraph graph = new StoreGraph(new AnalyticSchemaFactory().createSchema());
    VisualConcept.VertexAttribute.X.ensure(graph);
    VisualConcept.VertexAttribute.Y.ensure(graph);
    VisualConcept.VertexAttribute.Z.ensure(graph);
    final RecordStore recordStore = new GraphRecordStore();
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER, "foo");
    recordStore.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.IDENTIFIER, "bar");
    final File file = new File(TSVDropperNGTest.class.getResource("./resources/sample.tsv").getFile());
    final List<File> files = new ArrayList<>();
    files.add(file);
    final TSVDropperToGraphPlugin plugin = new TSVDropperToGraphPlugin(recordStore, files);
    final RecordStore expResult = plugin.query(recordStore, interaction, parameters);
    assertEquals(recordStore, expResult);
}
Also used : PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) AnalyticSchemaFactory(au.gov.asd.tac.constellation.graph.schema.analytic.AnalyticSchemaFactory) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) ArrayList(java.util.ArrayList) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) TSVDropperToGraphPlugin(au.gov.asd.tac.constellation.views.dataaccess.templates.TSVDropper.TSVDropperToGraphPlugin) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) File(java.io.File) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Example 27 with GraphRecordStore

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

the class TestParametersPluginNGTest method testQueryException2.

/**
 * Test of query method, of class TestParametersPlugin. Tests throwing of
 * info pluginException
 */
@Test(expectedExceptions = PluginException.class)
public void testQueryException2() throws Exception {
    System.out.println("throw pluginexception2");
    final TestParametersPlugin instance = new TestParametersPlugin();
    final PluginParameters result = instance.createParameters();
    final GraphRecordStore recordStore = new GraphRecordStore();
    final DefaultPluginInteraction interaction = new DefaultPluginInteraction(null, null);
    // Set plugin query name here before execution
    result.getParameters().get(CoreGlobalParameters.QUERY_NAME_PARAMETER_ID).setStringValue("TESTPARAMETERSPLUGIN");
    // Set plugin parameters here before execution
    result.getParameters().get(TestParametersPlugin.LEVEL_PARAMETER_ID).setStringValue("Info");
    try {
        instance.query(recordStore, interaction, result);
    } catch (final PluginException ex) {
        assertEquals(ex.getNotificationLevel(), PluginNotificationLevel.INFO);
        throw ex;
    }
}
Also used : PluginException(au.gov.asd.tac.constellation.plugins.PluginException) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) DefaultPluginInteraction(au.gov.asd.tac.constellation.graph.node.plugins.DefaultPluginInteraction) Test(org.testng.annotations.Test)

Example 28 with GraphRecordStore

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

the class TestParametersPluginNGTest method testQueryCrash2.

/**
 * Test of query method, of class TestParametersPlugin. Tests throwing
 * runtime exception
 */
@Test(expectedExceptions = RuntimeException.class)
public void testQueryCrash2() throws Exception {
    System.out.println("test query crash2");
    final TestParametersPlugin instance = new TestParametersPlugin();
    final PluginParameters result = instance.createParameters();
    final GraphRecordStore recordStore = new GraphRecordStore();
    final DefaultPluginInteraction interaction = new DefaultPluginInteraction(null, null);
    // Set plugin query name here before execution
    result.getParameters().get(CoreGlobalParameters.QUERY_NAME_PARAMETER_ID).setStringValue("TESTPARAMETERSPLUGIN");
    // Set plugin parameters here before execution
    result.getParameters().get(TestParametersPlugin.CRASH_PARAMETER_ID).setBooleanValue(true);
    instance.query(recordStore, interaction, result);
}
Also used : GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) DefaultPluginInteraction(au.gov.asd.tac.constellation.graph.node.plugins.DefaultPluginInteraction) Test(org.testng.annotations.Test)

Example 29 with GraphRecordStore

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

the class RecordStoreDropperNGTest method getRecordStoreAsStream.

private InputStream getRecordStoreAsStream() throws IOException {
    final RecordStore recordStore = new GraphRecordStore();
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER, "foo");
    recordStore.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.IDENTIFIER, "bar");
    final String RecordStoreAsJson = RecordStoreUtilities.toJson(recordStore);
    return new ByteArrayInputStream(("RecordStore=" + RecordStoreAsJson).getBytes());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) 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)

Example 30 with GraphRecordStore

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

the class CompareGraphPlugin method compareGraphs.

/**
 * Compare 2 graphs and create a {@link GraphRecordStore} to store the
 * differences.
 *
 * @param original The orignal graph
 * @param compare The graph to compare with
 * @param vertexPrimaryKeys Vertex primary keys
 * @param transactionPrimaryKeys Transaction primary keys
 * @param ignoreVertexAttributes Vertex attributes to ignore
 * @return A {@link GraphRecordStore} containing the differences
 * @throws PluginException
 */
protected GraphRecordStore compareGraphs(final String title, final GraphRecordStore original, final GraphRecordStore compare, final Set<String> vertexPrimaryKeys, final Set<String> transactionPrimaryKeys, final List<String> ignoreVertexAttributes, final List<String> ignoreTransactionAttributes, final ConstellationColor addedColour, final ConstellationColor removedColour, final ConstellationColor changedColour, final ConstellationColor unchangedColour) throws PluginException {
    final GraphRecordStore result = new GraphRecordStore();
    original.reset();
    compare.reset();
    result.add(original);
    result.add(compare);
    final Map<Set<String>, Integer> originalVertexKeysToIndex = getVertexKeysToRecordstoreIndex(original, vertexPrimaryKeys);
    final Map<Set<String>, Integer> compareVertexKeysToIndex = getVertexKeysToRecordstoreIndex(compare, vertexPrimaryKeys);
    // make sure transaction primary keys include the source and destination
    final Map<List<String>, Integer> originalTransactionKeysToIndex = getTransactionKeysToRecordstoreIndex(original, vertexPrimaryKeys, transactionPrimaryKeys);
    final Map<List<String>, Integer> compareTransactionKeysToIndex = getTransactionKeysToRecordstoreIndex(compare, vertexPrimaryKeys, transactionPrimaryKeys);
    final Set<Set<String>> seenVertices = new HashSet<>();
    // TODO: this could be a list of sets
    final Set<List<String>> seenTransactions = new HashSet<>();
    final List<String> attributes = result.keys();
    final Map<String, String> vertexSourceRecordPrimaryValues = new HashMap<>();
    final Map<String, String> vertexDestinationRecordPrimaryValues = new HashMap<>();
    final Map<String, String> transactionRecordPrimaryValues = new HashMap<>();
    // remove ignored attributes
    for (final String attribute : ignoreVertexAttributes) {
        attributes.remove(GraphRecordStoreUtilities.SOURCE + attribute);
        attributes.remove(GraphRecordStoreUtilities.DESTINATION + attribute);
    }
    for (final String attribute : ignoreTransactionAttributes) {
        attributes.remove(GraphRecordStoreUtilities.TRANSACTION + attribute);
    }
    final InputOutput io = IOProvider.getDefault().getIO(title, true);
    io.select();
    final OutputWriter output = io.getOut();
    final GraphRecordStore changes = new GraphRecordStore();
    result.reset();
    while (result.next()) {
        // make a cache of the primary key values
        vertexSourceRecordPrimaryValues.clear();
        vertexDestinationRecordPrimaryValues.clear();
        for (final String key : vertexPrimaryKeys) {
            final String sourceValue = result.get(GraphRecordStoreUtilities.SOURCE + key);
            if (sourceValue != null) {
                vertexSourceRecordPrimaryValues.put(key, sourceValue);
            }
            final String destinationValue = result.get(GraphRecordStoreUtilities.DESTINATION + key);
            if (destinationValue != null) {
                vertexDestinationRecordPrimaryValues.put(key, destinationValue);
            }
        }
        transactionRecordPrimaryValues.clear();
        for (final String key : transactionPrimaryKeys) {
            final String value = result.get(GraphRecordStoreUtilities.TRANSACTION + key);
            if (value != null) {
                transactionRecordPrimaryValues.put(key, value);
            }
        }
        // make a unique vertex
        final Set<String> vertex = new HashSet<>();
        vertex.addAll(vertexSourceRecordPrimaryValues.values());
        // make a unique transaction
        final List<String> transaction = new ArrayList<>();
        transaction.addAll(transactionRecordPrimaryValues.values());
        transaction.addAll(vertexDestinationRecordPrimaryValues.values());
        transaction.addAll(vertexSourceRecordPrimaryValues.values());
        // vertex compare
        final String originalSource = result.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL);
        if (!seenVertices.contains(vertex) && !originalVertexKeysToIndex.containsKey(vertex) && compareVertexKeysToIndex.containsKey(vertex)) {
            // added
            changes.add();
            changes.set(GraphRecordStoreUtilities.SOURCE + COMPARE_ATTRIBUTE, ADDED);
            changes.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.OVERLAY_COLOR, addedColour);
            addPrimaryKeyValuesToRecord(changes, GraphRecordStoreUtilities.SOURCE, vertexSourceRecordPrimaryValues);
            addAttributesToRecord(result, changes, GraphRecordStoreUtilities.SOURCE, result.index());
            output.println(String.format("Added node %s", originalSource));
            seenVertices.add(vertex);
        } else if (!seenVertices.contains(vertex) && originalVertexKeysToIndex.containsKey(vertex) && !compareVertexKeysToIndex.containsKey(vertex)) {
            // removed
            changes.add();
            changes.set(GraphRecordStoreUtilities.SOURCE + COMPARE_ATTRIBUTE, REMOVED);
            changes.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.OVERLAY_COLOR, removedColour);
            addPrimaryKeyValuesToRecord(changes, GraphRecordStoreUtilities.SOURCE, vertexSourceRecordPrimaryValues);
            addAttributesToRecord(result, changes, GraphRecordStoreUtilities.SOURCE, result.index());
            output.println(String.format("Removed node %s", originalSource));
            seenVertices.add(vertex);
        } else if (!seenVertices.contains(vertex) && originalVertexKeysToIndex.containsKey(vertex) && compareVertexKeysToIndex.containsKey(vertex)) {
            // changed
            boolean vertexChanged = false;
            for (final String attribute : attributes) {
                final int dividerPosition = attribute.indexOf(SeparatorConstants.PERIOD);
                if (dividerPosition != -1) {
                    final String keyType = attribute.substring(0, dividerPosition).toLowerCase();
                    final String keyAttribute = attribute.substring(dividerPosition + 1);
                    switch(keyType) {
                        case "source":
                            final String originalValue = original.get(originalVertexKeysToIndex.get(vertex), attribute);
                            final String compareValue = compare.get(compareVertexKeysToIndex.get(vertex), attribute);
                            if ((originalValue != null && !originalValue.equals(compareValue)) || (compareValue != null && !compareValue.equals(originalValue))) {
                                vertexChanged = true;
                                output.println(String.format("Changed node %s, '%s' value was '%s' and now '%s'", originalSource, keyAttribute, originalValue, compareValue));
                            }
                            break;
                        case "destination":
                        case "transaction":
                            // Intentionally left blank
                            break;
                        default:
                            break;
                    }
                }
            }
            if (vertexChanged) {
                changes.add();
                changes.set(GraphRecordStoreUtilities.SOURCE + COMPARE_ATTRIBUTE, CHANGED);
                changes.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.OVERLAY_COLOR, changedColour);
                addPrimaryKeyValuesToRecord(changes, GraphRecordStoreUtilities.SOURCE, vertexSourceRecordPrimaryValues);
                addAttributesToRecord(result, changes, GraphRecordStoreUtilities.SOURCE, result.index());
            } else {
                changes.add();
                changes.set(GraphRecordStoreUtilities.SOURCE + COMPARE_ATTRIBUTE, UNCHANGED);
                changes.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.OVERLAY_COLOR, unchangedColour);
                addPrimaryKeyValuesToRecord(changes, GraphRecordStoreUtilities.SOURCE, vertexSourceRecordPrimaryValues);
                addAttributesToRecord(result, changes, GraphRecordStoreUtilities.SOURCE, result.index());
            }
            seenVertices.add(vertex);
        } else {
        // Do nothing
        }
        // transaction compare
        final String originalDestination = result.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL);
        if (!seenTransactions.contains(transaction) && !originalTransactionKeysToIndex.containsKey(transaction) && compareTransactionKeysToIndex.containsKey(transaction)) {
            // added
            changes.add();
            changes.set(GraphRecordStoreUtilities.TRANSACTION + COMPARE_ATTRIBUTE, ADDED);
            changes.set(GraphRecordStoreUtilities.TRANSACTION + VisualConcept.TransactionAttribute.OVERLAY_COLOR, addedColour);
            addPrimaryKeyValuesToRecord(changes, GraphRecordStoreUtilities.SOURCE, vertexSourceRecordPrimaryValues);
            addPrimaryKeyValuesToRecord(changes, GraphRecordStoreUtilities.DESTINATION, vertexDestinationRecordPrimaryValues);
            addPrimaryKeyValuesToRecord(changes, GraphRecordStoreUtilities.TRANSACTION, transactionRecordPrimaryValues);
            addAttributesToRecord(result, changes, GraphRecordStoreUtilities.TRANSACTION, result.index());
            seenTransactions.add(transaction);
            output.println(String.format("Added transaction connecting %s to %s", originalSource, originalDestination));
        } else if (!seenTransactions.contains(transaction) && originalTransactionKeysToIndex.containsKey(transaction) && !compareTransactionKeysToIndex.containsKey(transaction)) {
            // removed
            changes.add();
            changes.set(GraphRecordStoreUtilities.TRANSACTION + COMPARE_ATTRIBUTE, REMOVED);
            changes.set(GraphRecordStoreUtilities.TRANSACTION + VisualConcept.TransactionAttribute.OVERLAY_COLOR, removedColour);
            addPrimaryKeyValuesToRecord(changes, GraphRecordStoreUtilities.SOURCE, vertexSourceRecordPrimaryValues);
            addPrimaryKeyValuesToRecord(changes, GraphRecordStoreUtilities.DESTINATION, vertexDestinationRecordPrimaryValues);
            addPrimaryKeyValuesToRecord(changes, GraphRecordStoreUtilities.TRANSACTION, transactionRecordPrimaryValues);
            addAttributesToRecord(result, changes, GraphRecordStoreUtilities.TRANSACTION, result.index());
            seenTransactions.add(transaction);
            output.println(String.format("Removed transaction connecting %s to %s", originalSource, originalDestination));
        } else if (!seenTransactions.contains(transaction) && originalTransactionKeysToIndex.containsKey(transaction) && compareTransactionKeysToIndex.containsKey(transaction)) {
            // changed
            boolean transactionChanged = false;
            for (final String attribute : attributes) {
                final int dividerPosition = attribute.indexOf(SeparatorConstants.PERIOD);
                if (dividerPosition != -1) {
                    final String keyType = attribute.substring(0, dividerPosition).toLowerCase();
                    final String keyAttribute = attribute.substring(dividerPosition + 1);
                    switch(keyType) {
                        case "source":
                        case "destination":
                            break;
                        case "transaction":
                            final Integer originalTransactionIndex = originalTransactionKeysToIndex.get(transaction);
                            final Integer compareTransactionIndex = compareTransactionKeysToIndex.get(transaction);
                            final String originalTransactionValue = original.get(originalTransactionIndex, GraphRecordStoreUtilities.TRANSACTION + keyAttribute);
                            final String compareTransactionValue = compare.get(compareTransactionIndex, GraphRecordStoreUtilities.TRANSACTION + keyAttribute);
                            if ((originalTransactionValue != null && !originalTransactionValue.equals(compareTransactionValue)) || (compareTransactionValue != null && !compareTransactionValue.equals(originalTransactionValue))) {
                                transactionChanged = true;
                                output.println(String.format("Changed transaction connecting %s to %s, attribute %s value was '%s' and now '%s'", originalSource, originalDestination, keyAttribute, originalTransactionValue, compareTransactionValue));
                            }
                            break;
                        default:
                            break;
                    }
                }
            }
            if (transactionChanged) {
                changes.add();
                changes.set(GraphRecordStoreUtilities.TRANSACTION + COMPARE_ATTRIBUTE, CHANGED);
                changes.set(GraphRecordStoreUtilities.TRANSACTION + VisualConcept.TransactionAttribute.OVERLAY_COLOR, changedColour);
                addPrimaryKeyValuesToRecord(changes, GraphRecordStoreUtilities.SOURCE, vertexSourceRecordPrimaryValues);
                addPrimaryKeyValuesToRecord(changes, GraphRecordStoreUtilities.DESTINATION, vertexDestinationRecordPrimaryValues);
                addPrimaryKeyValuesToRecord(changes, GraphRecordStoreUtilities.TRANSACTION, transactionRecordPrimaryValues);
                addAttributesToRecord(result, changes, GraphRecordStoreUtilities.TRANSACTION, result.index());
            } else {
                changes.add();
                changes.set(GraphRecordStoreUtilities.TRANSACTION + COMPARE_ATTRIBUTE, UNCHANGED);
                changes.set(GraphRecordStoreUtilities.TRANSACTION + VisualConcept.TransactionAttribute.OVERLAY_COLOR, unchangedColour);
                addPrimaryKeyValuesToRecord(changes, GraphRecordStoreUtilities.SOURCE, vertexSourceRecordPrimaryValues);
                addPrimaryKeyValuesToRecord(changes, GraphRecordStoreUtilities.DESTINATION, vertexDestinationRecordPrimaryValues);
                addPrimaryKeyValuesToRecord(changes, GraphRecordStoreUtilities.TRANSACTION, transactionRecordPrimaryValues);
                addAttributesToRecord(result, changes, GraphRecordStoreUtilities.TRANSACTION, result.index());
            }
            seenTransactions.add(transaction);
        } else {
        // Do nothing
        }
    }
    return changes;
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) InputOutput(org.openide.windows.InputOutput) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OutputWriter(org.openide.windows.OutputWriter) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) ArrayList(java.util.ArrayList) List(java.util.List) 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