diff --git a/src/org/labkey/test/components/ui/grids/ResponsiveGrid.java b/src/org/labkey/test/components/ui/grids/ResponsiveGrid.java index f21859cec3..ae0030bf46 100644 --- a/src/org/labkey/test/components/ui/grids/ResponsiveGrid.java +++ b/src/org/labkey/test/components/ui/grids/ResponsiveGrid.java @@ -256,7 +256,7 @@ private GridFilterModal initFilterColumn(CharSequence columnIdentifier, Filter.O { filterPanel.selectArrayFilterOperator(operator); } - if (value != null) + if (value != null && !((List) value).isEmpty()) { List values = (List) value; filterPanel.selectValue(values.get(0)); diff --git a/src/org/labkey/test/params/FieldDefinition.java b/src/org/labkey/test/params/FieldDefinition.java index 78585ac23e..0336d68b51 100644 --- a/src/org/labkey/test/params/FieldDefinition.java +++ b/src/org/labkey/test/params/FieldDefinition.java @@ -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); /** diff --git a/src/org/labkey/test/util/TestDataGenerator.java b/src/org/labkey/test/util/TestDataGenerator.java index 3432935859..bb916414f1 100644 --- a/src/org/labkey/test/util/TestDataGenerator.java +++ b/src/org/labkey/test/util/TestDataGenerator.java @@ -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 values = shuffleSelect(validator.getValues()); + Collections.sort(values); + entityData.put(key, values); + } } } @@ -491,6 +499,16 @@ public static String randomString(int size) return randomString(size, null); } + public static List randomTextChoice(int size) + { + List textChoices = new ArrayList<>(); + for (int i = 0; i < size; i++) + { + textChoices.add(randomString(randomInt(0, 30))); + } + return textChoices; + } + public static String randomString(int size, @Nullable String exclusion) { return randomString(size, exclusion, CHARSET_STRING); diff --git a/src/org/labkey/test/util/data/TestArrayDataUtils.java b/src/org/labkey/test/util/data/TestArrayDataUtils.java new file mode 100644 index 0000000000..8b48baa34e --- /dev/null +++ b/src/org/labkey/test/util/data/TestArrayDataUtils.java @@ -0,0 +1,66 @@ +package org.labkey.test.util.data; + +import org.labkey.remoteapi.query.Filter; + +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 +{ + + public static Map getMapWithIdAndMultiChoiceField(List> 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 Map filterMap(Map map, List searchValues, Filter.Operator filterType) + { + Comparator comparator = Comparator.comparing((String s) -> s.toLowerCase()).thenComparing(s -> s); + return map.entrySet().stream() + .filter(entry -> entry.getValue() instanceof List) + .map(entry -> Map.entry(entry.getKey(), (List) entry.getValue())) + .filter(entry -> isMatch(entry.getValue(), searchValues, filterType)) + .collect(Collectors.toMap( + Map.Entry::getKey, + e -> e.getValue().stream() + .sorted(comparator) + .collect(Collectors.joining(", ")), + (e1, e2) -> e1, + LinkedHashMap::new + )); + } + + private static boolean isMatch(List actualValues, List 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 -> true; + }; + } +} \ No newline at end of file