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);
}
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);
}
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");
}
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);
}
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));
}
Aggregations