use of au.gov.asd.tac.constellation.graph.schema.Schema in project constellation by constellation-app.
the class MergeNodesNGTest method setUpMethod.
@BeforeMethod
public void setUpMethod() throws Exception {
// create an analytic graph
final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
graph = new StoreGraph(schema);
// add attributes
vertexIdentifierAttribute = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
vertexTypeAttribute = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
vertexLatitudeAttribute = SpatialConcept.VertexAttribute.LATITUDE.ensure(graph);
vertexLongitudeAttribute = SpatialConcept.VertexAttribute.LONGITUDE.ensure(graph);
vertexShapeAttribute = SpatialConcept.VertexAttribute.SHAPE.ensure(graph);
vertexSelectedAttribute = VisualConcept.VertexAttribute.SELECTED.ensure(graph);
// add vertices
vxId1 = graph.addVertex();
vxId2 = graph.addVertex();
vxId3 = graph.addVertex();
vxId4 = graph.addVertex();
// set the identifier of three vertices to somthing unique but similar, and the remaining vertex to a duplicate
graph.setStringValue(vertexIdentifierAttribute, vxId1, "VERTEX_1");
graph.setStringValue(vertexIdentifierAttribute, vxId2, "VERTEX_2");
graph.setStringValue(vertexIdentifierAttribute, vxId3, "SPECIAL_VERTEX_1");
graph.setStringValue(vertexIdentifierAttribute, vxId4, "VERTEX_1");
// set the type of two vertices to a schema type, and the remaining two vertices to a non-schema type
graph.setStringValue(vertexTypeAttribute, vxId1, "Online Identifier");
graph.setStringValue(vertexTypeAttribute, vxId2, "Online Identifier");
graph.setStringValue(vertexTypeAttribute, vxId3, "Special Identifier");
graph.setStringValue(vertexTypeAttribute, vxId4, "Special Identifier");
// set the latitude and longitude of each pair of vertices to be geospatially close
graph.setFloatValue(vertexLatitudeAttribute, vxId1, 25.0f);
graph.setFloatValue(vertexLongitudeAttribute, vxId1, 25.0f);
graph.setFloatValue(vertexLatitudeAttribute, vxId2, 26.0f);
graph.setFloatValue(vertexLongitudeAttribute, vxId2, 26.0f);
graph.setFloatValue(vertexLatitudeAttribute, vxId3, -25.0f);
graph.setFloatValue(vertexLongitudeAttribute, vxId3, -25.0f);
graph.setFloatValue(vertexLatitudeAttribute, vxId4, -30.0f);
graph.setFloatValue(vertexLongitudeAttribute, vxId4, -30.0f);
// set all vertices to be selected
graph.setBooleanValue(vertexSelectedAttribute, vxId1, true);
graph.setBooleanValue(vertexSelectedAttribute, vxId2, true);
graph.setBooleanValue(vertexSelectedAttribute, vxId3, true);
graph.setBooleanValue(vertexSelectedAttribute, vxId4, true);
}
use of au.gov.asd.tac.constellation.graph.schema.Schema in project constellation by constellation-app.
the class MergeTransactionsPluginNGTest method setUpMethod.
@BeforeMethod
public void setUpMethod() throws Exception {
// create an analytic graph
final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
graph = new StoreGraph(schema);
// add attributes
vertexIdentifierAttribute = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
vertexTypeAttribute = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
transactionIdentifierAttribute = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(graph);
transactionTypeAttribute = AnalyticConcept.TransactionAttribute.TYPE.ensure(graph);
transactionDateTimeAttribute = TemporalConcept.TransactionAttribute.DATETIME.ensure(graph);
transactionSelectedAttribute = VisualConcept.TransactionAttribute.SELECTED.ensure(graph);
// add vertices
vxId1 = graph.addVertex();
vxId2 = graph.addVertex();
// set the identifier of each vertex to something unique
graph.setStringValue(vertexIdentifierAttribute, vxId1, "V1");
graph.setStringValue(vertexIdentifierAttribute, vxId2, "V2");
// add transactions
txId1 = graph.addTransaction(vxId1, vxId2, false);
txId2 = graph.addTransaction(vxId1, vxId2, false);
txId3 = graph.addTransaction(vxId1, vxId2, false);
txId4 = graph.addTransaction(vxId1, vxId2, false);
txId5 = graph.addTransaction(vxId1, vxId2, false);
// set the same activity
graph.setStringValue(transactionIdentifierAttribute, txId1, "");
graph.setStringValue(transactionIdentifierAttribute, txId2, "");
graph.setStringValue(transactionIdentifierAttribute, txId3, "");
graph.setStringValue(transactionIdentifierAttribute, txId4, null);
graph.setStringValue(transactionIdentifierAttribute, txId5, null);
// set the same type
graph.setStringValue(transactionTypeAttribute, txId1, "");
graph.setStringValue(transactionTypeAttribute, txId2, "");
graph.setStringValue(transactionTypeAttribute, txId3, "");
graph.setStringValue(transactionTypeAttribute, txId4, AnalyticConcept.VertexType.EMAIL_ADDRESS.getName());
graph.setStringValue(transactionTypeAttribute, txId5, AnalyticConcept.VertexType.COUNTRY.getName());
// set the time of each transaction 1 second apart
graph.setStringValue(transactionDateTimeAttribute, txId1, "2015-01-28 00:00:01.000 +00:00 [UTC]");
graph.setStringValue(transactionDateTimeAttribute, txId2, "2015-01-28 00:00:02.000 +00:00 [UTC]");
graph.setStringValue(transactionDateTimeAttribute, txId3, "2015-01-28 00:00:03.000 +00:00 [UTC]");
graph.setStringValue(transactionDateTimeAttribute, txId4, "2015-01-28 00:00:02.000 +00:00 [UTC]");
graph.setStringValue(transactionDateTimeAttribute, txId5, "2015-01-28 00:00:03.000 +00:00 [UTC]");
// select all
graph.setBooleanValue(transactionSelectedAttribute, txId1, true);
graph.setBooleanValue(transactionSelectedAttribute, txId2, true);
graph.setBooleanValue(transactionSelectedAttribute, txId3, true);
graph.setBooleanValue(transactionSelectedAttribute, txId4, true);
graph.setBooleanValue(transactionSelectedAttribute, txId5, true);
}
use of au.gov.asd.tac.constellation.graph.schema.Schema in project constellation by constellation-app.
the class SplitNodesPluginSplitLogicNGTest method setUpMethod.
@BeforeMethod
public void setUpMethod() throws Exception {
// create an analytic graph
final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
graph = new StoreGraph(schema);
final int attrX = VisualConcept.VertexAttribute.X.ensure(graph);
final int attrY = VisualConcept.VertexAttribute.Y.ensure(graph);
final int attrZ = VisualConcept.VertexAttribute.Z.ensure(graph);
// add attributes
vertexIdentifierAttribute = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
vertexAttributeX = VisualConcept.VertexAttribute.X.ensure(graph);
vertexAttributeY = VisualConcept.VertexAttribute.Y.ensure(graph);
vertexAttributeZ = VisualConcept.VertexAttribute.Z.ensure(graph);
vertexTypeAttribute = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
vertexLatitudeAttribute = SpatialConcept.VertexAttribute.LATITUDE.ensure(graph);
vertexLongitudeAttribute = SpatialConcept.VertexAttribute.LONGITUDE.ensure(graph);
vertexSelectedAttribute = VisualConcept.VertexAttribute.SELECTED.ensure(graph);
// add vertices
vxId1 = graph.addVertex();
vxId2 = graph.addVertex();
vxId3 = graph.addVertex();
vxId4 = graph.addVertex();
// set the identifier of four vertices to somthing unique but similar, and the remaining vertex to a duplicate
graph.setStringValue(vertexIdentifierAttribute, vxId1, ",,,");
graph.setStringValue(vertexIdentifierAttribute, vxId2, "v,,v");
graph.setStringValue(vertexIdentifierAttribute, vxId3, ",,v");
graph.setStringValue(vertexIdentifierAttribute, vxId4, "v,,");
// set the x,y,z of the vertices that will be splitted
graph.setDoubleValue(vertexAttributeX, vxId1, attrX);
graph.setDoubleValue(vertexAttributeY, vxId1, attrY);
graph.setDoubleValue(vertexAttributeZ, vxId1, attrZ);
graph.setDoubleValue(vertexAttributeX, vxId2, attrX + 10);
graph.setDoubleValue(vertexAttributeY, vxId2, attrY + 10);
graph.setDoubleValue(vertexAttributeZ, vxId2, attrZ);
// set the type of four vertices to a schema type, and the remaining two vertices to a non-schema type
graph.setStringValue(vertexTypeAttribute, vxId1, "Online Identifier");
graph.setStringValue(vertexTypeAttribute, vxId2, "Online Identifier");
graph.setStringValue(vertexTypeAttribute, vxId3, "Special Identifier");
graph.setStringValue(vertexTypeAttribute, vxId4, "Special Identifier");
// set the latitude and longitude of each pair of vertices to be geospatially close
graph.setFloatValue(vertexLatitudeAttribute, vxId1, 25.0f);
graph.setFloatValue(vertexLongitudeAttribute, vxId1, 25.0f);
graph.setFloatValue(vertexLatitudeAttribute, vxId2, 26.0f);
graph.setFloatValue(vertexLongitudeAttribute, vxId2, 26.0f);
graph.setFloatValue(vertexLatitudeAttribute, vxId3, -25.0f);
graph.setFloatValue(vertexLongitudeAttribute, vxId3, -25.0f);
graph.setFloatValue(vertexLatitudeAttribute, vxId4, -30.0f);
graph.setFloatValue(vertexLongitudeAttribute, vxId4, -30.0f);
// Add Transactions
graph.addTransaction(vxId1, vxId3, true);
graph.addTransaction(vxId2, vxId4, true);
graph.addTransaction(vxId1, vxId2, true);
}
use of au.gov.asd.tac.constellation.graph.schema.Schema 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.schema.Schema in project constellation by constellation-app.
the class CompareGraphPluginNGTest method testReadWithDuplicateGraphScenarioInReverse.
// @Test(expectedExceptions = DuplicateKeyException.class)
@Test
public void testReadWithDuplicateGraphScenarioInReverse() throws InterruptedException {
int vx0, vx1, vx2, tx0, tx1;
int identifierAttribute, vertexTypeAttribute, uniqueIdAttribute, transactionTypeAttribute, transactionDateTimeAttribute;
final Schema schema = SchemaFactoryUtilities.getSchemaFactory(AnalyticSchemaFactory.ANALYTIC_SCHEMA_ID).createSchema();
final StoreGraph originalGraph = new StoreGraph(schema);
identifierAttribute = VisualConcept.VertexAttribute.IDENTIFIER.ensure(originalGraph);
vertexTypeAttribute = AnalyticConcept.VertexAttribute.TYPE.ensure(originalGraph);
uniqueIdAttribute = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(originalGraph);
transactionTypeAttribute = AnalyticConcept.TransactionAttribute.TYPE.ensure(originalGraph);
transactionDateTimeAttribute = TemporalConcept.TransactionAttribute.DATETIME.ensure(originalGraph);
originalGraph.setPrimaryKey(GraphElementType.VERTEX, identifierAttribute, vertexTypeAttribute);
originalGraph.setPrimaryKey(GraphElementType.TRANSACTION, uniqueIdAttribute, transactionTypeAttribute, transactionDateTimeAttribute);
originalGraph.validateKeys();
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, "Vertex #0");
originalGraph.setStringValue(identifierAttribute, vx1, "Vertex #1");
// mimic creating nodes on visual schema which will create a DuplicateKeyException - i.e. this is a known issue
originalGraph.setStringValue(identifierAttribute, vx2, "Vertex #2");
originalGraph.setStringValue(vertexTypeAttribute, vx0, "Unknown");
originalGraph.setStringValue(vertexTypeAttribute, vx1, "Unknown");
originalGraph.setStringValue(vertexTypeAttribute, vx2, "Unknown");
Graph compareGraph;
GraphRecordStore compareAll;
try {
final Plugin copyGraphPlugin = PluginRegistry.get(InteractiveGraphPluginRegistry.COPY_TO_NEW_GRAPH);
final PluginParameters copyGraphParams = copyGraphPlugin.createParameters();
PluginExecution.withPlugin(copyGraphPlugin).withParameters(copyGraphParams).executeNow((GraphReadMethods) originalGraph);
compareGraph = (Graph) copyGraphParams.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);
wg.removeVertex(vx1);
Assert.assertEquals(wg.getVertexCount(), 2);
} finally {
wg.commit();
}
final ReadableGraph rg = compareGraph.getReadableGraph();
try {
compareAll = GraphRecordStoreUtilities.getAll(rg, false, true);
} finally {
rg.release();
}
final GraphRecordStore originalAll = GraphRecordStoreUtilities.getAll(originalGraph, false, true);
Set<String> vertexPrimaryKeys = null;
Set<String> transactionPrimaryKeys = null;
final ReadableGraph rg2 = compareGraph.getReadableGraph();
try {
vertexPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(rg2, GraphElementType.VERTEX);
transactionPrimaryKeys = PrimaryKeyUtilities.getPrimaryKeyNames(rg2, GraphElementType.TRANSACTION);
} finally {
rg2.release();
}
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("", compareAll, originalAll, vertexPrimaryKeys, transactionPrimaryKeys, ignoreVertexAttributes, ignoreTransactionAttributes, ADDED_COLOUR, REMOVED_COLOUR, CHANGED_COLOUR, UNCHANGED_COLOUR);
System.out.println("changes ==>\n" + changes.toStringVerbose());
// assertEquals(changes.size(), 3);
finalGraph = instance.createComparisonGraph(compareGraph, changes);
} catch (InterruptedException | PluginException ex) {
Assert.fail(ex.getLocalizedMessage());
}
// }
try {
SaveGraphUtilities.saveGraphToTemporaryDirectory(originalGraph, "originalGraph");
SaveGraphUtilities.saveGraphToTemporaryDirectory(compareGraph, "compareGraph", true);
SaveGraphUtilities.saveGraphToTemporaryDirectory(finalGraph, "finalGraph", true);
} catch (IOException | InterruptedException ex) {
Assert.fail(ex.getLocalizedMessage());
}
}
Aggregations