Search in sources :

Example 26 with RecordStore

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

the class GraphRecordStoreUtilitiesNGTest method addedRecordStoreSupportsTypesWithOverriddenDirectionWithInitialiseAndCompleteWithSchema.

@Test
public void addedRecordStoreSupportsTypesWithOverriddenDirectionWithInitialiseAndCompleteWithSchema() {
    final RecordStore recordStore = new GraphRecordStore();
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER, "vx0");
    recordStore.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.IDENTIFIER, "vx1");
    recordStore.set(GraphRecordStoreUtilities.TRANSACTION + GraphRecordStoreUtilities.DIRECTED_KEY, false);
    // the communication type is directed
    recordStore.set(GraphRecordStoreUtilities.TRANSACTION + AnalyticConcept.TransactionAttribute.TYPE, AnalyticConcept.TransactionType.COMMUNICATION);
    final boolean initializeWithSchema = true;
    final boolean completeWithSchema = true;
    final List<String> vertexIdAttributes = new ArrayList<>();
    final Map<String, Integer> vertexMap = new HashMap<>();
    final Map<String, Integer> transactionMap = new HashMap<>();
    final List<Integer> veritices = GraphRecordStoreUtilities.addRecordStoreToGraph(graph, recordStore, initializeWithSchema, completeWithSchema, vertexIdAttributes, vertexMap, transactionMap);
    assertEquals(2, veritices.size());
    assertEquals(2, graph.getVertexCount());
    assertEquals(1, graph.getTransactionCount());
    // try {
    // SaveGraphUtilities.saveGraphToTemporaryDirectory(graph, "testAddedRecordStoreSupportsTypesWithOverriddenDirectionWithInitialiseAndCompleteWithSchema");
    // } catch (IOException ex) {
    // Assert.fail(ex.getLocalizedMessage());
    // }
    final int transactionTypeId = AnalyticConcept.TransactionAttribute.TYPE.get(graph);
    SchemaTransactionType type = (SchemaTransactionType) graph.getObjectValue(transactionTypeId, 0);
    Assert.assertFalse(type.isDirected());
}
Also used : SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) HashMap(java.util.HashMap) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) ArrayList(java.util.ArrayList) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) Test(org.testng.annotations.Test)

Example 27 with RecordStore

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

the class GraphRecordStoreUtilitiesNGTest method addRecordStoreToGraphWithExistingGraph.

@Test
public void addRecordStoreToGraphWithExistingGraph() {
    int vx0, vx1;
    int identifierAttribute, colorAttribute;
    identifierAttribute = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
    colorAttribute = VisualConcept.VertexAttribute.COLOR.ensure(graph);
    graph.setPrimaryKey(GraphElementType.VERTEX, identifierAttribute);
    vx0 = graph.addVertex();
    vx1 = graph.addVertex();
    graph.setStringValue(identifierAttribute, vx0, "vx0");
    graph.setStringValue(identifierAttribute, vx1, "vx1");
    final RecordStore recordStore = new GraphRecordStore();
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER, "vx0");
    recordStore.set(GraphRecordStoreUtilities.SOURCE + "color", "DarkGreen");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER, "vx0");
    recordStore.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.IDENTIFIER, "vx1");
    final boolean initializeWithSchema = false;
    final boolean completeWithSchema = false;
    final List<String> vertexIdAttributes = new ArrayList<>();
    final Map<String, Integer> vertexMap = new HashMap<>();
    final Map<String, Integer> transactionMap = new HashMap<>();
    final List<Integer> verticies = GraphRecordStoreUtilities.addRecordStoreToGraph(graph, recordStore, initializeWithSchema, completeWithSchema, vertexIdAttributes, vertexMap, transactionMap);
    graph.validateKeys();
    assertEquals(3, verticies.size());
    assertEquals(2, graph.getVertexCount());
    assertEquals(1, graph.getTransactionCount());
    vx0 = graph.getVertex(vx0);
    vx1 = graph.getVertex(vx1);
    assertEquals("vx0", graph.getStringValue(identifierAttribute, vx0));
    assertEquals("DarkGreen", graph.getStringValue(colorAttribute, vx0));
    assertEquals("vx1", graph.getStringValue(identifierAttribute, vx1));
}
Also used : HashMap(java.util.HashMap) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) ArrayList(java.util.ArrayList) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) Test(org.testng.annotations.Test)

Example 28 with RecordStore

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

the class GraphRecordStoreUtilitiesNGTest method addedRecordStoreSupportsTypesWithOverriddenDirectionWithInitialiseSchema.

@Test
public void addedRecordStoreSupportsTypesWithOverriddenDirectionWithInitialiseSchema() {
    final RecordStore recordStore = new GraphRecordStore();
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.IDENTIFIER, "vx0");
    recordStore.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.IDENTIFIER, "vx1");
    recordStore.set(GraphRecordStoreUtilities.TRANSACTION + GraphRecordStoreUtilities.DIRECTED_KEY, false);
    // the communication type is directed
    recordStore.set(GraphRecordStoreUtilities.TRANSACTION + AnalyticConcept.TransactionAttribute.TYPE, AnalyticConcept.TransactionType.COMMUNICATION);
    final boolean initializeWithSchema = true;
    final boolean completeWithSchema = false;
    final List<String> vertexIdAttributes = new ArrayList<>();
    final Map<String, Integer> vertexMap = new HashMap<>();
    final Map<String, Integer> transactionMap = new HashMap<>();
    final List<Integer> veritices = GraphRecordStoreUtilities.addRecordStoreToGraph(graph, recordStore, initializeWithSchema, completeWithSchema, vertexIdAttributes, vertexMap, transactionMap);
    assertEquals(2, veritices.size());
    assertEquals(2, graph.getVertexCount());
    assertEquals(1, graph.getTransactionCount());
    // try {
    // SaveGraphUtilities.saveGraphToTemporaryDirectory(graph, "testAddedRecordStoreSupportsTypesWithOverriddenDirectionWithInitialiseSchema");
    // } catch (IOException ex) {
    // Assert.fail(ex.getLocalizedMessage());
    // }
    final int transactionTypeId = AnalyticConcept.TransactionAttribute.TYPE.get(graph);
    SchemaTransactionType type = (SchemaTransactionType) graph.getObjectValue(transactionTypeId, 0);
    Assert.assertFalse(type.isDirected());
}
Also used : SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) HashMap(java.util.HashMap) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) ArrayList(java.util.ArrayList) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) Test(org.testng.annotations.Test)

Example 29 with RecordStore

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

the class GraphRecordStoreUtilitiesNGTest method testAddRecordStoreToGraphIncludesAllRecords.

@Test
public void testAddRecordStoreToGraphIncludesAllRecords() {
    final RecordStore recordStore = new GraphRecordStore();
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx1");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx2");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx3");
    recordStore.set(GraphRecordStoreUtilities.SOURCE + "CustomAttribute", "Removed");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx4");
    recordStore.set(GraphRecordStoreUtilities.SOURCE + "CustomAttribute", "Changed");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    recordStore.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL, "vx1");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    recordStore.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL, "vx4");
    recordStore.set(GraphRecordStoreUtilities.TRANSACTION + "CustomAttribute", "Removed");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx1");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx2");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx4");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx5");
    recordStore.set(GraphRecordStoreUtilities.SOURCE + "CustomAttribute", "Added");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    recordStore.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL, "vx1");
    recordStore.add();
    recordStore.set(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL, "vx0");
    recordStore.set(GraphRecordStoreUtilities.DESTINATION + VisualConcept.VertexAttribute.LABEL, "vx5");
    recordStore.set(GraphRecordStoreUtilities.TRANSACTION + "CustomAttribute", "Added");
    // add recordstore to graph
    final boolean initializeWithSchema = true;
    final boolean completeWithSchema = false;
    final List<String> vertexIdAttributes = new ArrayList<>();
    vertexIdAttributes.add(VisualConcept.VertexAttribute.LABEL.getName() + "<string>");
    final List<Integer> veritices = GraphRecordStoreUtilities.addRecordStoreToGraph(graph, recordStore, initializeWithSchema, completeWithSchema, vertexIdAttributes);
    // check counts
    assertEquals(veritices.size(), 6);
    final int vxCount = graph.getVertexCount();
    assertEquals(vxCount, 6);
    final int txCount = graph.getTransactionCount();
    assertEquals(txCount, 4);
    // check that all vertices start with vx
    final int vxNameAttribute = VisualConcept.VertexAttribute.LABEL.get(graph);
    for (int i = 0; i < vxCount; i++) {
        int vxId = graph.getVertex(i);
        assertEquals(graph.getStringValue(vxNameAttribute, vxId), String.valueOf("vx" + vxId));
    }
// try {
// SaveGraphUtilities.saveGraphToTemporaryDirectory(graph, "testAddRecordStoreToGraphIncludesAllRecords");
// } catch (IOException ex) {
// Assert.fail(ex.getLocalizedMessage());
// }
}
Also used : RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) ArrayList(java.util.ArrayList) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) Test(org.testng.annotations.Test)

Aggregations

RecordStore (au.gov.asd.tac.constellation.graph.processing.RecordStore)29 GraphRecordStore (au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)20 Test (org.testng.annotations.Test)13 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)10 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)6 File (java.io.File)4 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)3 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)3 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)3 IOException (java.io.IOException)3 Graph (au.gov.asd.tac.constellation.graph.Graph)2 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)2 GraphReadMethods (au.gov.asd.tac.constellation.graph.GraphReadMethods)2 AnalyticSchemaFactory (au.gov.asd.tac.constellation.graph.schema.analytic.AnalyticSchemaFactory)2 CompositeNodeState (au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.CompositeNodeState)2 ExpandedCompositeNodeState (au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ExpandedCompositeNodeState)2 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)2 DateTimeRange (au.gov.asd.tac.constellation.plugins.parameters.types.DateTimeRange)2