Skip to content

Commit

Permalink
support legacy string with parenthesis
Browse files Browse the repository at this point in the history
  • Loading branch information
aallam committed Feb 1, 2022
1 parent 99a40c3 commit 6015b3e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ public List<List<String>> deserialize(JsonParser p, DeserializationContext ctxt)
result = buildFilters(list);
break;
case VALUE_STRING:
result =
Arrays.stream(p.getValueAsString().split(","))
.map(Collections::singletonList)
.collect(Collectors.toList());
String string = p.getValueAsString();
result = buildFilters(string);
break;
case VALUE_NULL:
break;
Expand All @@ -48,6 +46,7 @@ public List<List<String>> deserialize(JsonParser p, DeserializationContext ctxt)
return result;
}

/** Build filters from a list */
@SuppressWarnings("unchecked")
private List<List<String>> buildFilters(List list) {
return (List<List<String>>)
Expand All @@ -62,4 +61,16 @@ private List<List<String>> buildFilters(List list) {
})
.collect(Collectors.toList());
}

/** Build filters from (legacy) string */
private List<List<String>> buildFilters(String string) {
if (string.startsWith("(") && string.endsWith(")")) {
String input = string.substring(1, string.length() - 1);
return Collections.singletonList(Arrays.asList(input.split(",")));
} else {
return Arrays.stream(string.split(","))
.map(Collections::singletonList)
.collect(Collectors.toList());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ void testLegacyFiltersFormat(String input) throws IOException {
// Testing "one string" legacy filters => should be converted to "ANDED" filters
// [["color:green"],["color:yellow"]]
String stringFilters = String.format("{\"%s\":\"color:green,color:yellow\"}", input);

assertANDEDListResult(
extractFilters(
Defaults.getObjectMapper().readValue(stringFilters, ConsequenceParams.class), input));
Expand All @@ -193,6 +192,15 @@ void testLegacyFiltersFormat(String input) throws IOException {
Defaults.getObjectMapper().readValue(nestedArrayFilters, ConsequenceParams.class),
input));

// Testing "one string with parenthesis" legacy filters => should be converted to "ORED" filters
// [["color:green", "color:yellow"]]
String stringParenthesisFilters =
String.format("{\"%s\":\"(color:green,color:yellow)\"}", input);
assertOREDResult(
extractFilters(
Defaults.getObjectMapper().readValue(stringParenthesisFilters, ConsequenceParams.class),
input));

// Testing mixed case with array and string
// [["color:green","color:yellow"],"color:blue"]
String stringAndArrayFilters =
Expand Down

0 comments on commit 6015b3e

Please sign in to comment.