use of au.gov.asd.tac.constellation.views.find2.components.advanced.utilities.AdvancedSearchParameters in project constellation by constellation-app.
the class AdvancedSearchParameters method equals.
/**
* This checks equality between 2 AdvancedSearchParamter objects. It needs
* to check every attribute to determine true equality.
*
* @param object
* @return
*/
@Override
public boolean equals(final Object object) {
int matches = 0;
if (object == null || getClass() != object.getClass()) {
return false;
}
final AdvancedSearchParameters parameters = (AdvancedSearchParameters) object;
if (searchAllGraphs == parameters.isSearchAllGraphs()) {
matches++;
}
if (graphElementType.equals(parameters.getGraphElementType())) {
matches++;
}
if (allOrAny.equals(parameters.getAllOrAny())) {
matches++;
}
if (currentSelection == parameters.getCurrentSelection()) {
matches++;
}
// if the size is the same to the new object. continue
int i = 0;
if (criteriaValuesList.size() == parameters.getCriteriaValuesList().size()) {
// for each value in the criteriaValuesList
for (FindCriteriaValues values : criteriaValuesList) {
// if the two objects have different attributes return false
if (!values.getAttribute().equals(parameters.getCriteriaValuesList().get(i).getAttribute()) || !values.getAttributeType().equals(parameters.getCriteriaValuesList().get(i).getAttributeType()) || !values.getFilter().equals(parameters.getCriteriaValuesList().get(i).getFilter())) {
return false;
}
// if the two objects attributeType is the same. continue
if (values.getAttributeType().equals(parameters.getCriteriaValuesList().get(i).getAttributeType())) {
// for the object comparion all values must be identical
switch(values.getAttributeType()) {
// treat values as strings
case StringAttributeDescription.ATTRIBUTE_NAME:
StringCriteriaValues stringParameterValues = (StringCriteriaValues) values;
StringCriteriaValues stringActualValues = (StringCriteriaValues) parameters.getCriteriaValuesList().get(i);
if (!stringParameterValues.isIgnoreCase() == stringActualValues.isIgnoreCase() || !stringParameterValues.isUseList() == stringActualValues.isUseList() || (!stringActualValues.isUseList() && !stringParameterValues.getText().equals(stringActualValues.getText())) || (stringActualValues.isUseList() && !stringParameterValues.getTextList().equals(stringActualValues.getTextList()))) {
return false;
}
break;
// treat values as floats
case FloatAttributeDescription.ATTRIBUTE_NAME:
FloatCriteriaValues floatParameterValues = (FloatCriteriaValues) values;
FloatCriteriaValues floatActualValues = (FloatCriteriaValues) parameters.getCriteriaValuesList().get(i);
if (floatParameterValues.getFloatValuePrimary() != floatActualValues.getFloatValuePrimary() || floatParameterValues.getFloatValueSecondary() != floatActualValues.getFloatValueSecondary()) {
return false;
}
break;
// treat values as booleans
case BooleanAttributeDescription.ATTRIBUTE_NAME:
BooleanCriteriaValues boolParameterValues = (BooleanCriteriaValues) values;
BooleanCriteriaValues boolActualValues = (BooleanCriteriaValues) parameters.getCriteriaValuesList().get(i);
if (boolParameterValues.getBoolValue() != boolActualValues.getBoolValue()) {
return false;
}
break;
// treat values as colors
case ColorAttributeDescription.ATTRIBUTE_NAME:
ColourCriteriaValues colourParameterValues = (ColourCriteriaValues) values;
ColourCriteriaValues colourActualValues = (ColourCriteriaValues) parameters.getCriteriaValuesList().get(i);
if (!colourParameterValues.getColorValue().equals(colourActualValues.getColorValue())) {
return false;
}
break;
// treat values as dateTimes
case ZonedDateTimeAttributeDescription.ATTRIBUTE_NAME:
DateTimeCriteriaValues dateTimeParameterValues = (DateTimeCriteriaValues) values;
DateTimeCriteriaValues dateTimeActualValues = (DateTimeCriteriaValues) parameters.getCriteriaValuesList().get(i);
if (!dateTimeParameterValues.getDateTimeStringPrimaryValue().equals(dateTimeActualValues.getDateTimeStringPrimaryValue()) || !dateTimeParameterValues.getDateTimeStringSecondaryValue().equals(dateTimeActualValues.getDateTimeStringSecondaryValue())) {
return false;
}
break;
// treat values as icons
case IconAttributeDescription.ATTRIBUTE_NAME:
IconCriteriaValues iconParameterValues = (IconCriteriaValues) values;
IconCriteriaValues iconActualValues = (IconCriteriaValues) parameters.getCriteriaValuesList().get(i);
if (!iconParameterValues.getIconValue().equals(iconActualValues.getIconValue())) {
return false;
}
break;
default:
break;
}
}
i++;
}
} else {
return false;
}
/**
* matches will == 4 if all criteria of object a is the same as object
* b. It will return false if there is any criteria that doesn't match
*/
return matches == 4;
}
use of au.gov.asd.tac.constellation.views.find2.components.advanced.utilities.AdvancedSearchParameters in project constellation by constellation-app.
the class AdvancedSearchPlugin method edit.
@Override
protected void edit(GraphWriteMethods graph, PluginInteraction interaction, PluginParameters parameters) throws InterruptedException, PluginException {
// Retrieve the existing FindResultList Meta attribute
final int stateId = FindViewConcept.MetaAttribute.FINDVIEW_STATE.ensure(graph);
FindResultsList foundResult = graph.getObjectValue(stateId, 0);
/**
* If it doesn't exist or is null, create a new list with the starting
* index and the current find parameters. If it does exist, create a
* list with the correct index and the current find parameters
*/
if (foundResult == null) {
foundResult = new FindResultsList(STARTING_INDEX, this.parameters, graph.getId());
} else {
/**
* This is delicate, so don't change. This process, captures the
* users previous search and their current search, compares the 2 to
* see if they are the same. If yes then get the previous index of
* the last foundResult. If its different reset the index. The
* parameters are instantiated as new variables as there were
* manipulation issues elsewhere causing this process to fail.
*/
final FindResultsList oldList = new FindResultsList(STARTING_INDEX, foundResult.getAdvancedSearchParameters(), foundResult.getGraphId());
final AdvancedSearchParameters oldparameters = oldList.getAdvancedSearchParameters();
final AdvancedSearchParameters newParamters = new AdvancedSearchParameters(this.parameters);
final int newIndex = getIndex(newParamters, oldparameters, foundResult.getCurrentIndex());
foundResult = new FindResultsList(newIndex, newParamters, oldList.getGraphId());
}
foundResult.clear();
graph.setObjectValue(stateId, 0, foundResult);
final int elementCount = elementType.getElementCount(graph);
// do this if add to selection
if (IGNORE.equals(currentSelection)) {
clearSelection(graph);
}
findInCurrentSelectionList = new FindResultsList(graph.getId());
final FindResultsList findAllMatchingResultsList = new FindResultsList(graph.getId());
final int selectedAttribute = graph.getAttribute(elementType, VisualConcept.VertexAttribute.SELECTED.getName());
final Set<FindResult> findResultSet = new HashSet<>();
/**
* This loops through all existing graph elements, then loops through
* all criteria values, then determines what data type the criteria
* value corresponds to and proceeds the search based on that data type.
*
* For example if the data type of the criteria value was a string, it
* would continue the search as if the graph element attribute in
* question is a string
*/
for (int i = 0; i < elementCount; i++) {
// tracking number to see if a elements value matches all of the
// users input critera
int matchesAllCount = 0;
// get the current element and its unique id
final int currElement = elementType.getElement(graph, i);
final long uid = elementType.getUID(graph, currElement);
// loop through all of the criteriaValues
for (final FindCriteriaValues values : criteriaList) {
// get the int value of the current attribute
int attributeInt = graph.getAttribute(elementType, values.getAttribute());
// if the attribute int is greater than 0 it exists on this graph
if (attributeInt >= 0) {
/**
* matches will change to false if the attributes value
* matches the given critera.
*/
boolean matches = false;
// Determine what data type to treat the search as
switch(values.getAttributeType()) {
case StringAttributeDescription.ATTRIBUTE_NAME:
matches = searchAsString(values, attributeInt, currElement, graph);
break;
case FloatAttributeDescription.ATTRIBUTE_NAME:
matches = searchAsFloat(values, attributeInt, currElement, graph);
break;
case BooleanAttributeDescription.ATTRIBUTE_NAME:
matches = searchAsBoolean(values, attributeInt, currElement, graph);
break;
case ColorAttributeDescription.ATTRIBUTE_NAME:
matches = searchAsColor(values, attributeInt, currElement, graph);
break;
case ZonedDateTimeAttributeDescription.ATTRIBUTE_NAME:
matches = searchAsDateTime(values, attributeInt, currElement, graph);
break;
case IconAttributeDescription.ATTRIBUTE_NAME:
matches = searchAsIcon(values, attributeInt, currElement, graph);
break;
default:
break;
}
// if a match was found
if (matches) {
// increase the matchesAllCount by 1
matchesAllCount++;
// If the serach is select all and match critera = any
if (selectAll && ANY.equals(allOrAny)) {
// If the current selection = ignore or add to
if ((IGNORE.equals(currentSelection) || ADD_TO.equals(currentSelection))) {
// set the elements selection attribute to true
graph.setBooleanValue(selectedAttribute, currElement, true);
// add a new find result to the found results list
// of the element
foundResult.add(new FindResult(currElement, uid, elementType));
// if the current selection = find in and the graph element is already selected
} else if (FIND_IN.equals(currentSelection) && graph.getBooleanValue(selectedAttribute, currElement)) {
// add a new FindResult of the graph element to the findInCurrentSelection list
findInCurrentSelectionList.add(new FindResult(currElement, uid, elementType));
// if the current selection = remove from and the graph element is already selected
} else if (REMOVE_FROM.equals(currentSelection) && graph.getBooleanValue(selectedAttribute, currElement)) {
// set the graph element selection attribute to false
graph.setBooleanValue(selectedAttribute, currElement, false);
// add a new find result to the found results list
// of the element
foundResult.add(new FindResult(currElement, uid, elementType));
}
}
// if not select all and the match criteria = any
if (!selectAll && ANY.equals(allOrAny)) {
// add a new find result to the found results list
// of the element
foundResult.add(new FindResult(currElement, uid, elementType));
}
}
}
/**
* if match criteria = all and the attributes values match all
* of the criteria.
*/
if (allOrAny.equals(ALL) && matchesAllCount == criteriaList.size()) {
// add a new find result to the found results list
// of the element
foundResult.add(new FindResult(currElement, uid, elementType));
findResultSet.add(new FindResult(currElement, uid, elementType));
// if the attribute is already selected
if (graph.getBooleanValue(selectedAttribute, currElement)) {
// add it to the find in current selection list
findInCurrentSelectionList.add(new FindResult(currElement, uid, elementType));
}
}
}
}
findAllMatchingResultsList.addAll(findResultSet);
// if Find in select all the find in results
if (FIND_IN.equals(currentSelection)) {
selectFindInResults(FIND_IN.equals(currentSelection), findInCurrentSelectionList, foundResult, graph, selectedAttribute);
// if remove from, deselect all the remove from results
} else if (REMOVE_FROM.equals(currentSelection)) {
removeFindInResults(REMOVE_FROM.equals(currentSelection), findInCurrentSelectionList, foundResult, graph, selectedAttribute);
// if select all, select all the results that match all criteria
} else if (selectAll) {
selectMatchingAllResults(ALL.equals(allOrAny), findAllMatchingResultsList, foundResult, graph, selectedAttribute);
}
// if the user clicked find next or prev
if (!selectAll) {
// Clean the find results list to only contain unique graph elements
final List<FindResult> distinctValues = foundResult.stream().distinct().collect(Collectors.toList());
foundResult.clear();
foundResult.addAll(distinctValues);
/**
* If the list isn't empty, and the user clicked find next,
* increment the found lists index by 1, otherwise decrement it by
* 1. Set the element at the specified index to selected.
*/
if (!foundResult.isEmpty()) {
if (selectNext) {
foundResult.incrementCurrentIndex();
} else {
foundResult.decrementCurrentIndex();
}
final int elementId = foundResult.get(foundResult.getCurrentIndex()).getID();
graph.setBooleanValue(selectedAttribute, elementId, true);
}
graph.setObjectValue(stateId, 0, foundResult);
}
// If no results are found, set the meta attribute to null
graph.setObjectValue(stateId, 0, foundResult.isEmpty() ? null : foundResult);
}
use of au.gov.asd.tac.constellation.views.find2.components.advanced.utilities.AdvancedSearchParameters in project constellation by constellation-app.
the class AdvancedSearchPluginNGTest method testGetName.
/**
* Test of getName method, of class AdvancedSearchPlugin.
*/
@Test
public void testGetName() {
System.out.println("getName");
List<FindCriteriaValues> findCriteriaValuesList = new ArrayList<>();
StringCriteriaValues stringCriteriaValue1 = new StringCriteriaValues("string", "Identifier", "Is", "identifer name", true, false);
findCriteriaValuesList.add(stringCriteriaValue1);
AdvancedSearchParameters parameters = new AdvancedSearchParameters(findCriteriaValuesList, GraphElementType.VERTEX, "Any", "Ignore", false);
AdvancedSearchPlugin instance = new AdvancedSearchPlugin(parameters, true, false);
String expResult = "Find: Advanced Search";
String result = instance.getName();
assertEquals(result, expResult);
}
use of au.gov.asd.tac.constellation.views.find2.components.advanced.utilities.AdvancedSearchParameters 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);
}
use of au.gov.asd.tac.constellation.views.find2.components.advanced.utilities.AdvancedSearchParameters 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();
}
Aggregations