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