Search in sources :

Example 11 with GraphNode

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

the class AutosaveGraphPluginNGTest method testExecute.

/**
 * Test of execute method, of class AutosaveGraphPlugin.
 *
 * @throws java.lang.Exception
 */
@Test
public void testExecute() throws Exception {
    final File saveDir = AutosaveUtilities.getAutosaveDir();
    final File saveFile = new File(saveDir, graph.getId() + FileExtensionConstants.STAR);
    // check the autosave file doesn't exist before running the plugin
    assertEquals(saveFile.exists(), false);
    TopComponent tc = new TopComponent();
    tc.setName("TestName");
    final GraphDataObject gdo = GraphObjectUtilities.createMemoryDataObject("graph", true);
    final GraphNode graphNode = new GraphNode(graph, gdo, tc, null);
    AutosaveGraphPlugin instance = new AutosaveGraphPlugin();
    PluginExecution.withPlugin(instance).executeNow(graph);
    // check that the autosave file does now exist
    assertEquals(saveFile.exists(), true);
    final Graph openSavedGraph = new GraphJsonReader().readGraphZip(saveFile, new TextIoProgress(false));
    final ReadableGraph rg = openSavedGraph.getReadableGraph();
    try {
        // check that the graph from the autosave matches the original graph
        assertEquals(rg.getVertexCount(), 7);
        assertEquals(rg.getStringValue(vAttrId, vxId1), "false");
        assertEquals(rg.getStringValue(vAttrId, vxId2), "true");
        assertEquals(rg.getStringValue(vAttrId, vxId3), "false");
        assertEquals(rg.getStringValue(vAttrId, vxId4), "false");
        assertEquals(rg.getStringValue(vAttrId, vxId5), "true");
        assertEquals(rg.getTransactionCount(), 5);
    } finally {
        rg.release();
        // deleting the file afterwards
        AutosaveUtilities.deleteAutosave(saveFile);
        graphNode.destroy();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) GraphDataObject(au.gov.asd.tac.constellation.graph.file.GraphDataObject) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) TextIoProgress(au.gov.asd.tac.constellation.utilities.gui.TextIoProgress) File(java.io.File) TopComponent(org.openide.windows.TopComponent) GraphJsonReader(au.gov.asd.tac.constellation.graph.file.io.GraphJsonReader) Test(org.testng.annotations.Test)

Example 12 with GraphNode

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

the class PermanentMergeNodeContextMenu method selectItem.

@Override
public void selectItem(final String item, final Graph graph, final GraphElementType elementType, final int element, final Vector3f unprojected) {
    final GraphNode gNode = GraphNode.getGraphNode(graph);
    final PermanentMergeAction action = new PermanentMergeAction(gNode);
    new Thread(() -> {
        try {
            action.execute(element);
        } catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
        }
    }).start();
}
Also used : GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode)

Example 13 with GraphNode

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

the class GetGraphImage method callService.

@Override
public void callService(final PluginParameters parameters, final InputStream in, final OutputStream out) throws IOException {
    final Graph graph = GraphManager.getDefault().getActiveGraph();
    if (graph == null) {
        throw new RestServiceException(HTTP_UNPROCESSABLE_ENTITY, "No graph is opened in Constellation");
    }
    // This is asynchronous, so we need a Semaphore.
    // 
    final GraphNode graphNode = GraphNode.getGraphNode(graph);
    final VisualManager visualManager = graphNode.getVisualManager();
    final BufferedImage[] img1 = new BufferedImage[1];
    if (visualManager != null) {
        final Semaphore waiter = new Semaphore(0);
        visualManager.exportToBufferedImage(img1, waiter);
        waiter.acquireUninterruptibly();
        ImageIO.write(img1[0], "png", out);
    } else {
        throw new IOException("Graph image unavailable");
    }
}
Also used : RestServiceException(au.gov.asd.tac.constellation.webserver.restapi.RestServiceException) VisualManager(au.gov.asd.tac.constellation.utilities.visual.VisualManager) Graph(au.gov.asd.tac.constellation.graph.Graph) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) Semaphore(java.util.concurrent.Semaphore) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage)

Example 14 with GraphNode

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

the class FindNGTest method findSingleNodeContainTest.

@Test
public void findSingleNodeContainTest() throws InterruptedException, PluginException {
    ArrayList<FindRule> rules = new ArrayList<>();
    ReadableGraph rg = graph.getReadableGraph();
    try {
        // setup find criteria / rules
        HashMap<String, Object> values = new HashMap<>();
        values.put("string_content", "e1");
        values.put("string_case_sensitive", false);
        values.put("string_use_list", false);
        FindRule rule1 = new FindRule(FindTypeOperators.Type.STRING, new GraphAttribute(rg, rg.getAttribute(GraphElementType.VERTEX, vNameAttr)), FindTypeOperators.Operator.CONTAINS, values);
        rules.add(rule1);
        // perform find search
        // need to create temporary GraphNode and skip the RemoteInit portion of the initialisation
        GraphNode aGraphNode = new GraphNode(graph, null, new TopComponent(), null);
        final AdvancedFindPlugin queryPlugin = new AdvancedFindPlugin(GraphElementType.VERTEX, rules, false);
        PluginExecution.withPlugin(queryPlugin).executeNow(graph);
        final List<FindResult> results = queryPlugin.getResults();
        // validate results
        assertEquals("result size", 1, results.size());
        assertTrue("node 'name1' found", nodeFound(rg, "name1", results));
    } finally {
        rg.release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) AdvancedFindPlugin(au.gov.asd.tac.constellation.views.find.advanced.AdvancedFindPlugin) HashMap(java.util.HashMap) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) FindRule(au.gov.asd.tac.constellation.views.find.advanced.FindRule) ArrayList(java.util.ArrayList) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) TopComponent(org.openide.windows.TopComponent) FindResult(au.gov.asd.tac.constellation.views.find.advanced.FindResult) Test(org.testng.annotations.Test)

Example 15 with GraphNode

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

the class FindNGTest method findTransactionsTest.

@Test
public void findTransactionsTest() throws InterruptedException, PluginException {
    ArrayList<FindRule> rules = new ArrayList<>();
    ReadableGraph rg = graph.getReadableGraph();
    try {
        // setup find criteria / rules
        HashMap<String, Object> values = new HashMap<>();
        values.put("string_content", "name");
        values.put("string_case_sensitive", true);
        values.put("string_use_list", false);
        FindRule rule1 = new FindRule(FindTypeOperators.Type.STRING, new GraphAttribute(rg, tNameAttr), FindTypeOperators.Operator.CONTAINS, values);
        rules.add(rule1);
        // perform find search
        // need to create temporary GraphNode and skip the RemoteInit portion of the initialisation
        GraphNode aGraphNode = new GraphNode(graph, null, new TopComponent(), null);
        final AdvancedFindPlugin queryPlugin = new AdvancedFindPlugin(GraphElementType.TRANSACTION, rules, false);
        PluginExecution.withPlugin(queryPlugin).executeNow(graph);
        final List<FindResult> results = queryPlugin.getResults();
        // validate results
        assertEquals("result size", 5, results.size());
        assertTrue("tx 'name101' found", transactionFound(rg, "name101", results));
        assertTrue("tx 'name102' found", transactionFound(rg, "name102", results));
        assertTrue("tx 'name103' found", transactionFound(rg, "name103", results));
        assertTrue("tx 'name104' found", transactionFound(rg, "name104", results));
        assertTrue("tx 'name105' found", transactionFound(rg, "name105", results));
    } finally {
        rg.release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) AdvancedFindPlugin(au.gov.asd.tac.constellation.views.find.advanced.AdvancedFindPlugin) HashMap(java.util.HashMap) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) FindRule(au.gov.asd.tac.constellation.views.find.advanced.FindRule) ArrayList(java.util.ArrayList) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) TopComponent(org.openide.windows.TopComponent) FindResult(au.gov.asd.tac.constellation.views.find.advanced.FindResult) Test(org.testng.annotations.Test)

Aggregations

GraphNode (au.gov.asd.tac.constellation.graph.node.GraphNode)21 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)11 TopComponent (org.openide.windows.TopComponent)9 Test (org.testng.annotations.Test)9 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)8 AdvancedFindPlugin (au.gov.asd.tac.constellation.views.find.advanced.AdvancedFindPlugin)8 FindResult (au.gov.asd.tac.constellation.views.find.advanced.FindResult)8 FindRule (au.gov.asd.tac.constellation.views.find.advanced.FindRule)8 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 Graph (au.gov.asd.tac.constellation.graph.Graph)6 File (java.io.File)5 IOException (java.io.IOException)5 VisualManager (au.gov.asd.tac.constellation.utilities.visual.VisualManager)3 RestServiceException (au.gov.asd.tac.constellation.webserver.restapi.RestServiceException)2 BufferedImage (java.awt.image.BufferedImage)2 Semaphore (java.util.concurrent.Semaphore)2 GraphReadMethods (au.gov.asd.tac.constellation.graph.GraphReadMethods)1 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)1 GraphDataObject (au.gov.asd.tac.constellation.graph.file.GraphDataObject)1