Search in sources :

Example 1 with FindResult

use of au.gov.asd.tac.constellation.views.find.advanced.FindResult in project constellation by constellation-app.

the class FindTopComponent method performSearch.

/**
 * Gathers the state from the graph, and executes the
 * <code>AdvancedQueryPlugin</code>, passing it the rules from the state.
 * <p>
 * (Where each <code>FindCriteriaPanel</code> represents an individual
 * rule.)
 */
@SuppressWarnings("unchecked")
private void performSearch() {
    final Graph graph = graphNode.getGraph();
    final FindState state = saveStateToGraph();
    final AdvancedFindPlugin queryPlugin = new AdvancedFindPlugin(type, state.getRules(), !state.isAny());
    final Future<?> future = PluginExecution.withPlugin(queryPlugin).interactively(true).executeLater(graph);
    // Wait for the search to find its results:
    try {
        future.get();
    } catch (final InterruptedException ex) {
        LOGGER.log(Level.SEVERE, "Thread was interrupted", ex);
        Thread.currentThread().interrupt();
    } catch (final ExecutionException ex) {
        LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
    }
    final List<FindResult> results = queryPlugin.getResults();
    final SelectFindResultsPlugin selectPlugin = new SelectFindResultsPlugin(results, state.isHeld());
    PluginExecution.withPlugin(selectPlugin).interactively(true).executeLater(graph);
}
Also used : AdvancedFindPlugin(au.gov.asd.tac.constellation.views.find.advanced.AdvancedFindPlugin) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) FindState(au.gov.asd.tac.constellation.views.find.advanced.FindState) SelectFindResultsPlugin(au.gov.asd.tac.constellation.views.find.advanced.SelectFindResultsPlugin) ExecutionException(java.util.concurrent.ExecutionException) FindResult(au.gov.asd.tac.constellation.views.find.advanced.FindResult)

Example 2 with FindResult

use of au.gov.asd.tac.constellation.views.find.advanced.FindResult in project constellation by constellation-app.

the class TransactionQuickSearchProvider method evaluate.

/**
 * Determines whether any content from the current Graph matches the search
 * term.
 *
 * @param request The content being entered into the QuickSearch box.
 * @param response The content to be returned to the QuickSearch box.
 */
@Override
@SuppressWarnings("unchecked")
public void evaluate(final SearchRequest request, final SearchResponse response) {
    final Graph graph = graphRetriever.getGraph();
    if (graph != null) {
        final QuickFindPlugin plugin = new QuickFindPlugin(GraphElementType.TRANSACTION, request.getText());
        final Future<?> future = PluginExecution.withPlugin(plugin).interactively(true).executeLater(graph);
        // Wait for results:
        try {
            future.get();
        } catch (final InterruptedException ex) {
            LOGGER.log(Level.SEVERE, "Quick Find was interrupted", ex);
            Thread.currentThread().interrupt();
        } catch (final ExecutionException ex) {
            LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
        }
        final List<FindResult> results = plugin.getResults();
        for (FindResult item : results) {
            if (item != null) {
                // We have a valid result, so report:
                response.addResult(new SelectContent(graph, item), item.toString());
            }
        }
    }
}
Also used : Graph(au.gov.asd.tac.constellation.graph.Graph) ExecutionException(java.util.concurrent.ExecutionException) QuickFindPlugin(au.gov.asd.tac.constellation.views.find.advanced.QuickFindPlugin) FindResult(au.gov.asd.tac.constellation.views.find.advanced.FindResult)

Example 3 with FindResult

use of au.gov.asd.tac.constellation.views.find.advanced.FindResult in project constellation by constellation-app.

the class FindNGTest method findBooleanValuesTest.

@Test
public void findBooleanValuesTest() 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("boolean_content", true);
        FindRule rule1 = new FindRule(FindTypeOperators.Type.BOOLEAN, new GraphAttribute(rg, vSelAttr), FindTypeOperators.Operator.IS, 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", 3, results.size());
        assertTrue("node 'name2' found", nodeFound(rg, "name2", results));
        assertTrue("node 'name4' found", nodeFound(rg, "name4", results));
        assertTrue("node 'name6' found", nodeFound(rg, "name6", 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 4 with FindResult

use of au.gov.asd.tac.constellation.views.find.advanced.FindResult in project constellation by constellation-app.

the class FindNGTest method findSingleNodeCaseSensitiveFindTest.

@Test
public void findSingleNodeCaseSensitiveFindTest() 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", "name1");
        values.put("string_case_sensitive", true);
        values.put("string_use_list", false);
        FindRule rule1 = new FindRule(FindTypeOperators.Type.STRING, new GraphAttribute(rg, rg.getAttribute(GraphElementType.VERTEX, vNameAttr)), FindTypeOperators.Operator.IS, values);
        rules.add(rule1);
        // perform find search
        // need to create temporary GraphNode and skip the RemoteInit portion of the initialisation
        GraphNode gn = 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 5 with FindResult

use of au.gov.asd.tac.constellation.views.find.advanced.FindResult in project constellation by constellation-app.

the class FindNGTest method findFloatValuesTest.

@Test
public void findFloatValuesTest() 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("float_first_item", 5.1f);
        FindRule rule1 = new FindRule(FindTypeOperators.Type.FLOAT, new GraphAttribute(rg, attrX), FindTypeOperators.Operator.GREATER_THAN, 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", 2, results.size());
        assertTrue("node 'name6' found", nodeFound(rg, "name6", results));
        assertTrue("node 'name7' found", nodeFound(rg, "name7", 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

FindResult (au.gov.asd.tac.constellation.views.find.advanced.FindResult)25 Test (org.testng.annotations.Test)20 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)9 AdvancedFindPlugin (au.gov.asd.tac.constellation.views.find.advanced.AdvancedFindPlugin)9 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)8 GraphNode (au.gov.asd.tac.constellation.graph.node.GraphNode)8 FindRule (au.gov.asd.tac.constellation.views.find.advanced.FindRule)8 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 TopComponent (org.openide.windows.TopComponent)8 Graph (au.gov.asd.tac.constellation.graph.Graph)5 ExecutionException (java.util.concurrent.ExecutionException)5 QuickFindPlugin (au.gov.asd.tac.constellation.views.find.advanced.QuickFindPlugin)4 FindState (au.gov.asd.tac.constellation.views.find.advanced.FindState)1 SelectFindResultsPlugin (au.gov.asd.tac.constellation.views.find.advanced.SelectFindResultsPlugin)1