use of au.gov.asd.tac.constellation.graph.locking.DualGraph in project constellation by constellation-app.
the class FindViewControllerNGTest method setupGraph.
/**
* Set up a graph with two vertices and two transactions on layer 1.
*/
private void setupGraph() {
graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
graph2 = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
graphMap.put(graph.getId(), graph);
graphMap.put(graph2.getId(), graph2);
try {
WritableGraph wg = graph.getWritableGraph("", true);
// Create Selected Attributes
selectedV = VisualConcept.VertexAttribute.SELECTED.ensure(wg);
labelV = VisualConcept.VertexAttribute.LABEL.ensure(wg);
identifierV = VisualConcept.VertexAttribute.IDENTIFIER.ensure(wg);
xV = VisualConcept.VertexAttribute.X.ensure(wg);
selectedT = VisualConcept.TransactionAttribute.SELECTED.ensure(wg);
labelT = VisualConcept.TransactionAttribute.LABEL.ensure(wg);
identiferT = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(wg);
widthT = VisualConcept.TransactionAttribute.WIDTH.ensure(wg);
int[] vertexList = { vxId1, vxId2, vxId3, vxId4 };
for (int vertex : vertexList) {
vertex = wg.addVertex();
wg.setBooleanValue(selectedV, vertex, false);
wg.setStringValue(labelV, vertex, "label name");
wg.setStringValue(identifierV, vertex, "identifer name");
wg.setIntValue(xV, vertex, 1);
}
int[] transactionList = { txId1, txId2, txId3, txId4 };
int count = 0;
for (int transaction : transactionList) {
int vertex = vertexList[count];
transaction = wg.addTransaction(vxId1, vertex, false);
wg.setBooleanValue(selectedT, transaction, false);
wg.setStringValue(labelT, transaction, "label name");
wg.setStringValue(identiferT, transaction, "identifer name");
wg.setIntValue(widthT, transaction, 1);
if (count != vertexList.length) {
count++;
}
}
wg.commit();
} catch (final InterruptedException ex) {
Exceptions.printStackTrace(ex);
Thread.currentThread().interrupt();
}
}
use of au.gov.asd.tac.constellation.graph.locking.DualGraph in project constellation by constellation-app.
the class StringCriteriaPanelNGTest method setupGraph.
private void setupGraph() {
graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
graph2 = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
graphMap.put(graph.getId(), graph);
graphMap.put(graph2.getId(), graph2);
try {
WritableGraph wg = graph.getWritableGraph("", true);
// Create Selected Attributes
selectedV = VisualConcept.VertexAttribute.SELECTED.ensure(wg);
labelV = VisualConcept.VertexAttribute.LABEL.ensure(wg);
identifierV = VisualConcept.VertexAttribute.IDENTIFIER.ensure(wg);
xV = VisualConcept.VertexAttribute.X.ensure(wg);
selectedT = VisualConcept.TransactionAttribute.SELECTED.ensure(wg);
labelT = VisualConcept.TransactionAttribute.LABEL.ensure(wg);
identiferT = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(wg);
widthT = VisualConcept.TransactionAttribute.WIDTH.ensure(wg);
vxId1 = wg.addVertex();
wg.setBooleanValue(selectedV, vxId1, false);
wg.setStringValue(labelV, vxId1, "label name");
wg.setStringValue(identifierV, vxId1, "identifer name");
wg.setFloatValue(xV, vxId1, 1);
wg.commit();
} catch (final InterruptedException ex) {
Exceptions.printStackTrace(ex);
Thread.currentThread().interrupt();
}
}
use of au.gov.asd.tac.constellation.graph.locking.DualGraph in project constellation by constellation-app.
the class GraphSavingNGTest method setUpMethod.
@BeforeMethod
public void setUpMethod() throws Exception {
graph = new DualGraph(null);
WritableGraph wg = graph.getWritableGraph("add", true);
try {
attrX = wg.addAttribute(GraphElementType.VERTEX, FloatAttributeDescription.ATTRIBUTE_NAME, "x", "x", 0.0, null);
if (attrX == Graph.NOT_FOUND) {
fail();
}
attrY = wg.addAttribute(GraphElementType.VERTEX, FloatAttributeDescription.ATTRIBUTE_NAME, "y", "y", 0.0, null);
if (attrY == Graph.NOT_FOUND) {
fail();
}
attrZ = wg.addAttribute(GraphElementType.VERTEX, FloatAttributeDescription.ATTRIBUTE_NAME, "z", "z", 0.0, null);
if (attrZ == Graph.NOT_FOUND) {
fail();
}
vNameAttr = wg.addAttribute(GraphElementType.VERTEX, StringAttributeDescription.ATTRIBUTE_NAME, "name", "descr", "", null);
if (vNameAttr == Graph.NOT_FOUND) {
fail();
}
tNameAttr = wg.addAttribute(GraphElementType.TRANSACTION, StringAttributeDescription.ATTRIBUTE_NAME, "name", "descr", "", null);
if (tNameAttr == Graph.NOT_FOUND) {
fail();
}
vSelAttr = wg.addAttribute(GraphElementType.VERTEX, BooleanAttributeDescription.ATTRIBUTE_NAME, "selected", "selected", false, null);
if (vSelAttr == Graph.NOT_FOUND) {
fail();
}
tSelAttr = wg.addAttribute(GraphElementType.TRANSACTION, BooleanAttributeDescription.ATTRIBUTE_NAME, "selected", "selected", false, null);
if (tSelAttr == Graph.NOT_FOUND) {
fail();
}
vxId1 = wg.addVertex();
wg.setFloatValue(attrX, vxId1, 1.0f);
wg.setFloatValue(attrY, vxId1, 1.1f);
wg.setBooleanValue(vSelAttr, vxId1, false);
wg.setStringValue(vNameAttr, vxId1, "name1");
vxId2 = wg.addVertex();
wg.setFloatValue(attrX, vxId2, 2.0f);
wg.setFloatValue(attrY, vxId2, 2.2f);
wg.setBooleanValue(vSelAttr, vxId2, true);
wg.setStringValue(vNameAttr, vxId2, "name2");
vxId3 = wg.addVertex();
wg.setFloatValue(attrX, vxId3, 3.0f);
wg.setFloatValue(attrY, vxId3, 3.3f);
wg.setBooleanValue(vSelAttr, vxId3, false);
wg.setStringValue(vNameAttr, vxId3, "name3");
vxId4 = wg.addVertex();
wg.setFloatValue(attrX, vxId4, 4.0f);
wg.setFloatValue(attrY, vxId4, 4.4f);
wg.setBooleanValue(vSelAttr, vxId4, true);
wg.setStringValue(vNameAttr, vxId4, "name4");
vxId5 = wg.addVertex();
wg.setFloatValue(attrX, vxId5, 5.0f);
wg.setFloatValue(attrY, vxId5, 5.5f);
wg.setBooleanValue(vSelAttr, vxId5, false);
wg.setStringValue(vNameAttr, vxId5, "name5");
vxId6 = wg.addVertex();
wg.setFloatValue(attrX, vxId6, 6.0f);
wg.setFloatValue(attrY, vxId6, 6.60f);
wg.setBooleanValue(vSelAttr, vxId6, true);
wg.setStringValue(vNameAttr, vxId6, "name6");
vxId7 = wg.addVertex();
wg.setFloatValue(attrX, vxId7, 7.0f);
wg.setFloatValue(attrY, vxId7, 7.7f);
wg.setBooleanValue(vSelAttr, vxId7, false);
wg.setStringValue(vNameAttr, vxId7, "name7");
txId1 = wg.addTransaction(vxId1, vxId2, false);
wg.setBooleanValue(tSelAttr, txId1, false);
wg.setStringValue(tNameAttr, txId1, "name101");
txId2 = wg.addTransaction(vxId1, vxId3, false);
wg.setBooleanValue(tSelAttr, txId2, true);
wg.setStringValue(tNameAttr, txId2, "name102");
txId3 = wg.addTransaction(vxId2, vxId4, true);
wg.setBooleanValue(tSelAttr, txId3, false);
wg.setStringValue(tNameAttr, txId3, "name103");
txId4 = wg.addTransaction(vxId4, vxId2, true);
wg.setBooleanValue(tSelAttr, txId4, true);
wg.setStringValue(tNameAttr, txId4, "name104");
txId5 = wg.addTransaction(vxId5, vxId6, false);
wg.setBooleanValue(tSelAttr, txId5, false);
wg.setStringValue(tNameAttr, txId5, "name105");
} finally {
wg.commit();
}
}
use of au.gov.asd.tac.constellation.graph.locking.DualGraph 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());
}
}
use of au.gov.asd.tac.constellation.graph.locking.DualGraph in project constellation by constellation-app.
the class ManipulateDeletedElementsNGTest method setIndexedAttributeValueOfDeletedVertexTest.
@Test
public void setIndexedAttributeValueOfDeletedVertexTest() {
final DualGraph g = new DualGraph(new StoreGraph(), false);
int attr, v1;
try {
// Add an indexed boolean attribute, then add a vertex, then delete that vertex.
final WritableGraph wg = g.getWritableGraph("add attribute, add/remove vertex", true);
try {
attr = wg.addAttribute(GraphElementType.VERTEX, BooleanAttributeDescription.ATTRIBUTE_NAME, "attr", null, false, null);
wg.setAttributeIndexType(attr, GraphIndexType.UNORDERED);
v1 = wg.addVertex();
wg.removeVertex(v1);
} finally {
wg.commit();
}
// Set the attribute value of the deleted vertex.
final WritableGraph wg2 = g.getWritableGraph("set deleted value", true);
try {
wg2.setBooleanValue(attr, v1, true);
} finally {
wg2.commit();
}
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
Aggregations