Search in sources :

Example 1 with FindRule

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

the class FindTopComponent method setDefaultFindCriteriaPanels.

/**
 * add set of find criteria panel based on primary keys, otherwise just add
 * one with the first column in it
 */
private void setDefaultFindCriteriaPanels() {
    final Graph graph = graphNode.getGraph();
    ReadableGraph rg = graph.getReadableGraph();
    try {
        int[] keys = rg.getPrimaryKey(type);
        if (keys.length == 0) {
            addFindCriteriaPanel();
        } else {
            for (int i = 0; i < keys.length; i++) {
                Attribute attr = new GraphAttribute(rg, keys[i]);
                FindRule rule = new FindRule();
                rule.setAttribute(attr);
                if ("boolean".equalsIgnoreCase(attr.getAttributeType())) {
                    rule.addBooleanBasedRule(true);
                    rule.setOperator(FindTypeOperators.Operator.IS);
                } else if ("color".equalsIgnoreCase(attr.getAttributeType())) {
                    rule.addColorBasedRule(Color.BLACK);
                    rule.setOperator(FindTypeOperators.Operator.IS);
                } else if ("date".equalsIgnoreCase(attr.getAttributeType())) {
                    rule.addDateBasedRule(new Date(), new Date());
                    rule.setOperator(FindTypeOperators.Operator.OCCURRED_ON);
                } else if (attr.getAttributeType().equalsIgnoreCase(ZonedDateTimeAttributeDescription.ATTRIBUTE_NAME)) {
                    rule.addDateTimeBasedRule(new GregorianCalendar(), new GregorianCalendar());
                    rule.setOperator(FindTypeOperators.Operator.OCCURRED_ON);
                } else if ("time".equalsIgnoreCase(attr.getAttributeType())) {
                    rule.addTimeBasedRule(new GregorianCalendar(), new GregorianCalendar());
                    rule.setOperator(FindTypeOperators.Operator.OCCURRED_ON);
                } else if ("float".equalsIgnoreCase(attr.getAttributeType())) {
                    rule.addFloatBasedRule(0.0F, 0.0F);
                    rule.setOperator(FindTypeOperators.Operator.IS);
                } else if ("integer".equalsIgnoreCase(attr.getAttributeType())) {
                    rule.addIntegerBasedRule(0, 0);
                    rule.setOperator(FindTypeOperators.Operator.IS);
                } else if ("icon".equalsIgnoreCase(attr.getAttributeType())) {
                    rule.addIconBasedRule("");
                    rule.setOperator(FindTypeOperators.Operator.IS);
                } else {
                    // string
                    rule.addStringBasedRule("", false, false);
                    rule.setOperator(FindTypeOperators.Operator.CONTAINS);
                }
                addFindCriteriaPanel(rule);
            }
        }
    } finally {
        rg.release();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) FindRule(au.gov.asd.tac.constellation.views.find.advanced.FindRule) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date)

Example 2 with FindRule

use of au.gov.asd.tac.constellation.views.find.advanced.FindRule 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 3 with FindRule

use of au.gov.asd.tac.constellation.views.find.advanced.FindRule 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 4 with FindRule

use of au.gov.asd.tac.constellation.views.find.advanced.FindRule 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)

Example 5 with FindRule

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

the class FindNGTest method findSingleNodeCaseSensitiveNoFindTest.

@Test
public void findSingleNodeCaseSensitiveNoFindTest() 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 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", 0, results.size());
    } 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

FindRule (au.gov.asd.tac.constellation.views.find.advanced.FindRule)10 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)9 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)9 GraphNode (au.gov.asd.tac.constellation.graph.node.GraphNode)8 AdvancedFindPlugin (au.gov.asd.tac.constellation.views.find.advanced.AdvancedFindPlugin)8 FindResult (au.gov.asd.tac.constellation.views.find.advanced.FindResult)8 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 TopComponent (org.openide.windows.TopComponent)8 Test (org.testng.annotations.Test)8 Attribute (au.gov.asd.tac.constellation.graph.Attribute)1 Graph (au.gov.asd.tac.constellation.graph.Graph)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1