From 8a9c275b9d1793f558652ab70fd69b488f3fec7f Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Fri, 24 Aug 2018 14:10:06 +0200 Subject: [PATCH 01/13] updating poms for 1.3.1-SNAPSHOT development --- api/pom.xml | 2 +- bundle/pom.xml | 2 +- core/pom.xml | 2 +- examples/pom.xml | 2 +- pom.xml | 2 +- ui.apps/pom.xml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 18690fdf..6a0843c8 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 1.2.1-SNAPSHOT + 1.3.1-SNAPSHOT aecu.api diff --git a/bundle/pom.xml b/bundle/pom.xml index 737a176e..95fbbae7 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 1.2.1-SNAPSHOT + 1.3.1-SNAPSHOT aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index 14ffc9e9..3e4dcb95 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 1.2.1-SNAPSHOT + 1.3.1-SNAPSHOT aecu.core diff --git a/examples/pom.xml b/examples/pom.xml index 856ef072..367405c1 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 1.2.1-SNAPSHOT + 1.3.1-SNAPSHOT aecu.examples diff --git a/pom.xml b/pom.xml index 657ffbdd..1cf2662c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 1.2.1-SNAPSHOT + 1.3.1-SNAPSHOT AECU AEM Easy COntent Upgrade https://github.com/valtech/aem-easy-content-upgrade diff --git a/ui.apps/pom.xml b/ui.apps/pom.xml index 8445f22a..89309cb3 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 1.2.1-SNAPSHOT + 1.3.1-SNAPSHOT aecu.ui.apps From 62ff0df4254e7646d62b0decd688c96a14c89af3 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Fri, 24 Aug 2018 14:13:27 +0200 Subject: [PATCH 02/13] updating develop poms to master versions to avoid merge conflicts --- api/pom.xml | 2 +- bundle/pom.xml | 2 +- core/pom.xml | 2 +- examples/pom.xml | 2 +- pom.xml | 2 +- ui.apps/pom.xml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 6a0843c8..869eb4b9 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 1.3.1-SNAPSHOT + 1.3.0 aecu.api diff --git a/bundle/pom.xml b/bundle/pom.xml index 95fbbae7..c62427c4 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 1.3.1-SNAPSHOT + 1.3.0 aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index 3e4dcb95..e813842d 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 1.3.1-SNAPSHOT + 1.3.0 aecu.core diff --git a/examples/pom.xml b/examples/pom.xml index 367405c1..bf6e34cb 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 1.3.1-SNAPSHOT + 1.3.0 aecu.examples diff --git a/pom.xml b/pom.xml index 1cf2662c..c3776c61 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 1.3.1-SNAPSHOT + 1.3.0 AECU AEM Easy COntent Upgrade https://github.com/valtech/aem-easy-content-upgrade diff --git a/ui.apps/pom.xml b/ui.apps/pom.xml index 89309cb3..2089c947 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 1.3.1-SNAPSHOT + 1.3.0 aecu.ui.apps From 8a68ba17f3576193a8d3e768d201b989c8686393 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Fri, 24 Aug 2018 14:13:28 +0200 Subject: [PATCH 03/13] Updating develop poms back to pre merge state --- api/pom.xml | 2 +- bundle/pom.xml | 2 +- core/pom.xml | 2 +- examples/pom.xml | 2 +- pom.xml | 2 +- ui.apps/pom.xml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 869eb4b9..6a0843c8 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 1.3.0 + 1.3.1-SNAPSHOT aecu.api diff --git a/bundle/pom.xml b/bundle/pom.xml index c62427c4..95fbbae7 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 1.3.0 + 1.3.1-SNAPSHOT aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index e813842d..3e4dcb95 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 1.3.0 + 1.3.1-SNAPSHOT aecu.core diff --git a/examples/pom.xml b/examples/pom.xml index bf6e34cb..367405c1 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 1.3.0 + 1.3.1-SNAPSHOT aecu.examples diff --git a/pom.xml b/pom.xml index c3776c61..1cf2662c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 1.3.0 + 1.3.1-SNAPSHOT AECU AEM Easy COntent Upgrade https://github.com/valtech/aem-easy-content-upgrade diff --git a/ui.apps/pom.xml b/ui.apps/pom.xml index 2089c947..89309cb3 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 1.3.0 + 1.3.1-SNAPSHOT aecu.ui.apps From c24d910e62bd857f94fc073d55d247e0292fcde5 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 27 Aug 2018 11:34:17 +0200 Subject: [PATCH 04/13] added Central repo --- pom.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pom.xml b/pom.xml index 1cf2662c..2d29897b 100644 --- a/pom.xml +++ b/pom.xml @@ -629,6 +629,14 @@ http://repo.adobe.com/nexus/content/groups/public/ default + + central + http://repo1.maven.org/maven2 + default + + false + + From 4dfeb39f5e92b4ee13f9c592a8486eafdfeddb20 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 27 Aug 2018 14:24:19 +0200 Subject: [PATCH 05/13] added line break --- .../java/de/valtech/aecu/core/installhook/AecuInstallHook.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/de/valtech/aecu/core/installhook/AecuInstallHook.java b/core/src/main/java/de/valtech/aecu/core/installhook/AecuInstallHook.java index f1505baf..11a2607d 100644 --- a/core/src/main/java/de/valtech/aecu/core/installhook/AecuInstallHook.java +++ b/core/src/main/java/de/valtech/aecu/core/installhook/AecuInstallHook.java @@ -204,7 +204,7 @@ private HistoryEntry executeScript(AecuService aecuService, HistoryEntry install listener.logMessage("Executing script " + groovyScriptPath); ExecutionResult result = aecuService.execute(groovyScriptPath); installationHistory = aecuService.storeExecutionInHistory(installationHistory, result); - listener.logMessage("Executed script " + groovyScriptPath + ", output: " + result.getOutput()); + listener.logMessage("Executed script " + groovyScriptPath + ", output: \n" + result.getOutput()); return installationHistory; } From efea695e6f8701e73aa6f030b394432583b390f3 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 27 Aug 2018 15:03:53 +0200 Subject: [PATCH 06/13] updated docs --- Readme.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 9b0893d4..d81c7147 100644 --- a/Readme.md +++ b/Readme.md @@ -161,10 +161,15 @@ println aecu.contentUpgradeBuilder() These methods can be used to filter the nodes that were collected above. Multiple filters can be applied for one run. ### Filter by Properties -Use this to filter by a list of property values (e.g. sling:resourceType). + +Filters the resources by property values. + +* filterByProperties: use this to filter by a list of property values (e.g. sling:resourceType). All properties in the map are required to to match. Filter does not match if attribute does not exist. +* filterByMultiValuePropContains: checks if all condition values are contained in the defined attribute. Filter does not match if attribute does not exist. ```java filterByProperties(Map properties) +filterByMultiValuePropContains(String name, Object[] conditionValues) ``` Example: @@ -176,6 +181,7 @@ conditionMap["sling:resourceType"] = "weretail/components/structure/page" println aecu.contentUpgradeBuilder() .forChildResourcesOf("/content/we-retail/ca/en") .filterByProperties(conditionMap) + .filterByMultiValuePropContains("myAttribute", ["value"] as String[]) .doSetProperty("name", "value") .run() ``` From 72ed4ef9eb96a76c5411106b582001ba74e5aa41 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Tue, 28 Aug 2018 08:38:37 +0200 Subject: [PATCH 07/13] added filterByProperty() --- Readme.md | 3 + .../console/bindings/ContentUpgrade.java | 18 +++- .../bindings/filters/FilterByProperty.java | 55 ++++++++++++ .../filters/FilterByPropertyTest.java | 89 +++++++++++++++++++ .../bindings/impl/ContentUpgradeImpl.java | 35 +++++--- 5 files changed, 183 insertions(+), 17 deletions(-) create mode 100644 api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByProperty.java create mode 100644 api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByPropertyTest.java diff --git a/Readme.md b/Readme.md index d81c7147..9a558a10 100644 --- a/Readme.md +++ b/Readme.md @@ -164,10 +164,12 @@ These methods can be used to filter the nodes that were collected above. Multipl Filters the resources by property values. +* filterByProperty: matches all nodes that have the given attribute value. Filter does not match if attribute is not present. * filterByProperties: use this to filter by a list of property values (e.g. sling:resourceType). All properties in the map are required to to match. Filter does not match if attribute does not exist. * filterByMultiValuePropContains: checks if all condition values are contained in the defined attribute. Filter does not match if attribute does not exist. ```java +filterByProperty(String name, Object value) filterByProperties(Map properties) filterByMultiValuePropContains(String name, Object[] conditionValues) ``` @@ -180,6 +182,7 @@ conditionMap["sling:resourceType"] = "weretail/components/structure/page" println aecu.contentUpgradeBuilder() .forChildResourcesOf("/content/we-retail/ca/en") + .filterByProperty("sling:resourceType", "wcm/foundation/components/responsivegrid") .filterByProperties(conditionMap) .filterByMultiValuePropContains("myAttribute", ["value"] as String[]) .doSetProperty("name", "value") diff --git a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ContentUpgrade.java b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ContentUpgrade.java index cf9ab539..3359bf94 100644 --- a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ContentUpgrade.java +++ b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ContentUpgrade.java @@ -18,11 +18,11 @@ */ package de.valtech.aecu.api.groovy.console.bindings; -import de.valtech.aecu.api.groovy.console.bindings.filters.FilterBy; +import java.util.Map; import org.apache.sling.api.resource.PersistenceException; -import java.util.Map; +import de.valtech.aecu.api.groovy.console.bindings.filters.FilterBy; /** * This class provides the builder methods to perform a content upgrade. @@ -64,6 +64,15 @@ public interface ContentUpgrade { */ ContentUpgrade forResourcesInSubtree(String path); + /** + * Filters by a single property. + * + * @param name property name + * @param value property value + * @return upgrade object + */ + ContentUpgrade filterByProperty(String name, Object value); + /** * Filters by properties. Can be used also for Multi-value properties. * @@ -75,11 +84,11 @@ public interface ContentUpgrade { /** * Filters by multi-value with the given name containing the given conditionValues * - * @param name name of the multi-value property + * @param name name of the multi-value property * @param conditionValues values to search for * @return upgrade object */ - ContentUpgrade filterByMultiValuePropContains(String name, Object[] conditionValues); + ContentUpgrade filterByMultiValuePropContains(String name, Object[] conditionValues); /** * Filters by node name exact match. @@ -233,4 +242,5 @@ public interface ContentUpgrade { * @throws PersistenceException error during execution */ StringBuffer run(boolean dryRun) throws PersistenceException; + } diff --git a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByProperty.java b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByProperty.java new file mode 100644 index 00000000..573946e1 --- /dev/null +++ b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByProperty.java @@ -0,0 +1,55 @@ +/* + * Copyright 2018 Valtech GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and + * associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT + * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package de.valtech.aecu.api.groovy.console.bindings.filters; + +import javax.annotation.Nonnull; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ValueMap; + +/** + * Filters resources by a given property. The filter only matches if the attribute exists and has + * the exact given value. + * + * @author Roland Gruber + */ +public class FilterByProperty implements FilterBy { + + private String name; + private Object value; + + /** + * Constructor + * + * @param name attribute name + * @param value attribute value + */ + public FilterByProperty(@Nonnull String name, Object value) { + this.name = name; + this.value = value; + } + + @Override + public boolean filter(@Nonnull Resource resource) { + ValueMap properties = resource.getValueMap(); + Object attrValue = properties.get(name); + return (value == null) && (attrValue == null) || ((value != null) && value.equals(attrValue)); + } +} + diff --git a/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByPropertyTest.java b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByPropertyTest.java new file mode 100644 index 00000000..0072bd5a --- /dev/null +++ b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByPropertyTest.java @@ -0,0 +1,89 @@ +/* + * Copyright 2018 Valtech GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and + * associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT + * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package de.valtech.aecu.core.groovy.console.bindings.filters; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ValueMap; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByProperty; + +/** + * Tests FilterByProperty + * + * @author Roland Gruber + */ +@RunWith(MockitoJUnitRunner.class) +public class FilterByPropertyTest { + + private static final String NAME = "name"; + private static final String VALUE = "value"; + + @Mock + private Resource resource; + + @Mock + ValueMap values; + + @Before + public void setup() { + when(resource.getValueMap()).thenReturn(values); + } + + @Test + public void filterAttributeNullValueNull() { + FilterByProperty filter = new FilterByProperty(NAME, null); + when(values.get(NAME)).thenReturn(null); + + assertTrue(filter.filter(resource)); + } + + @Test + public void filterAttributeNullValueNonNull() { + FilterByProperty filter = new FilterByProperty(NAME, VALUE); + when(values.get(NAME)).thenReturn(null); + + assertFalse(filter.filter(resource)); + } + + @Test + public void filterAttributeNonNullValueNull() { + FilterByProperty filter = new FilterByProperty(NAME, null); + when(values.get(NAME)).thenReturn(VALUE); + + assertFalse(filter.filter(resource)); + } + + @Test + public void filterAttributeNonNullValueNonNull() { + FilterByProperty filter = new FilterByProperty(NAME, VALUE); + when(values.get(NAME)).thenReturn(VALUE); + + assertTrue(filter.filter(resource)); + } + +} diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/ContentUpgradeImpl.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/ContentUpgradeImpl.java index 193fe033..b347ea81 100644 --- a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/ContentUpgradeImpl.java +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/ContentUpgradeImpl.java @@ -1,11 +1,25 @@ package de.valtech.aecu.core.groovy.console.bindings.impl; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import javax.annotation.Nonnull; + +import org.apache.sling.api.resource.PersistenceException; +import org.apache.sling.api.resource.ResourceResolver; +import org.scribe.utils.MapUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import de.valtech.aecu.api.groovy.console.bindings.ContentUpgrade; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterBy; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByMultiValuePropContains; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByNodeName; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByNodeNameRegex; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByProperties; +import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByProperty; import de.valtech.aecu.core.groovy.console.bindings.actions.Action; import de.valtech.aecu.core.groovy.console.bindings.actions.PrintPath; import de.valtech.aecu.core.groovy.console.bindings.actions.multivalue.AddMultiValues; @@ -24,19 +38,6 @@ import de.valtech.aecu.core.groovy.console.bindings.traversers.ForResources; import de.valtech.aecu.core.groovy.console.bindings.traversers.TraversData; -import org.apache.sling.api.resource.PersistenceException; -import org.apache.sling.api.resource.ResourceResolver; -import org.scribe.utils.MapUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import javax.annotation.Nonnull; - public class ContentUpgradeImpl implements ContentUpgrade { private static Logger LOG = LoggerFactory.getLogger(ContentUpgrade.class); @@ -87,12 +88,20 @@ public ContentUpgrade filterByProperties(@Nonnull Map conditionP return this; } + @Override + public ContentUpgrade filterByProperty(@Nonnull String name, Object value) { + LOG.debug("filterByProperty: {} {}", name, value); + filter = new FilterByProperty(name, value); + return this; + } + @Override public ContentUpgrade filterByMultiValuePropContains(@Nonnull String name, @Nonnull Object[] conditionValues) { LOG.debug("filterByMultiValuePropContains {} : {}", name, Arrays.toString(conditionValues)); filter = new FilterByMultiValuePropContains(name, conditionValues); return this; } + @Override public ContentUpgrade filterByNodeName(@Nonnull String nodeName) { LOG.debug("filterByNodeName: {}", nodeName); From 0aca36c047eed26a11ec31052c086d9117ce502c Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Tue, 28 Aug 2018 08:39:54 +0200 Subject: [PATCH 08/13] filterByProperty --- HISTORY | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/HISTORY b/HISTORY index 451eec90..24d848d7 100644 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,7 @@ +1.4.0 + - Groovy Console extension: + - added filterByProperty() + 2018-08-24 1.3.0 - Execute scripts in alphabetical order - Stop execution after first failed script From a5d036698ec4aead589b4288644ba81fa21569c2 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Tue, 28 Aug 2018 13:28:00 +0200 Subject: [PATCH 09/13] added filterByHasProperty() --- HISTORY | 1 + Readme.md | 3 + .../console/bindings/ContentUpgrade.java | 8 ++ .../bindings/filters/FilterByHasProperty.java | 52 +++++++++++++ .../filters/FilterByHasPropertyTest.java | 73 +++++++++++++++++++ .../bindings/impl/ContentUpgradeImpl.java | 8 ++ 6 files changed, 145 insertions(+) create mode 100644 api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByHasProperty.java create mode 100644 api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByHasPropertyTest.java diff --git a/HISTORY b/HISTORY index 24d848d7..7b1d83d7 100644 --- a/HISTORY +++ b/HISTORY @@ -1,6 +1,7 @@ 1.4.0 - Groovy Console extension: - added filterByProperty() + - added filterByHasProperty() 2018-08-24 1.3.0 - Execute scripts in alphabetical order diff --git a/Readme.md b/Readme.md index 9a558a10..98e2f02d 100644 --- a/Readme.md +++ b/Readme.md @@ -164,11 +164,13 @@ These methods can be used to filter the nodes that were collected above. Multipl Filters the resources by property values. +* filterByHasProperty: matches all nodes that have the given property. The value of the property is not relevant. * filterByProperty: matches all nodes that have the given attribute value. Filter does not match if attribute is not present. * filterByProperties: use this to filter by a list of property values (e.g. sling:resourceType). All properties in the map are required to to match. Filter does not match if attribute does not exist. * filterByMultiValuePropContains: checks if all condition values are contained in the defined attribute. Filter does not match if attribute does not exist. ```java +filterByHasProperty(String name) filterByProperty(String name, Object value) filterByProperties(Map properties) filterByMultiValuePropContains(String name, Object[] conditionValues) @@ -182,6 +184,7 @@ conditionMap["sling:resourceType"] = "weretail/components/structure/page" println aecu.contentUpgradeBuilder() .forChildResourcesOf("/content/we-retail/ca/en") + .filterByHasProperty("myProperty") .filterByProperty("sling:resourceType", "wcm/foundation/components/responsivegrid") .filterByProperties(conditionMap) .filterByMultiValuePropContains("myAttribute", ["value"] as String[]) diff --git a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ContentUpgrade.java b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ContentUpgrade.java index 3359bf94..20d37abd 100644 --- a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ContentUpgrade.java +++ b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ContentUpgrade.java @@ -64,6 +64,14 @@ public interface ContentUpgrade { */ ContentUpgrade forResourcesInSubtree(String path); + /** + * Filters by existence of a single property. + * + * @param name property name + * @return upgrade object + */ + ContentUpgrade filterByHasProperty(String name); + /** * Filters by a single property. * diff --git a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByHasProperty.java b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByHasProperty.java new file mode 100644 index 00000000..b2eea16d --- /dev/null +++ b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByHasProperty.java @@ -0,0 +1,52 @@ +/* + * Copyright 2018 Valtech GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and + * associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT + * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package de.valtech.aecu.api.groovy.console.bindings.filters; + +import javax.annotation.Nonnull; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ValueMap; + +/** + * Filters resources by the existence a given property. The filter only matches if the attribute + * exists. The value of the property is not relevant. + * + * @author Roland Gruber + */ +public class FilterByHasProperty implements FilterBy { + + private String name; + + /** + * Constructor + * + * @param name attribute name + */ + public FilterByHasProperty(@Nonnull String name) { + this.name = name; + } + + @Override + public boolean filter(@Nonnull Resource resource) { + ValueMap properties = resource.getValueMap(); + Object attrValue = properties.get(name); + return (attrValue != null); + } +} + diff --git a/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByHasPropertyTest.java b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByHasPropertyTest.java new file mode 100644 index 00000000..b038b553 --- /dev/null +++ b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByHasPropertyTest.java @@ -0,0 +1,73 @@ +/* + * Copyright 2018 Valtech GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and + * associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT + * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package de.valtech.aecu.core.groovy.console.bindings.filters; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ValueMap; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByHasProperty; + +/** + * Tests FilterByHasProperty + * + * @author Roland Gruber + */ +@RunWith(MockitoJUnitRunner.class) +public class FilterByHasPropertyTest { + + private static final String NAME = "name"; + private static final String VALUE = "value"; + + @Mock + private Resource resource; + + @Mock + ValueMap values; + + @Before + public void setup() { + when(resource.getValueMap()).thenReturn(values); + } + + @Test + public void filterAttributeNullValue() { + FilterByHasProperty filter = new FilterByHasProperty(NAME); + when(values.get(NAME)).thenReturn(null); + + assertFalse(filter.filter(resource)); + } + + @Test + public void filterAttributeNonNullValue() { + FilterByHasProperty filter = new FilterByHasProperty(NAME); + when(values.get(NAME)).thenReturn(VALUE); + + assertTrue(filter.filter(resource)); + } + +} diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/ContentUpgradeImpl.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/ContentUpgradeImpl.java index b347ea81..df40dac1 100644 --- a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/ContentUpgradeImpl.java +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/ContentUpgradeImpl.java @@ -15,6 +15,7 @@ import de.valtech.aecu.api.groovy.console.bindings.ContentUpgrade; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterBy; +import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByHasProperty; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByMultiValuePropContains; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByNodeName; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByNodeNameRegex; @@ -95,6 +96,13 @@ public ContentUpgrade filterByProperty(@Nonnull String name, Object value) { return this; } + @Override + public ContentUpgrade filterByHasProperty(@Nonnull String name) { + LOG.debug("filterByHasProperty: {} {}", name); + filter = new FilterByHasProperty(name); + return this; + } + @Override public ContentUpgrade filterByMultiValuePropContains(@Nonnull String name, @Nonnull Object[] conditionValues) { LOG.debug("filterByMultiValuePropContains {} : {}", name, Arrays.toString(conditionValues)); From b686c1a0ae5da1a6a08553a3bacd5fb956fdf83d Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 29 Aug 2018 14:06:34 +0200 Subject: [PATCH 10/13] use correct service resource resolver --- .../aecu/core/healthcheck/SelfCheckHealthCheck.java | 7 ++++++- .../java/de/valtech/aecu/core/service/AecuServiceImpl.java | 2 +- ui.apps/src/main/content/jcr_root/_rep_policy.xml | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/de/valtech/aecu/core/healthcheck/SelfCheckHealthCheck.java b/core/src/main/java/de/valtech/aecu/core/healthcheck/SelfCheckHealthCheck.java index 74d2a107..9b657a14 100644 --- a/core/src/main/java/de/valtech/aecu/core/healthcheck/SelfCheckHealthCheck.java +++ b/core/src/main/java/de/valtech/aecu/core/healthcheck/SelfCheckHealthCheck.java @@ -44,7 +44,12 @@ public class SelfCheckHealthCheck implements HealthCheck { public Result execute() { final FormattingResultLog resultLog = new FormattingResultLog(); try (ResourceResolver resolver = resolverService.getServiceResourceResolver()) { - resultLog.info("Ok"); + resultLog.info("Service user ok"); + } catch (LoginException e) { + resultLog.critical("Unable to open service resource resolver {}", e.getMessage()); + } + try (ResourceResolver resolver = resolverService.getContentMigratorResourceResolver()) { + resultLog.info("Migration user ok"); } catch (LoginException e) { resultLog.critical("Unable to open service resource resolver {}", e.getMessage()); } diff --git a/core/src/main/java/de/valtech/aecu/core/service/AecuServiceImpl.java b/core/src/main/java/de/valtech/aecu/core/service/AecuServiceImpl.java index efedbb8a..670ba445 100644 --- a/core/src/main/java/de/valtech/aecu/core/service/AecuServiceImpl.java +++ b/core/src/main/java/de/valtech/aecu/core/service/AecuServiceImpl.java @@ -152,7 +152,7 @@ public boolean isValidScriptName(String name) { @Override public ExecutionResult execute(String path) throws AecuException { - try (ResourceResolver resolver = resolverService.getServiceResourceResolver()) { + try (ResourceResolver resolver = resolverService.getContentMigratorResourceResolver()) { Resource resource = resolver.getResource(path); if (resource == null) { throw new AecuException("Path is invalid"); diff --git a/ui.apps/src/main/content/jcr_root/_rep_policy.xml b/ui.apps/src/main/content/jcr_root/_rep_policy.xml index 3b0dc6d0..ab16f9c6 100644 --- a/ui.apps/src/main/content/jcr_root/_rep_policy.xml +++ b/ui.apps/src/main/content/jcr_root/_rep_policy.xml @@ -5,4 +5,8 @@ jcr:primaryType="rep:GrantACE" rep:principalName="aecu-service" rep:privileges="{Name}[jcr:read]"/> + \ No newline at end of file From 7393e2524efe7dc45e04ca3023989171ff29bb39 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 29 Aug 2018 14:11:58 +0200 Subject: [PATCH 11/13] 1.4.0 --- HISTORY | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/HISTORY b/HISTORY index 7b1d83d7..764a243e 100644 --- a/HISTORY +++ b/HISTORY @@ -1,7 +1,8 @@ -1.4.0 +2018-08-29 1.4.0 - Groovy Console extension: - added filterByProperty() - added filterByHasProperty() + - Fixed issue with access rights 2018-08-24 1.3.0 - Execute scripts in alphabetical order From d595bb1789d984ab838d3f6c8ffa940e2317cf93 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 29 Aug 2018 14:12:21 +0200 Subject: [PATCH 12/13] updating poms for 1.4.0 branch with snapshot versions --- api/pom.xml | 2 +- bundle/pom.xml | 2 +- core/pom.xml | 2 +- examples/pom.xml | 2 +- pom.xml | 2 +- ui.apps/pom.xml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 6a0843c8..90c92c84 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 1.3.1-SNAPSHOT + 1.4.0-rc-SNAPSHOT aecu.api diff --git a/bundle/pom.xml b/bundle/pom.xml index 95fbbae7..9221abe3 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 1.3.1-SNAPSHOT + 1.4.0-rc-SNAPSHOT aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index 3e4dcb95..fce1700b 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 1.3.1-SNAPSHOT + 1.4.0-rc-SNAPSHOT aecu.core diff --git a/examples/pom.xml b/examples/pom.xml index 367405c1..ebdbf22c 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 1.3.1-SNAPSHOT + 1.4.0-rc-SNAPSHOT aecu.examples diff --git a/pom.xml b/pom.xml index 2d29897b..8026a345 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 1.3.1-SNAPSHOT + 1.4.0-rc-SNAPSHOT AECU AEM Easy COntent Upgrade https://github.com/valtech/aem-easy-content-upgrade diff --git a/ui.apps/pom.xml b/ui.apps/pom.xml index 89309cb3..9e230659 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 1.3.1-SNAPSHOT + 1.4.0-rc-SNAPSHOT aecu.ui.apps From 80de21836861c6a67ca005a0d63585d1fef2756f Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 29 Aug 2018 14:12:53 +0200 Subject: [PATCH 13/13] updating poms for branch'release/1.4.0' with non-snapshot versions --- api/pom.xml | 2 +- bundle/pom.xml | 2 +- core/pom.xml | 2 +- examples/pom.xml | 2 +- pom.xml | 2 +- ui.apps/pom.xml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 90c92c84..7c36dd6a 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 1.4.0-rc-SNAPSHOT + 1.4.0 aecu.api diff --git a/bundle/pom.xml b/bundle/pom.xml index 9221abe3..d700de12 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 1.4.0-rc-SNAPSHOT + 1.4.0 aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index fce1700b..c8f80e12 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 1.4.0-rc-SNAPSHOT + 1.4.0 aecu.core diff --git a/examples/pom.xml b/examples/pom.xml index ebdbf22c..fe95bd3d 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 1.4.0-rc-SNAPSHOT + 1.4.0 aecu.examples diff --git a/pom.xml b/pom.xml index 8026a345..33904f30 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 1.4.0-rc-SNAPSHOT + 1.4.0 AECU AEM Easy COntent Upgrade https://github.com/valtech/aem-easy-content-upgrade diff --git a/ui.apps/pom.xml b/ui.apps/pom.xml index 9e230659..7c71d1ab 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 1.4.0-rc-SNAPSHOT + 1.4.0 aecu.ui.apps