Search in sources :

Example 6 with GraphRecordStore

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

the class RecordStoreDropperNGTest method testRecordStoreDropperToGraphPlugin.

@Test
public void testRecordStoreDropperToGraphPlugin() 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 RecordStoreDropperToGraphPlugin plugin = new RecordStoreDropperToGraphPlugin(recordStore);
    final RecordStore expResult = plugin.query(recordStore, interaction, parameters);
    assertEquals(recordStore, expResult);
}
Also used : RecordStoreDropperToGraphPlugin(au.gov.asd.tac.constellation.views.dataaccess.templates.RecordStoreDropper.RecordStoreDropperToGraphPlugin) 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) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Example 7 with GraphRecordStore

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

the class TestParametersPluginNGTest method testQueryCrash1.

/**
 * Test of query method, of class TestParametersPlugin. Tests not throwing
 * runtime exception
 */
@Test
public void testQueryCrash1() throws Exception {
    System.out.println("test query crash1");
    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(false);
    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 8 with GraphRecordStore

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

the class RecordStoreQueryPluginNGTest method testEdit.

/**
 * Test of edit method, of class RecordStoreQueryPlugin.
 */
@Test
public void testEdit() throws InterruptedException, PluginException {
    System.out.println("edit");
    final RecordStoreQueryPlugin instance = new RecordStoreQueryPluginMockImpl();
    final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
    // only using a dual graph because of the need to pass a GraphWriteMethods graph to the edit() method.
    final Graph graph = new DualGraph(schema);
    final PluginInteraction interaction = null;
    final PluginParameters parameters = null;
    ReadableGraph rg = graph.getReadableGraph();
    try {
        instance.read(rg, interaction, parameters);
        instance.query(interaction, parameters);
    } finally {
        rg.release();
    }
    GraphRecordStore query;
    rg = graph.getReadableGraph();
    try {
        query = GraphRecordStoreUtilities.getAll(rg, false, false);
    } finally {
        rg.release();
    }
    final WritableGraph wg = graph.getWritableGraph("", true);
    try {
        VisualConcept.VertexAttribute.X.ensure(wg);
        VisualConcept.VertexAttribute.Y.ensure(wg);
        VisualConcept.VertexAttribute.Z.ensure(wg);
        VisualConcept.GraphAttribute.CAMERA.ensure(wg);
        instance.edit(wg, interaction, parameters);
    } finally {
        wg.commit();
    }
    rg = graph.getReadableGraph();
    try {
        query = GraphRecordStoreUtilities.getTransactions(rg, false, false);
    } finally {
        rg.release();
    }
    // verify nothing has moved
    query.reset();
    query.next();
    assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.X), "10.0");
    assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Y), "10.0");
    assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Z), "10.0");
    assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.X), "20.0");
    assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Y), "20.0");
    assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Z), "20.0");
    query.next();
    assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.X), "30.0");
    assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Y), "30.0");
    assertEquals(query.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.Z), "30.0");
    assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.X), "40.0");
    assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Y), "40.0");
    assertEquals(query.get(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.Z), "40.0");
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Example 9 with GraphRecordStore

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

the class CompareGraphPlugin method read.

@Override
protected void read(final GraphReadMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    final String originalGraphName = parameters.getParameters().get(ORIGINAL_GRAPH_PARAMETER_ID).getStringValue();
    final String compareGraphName = parameters.getParameters().get(COMPARE_GRAPH_PARAMETER_ID).getStringValue();
    if (originalGraphName == null || compareGraphName == null) {
        throw new PluginException(PluginNotificationLevel.ERROR, "You must choose two graphs to compare");
    }
    final List<String> ignoreVertexAttributes = new ArrayList<>(parameters.getParameters().get(IGNORE_VERTEX_ATTRIBUTES_PARAMETER_ID).getMultiChoiceValue().getChoices());
    final List<String> ignoreTransactionAttributes = new ArrayList<>(parameters.getParameters().get(IGNORE_TRANSACTION_ATTRIBUTES_PARAMETER_ID).getMultiChoiceValue().getChoices());
    final ConstellationColor addedColour = parameters.getParameters().get(ADDED_COLOUR_PARAMETER_ID).getColorValue();
    final ConstellationColor removedColour = parameters.getParameters().get(REMOVED_COLOUR_PARAMETER_ID).getColorValue();
    final ConstellationColor changedColour = parameters.getParameters().get(CHANGED_COLOUR_PARAMETER_ID).getColorValue();
    final ConstellationColor unchangedColour = parameters.getParameters().get(UNCHANGED_COLOUR_PARAMETER_ID).getColorValue();
    final ConstellationColor addedColourValue = ConstellationColor.getColorValue(addedColour.getRed(), addedColour.getGreen(), addedColour.getBlue(), ConstellationColor.ZERO_ALPHA);
    final ConstellationColor removedColourValue = ConstellationColor.getColorValue(removedColour.getRed(), removedColour.getGreen(), removedColour.getBlue(), ConstellationColor.ZERO_ALPHA);
    final ConstellationColor changedColourValue = ConstellationColor.getColorValue(changedColour.getRed(), changedColour.getGreen(), changedColour.getBlue(), ConstellationColor.ZERO_ALPHA);
    final ConstellationColor unchangedColourValue = ConstellationColor.getColorValue(unchangedColour.getRed(), unchangedColour.getGreen(), unchangedColour.getBlue(), ConstellationColor.ZERO_ALPHA);
    final Graph originalGraph = getGraphFromName(originalGraphName);
    final Graph compareGraph = getGraphFromName(compareGraphName);
    if (originalGraph == null) {
        throw new PluginException(PluginNotificationLevel.ERROR, String.format(GRAPH_NOT_FOUND_ERROR, originalGraphName));
    }
    if (compareGraph == null) {
        throw new PluginException(PluginNotificationLevel.ERROR, String.format(GRAPH_NOT_FOUND_ERROR, compareGraphName));
    }
    final GraphRecordStore originalAll;
    final GraphRecordStore compareAll;
    final Set<String> vertexPrimaryKeys;
    final Set<String> transactionPrimaryKeys;
    // get a copy of the graph's record store and statistical info
    ReadableGraph rg = originalGraph.getReadableGraph();
    try {
        originalAll = GraphRecordStoreUtilities.getAll(rg, false, true);
        vertexPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(rg, GraphElementType.VERTEX);
        transactionPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(rg, GraphElementType.TRANSACTION);
    } finally {
        rg.release();
    }
    rg = compareGraph.getReadableGraph();
    try {
        compareAll = GraphRecordStoreUtilities.getAll(rg, false, true);
    } finally {
        rg.release();
    }
    // ignore the id attributes to avoid reporting on them
    ignoreVertexAttributes.add("[id]");
    ignoreTransactionAttributes.add("[id]");
    // graph changes
    final String title = String.format("Compare: %s <> %s", originalGraphName, compareGraphName);
    final GraphRecordStore changes = compareGraphs(title, originalAll, compareAll, vertexPrimaryKeys, transactionPrimaryKeys, ignoreVertexAttributes, ignoreTransactionAttributes, addedColourValue, removedColourValue, changedColourValue, unchangedColourValue);
    // create new graph
    createComparisonGraph(originalGraph, changes);
    interaction.setProgress(1, 0, changes + " changes were found.", true);
}
Also used : ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) ArrayList(java.util.ArrayList) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)

Example 10 with GraphRecordStore

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

the class CompareGraphPluginNGTest method testCompareGraphsWithDifferentValuesOnCompareGraph.

@Test
public void testCompareGraphsWithDifferentValuesOnCompareGraph() throws Exception {
    // mimic GraphRecordStoreUtilities.getAll()
    final GraphRecordStore original = new GraphRecordStore();
    original.add();
    original.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    original.set(GraphRecordStoreUtilities.SOURCE + "foo", "vx0");
    original.add();
    original.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx1");
    original.add();
    original.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    original.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL, "vx1");
    final GraphRecordStore compare = new GraphRecordStore();
    compare.add();
    compare.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    compare.set(GraphRecordStoreUtilities.SOURCE + "foo", "bar");
    compare.add();
    compare.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx1");
    compare.add();
    compare.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    compare.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL, "vx1");
    final Set<String> vertexPrimaryKeys = new HashSet<>();
    vertexPrimaryKeys.add(VisualConcept.VertexAttribute.LABEL.getName());
    final List<String> ignoreVertexAttributes = new ArrayList<>();
    final List<String> ignoreTransactionAttributes = new ArrayList<>();
    ignoreVertexAttributes.add("[id]");
    ignoreTransactionAttributes.add("[id]");
    final CompareGraphPlugin instance = new CompareGraphPlugin();
    final GraphRecordStore changes = instance.compareGraphs("", original, compare, vertexPrimaryKeys, new HashSet<>(), ignoreVertexAttributes, ignoreTransactionAttributes, ADDED_COLOUR, REMOVED_COLOUR, CHANGED_COLOUR, UNCHANGED_COLOUR);
    System.out.println("original ==>\n" + original.toStringVerbose());
    System.out.println("compare ==>\n" + compare.toStringVerbose());
    System.out.println("changes ==>\n" + changes.toStringVerbose());
    assertEquals(changes.size(), 3);
    changes.reset();
    changes.next();
    assertEquals("vx0", changes.get(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL));
    assertEquals(CompareGraphPlugin.CHANGED, changes.get(GraphRecordStoreUtilities.SOURCE + CompareGraphPlugin.COMPARE_ATTRIBUTE));
}
Also used : ArrayList(java.util.ArrayList) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

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