From b29f6d428a770d6da20a1ad7bcd36921375aeeb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Garc=C3=ADa=20Pimentel?= Date: Thu, 4 Jun 2026 12:26:35 +0200 Subject: [PATCH 1/2] allow the union function to concatenate more than two collections --- .../tools/actool/configreader/YamlMacroElEvaluator.java | 9 +++++---- .../actool/configreader/YamlMacroElEvaluatorTest.java | 3 ++- .../actool/configreader/YamlMacroProcessorTest.java | 2 +- .../src/test/resources/test-array-union-function.yaml | 7 ++++++- docs/AdvancedFeatures.md | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroElEvaluator.java b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroElEvaluator.java index cc72522b..8b6893fc 100644 --- a/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroElEvaluator.java +++ b/accesscontroltool-bundle/src/main/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroElEvaluator.java @@ -17,6 +17,7 @@ import java.beans.FeatureDescriptor; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -24,7 +25,6 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import java.util.stream.Stream; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringEscapeUtils; @@ -162,7 +162,7 @@ public ElFunctionMapper() { YamlMacroElEvaluator.ElFunctionMapper.class.getMethod("keys", new Class[] { Map.class }), YamlMacroElEvaluator.ElFunctionMapper.class.getMethod("values", new Class[] { Map.class }), YamlMacroElEvaluator.ElFunctionMapper.class.getMethod("escapeXml", new Class[] { String.class }), - YamlMacroElEvaluator.ElFunctionMapper.class.getMethod("union", new Class[] { Collection.class, Collection.class }) + YamlMacroElEvaluator.ElFunctionMapper.class.getMethod("union", new Class[] { Collection[].class }) }; for (Method method : exportedMethods) { functionMap.put(method.getName(), method); @@ -205,8 +205,9 @@ public static String escapeXml(String input) { return StringEscapeUtils.escapeXml10(input); } - public static List union(Collection collection1, Collection collection2){ - return Stream.concat(collection1.stream(),collection2.stream()).collect(Collectors.toList()); + @SafeVarargs + public static List union(Collection... collections){ + return Arrays.stream(collections).flatMap(Collection::stream).collect(Collectors.toList()); } } diff --git a/accesscontroltool-bundle/src/test/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroElEvaluatorTest.java b/accesscontroltool-bundle/src/test/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroElEvaluatorTest.java index 0712bdd5..5a0c9a00 100644 --- a/accesscontroltool-bundle/src/test/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroElEvaluatorTest.java +++ b/accesscontroltool-bundle/src/test/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroElEvaluatorTest.java @@ -49,8 +49,9 @@ void testFunctions() { assertEquals("foo", evaluateSimpleExpression("defaultIfBlank(\" \",\"foo\")")); assertEquals("bar", evaluateSimpleExpression("defaultIfBlank(\"bar\",\"foo\")")); - Map lists= ImmutableMap.of("list1",Arrays.asList("foo","bar"), "list2",Arrays.asList("fizz","buzz")); + Map lists= ImmutableMap.of("list1",Arrays.asList("foo","bar"), "list2",Arrays.asList("fizz","buzz"), "list3",Arrays.asList("ping","pong")); assertIterableEquals(Arrays.asList("foo","bar","fizz","buzz"), (Iterable)evaluateSimpleExpression("union(list1,list2)",lists)); + assertIterableEquals(Arrays.asList("foo","bar","fizz","buzz","ping","pong"), (Iterable)evaluateSimpleExpression("union(list1,list2,list3)",lists)); assertIterableEquals(Arrays.asList("item1"),(Iterable) evaluateSimpleExpression("keys(list)",Collections.singletonMap("list", ImmutableMap.of("item1","value")))); } diff --git a/accesscontroltool-bundle/src/test/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroProcessorTest.java b/accesscontroltool-bundle/src/test/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroProcessorTest.java index c4889ba4..0abe0542 100644 --- a/accesscontroltool-bundle/src/test/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroProcessorTest.java +++ b/accesscontroltool-bundle/src/test/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroProcessorTest.java @@ -483,7 +483,7 @@ public void testUnionFunction() throws Exception { yamlList = yamlMacroProcessor.processMacros(yamlList, globalVariables, installLog, session); AuthorizablesConfig groups = readGroupConfigs(yamlList); - assertEquals(9, groups.size(), "Number of ACEs expected to be 9"); + assertEquals(12, groups.size(), "Number of ACEs expected to be 9"); } @Test diff --git a/accesscontroltool-bundle/src/test/resources/test-array-union-function.yaml b/accesscontroltool-bundle/src/test/resources/test-array-union-function.yaml index 1694b287..a9baa8fe 100644 --- a/accesscontroltool-bundle/src/test/resources/test-array-union-function.yaml +++ b/accesscontroltool-bundle/src/test/resources/test-array-union-function.yaml @@ -16,13 +16,18 @@ - US - Mexico +- DEF countriesAPAC=: + - Japan + - China + - South Korea + - group_config: - FOR country IN ${countriesEU}: - group-${country}-europe: - path: /home/groups/netcentric - - FOR country IN ${union(countriesEU,countriesNA)}: + - FOR country IN ${union(countriesEU,countriesNA,countriesAPAC)}: - group-${country}-global: - path: /home/groups/netcentric diff --git a/docs/AdvancedFeatures.md b/docs/AdvancedFeatures.md index c5e128f0..03206aa2 100644 --- a/docs/AdvancedFeatures.md +++ b/docs/AdvancedFeatures.md @@ -14,7 +14,7 @@ Function Signature | Description `containsAllItems(List list, List items)`| Returns `true` if all of the items are contained in the given list (independent of their order). | 2.6.1 `containsAnyItem(List list, List items)`| Returns `true` if any of the items is contained in the given list. | 2.6.1 `containsItem(List list, String item)`| Returns `true` if the item is contained in the given list. | 2.2.0 -`union(Collection list, Collection list)`| Concatenates two collections. | 3.6.3 +`union(Collection... lists)`| Concatenates two or more collections. | 3.6.3 `defaultIfBlank(String str, String default)` | [`StringUtils.defaultIfBlank(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#defaultIfBlank(T,%20T)) | 3.3.0 `defaultIfEmpty(String str, String default)` | [`StringUtils.defaultIfEmpty(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#defaultIfEmpty(T,%20T)) | 2.5.0 `endsWith(String str, String suffix)`| [`StringUtils.endsWith(...)`](https://commons.apache.org/proper/commons-lang/javadocs/api-3.3/org/apache/commons/lang3/StringUtils.html#endsWith(java.lang.CharSequence,%20java.lang.CharSequence)) | 1.8.0 From 0427c8be6e024de8cfd3784687b550f9700b1941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Garc=C3=ADa=20Pimentel?= Date: Thu, 4 Jun 2026 14:26:56 +0200 Subject: [PATCH 2/2] fix expected message in union unit test --- .../cq/tools/actool/configreader/YamlMacroProcessorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accesscontroltool-bundle/src/test/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroProcessorTest.java b/accesscontroltool-bundle/src/test/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroProcessorTest.java index 0abe0542..a6abb89b 100644 --- a/accesscontroltool-bundle/src/test/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroProcessorTest.java +++ b/accesscontroltool-bundle/src/test/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroProcessorTest.java @@ -483,7 +483,7 @@ public void testUnionFunction() throws Exception { yamlList = yamlMacroProcessor.processMacros(yamlList, globalVariables, installLog, session); AuthorizablesConfig groups = readGroupConfigs(yamlList); - assertEquals(12, groups.size(), "Number of ACEs expected to be 9"); + assertEquals(12, groups.size(), "Number of ACEs expected to be 12"); } @Test