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();
}
}
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();
}
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");
}
}
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();
}
}
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();
}
}
Aggregations