Skip to content
Merged
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
18 changes: 17 additions & 1 deletion api/src/org/labkey/api/data/NameGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.labkey.api.exp.api.ExpMaterial.ALIQUOTED_FROM_INPUT;
Expand Down Expand Up @@ -729,7 +730,7 @@ protected int write()
.filter(s -> !s.isEmpty());
}

public static Stream<String> parentNames(Object value, String parentColName, TSVWriter tsvWriter, @Nullable BatchValidationException errors)
public static @Nullable Stream<String> parentNames(Object value, String parentColName, TSVWriter tsvWriter, @Nullable BatchValidationException errors)
{
if (value == null)
return Stream.empty();
Expand Down Expand Up @@ -783,6 +784,21 @@ else if (value instanceof JSONArray jsonArray)
throw new IllegalStateException("For parent values in naming pattern, expected string or collection for '" + parentColName + "': " + value);
}

if (values != null)
{
List<String> valueList = values.toList();
Set<String> valueSet = new HashSet<>();
Set<String> duplicates = valueList.stream().filter(s -> !valueSet.add(s)).collect(Collectors.toSet());
if (!duplicates.isEmpty())
{
if (errors != null)
errors.addRowError(new ValidationException("Duplicate parent names found: " + StringUtils.join(duplicates, ", "), parentColName));
else
throw new IllegalStateException("Duplicate parent names found: " + StringUtils.join(duplicates, ", "));
}
return valueList.stream();
}

return values;
}

Expand Down
Loading