Search in sources :

Example 86 with WritableGraph

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

the class QualityControlStateUpdaterNGTest method testReadNoNodes.

@Test
public void testReadNoNodes() throws Exception {
    System.out.println("read No Nodes");
    graph = new DualGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
    WritableGraph wg = graph.getWritableGraph("Add Elements", true);
    try {
        // Add X,Y,Z vertex attributes
        attrX = VisualConcept.VertexAttribute.X.ensure(wg);
        attrY = VisualConcept.VertexAttribute.Y.ensure(wg);
        attrZ = VisualConcept.VertexAttribute.Z.ensure(wg);
        // Add vertex and transaction SELECTED attributes
        vSelectedAttrId = VisualConcept.VertexAttribute.SELECTED.ensure(wg);
        tSelectedAttrId = VisualConcept.TransactionAttribute.SELECTED.ensure(wg);
        // Add vertex IDENTIFIER attribute and label each vertice.
        vxIdentifierAttrId = VisualConcept.VertexAttribute.IDENTIFIER.ensure(wg);
        // Add vertex TYPE attribute and set each type to unknown
        typeAttrId = AnalyticConcept.VertexAttribute.TYPE.ensure(wg);
    } finally {
        wg.commit();
    }
    // Expected rules and events
    final List<QualityControlEvent> expectedQualityControlEvents = new ArrayList<>();
    final List<QualityControlRule> expectedRegisteredRules = new ArrayList<>();
    final List<QualityControlRule> uExpectedRegisteredRules = Collections.unmodifiableList(expectedRegisteredRules);
    // Call update state to trigger checking of rules
    PluginExecution.withPlugin(new QualityControlStateUpdater()).executeNow(graph);
    // get the state and events
    final QualityControlState state = QualityControlAutoVetter.getInstance().getQualityControlState();
    final List<QualityControlEvent> qualityControlEvents = state.getQualityControlEvents();
    final List<QualityControlRule> registeredRules = state.getRegisteredRules();
    // check equality of the events and rules
    assertEquals(qualityControlEvents, expectedQualityControlEvents);
    assertEquals(registeredRules, uExpectedRegisteredRules);
}
Also used : QualityControlRule(au.gov.asd.tac.constellation.views.qualitycontrol.rules.QualityControlRule) QualityControlEvent(au.gov.asd.tac.constellation.views.qualitycontrol.QualityControlEvent) ArrayList(java.util.ArrayList) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Example 87 with WritableGraph

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

the class GLVisualProcessorGraphTester method main.

public static void main(String[] args) {
    final GLVisualProcessorDemo demo = new GLVisualProcessorDemo();
    final StoreGraph graph = createGraph();
    final Graph dualGraph = new DualGraph(graph, false);
    final GraphVisualAccess access = new GraphVisualAccess(dualGraph);
    final GLVisualProcessor processor = new GLVisualProcessor();
    final VisualManager visualManager = new VisualManager(access, processor);
    processor.startVisualising(visualManager);
    demo.runDemo(processor, visualManager);
    final GraphChangeListener gct = (event) -> visualManager.updateFromIndigenousChanges();
    gct.graphChanged(null);
    try {
        Thread.sleep(3000);
    } catch (InterruptedException ex) {
    }
    try {
        WritableGraph wg = dualGraph.getWritableGraph("linkmode", false);
        try {
            final int connectionModeAttr = VisualConcept.GraphAttribute.CONNECTION_MODE.ensure(wg);
            wg.setObjectValue(connectionModeAttr, 0, ConnectionMode.LINK);
        } finally {
            wg.commit();
        }
    } catch (InterruptedException ex) {
    }
    gct.graphChanged(null);
    try {
        Thread.sleep(2000);
    } catch (InterruptedException ex) {
    }
    try {
        WritableGraph wg = dualGraph.getWritableGraph("transmode", false);
        try {
            final int connectionModeAttr = VisualConcept.GraphAttribute.CONNECTION_MODE.ensure(wg);
            wg.setObjectValue(connectionModeAttr, 0, ConnectionMode.TRANSACTION);
        } finally {
            wg.commit();
        }
    } catch (InterruptedException ex) {
    }
    gct.graphChanged(null);
    try {
        Thread.sleep(2000);
    } catch (InterruptedException ex) {
    }
    final int[] changed = new int[] { 0, 1 };
    try {
        WritableGraph wg = dualGraph.getWritableGraph("blazin", false);
        try {
            final int blazeAttr = VisualConcept.VertexAttribute.BLAZE.ensure(wg);
            for (int i = 0; i < 10000; i++) {
                try {
                    Thread.sleep(1);
                } catch (InterruptedException ex) {
                }
                wg.setObjectValue(blazeAttr, 0, new Blaze(((Blaze) wg.getObjectValue(blazeAttr, 0)).getAngle() + 1, ConstellationColor.BLUE));
                wg = wg.flush(false);
                visualManager.addSingleChangeOperation(new VisualChangeBuilder(VisualProperty.VERTEX_BLAZE_ANGLE).forItems(changed).build());
            }
        } finally {
            wg.commit();
        }
    } catch (InterruptedException ex) {
    }
}
Also used : WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Frame(java.awt.Frame) GLVisualProcessor(au.gov.asd.tac.constellation.visual.opengl.renderer.GLVisualProcessor) Blaze(au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.Blaze) ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) DefaultIconProvider(au.gov.asd.tac.constellation.utilities.icon.DefaultIconProvider) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) WindowAdapter(java.awt.event.WindowAdapter) JFXPanel(javafx.embed.swing.JFXPanel) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) Component(java.awt.Component) WindowEvent(java.awt.event.WindowEvent) VisualProcessor(au.gov.asd.tac.constellation.utilities.visual.VisualProcessor) VisualProperty(au.gov.asd.tac.constellation.utilities.visual.VisualProperty) Graph(au.gov.asd.tac.constellation.graph.Graph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) GraphChangeListener(au.gov.asd.tac.constellation.graph.monitor.GraphChangeListener) Camera(au.gov.asd.tac.constellation.utilities.camera.Camera) VisualChangeBuilder(au.gov.asd.tac.constellation.utilities.visual.VisualChangeBuilder) VisualManager(au.gov.asd.tac.constellation.utilities.visual.VisualManager) ConnectionMode(au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.ConnectionMode) GraphVisualAccess(au.gov.asd.tac.constellation.graph.visual.framework.GraphVisualAccess) VisualChangeBuilder(au.gov.asd.tac.constellation.utilities.visual.VisualChangeBuilder) GraphVisualAccess(au.gov.asd.tac.constellation.graph.visual.framework.GraphVisualAccess) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) VisualManager(au.gov.asd.tac.constellation.utilities.visual.VisualManager) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) GLVisualProcessor(au.gov.asd.tac.constellation.visual.opengl.renderer.GLVisualProcessor) GraphChangeListener(au.gov.asd.tac.constellation.graph.monitor.GraphChangeListener) Blaze(au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.Blaze) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph)

Example 88 with WritableGraph

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

the class CompositesNGTest method compositeNonCompositeAndExpandedConstituentTest.

@Test
public void compositeNonCompositeAndExpandedConstituentTest() throws InterruptedException, PluginException {
    final WritableGraph wg = graph.getWritableGraph("test", true);
    wg.getSchema().newGraph(wg);
    int v0, v1, v2, v3;
    final String v0name, v1name, v2name, v3name;
    final int nameAttr;
    final int selectedAttr;
    final int compositeAttr;
    try {
        // Add four vertices
        v0 = wg.addVertex();
        wg.getSchema().newVertex(wg, v0);
        v1 = wg.addVertex();
        wg.getSchema().newVertex(wg, v1);
        v2 = wg.addVertex();
        wg.getSchema().newVertex(wg, v2);
        v3 = wg.addVertex();
        wg.getSchema().newVertex(wg, v3);
        // Store the names of these vertices
        nameAttr = VisualConcept.VertexAttribute.LABEL.get(wg);
        v0name = wg.getStringValue(nameAttr, v0);
        v1name = wg.getStringValue(nameAttr, v1);
        v2name = wg.getStringValue(nameAttr, v2);
        v3name = wg.getStringValue(nameAttr, v3);
        // Add transactions from v0 to v1, and from v1 to v2
        final int t0_1 = wg.addTransaction(v0, v1, true);
        wg.getSchema().newTransaction(wg, t0_1);
        final int t1_2 = wg.addTransaction(v1, v2, true);
        wg.getSchema().newTransaction(wg, t1_2);
        // Select v0 and v1, but not v2 or v3
        selectedAttr = VisualConcept.VertexAttribute.SELECTED.get(wg);
        wg.setBooleanValue(selectedAttr, v0, true);
        wg.setBooleanValue(selectedAttr, v1, true);
        wg.setBooleanValue(selectedAttr, v2, false);
        wg.setBooleanValue(selectedAttr, v3, false);
        // Make a composite from the selection then expand all composites, then finally deselect all
        PluginExecutor.startWith(PluginRegistry.get(InteractiveGraphPluginRegistry.CREATE_COMPOSITE_FROM_SELECTION)).followedBy(PluginRegistry.get(InteractiveGraphPluginRegistry.EXPAND_ALL_COMPOSITES)).followedBy(PluginRegistry.get(VisualGraphPluginRegistry.DESELECT_ALL)).executeNow(wg);
        compositeAttr = AnalyticConcept.VertexAttribute.COMPOSITE_STATE.get(wg);
        // Select v2 and the expanded vertex corresponding to v0
        v0 = Graph.NOT_FOUND;
        for (int i = 0; i < 4; i++) {
            final int id = wg.getVertex(i);
            final String name = wg.getStringValue(nameAttr, id);
            if (name.equals(v0name)) {
                v0 = id;
                break;
            }
        }
        wg.setBooleanValue(selectedAttr, v2, true);
        wg.setBooleanValue(selectedAttr, v0, true);
        // Make a composite from the selection
        PluginExecution.withPlugin(PluginRegistry.get(InteractiveGraphPluginRegistry.CREATE_COMPOSITE_FROM_SELECTION)).executeNow(wg);
    } finally {
        wg.commit();
    }
    final ReadableGraph rg = graph.getReadableGraph();
    try {
        // Assert that there is one vertex that is a composite containing two nodes,
        // and both v1 and v3 as non-composite
        assertEquals(rg.getVertexCount(), 3);
        int compositeNode = Graph.NOT_FOUND;
        v1 = Graph.NOT_FOUND;
        for (int i = 0; i < 3; i++) {
            final int id = wg.getVertex(i);
            final String name = wg.getStringValue(nameAttr, id);
            if (name.equals(v1name)) {
                v1 = id;
            } else if (id != v3) {
                compositeNode = id;
            }
        }
        final CompositeNodeState compositeState = (CompositeNodeState) rg.getObjectValue(compositeAttr, compositeNode);
        assertNotNull(compositeState);
        assertEquals(compositeState.getNumberOfNodes(), 2);
        assertTrue(compositeState.isComposite());
        assertEquals(rg.getStringValue(nameAttr, v3), v3name);
        final CompositeNodeState compositeState0 = (CompositeNodeState) rg.getObjectValue(compositeAttr, v3);
        assertNull(compositeState0);
        assertEquals(rg.getStringValue(nameAttr, v1), v1name);
        final CompositeNodeState compositeState1 = (CompositeNodeState) rg.getObjectValue(compositeAttr, v1);
        assertNull(compositeState1);
        // Assert that there are two transactions between the composite and v1
        // (one for each of the constituents, should be in different directions), and no others.
        assertEquals(rg.getTransactionCount(), 2);
        final int lc_1 = rg.getLink(compositeNode, v1);
        assertEquals(rg.getLinkTransactionCount(lc_1), 2);
        final int tc_1_0 = rg.getLinkTransaction(lc_1, 0);
        assertFalse(rg.getTransactionDirection(tc_1_0) == Graph.FLAT);
        final int tc_1_1 = rg.getLinkTransaction(lc_1, 1);
        assertFalse(rg.getTransactionDirection(tc_1_1) == Graph.FLAT);
        assertTrue(rg.getTransactionSourceVertex(tc_1_0) != rg.getTransactionSourceVertex(tc_1_1));
    } finally {
        rg.release();
    }
    final WritableGraph wg2 = graph.getWritableGraph("test", true);
    try {
        // Expand all composites
        PluginExecution.withPlugin(PluginRegistry.get(InteractiveGraphPluginRegistry.EXPAND_ALL_COMPOSITES)).executeNow(wg2);
    } finally {
        wg2.commit();
    }
    final ReadableGraph rg2 = graph.getReadableGraph();
    try {
        // Assert that the original four vertices exist; v2 and v0 with expanded composite states
        assertEquals(rg2.getVertexCount(), 4);
        v0 = Graph.NOT_FOUND;
        v1 = Graph.NOT_FOUND;
        v2 = Graph.NOT_FOUND;
        v3 = Graph.NOT_FOUND;
        for (int i = 0; i < 4; i++) {
            final int id = rg.getVertex(i);
            final String name = rg.getStringValue(nameAttr, id);
            if (name.equals(v0name)) {
                v0 = id;
            } else if (name.equals(v1name)) {
                v1 = id;
            } else if (name.equals(v2name)) {
                v2 = id;
            } else {
                v3 = id;
            }
        }
        assertEquals(rg2.getStringValue(nameAttr, v0), v0name);
        final CompositeNodeState compositeState0 = (CompositeNodeState) rg2.getObjectValue(compositeAttr, v0);
        assertNotNull(compositeState0);
        assertEquals(compositeState0.getNumberOfNodes(), 2);
        assertFalse(compositeState0.isComposite());
        assertEquals(rg2.getStringValue(nameAttr, v1), v1name);
        final CompositeNodeState compositeState1 = (CompositeNodeState) rg2.getObjectValue(compositeAttr, v1);
        assertNull(compositeState1);
        assertEquals(rg2.getStringValue(nameAttr, v2), v2name);
        final CompositeNodeState compositeState2 = (CompositeNodeState) rg2.getObjectValue(compositeAttr, v2);
        assertNotNull(compositeState2);
        assertEquals(compositeState2.getNumberOfNodes(), 2);
        assertFalse(compositeState2.isComposite());
        assertEquals(rg2.getStringValue(nameAttr, v3), v3name);
        final CompositeNodeState compositeState3 = (CompositeNodeState) rg2.getObjectValue(compositeAttr, v3);
        assertNull(compositeState3);
        // assert that the original transactions exist and none others
        assertEquals(rg.getTransactionCount(), 2);
        final int l0_1 = rg2.getLink(v0, v1);
        assertEquals(rg2.getLinkTransactionCount(l0_1), 1);
        final int t0_1 = rg2.getLinkTransaction(l0_1, 0);
        assertFalse(rg2.getTransactionDirection(t0_1) == Graph.FLAT);
        assertEquals(rg2.getTransactionSourceVertex(t0_1), v0);
        final int l1_2 = rg2.getLink(v1, v2);
        assertEquals(rg2.getLinkTransactionCount(l1_2), 1);
        final int t1_2 = rg2.getLinkTransaction(l1_2, 0);
        assertFalse(rg2.getTransactionDirection(t1_2) == Graph.FLAT);
        assertEquals(rg2.getTransactionSourceVertex(t1_2), v1);
    } finally {
        rg2.release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) CompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.CompositeNodeState) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Example 89 with WritableGraph

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

the class CompositesNGTest method makeAddTransactionExpandTest.

@Test
public void makeAddTransactionExpandTest() throws InterruptedException, PluginException {
    final WritableGraph wg = graph.getWritableGraph("test", true);
    wg.getSchema().newGraph(wg);
    final int v0, v1, v2;
    final String v0name, v1name, v2name;
    final int nameAttr;
    final int selectedAttr;
    final int compositeAttr;
    try {
        // Add three vertices
        v0 = wg.addVertex();
        wg.getSchema().newVertex(wg, v0);
        v1 = wg.addVertex();
        wg.getSchema().newVertex(wg, v1);
        v2 = wg.addVertex();
        wg.getSchema().newVertex(wg, v2);
        // Store the names of these vertices
        nameAttr = VisualConcept.VertexAttribute.LABEL.get(wg);
        v0name = wg.getStringValue(nameAttr, v0);
        v1name = wg.getStringValue(nameAttr, v1);
        v2name = wg.getStringValue(nameAttr, v2);
        // Add transactions from v0 to v1, and from v1 to v2
        final int t0_1 = wg.addTransaction(v0, v1, true);
        wg.getSchema().newTransaction(wg, t0_1);
        final int t1_2 = wg.addTransaction(v1, v2, true);
        wg.getSchema().newTransaction(wg, t1_2);
        // Select v0 and v1, but not v2
        selectedAttr = VisualConcept.VertexAttribute.SELECTED.get(wg);
        wg.setBooleanValue(selectedAttr, v0, true);
        wg.setBooleanValue(selectedAttr, v1, true);
        wg.setBooleanValue(selectedAttr, v2, false);
        // Make a composite from the selection
        PluginExecution.withPlugin(PluginRegistry.get(InteractiveGraphPluginRegistry.CREATE_COMPOSITE_FROM_SELECTION)).executeNow(wg);
        compositeAttr = AnalyticConcept.VertexAttribute.COMPOSITE_STATE.get(wg);
        // Add a transaction from the composite to the non-composite then expand all composites
        final int compositeNode = wg.getVertex(0) != v2 ? wg.getVertex(0) : wg.getVertex(1);
        final int addedTx = wg.addTransaction(compositeNode, v2, true);
        wg.getSchema().newTransaction(wg, addedTx);
        PluginExecution.withPlugin(PluginRegistry.get(InteractiveGraphPluginRegistry.EXPAND_ALL_COMPOSITES)).executeNow(wg);
    } finally {
        wg.commit();
    }
    final ReadableGraph rg = graph.getReadableGraph();
    try {
        // Assert that there are three nodes, that v2 is the same with a null composite state,
        // and that the other two have expanded composite states
        assertEquals(rg.getVertexCount(), 3);
        assertEquals(rg.getStringValue(nameAttr, v2), v2name);
        assertNull(rg.getObjectValue(compositeAttr, v2));
        final int v2pos = rg.getVertexPosition(v2);
        final int comp0 = v2pos != 0 ? rg.getVertex(0) : rg.getVertex(2);
        final int comp1 = v2pos != 1 ? rg.getVertex(1) : rg.getVertex(2);
        final int expanded_v0 = rg.getStringValue(nameAttr, comp0).equals(v0name) ? comp0 : comp1;
        final int expanded_v1 = expanded_v0 == comp0 ? comp1 : comp0;
        final CompositeNodeState compositeState0 = (CompositeNodeState) rg.getObjectValue(compositeAttr, expanded_v0);
        final CompositeNodeState compositeState1 = (CompositeNodeState) rg.getObjectValue(compositeAttr, expanded_v1);
        assertNotNull(compositeState0);
        assertEquals(compositeState0.getNumberOfNodes(), 2);
        assertTrue(compositeState0.comprisesAComposite());
        assertEquals(rg.getStringValue(nameAttr, expanded_v0), v0name);
        assertNotNull(compositeState1);
        assertEquals(compositeState1.getNumberOfNodes(), 2);
        assertTrue(compositeState1.comprisesAComposite());
        assertEquals(rg.getStringValue(nameAttr, expanded_v1), v1name);
        // Assert that there are two transaction from v1 to v2, and one from v0 to v2, as well as one from v0 to v1. This is as a result of the transaction added to the composite being added to all constituents upon expansion.
        assertEquals(rg.getTransactionCount(), 4);
        final int l0_1 = rg.getLink(expanded_v0, expanded_v1);
        assertEquals(rg.getLinkTransactionCount(l0_1), 1);
        final int t0_1 = rg.getLinkTransaction(l0_1, 0);
        assertEquals(rg.getTransactionSourceVertex(t0_1), expanded_v0);
        assertFalse(rg.getTransactionDirection(t0_1) == Graph.FLAT);
        final int l0_2 = rg.getLink(expanded_v0, v2);
        assertEquals(rg.getLinkTransactionCount(l0_2), 1);
        final int t0_2 = rg.getLinkTransaction(l0_1, 0);
        assertEquals(rg.getTransactionSourceVertex(t0_2), expanded_v0);
        assertFalse(rg.getTransactionDirection(t0_2) == Graph.FLAT);
        final int l1_2 = rg.getLink(expanded_v1, v2);
        assertEquals(rg.getLinkTransactionCount(l1_2), 2);
        final int t1_2_0 = rg.getLinkTransaction(l1_2, 0);
        final int t1_2_1 = rg.getLinkTransaction(l1_2, 1);
        assertEquals(rg.getTransactionSourceVertex(t1_2_0), expanded_v1);
        assertEquals(rg.getTransactionSourceVertex(t1_2_1), expanded_v1);
        assertFalse(rg.getTransactionDirection(t1_2_0) == Graph.FLAT);
        assertFalse(rg.getTransactionDirection(t1_2_1) == Graph.FLAT);
    } finally {
        rg.release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) CompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.CompositeNodeState) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Example 90 with WritableGraph

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

the class CompositesNGTest method makeExpandContractCompositeTest.

@Test
public void makeExpandContractCompositeTest() throws InterruptedException, PluginException {
    final WritableGraph wg = graph.getWritableGraph("test", true);
    wg.getSchema().newGraph(wg);
    final int v0, v1, v2;
    final String v0name, v1name, v2name;
    final int nameAttr;
    final int selectedAttr;
    final int compositeAttr;
    try {
        // Add three vertices
        v0 = wg.addVertex();
        wg.getSchema().newVertex(wg, v0);
        v1 = wg.addVertex();
        wg.getSchema().newVertex(wg, v1);
        v2 = wg.addVertex();
        wg.getSchema().newVertex(wg, v2);
        // Store the names of these vertices
        nameAttr = VisualConcept.VertexAttribute.LABEL.get(wg);
        v0name = wg.getStringValue(nameAttr, v0);
        v1name = wg.getStringValue(nameAttr, v1);
        v2name = wg.getStringValue(nameAttr, v2);
        // Add transactions from v0 to v1, and from v1 to v2
        final int t0_1 = wg.addTransaction(v0, v1, true);
        wg.getSchema().newTransaction(wg, t0_1);
        final int t1_2 = wg.addTransaction(v1, v2, true);
        wg.getSchema().newTransaction(wg, t1_2);
        // Select v0 and v1, but not v2
        selectedAttr = VisualConcept.VertexAttribute.SELECTED.get(wg);
        wg.setBooleanValue(selectedAttr, v0, true);
        wg.setBooleanValue(selectedAttr, v1, true);
        wg.setBooleanValue(selectedAttr, v2, false);
        // Make a composite from the selection
        PluginExecution.withPlugin(InteractiveGraphPluginRegistry.CREATE_COMPOSITE_FROM_SELECTION).executeNow(wg);
        compositeAttr = AnalyticConcept.VertexAttribute.COMPOSITE_STATE.get(wg);
    } finally {
        wg.commit();
    }
    final ReadableGraph rg = graph.getReadableGraph();
    try {
        // Assert that there are two vertices, that the composite node has a composite state containing two nodes,
        // and that the non-composite node has a null composite state and its original name.
        assertEquals(rg.getVertexCount(), 2);
        assertEquals(rg.getStringValue(nameAttr, v2), v2name);
        assertNull(rg.getObjectValue(compositeAttr, v2));
        final int compositeNode = rg.getVertex(0) != v2 ? rg.getVertex(0) : rg.getVertex(1);
        final CompositeNodeState compositeState = (CompositeNodeState) rg.getObjectValue(compositeAttr, compositeNode);
        assertNotNull(compositeState);
        assertEquals(compositeState.getNumberOfNodes(), 2);
        assertTrue(compositeState.isComposite());
        // Assert that the link between the composite node and the non-composite node exists,
        // and contains one transaction from the composite node to the non-composite node
        final int compLink = rg.getLink(compositeNode, v2);
        assertEquals(rg.getLinkTransactionCount(compLink), 1);
        final int compTrans = rg.getLinkTransaction(compLink, 0);
        assertFalse(rg.getTransactionDirection(compTrans) == Graph.FLAT);
        assertEquals(rg.getTransactionSourceVertex(compTrans), compositeNode);
    } finally {
        rg.release();
    }
    final WritableGraph wg2 = graph.getWritableGraph("test", true);
    try {
        // Contract all composites - nothing should happen
        PluginExecution.withPlugin(InteractiveGraphPluginRegistry.CONTRACT_ALL_COMPOSITES).executeNow(wg2);
    } finally {
        wg2.commit();
    }
    final ReadableGraph rg2 = graph.getReadableGraph();
    try {
        // Assert everything from above - nothing should have changed.
        assertEquals(rg2.getVertexCount(), 2);
        assertEquals(rg2.getStringValue(nameAttr, v2), v2name);
        assertNull(rg2.getObjectValue(compositeAttr, v2));
        final int compositeNode = rg2.getVertex(0) != v2 ? rg2.getVertex(0) : rg2.getVertex(1);
        final CompositeNodeState compositeState = (CompositeNodeState) rg2.getObjectValue(compositeAttr, compositeNode);
        assertNotNull(compositeState);
        assertEquals(compositeState.getNumberOfNodes(), 2);
        assertTrue(compositeState.isComposite());
        final int compLink = rg2.getLink(compositeNode, v2);
        assertEquals(rg2.getLinkTransactionCount(compLink), 1);
        final int compTrans = rg2.getLinkTransaction(compLink, 0);
        assertFalse(rg2.getTransactionDirection(compTrans) == Graph.FLAT);
        assertEquals(rg2.getTransactionSourceVertex(compTrans), compositeNode);
    } finally {
        rg2.release();
    }
    final WritableGraph wg3 = graph.getWritableGraph("test", true);
    try {
        // Expand all composites
        PluginExecution.withPlugin(InteractiveGraphPluginRegistry.EXPAND_ALL_COMPOSITES).executeNow(wg3);
    } finally {
        wg3.commit();
    }
    final ReadableGraph rg3 = graph.getReadableGraph();
    try {
        // Assert that there are three nodes, that v2 is the same with a null composite state,
        // and that the other two have expanded composite states
        assertEquals(rg3.getVertexCount(), 3);
        assertEquals(rg3.getStringValue(nameAttr, v2), v2name);
        assertNull(rg3.getObjectValue(compositeAttr, v2));
        final int v2pos = rg3.getVertexPosition(v2);
        final int comp0 = v2pos != 0 ? rg3.getVertex(0) : rg3.getVertex(2);
        final int comp1 = v2pos != 1 ? rg3.getVertex(1) : rg3.getVertex(2);
        final int expanded_v0 = rg3.getStringValue(nameAttr, comp0).equals(v0name) ? comp0 : comp1;
        final int expanded_v1 = expanded_v0 == comp0 ? comp1 : comp0;
        final CompositeNodeState compositeState0 = (CompositeNodeState) rg3.getObjectValue(compositeAttr, expanded_v0);
        final CompositeNodeState compositeState1 = (CompositeNodeState) rg3.getObjectValue(compositeAttr, expanded_v1);
        assertNotNull(compositeState0);
        assertEquals(compositeState0.getNumberOfNodes(), 2);
        assertTrue(compositeState0.comprisesAComposite());
        assertEquals(rg3.getStringValue(nameAttr, expanded_v0), v0name);
        assertNotNull(compositeState1);
        assertEquals(compositeState1.getNumberOfNodes(), 2);
        assertTrue(compositeState1.comprisesAComposite());
        assertEquals(rg3.getStringValue(nameAttr, expanded_v1), v1name);
        // Assert that the the original transactions exist and no others.
        assertEquals(rg3.getTransactionCount(), 2);
        final int l0_1 = rg3.getLink(expanded_v0, expanded_v1);
        assertEquals(rg3.getLinkTransactionCount(l0_1), 1);
        final int t0_1 = rg3.getLinkTransaction(l0_1, 0);
        assertEquals(rg3.getTransactionSourceVertex(t0_1), expanded_v0);
        assertFalse(rg3.getTransactionDirection(t0_1) == Graph.FLAT);
        final int l0_2 = rg3.getLink(expanded_v0, v2);
        final int l1_2 = rg3.getLink(expanded_v1, v2);
        assertEquals(l0_2, Graph.NOT_FOUND);
        assertEquals(rg3.getLinkTransactionCount(l1_2), 1);
        final int t1_2 = rg3.getLinkTransaction(l1_2, 0);
        assertEquals(rg3.getTransactionSourceVertex(t1_2), expanded_v1);
        assertFalse(rg3.getTransactionDirection(t1_2) == Graph.FLAT);
    } finally {
        rg3.release();
    }
    final WritableGraph wg4 = graph.getWritableGraph("test", true);
    try {
        // Expand all composites - nothing should happen
        PluginExecution.withPlugin(PluginRegistry.get(InteractiveGraphPluginRegistry.EXPAND_ALL_COMPOSITES)).executeNow(wg4);
    } finally {
        wg4.commit();
    }
    final ReadableGraph rg4 = graph.getReadableGraph();
    try {
        // Assert everything from above - nothing should have changed.
        assertEquals(rg4.getVertexCount(), 3);
        assertEquals(rg4.getStringValue(nameAttr, v2), v2name);
        assertNull(rg4.getObjectValue(compositeAttr, v2));
        final int v2pos = rg4.getVertexPosition(v2);
        final int comp0 = v2pos != 0 ? rg4.getVertex(0) : rg4.getVertex(2);
        final int comp1 = v2pos != 1 ? rg4.getVertex(1) : rg4.getVertex(2);
        final int expanded_v0 = rg4.getStringValue(nameAttr, comp0).equals(v0name) ? comp0 : comp1;
        final int expanded_v1 = expanded_v0 == comp0 ? comp1 : comp0;
        final CompositeNodeState compositeState0 = (CompositeNodeState) rg4.getObjectValue(compositeAttr, expanded_v0);
        final CompositeNodeState compositeState1 = (CompositeNodeState) rg4.getObjectValue(compositeAttr, expanded_v1);
        assertNotNull(compositeState0);
        assertEquals(compositeState0.getNumberOfNodes(), 2);
        assertTrue(compositeState0.comprisesAComposite());
        assertEquals(rg4.getStringValue(nameAttr, expanded_v0), v0name);
        assertNotNull(compositeState1);
        assertEquals(compositeState1.getNumberOfNodes(), 2);
        assertTrue(compositeState1.comprisesAComposite());
        assertEquals(rg4.getStringValue(nameAttr, expanded_v1), v1name);
        // Assert that the the original transactions exist and no others.
        assertEquals(rg4.getTransactionCount(), 2);
        final int l0_1 = rg4.getLink(expanded_v0, expanded_v1);
        assertEquals(rg4.getLinkTransactionCount(l0_1), 1);
        final int t0_1 = rg4.getLinkTransaction(l0_1, 0);
        assertEquals(rg4.getTransactionSourceVertex(t0_1), expanded_v0);
        assertFalse(rg4.getTransactionDirection(t0_1) == Graph.FLAT);
        final int l0_2 = rg4.getLink(expanded_v0, v2);
        final int l1_2 = rg4.getLink(expanded_v1, v2);
        assertEquals(l0_2, Graph.NOT_FOUND);
        assertEquals(rg4.getLinkTransactionCount(l1_2), 1);
        final int t1_2 = rg4.getLinkTransaction(l1_2, 0);
        assertEquals(rg4.getTransactionSourceVertex(t1_2), expanded_v1);
        assertFalse(rg4.getTransactionDirection(t1_2) == Graph.FLAT);
    } finally {
        rg4.release();
    }
    final WritableGraph wg5 = graph.getWritableGraph("test", true);
    try {
        // Contract all composites
        PluginExecution.withPlugin(PluginRegistry.get(InteractiveGraphPluginRegistry.CONTRACT_ALL_COMPOSITES)).executeNow(wg5);
    } finally {
        wg5.commit();
    }
    // Assert everything that was previously true when we first made the composites
    final ReadableGraph rg5 = graph.getReadableGraph();
    try {
        // Assert everything from above - nothing should have changed.
        assertEquals(rg5.getVertexCount(), 2);
        assertEquals(rg5.getStringValue(nameAttr, v2), v2name);
        assertNull(rg5.getObjectValue(compositeAttr, v2));
        final int compositeNode = rg5.getVertex(0) != v2 ? rg5.getVertex(0) : rg5.getVertex(1);
        final CompositeNodeState compositeState = (CompositeNodeState) rg5.getObjectValue(compositeAttr, compositeNode);
        assertNotNull(compositeState);
        assertEquals(compositeState.getNumberOfNodes(), 2);
        assertTrue(compositeState.isComposite());
        final int compLink = rg5.getLink(compositeNode, v2);
        assertEquals(rg5.getLinkTransactionCount(compLink), 1);
        final int compTrans = rg5.getLinkTransaction(compLink, 0);
        assertFalse(rg5.getTransactionDirection(compTrans) == Graph.FLAT);
        assertEquals(rg5.getTransactionSourceVertex(compTrans), compositeNode);
    } finally {
        rg5.release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) CompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.CompositeNodeState) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Aggregations

WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)116 Test (org.testng.annotations.Test)77 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)39 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)37 Graph (au.gov.asd.tac.constellation.graph.Graph)20 ArrayList (java.util.ArrayList)14 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)9 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)8 CompositeNodeState (au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.CompositeNodeState)8 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)7 BeforeMethod (org.testng.annotations.BeforeMethod)7 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)6 Schema (au.gov.asd.tac.constellation.graph.schema.Schema)6 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)6 Attribute (au.gov.asd.tac.constellation.graph.Attribute)5 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)5 CopyToNewGraphPlugin (au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.CopyToNewGraphPlugin)5 ConstellationColor (au.gov.asd.tac.constellation.utilities.color.ConstellationColor)4 DuplicateKeyException (au.gov.asd.tac.constellation.graph.DuplicateKeyException)3 GraphRecordStore (au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)3