Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private GridFilterModal initFilterColumn(CharSequence columnIdentifier, Filter.O
{
filterPanel.selectArrayFilterOperator(operator);
}
if (value != null)
if (value != null && !((List<String>) value).isEmpty())
{
List<String> values = (List<String>) value;
filterPanel.selectValue(values.get(0));
Expand Down
11 changes: 10 additions & 1 deletion src/org/labkey/test/components/ui/search/FilterFacetedPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import static org.labkey.test.WebDriverWrapper.waitFor;
import static org.labkey.test.components.html.Input.Input;

public class FilterFacetedPanel extends WebDriverComponent<FilterFacetedPanel.ElementCache>
Expand Down Expand Up @@ -74,9 +77,15 @@ public boolean isChecked(String value)
*/
public void checkValues(String... values)
{
// waitForElement(elementCache().findCheckbox(values[0]));
// waitFor(() -> elementCache().findCheckbox(values[0]).isDisplayed(), 10000);
for (String value : values)
{
elementCache().findCheckbox(value).check();
try{
elementCache().findCheckbox(value).check();}
catch (Exception e){
elementCache().findCheckbox(value).check();
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/org/labkey/test/params/FieldDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ public boolean isMeasureByDefault()
ColumnType Sample = new ColumnTypeImpl("Sample", "int", "http://www.labkey.org/exp/xml#sample", new IntLookup( "exp", "Materials"));
ColumnType Barcode = new ColumnTypeImpl("Unique ID", "string", "http://www.labkey.org/types#storageUniqueId", null);
ColumnType TextChoice = new ColumnTypeImpl("Text Choice", "string", "http://www.labkey.org/types#textChoice", null);
ColumnType MultiValueTextChoice = new ColumnTypeImpl("Text Choice", "string", "http://cpas.fhcrc.org/exp/xml#multiChoice", null);
ColumnType MultiValueTextChoice = new ColumnTypeImpl("Text Choice", "http://cpas.fhcrc.org/exp/xml#multiChoice", null, null);
ColumnType SMILES = new ColumnTypeImpl("SMILES", "string", "http://www.labkey.org/exp/xml#smiles", null);
ColumnType Calculation = new ColumnTypeImpl("Calculation", null, "http://www.labkey.org/exp/xml#calculated", null);
/**
Expand Down
18 changes: 18 additions & 0 deletions src/org/labkey/test/util/TestDataGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ else if (fieldDefinition.getType().equals(FieldDefinition.ColumnType.TextChoice)
else
entityData.put(key, textChoices.get(textChoiceIndex));
}
else if (fieldDefinition.getType().equals(FieldDefinition.ColumnType.MultiValueTextChoice))
{
FieldDefinition.TextChoiceValidator validator =
(FieldDefinition.TextChoiceValidator) fieldDefinition.getValidators().getFirst();
List<String> values = shuffleSelect(validator.getValues());
Collections.sort(values);
entityData.put(key, values);
}
}
}

Expand Down Expand Up @@ -491,6 +499,16 @@ public static String randomString(int size)
return randomString(size, null);
}

public static List<String> randomTextChoice(int size)
{
List<String> textChoices = new ArrayList<>();
for (int i = 0; i < size; i++)
{
textChoices.add(randomString(randomInt(1, 25)));
}
return textChoices;
}

public static String randomString(int size, @Nullable String exclusion)
{
return randomString(size, exclusion, CHARSET_STRING);
Expand Down
105 changes: 105 additions & 0 deletions src/org/labkey/test/util/data/TestArrayDataUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package org.labkey.test.util.data;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import org.labkey.remoteapi.query.Filter;

import java.io.IOException;
import java.io.StringReader;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static org.labkey.test.util.samplemanagement.SMTestUtils.COL_SAMPLE_ID_NAME;
import static org.labkey.test.util.samplemanagement.SMTestUtils.COL_SAMPLE_NAME_NAME;

public class TestArrayDataUtils
{
Comment on lines +19 to +20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider moving TestDataUtils.parseMultiValueText and ResponsiveGrid.ARRAY_OPERATORS into this class.


public static <T> Map<String, T> getMapWithIdAndMultiChoiceField(List<Map<String, T>> data)
{
return data.stream()
.collect(Collectors.toMap(
row -> String.valueOf(row.get(COL_SAMPLE_NAME_NAME) != null ? row.get(COL_SAMPLE_NAME_NAME) : row.get(COL_SAMPLE_ID_NAME)),
row ->
{
String complexKey = row.keySet().stream()
.filter(k -> k.contains("Multi Choice"))
.findFirst()
.orElse("");
return row.get(complexKey);
}
));
}

/**
* Filtering Map according to filter and then sorting values in alphabetical order.
*
* @return filtered Map
*/
public static <T> Map<String, List<String>> filterMap(Map<String, T> map, List<String> searchValues, Filter.Operator filterType)
{
return map.entrySet().stream()
.filter(entry -> entry.getValue() instanceof List)
.map(entry -> Map.entry(entry.getKey(), (List<String>) entry.getValue()))
.filter(entry -> isMatch(entry.getValue(), searchValues, filterType))
.collect(Collectors.toMap(
Map.Entry::getKey,
e -> e.getValue().stream()
.sorted(Comparator
.comparing((String s) -> s.substring(0, 1).toLowerCase())
.thenComparing(s -> s.substring(0, 1))
.thenComparing(s -> s))
.collect(Collectors.toList()),
(e1, e2) -> e1,
LinkedHashMap::new
));
}

public static Map<String, String> prepareMapForCheck(Map<String, List<String>> map)
{
return map.entrySet().stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
entry -> String.join(", ", entry.getValue()),
(e1, e2) -> e1,
LinkedHashMap::new
));
}

public static <T> Map<String, String> filterAndPrepareMap(Map<String, T> map, List<String> searchValues, Filter.Operator filterType)
{
return prepareMapForCheck(filterMap(map, searchValues, filterType));
}

public static List<String> parseMultiValueText(String multiValueString) throws IOException
{
CSVFormat format = CSVFormat.RFC4180.builder()
.setIgnoreSurroundingSpaces(true).setTrim(true).get();
try (CSVParser parser = format.parse(new StringReader(multiValueString)))
{
List<CSVRecord> records = parser.getRecords();
if (records.size() != 1)
throw new IllegalArgumentException("Invalid multi-value text string: " + multiValueString);
return records.getFirst().toList();
}
}

private static boolean isMatch(List<String> actualValues, List<String> searchValues, Filter.Operator type)
{
return switch (type)
{
case ARRAY_CONTAINS_ALL -> actualValues.containsAll(searchValues);
case ARRAY_CONTAINS_ANY -> searchValues.stream().anyMatch(actualValues::contains);
case ARRAY_CONTAINS_EXACT -> actualValues.size() == searchValues.size() && actualValues.containsAll(searchValues);
case ARRAY_CONTAINS_NONE -> searchValues.stream().noneMatch(actualValues::contains);
case ARRAY_CONTAINS_NOT_EXACT -> !(actualValues.size() == searchValues.size() && actualValues.containsAll(searchValues));
case ARRAY_ISEMPTY -> actualValues.isEmpty();
case ARRAY_ISNOTEMPTY -> !actualValues.isEmpty();
default -> throw new IllegalArgumentException("Invalid filter type " + type);
};
}
}
13 changes: 0 additions & 13 deletions src/org/labkey/test/util/data/TestDataUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -578,19 +578,6 @@ public static List<List<String>> readRowsFromFile(File file, CSVFormat format) t
}
}

public static List<String> parseMultiValueText(String multiValueString) throws IOException
{
CSVFormat format = CSVFormat.RFC4180.builder()
.setIgnoreSurroundingSpaces(true).setTrim(true).get();
try (CSVParser parser = format.parse(new StringReader(multiValueString)))
{
List<CSVRecord> records = parser.getRecords();
if (records.size() != 1)
throw new IllegalArgumentException("Invalid multi-value text string: " + multiValueString);
return records.getFirst().toList();
}
}

public static <T> String stringFromRows(List<List<T>> rows, CSVFormat format)
{
StringWriter stringWriter = new StringWriter();
Expand Down
Loading