Search in sources :

Example 11 with FindCriteriaValues

use of au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues in project constellation by constellation-app.

the class AdvancedSearchPlugin method searchAsIcon.

/**
 * This function checks to see if a graph elements icon attribute matches
 * the criteria specified by the IconCriteriaValues.
 *
 * @param values the icon criteriaValues
 * @param attributeInt the int of the attribute
 * @param currElement the currentElement
 * @param graph the current graph
 * @return
 */
private boolean searchAsIcon(final FindCriteriaValues values, final int attributeInt, final int currElement, final GraphWriteMethods graph) {
    final IconCriteriaValues iconValues = (IconCriteriaValues) values;
    final ConstellationIcon icon = graph.getObjectValue(attributeInt, currElement);
    boolean matches = false;
    // if the icon of the attribute matches the users icon matches = true
    if (iconValues.getFilter().equals(IS) && iconValues.getIconValue().equals(icon)) {
        matches = true;
    // if the icon of the attribute does not match the users icon matches = true
    } else if (iconValues.getFilter().equals(IS_NOT) && !iconValues.getIconValue().equals(icon)) {
        matches = true;
    }
    return matches;
}
Also used : IconCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.IconCriteriaValues) ConstellationIcon(au.gov.asd.tac.constellation.utilities.icon.ConstellationIcon)

Example 12 with FindCriteriaValues

use of au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues in project constellation by constellation-app.

the class AdvancedFindTab method updateAdvancedSearchParameters.

/**
 * This function takes a graph element type, gets the corresponding criteria
 * values list and saves all the UI preferences into a
 * AdvancedSearchParamters object. This object is then saved into the
 * AdvancedSerachParamter object in the controller.
 *
 * @param type The graph element type being saved
 */
public void updateAdvancedSearchParameters(final GraphElementType type) {
    final List<FindCriteriaValues> criteriaValuesList = getCriteriaValues(getCorrespondingCriteriaList(type));
    final AdvancedSearchParameters parameters = new AdvancedSearchParameters(criteriaValuesList, type, matchCriteriaChoiceBox.getSelectionModel().getSelectedItem(), currentSelectionChoiceBox.getSelectionModel().getSelectedItem(), searchAllGraphs.isSelected());
    FindViewController.getDefault().updateAdvancedSearchParameters(parameters);
}
Also used : FindCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues) AdvancedSearchParameters(au.gov.asd.tac.constellation.views.find2.components.advanced.utilities.AdvancedSearchParameters)

Example 13 with FindCriteriaValues

use of au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues in project constellation by constellation-app.

the class AdvancedSearchPluginNGTest method testEdit.

/**
 * Test of edit method, of class AdvancedSearchPlugin.
 */
@Test
public void testEdit() throws Exception {
    System.out.println("edit");
    setupGraph();
    GraphElementType elementType = GraphElementType.VERTEX;
    final String all = "All";
    final String any = "Any";
    final String ignore = "Ignore";
    final String addTo = "Add To";
    final String removeFrom = "Remove From";
    final String findIn = "Find In";
    boolean searchAllGraphs = false;
    // STRING | VERTEX | MATCH ANY CRITERIA | INGORE CURRENT SELECTION | SEARCH 1 GRAPH
    // Is
    List<FindCriteriaValues> findCriteriaValuesList = new ArrayList<>();
    StringCriteriaValues stringCriteriaValue1 = new StringCriteriaValues("string", "Identifier", "Is", "identifer name", true, false);
    findCriteriaValuesList.add(stringCriteriaValue1);
    AdvancedSearchParameters parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    AdvancedSearchPlugin advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    ReadableGraph rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId4), true);
    rg.close();
    // Is not
    findCriteriaValuesList = new ArrayList<>();
    stringCriteriaValue1 = new StringCriteriaValues("string", "Identifier", "Is Not", "identifer name", true, false);
    findCriteriaValuesList.add(stringCriteriaValue1);
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId4), false);
    rg.close();
    // Contains
    findCriteriaValuesList = new ArrayList<>();
    stringCriteriaValue1 = new StringCriteriaValues("string", "Identifier", "Contains", "identifer", true, false);
    findCriteriaValuesList.add(stringCriteriaValue1);
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId4), true);
    rg.close();
    // Doesn't Contain
    findCriteriaValuesList = new ArrayList<>();
    stringCriteriaValue1 = new StringCriteriaValues("string", "Identifier", "Doesn't Contain", "identifer", true, false);
    findCriteriaValuesList.add(stringCriteriaValue1);
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId4), false);
    rg.close();
    // Begins With
    findCriteriaValuesList = new ArrayList<>();
    stringCriteriaValue1 = new StringCriteriaValues("string", "Identifier", "Begins With", "iden", true, false);
    findCriteriaValuesList.add(stringCriteriaValue1);
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId4), true);
    rg.close();
    // Ends With
    findCriteriaValuesList = new ArrayList<>();
    stringCriteriaValue1 = new StringCriteriaValues("string", "Identifier", "Ends With", "name", true, false);
    findCriteriaValuesList.add(stringCriteriaValue1);
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId4), true);
    rg.close();
    // Matches (Regex)
    findCriteriaValuesList = new ArrayList<>();
    stringCriteriaValue1 = new StringCriteriaValues("string", "Identifier", "Matches (Regex)", "den", true, false);
    findCriteriaValuesList.add(stringCriteriaValue1);
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId4), true);
    rg.close();
    // Float
    // Is
    findCriteriaValuesList = new ArrayList<>();
    FloatCriteriaValues floatCriteriaValues = new FloatCriteriaValues("float", "x", "Is", 1);
    findCriteriaValuesList.add(floatCriteriaValues);
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId4), true);
    rg.close();
    // Is Not
    findCriteriaValuesList = new ArrayList<>();
    floatCriteriaValues = new FloatCriteriaValues("float", "x", "Is Not", 1);
    findCriteriaValuesList.add(floatCriteriaValues);
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId4), false);
    rg.close();
    // Is Less Than
    findCriteriaValuesList = new ArrayList<>();
    floatCriteriaValues = new FloatCriteriaValues("float", "x", "Is Less Than", 4);
    findCriteriaValuesList.add(floatCriteriaValues);
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId4), true);
    rg.close();
    // Is Greater Than
    findCriteriaValuesList = new ArrayList<>();
    floatCriteriaValues = new FloatCriteriaValues("float", "x", "Is Greater Than", 0);
    findCriteriaValuesList.add(floatCriteriaValues);
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId4), true);
    rg.close();
    // Is Between
    findCriteriaValuesList = new ArrayList<>();
    floatCriteriaValues = new FloatCriteriaValues("float", "x", "Is Between", 0, 4);
    findCriteriaValuesList.add(floatCriteriaValues);
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId4), true);
    rg.close();
    // Boolean
    // Is
    findCriteriaValuesList = new ArrayList<>();
    BooleanCriteriaValues booleanCriteriaValue = new BooleanCriteriaValues("boolean", "dim", "Is", true);
    findCriteriaValuesList.add(booleanCriteriaValue);
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId4), true);
    rg.close();
    // Constellation Color
    // Is
    findCriteriaValuesList = new ArrayList<>();
    ColourCriteriaValues colourCriteriaValue = new ColourCriteriaValues("color", "color", "Is", ConstellationColor.BLUE);
    findCriteriaValuesList.add(colourCriteriaValue);
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId4), true);
    rg.close();
    // Is Not
    findCriteriaValuesList = new ArrayList<>();
    colourCriteriaValue = new ColourCriteriaValues("color", "color", "Is Not", ConstellationColor.BLUE);
    findCriteriaValuesList.add(colourCriteriaValue);
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId4), false);
    rg.close();
    // Constellation Icon
    // Is
    findCriteriaValuesList = new ArrayList<>();
    IconCriteriaValues iconCriteriaValue = new IconCriteriaValues("icon", "background_icon", "Is", IconManager.getIcon("Flag.Australia"));
    findCriteriaValuesList.add(iconCriteriaValue);
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId4), true);
    rg.close();
    // Is Not
    findCriteriaValuesList = new ArrayList<>();
    iconCriteriaValue = new IconCriteriaValues("icon", "background_icon", "Is Not", IconManager.getIcon("Flag.Australia"));
    findCriteriaValuesList.add(iconCriteriaValue);
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId4), false);
    rg.close();
    // DateTime
    // Occured On
    findCriteriaValuesList = new ArrayList<>();
    DateTimeCriteriaValues dateTimeCriteriaValue = new DateTimeCriteriaValues("datetime", "DateTime", "Occured On", formatDateTime(testTime));
    findCriteriaValuesList.add(dateTimeCriteriaValue);
    elementType = GraphElementType.TRANSACTION;
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    LOG.log(Level.SEVERE, dateTimeCriteriaValue.getDateTimeStringPrimaryValue());
    LOG.log(Level.SEVERE, dateTimeCriteriaValue.getDateTimeStringPrimaryValue());
    LOG.log(Level.SEVERE, rg.getObjectValue(dateTimeT, txId1).toString());
    assertEquals(rg.getBooleanValue(selectedT, txId1), true);
    assertEquals(rg.getBooleanValue(selectedT, txId2), true);
    assertEquals(rg.getBooleanValue(selectedT, txId3), false);
    assertEquals(rg.getBooleanValue(selectedT, txId4), false);
    rg.close();
    // Didn't Occur On
    findCriteriaValuesList = new ArrayList<>();
    dateTimeCriteriaValue = new DateTimeCriteriaValues("datetime", "DateTime", "Didn't Occur On", formatDateTime(testTime));
    findCriteriaValuesList.add(dateTimeCriteriaValue);
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedT, txId1), false);
    assertEquals(rg.getBooleanValue(selectedT, txId2), false);
    assertEquals(rg.getBooleanValue(selectedT, txId3), true);
    assertEquals(rg.getBooleanValue(selectedT, txId4), true);
    rg.close();
    // Occured Before
    findCriteriaValuesList = new ArrayList<>();
    dateTimeCriteriaValue = new DateTimeCriteriaValues("datetime", "DateTime", "Occured Before", formatDateTime(plus1YearTestTime));
    findCriteriaValuesList.add(dateTimeCriteriaValue);
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedT, txId1), true);
    assertEquals(rg.getBooleanValue(selectedT, txId2), true);
    assertEquals(rg.getBooleanValue(selectedT, txId3), true);
    assertEquals(rg.getBooleanValue(selectedT, txId4), false);
    rg.close();
    // Occured After
    findCriteriaValuesList = new ArrayList<>();
    dateTimeCriteriaValue = new DateTimeCriteriaValues("datetime", "DateTime", "Occured After", formatDateTime(plus1YearTestTime));
    findCriteriaValuesList.add(dateTimeCriteriaValue);
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedT, txId1), false);
    assertEquals(rg.getBooleanValue(selectedT, txId2), false);
    assertEquals(rg.getBooleanValue(selectedT, txId3), true);
    assertEquals(rg.getBooleanValue(selectedT, txId4), true);
    rg.close();
    // Occured Between
    findCriteriaValuesList = new ArrayList<>();
    dateTimeCriteriaValue = new DateTimeCriteriaValues("datetime", "DateTime", "Occured Between", formatDateTime(testTime), formatDateTime(plus2YearTestTime));
    findCriteriaValuesList.add(dateTimeCriteriaValue);
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedT, txId1), false);
    assertEquals(rg.getBooleanValue(selectedT, txId2), false);
    assertEquals(rg.getBooleanValue(selectedT, txId3), true);
    assertEquals(rg.getBooleanValue(selectedT, txId4), false);
    rg.close();
    // Test multiple criteria (any)
    findCriteriaValuesList = new ArrayList<>();
    stringCriteriaValue1 = new StringCriteriaValues("string", "Identifier", "Is", "identifer name", true, false);
    iconCriteriaValue = new IconCriteriaValues("icon", "background_icon", "Is", IconManager.getIcon("Flag.Australia"));
    findCriteriaValuesList.add(stringCriteriaValue1);
    findCriteriaValuesList.add(iconCriteriaValue);
    elementType = GraphElementType.VERTEX;
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId4), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId6), false);
    rg.close();
    // Test multiple criteria (any)
    findCriteriaValuesList = new ArrayList<>();
    stringCriteriaValue1 = new StringCriteriaValues("string", "Identifier", "Is", "a vertex", true, false);
    iconCriteriaValue = new IconCriteriaValues("icon", "background_icon", "Is", IconManager.getIcon("Flag.England"));
    findCriteriaValuesList.add(stringCriteriaValue1);
    findCriteriaValuesList.add(iconCriteriaValue);
    elementType = GraphElementType.VERTEX;
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, all, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId4), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId6), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId7), false);
    rg.close();
    // Test find next
    findCriteriaValuesList = new ArrayList<>();
    stringCriteriaValue1 = new StringCriteriaValues("string", "Identifier", "Is", "identifer name", true, false);
    findCriteriaValuesList.add(stringCriteriaValue1);
    elementType = GraphElementType.VERTEX;
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, false, true);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), false);
    rg.close();
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, false, true);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), false);
    rg.close();
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, false, true);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), true);
    rg.close();
    // Test find prev
    elementType = GraphElementType.VERTEX;
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, ignore, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, false, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), false);
    rg.close();
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, false, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId1), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), false);
    rg.close();
    // Test add to
    elementType = GraphElementType.VERTEX;
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, addTo, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    WritableGraph wg = graph.getWritableGraph("", true);
    wg.setBooleanValue(selectedV, vxId6, true);
    wg.setBooleanValue(selectedV, vxId7, true);
    wg.commit();
    rg = graph.getReadableGraph();
    assertEquals(rg.getBooleanValue(selectedV, vxId6), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId7), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId1), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), true);
    rg.close();
    // Test Remove From
    elementType = GraphElementType.VERTEX;
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, removeFrom, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    rg = graph.getReadableGraph();
    // all but vxId6 match the criteria, so vxId6 remains selected
    assertEquals(rg.getBooleanValue(selectedV, vxId6), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId7), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId1), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), false);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), false);
    rg.close();
    // Test Find In
    elementType = GraphElementType.VERTEX;
    parameters = new AdvancedSearchParameters(findCriteriaValuesList, elementType, any, findIn, searchAllGraphs);
    advancedSearchPlugin = new AdvancedSearchPlugin(parameters, true, false);
    PluginExecution.withPlugin(advancedSearchPlugin).executeNow(graph);
    wg = graph.getWritableGraph("", true);
    wg.setBooleanValue(selectedV, vxId1, true);
    wg.setBooleanValue(selectedV, vxId2, true);
    wg.commit();
    rg = graph.getReadableGraph();
    // vxId3 is not selected so will not be considered in the
    assertEquals(rg.getBooleanValue(selectedV, vxId1), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId2), true);
    assertEquals(rg.getBooleanValue(selectedV, vxId3), false);
    rg.close();
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ArrayList(java.util.ArrayList) ColourCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.ColourCriteriaValues) DateTimeCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.DateTimeCriteriaValues) AdvancedSearchParameters(au.gov.asd.tac.constellation.views.find2.components.advanced.utilities.AdvancedSearchParameters) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) StringCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.StringCriteriaValues) FloatCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FloatCriteriaValues) FindCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues) IconCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.IconCriteriaValues) BooleanCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.BooleanCriteriaValues) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Test(org.testng.annotations.Test)

Example 14 with FindCriteriaValues

use of au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues in project constellation by constellation-app.

the class AdvancedFindTabNGTest method testFindAllAction.

/**
 * Test of findAllAction method, of class AdvancedFindTab.
 */
@Test
public void testFindAllAction() {
    System.out.println("findAllAction");
    setupGraph();
    // Create a controller mock and do nothing on retriveMatchingElements()
    FindViewController mockController = mock(FindViewController.class);
    mockController.init(spyTopComponent);
    doNothing().when(mockController).retrieveAdvancedSearch(Mockito.eq(true), Mockito.eq(false));
    GraphElementType graphElementType = GraphElementType.VERTEX;
    /**
     * Create temporary advancedFindMock, pane, criteriaPaneList,
     * LookForChoiceBox, findCriteriaValuesList and a stringCriteriaValue
     */
    AdvancedFindTab advancedFindMock = mock(AdvancedFindTab.class);
    StringCriteriaPanel tempPane = new StringCriteriaPanel(advancedTab, "Identifer", graphElementType);
    tempPane.setSearchFieldText("hello");
    final List<AdvancedCriteriaBorderPane> criteriaPaneList = new ArrayList<>();
    criteriaPaneList.add(tempPane);
    final ChoiceBox<String> lookForChoiceBox = new ChoiceBox<>();
    lookForChoiceBox.getItems().add("Node");
    lookForChoiceBox.getSelectionModel().select(0);
    final List<FindCriteriaValues> findCriteriaValues = new ArrayList<>();
    final StringCriteriaValues stringCriteriaValue = new StringCriteriaValues("string", "Identifer", "Is", "hello", false, false);
    findCriteriaValues.add(stringCriteriaValue);
    // When each function is called return the temporarily created elements above
    when(advancedFindMock.getCorrespondingCriteriaList(graphElementType)).thenReturn(criteriaPaneList);
    when(advancedFindMock.getCriteriaValues(criteriaPaneList)).thenReturn(findCriteriaValues);
    when(advancedFindMock.getLookForChoiceBox()).thenReturn(lookForChoiceBox);
    // Do real call on findAllAction
    doCallRealMethod().when(advancedFindMock).findAllAction();
    // Do nothing on updateAdvancedSearchParameters()
    doNothing().when(advancedFindMock).updateAdvancedSearchParameters(graphElementType);
    /**
     * Create a static mock of the FindViewController. Call the
     * findAllAction() then verify that updateAdvancedSearchParameters and
     * retrieveAdvancedSearch were all called once.
     */
    try (MockedStatic<FindViewController> mockedStatic = Mockito.mockStatic(FindViewController.class)) {
        mockedStatic.when(() -> FindViewController.getDefault()).thenReturn(mockController);
        advancedFindMock.findAllAction();
        verify(advancedFindMock, times(1)).updateAdvancedSearchParameters(graphElementType);
        verify(mockController, times(1)).retrieveAdvancedSearch(true, false);
    }
}
Also used : ArrayList(java.util.ArrayList) StringCriteriaPanel(au.gov.asd.tac.constellation.views.find2.components.advanced.StringCriteriaPanel) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) AdvancedCriteriaBorderPane(au.gov.asd.tac.constellation.views.find2.components.advanced.AdvancedCriteriaBorderPane) StringCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.StringCriteriaValues) ChoiceBox(javafx.scene.control.ChoiceBox) FindCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues) FindViewController(au.gov.asd.tac.constellation.views.find2.FindViewController) Test(org.testng.annotations.Test)

Example 15 with FindCriteriaValues

use of au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues in project constellation by constellation-app.

the class AdvancedFindTabNGTest method testFindPreviousAction.

/**
 * Test of findPreviousAction method, of class AdvancedFindTab.
 */
@Test
public void testFindPreviousAction() {
    System.out.println("findPreviousAction");
    setupGraph();
    // Create a controller mock and do nothing on retriveMatchingElements()
    FindViewController mockController = mock(FindViewController.class);
    mockController.init(spyTopComponent);
    doNothing().when(mockController).retrieveAdvancedSearch(Mockito.eq(false), Mockito.eq(false));
    GraphElementType graphElementType = GraphElementType.VERTEX;
    /**
     * Create temporary advancedFindMock, pane, criteriaPaneList,
     * LookForChoiceBox, findCriteriaValuesList and a stringCriteriaValue
     */
    AdvancedFindTab advancedFindMock = mock(AdvancedFindTab.class);
    StringCriteriaPanel tempPane = new StringCriteriaPanel(advancedTab, "Identifer", graphElementType);
    tempPane.setSearchFieldText("hello");
    final List<AdvancedCriteriaBorderPane> criteriaPaneList = new ArrayList<>();
    criteriaPaneList.add(tempPane);
    final ChoiceBox<String> lookForChoiceBox = new ChoiceBox<>();
    lookForChoiceBox.getItems().add("Node");
    lookForChoiceBox.getSelectionModel().select(0);
    final List<FindCriteriaValues> findCriteriaValues = new ArrayList<>();
    final StringCriteriaValues stringCriteriaValue = new StringCriteriaValues("string", "Identifer", "Is", "hello", false, false);
    findCriteriaValues.add(stringCriteriaValue);
    // When each function is called return the temporarily created elements above
    when(advancedFindMock.getCorrespondingCriteriaList(graphElementType)).thenReturn(criteriaPaneList);
    when(advancedFindMock.getCriteriaValues(criteriaPaneList)).thenReturn(findCriteriaValues);
    when(advancedFindMock.getLookForChoiceBox()).thenReturn(lookForChoiceBox);
    // Do real call on findAllAction
    doCallRealMethod().when(advancedFindMock).findPreviousAction();
    // Do nothing on updateAdvancedSearchParameters()
    doNothing().when(advancedFindMock).updateAdvancedSearchParameters(graphElementType);
    /**
     * Create a static mock of the FindViewController. Call the
     * findNextAction() then verify that updateAdvancedSearchParameters and
     * retrieveAdvancedSearch were all called once.
     */
    try (MockedStatic<FindViewController> mockedStatic = Mockito.mockStatic(FindViewController.class)) {
        mockedStatic.when(() -> FindViewController.getDefault()).thenReturn(mockController);
        advancedFindMock.findPreviousAction();
        verify(advancedFindMock, times(1)).updateAdvancedSearchParameters(graphElementType);
        verify(mockController, times(1)).retrieveAdvancedSearch(false, false);
    }
}
Also used : ArrayList(java.util.ArrayList) StringCriteriaPanel(au.gov.asd.tac.constellation.views.find2.components.advanced.StringCriteriaPanel) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) AdvancedCriteriaBorderPane(au.gov.asd.tac.constellation.views.find2.components.advanced.AdvancedCriteriaBorderPane) StringCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.StringCriteriaValues) ChoiceBox(javafx.scene.control.ChoiceBox) FindCriteriaValues(au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues) FindViewController(au.gov.asd.tac.constellation.views.find2.FindViewController) Test(org.testng.annotations.Test)

Aggregations

FindCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues)15 ArrayList (java.util.ArrayList)11 Test (org.testng.annotations.Test)11 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)9 StringCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.StringCriteriaValues)9 BooleanCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.BooleanCriteriaValues)5 ColourCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.ColourCriteriaValues)5 FloatCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FloatCriteriaValues)5 AdvancedFindTab (au.gov.asd.tac.constellation.views.find2.components.AdvancedFindTab)4 AdvancedCriteriaBorderPane (au.gov.asd.tac.constellation.views.find2.components.advanced.AdvancedCriteriaBorderPane)4 StringCriteriaPanel (au.gov.asd.tac.constellation.views.find2.components.advanced.StringCriteriaPanel)4 DateTimeCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.DateTimeCriteriaValues)4 IconCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.IconCriteriaValues)4 AdvancedSearchParameters (au.gov.asd.tac.constellation.views.find2.components.advanced.utilities.AdvancedSearchParameters)4 GridPane (javafx.scene.layout.GridPane)4 FindViewController (au.gov.asd.tac.constellation.views.find2.FindViewController)3 ChoiceBox (javafx.scene.control.ChoiceBox)3 ZonedDateTime (java.time.ZonedDateTime)2 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)1 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)1