Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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(0, 30)));
}
return textChoices;
}

public static String randomString(int size, @Nullable String exclusion)
{
return randomString(size, exclusion, CHARSET_STRING);
Expand Down
66 changes: 66 additions & 0 deletions src/org/labkey/test/util/data/TestArrayDataUtils.java
Original file line number Diff line number Diff line change
@@ -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
{
Comment on lines +14 to +15
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, String> filterMap(Map<String, T> map, List<String> searchValues, Filter.Operator filterType)
{
Comparator<String> 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<String>) 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<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 -> true;
Copy link
Member

Choose a reason for hiding this comment

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

Should this default to true for non-array operators? What does the server do?
Unless this matches the actual product behavior, we should just throw an IllegalArgumentException for non-array operators.

};
}
}
Loading