From a6374faa86148ce19b7ac60bb6577a2f02b29a11 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 21 Dec 2020 08:06:22 +0100 Subject: [PATCH 01/29] updating poms for 4.0.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 6bab112c..6c1a82a6 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 4.0.0-SNAPSHOT + 4.0.1-SNAPSHOT aecu.api diff --git a/bundle/pom.xml b/bundle/pom.xml index fbca12d5..438e0415 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.0.0-SNAPSHOT + 4.0.1-SNAPSHOT aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index f51a7581..d07a02d0 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 4.0.0-SNAPSHOT + 4.0.1-SNAPSHOT aecu.core diff --git a/examples/pom.xml b/examples/pom.xml index 97f27856..30af23e3 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.0.0-SNAPSHOT + 4.0.1-SNAPSHOT aecu.examples diff --git a/pom.xml b/pom.xml index 8dac25d1..3befd7d7 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 4.0.0-SNAPSHOT + 4.0.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 48946725..4dcc659e 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.0.0-SNAPSHOT + 4.0.1-SNAPSHOT aecu.ui.apps From 28fd67a2c30b6c17569953dd7c525e89cfa54e57 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 21 Dec 2020 08:13:34 +0100 Subject: [PATCH 02/29] 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 6c1a82a6..69b12203 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 4.0.1-SNAPSHOT + 4.0.0 aecu.api diff --git a/bundle/pom.xml b/bundle/pom.xml index 438e0415..1cdcc80a 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.0.1-SNAPSHOT + 4.0.0 aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index d07a02d0..07294c1a 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 4.0.1-SNAPSHOT + 4.0.0 aecu.core diff --git a/examples/pom.xml b/examples/pom.xml index 30af23e3..54d98f96 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.0.1-SNAPSHOT + 4.0.0 aecu.examples diff --git a/pom.xml b/pom.xml index 3befd7d7..fb5f8e61 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 4.0.1-SNAPSHOT + 4.0.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 4dcc659e..c9248268 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.0.1-SNAPSHOT + 4.0.0 aecu.ui.apps From 5431ebae3904684bd697aff90ee6d7a7111bf78f Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 21 Dec 2020 08:13:35 +0100 Subject: [PATCH 03/29] 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 69b12203..6c1a82a6 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 4.0.0 + 4.0.1-SNAPSHOT aecu.api diff --git a/bundle/pom.xml b/bundle/pom.xml index 1cdcc80a..438e0415 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.0.0 + 4.0.1-SNAPSHOT aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index 07294c1a..d07a02d0 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 4.0.0 + 4.0.1-SNAPSHOT aecu.core diff --git a/examples/pom.xml b/examples/pom.xml index 54d98f96..30af23e3 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.0.0 + 4.0.1-SNAPSHOT aecu.examples diff --git a/pom.xml b/pom.xml index fb5f8e61..3befd7d7 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 4.0.0 + 4.0.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 c9248268..4dcc659e 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.0.0 + 4.0.1-SNAPSHOT aecu.ui.apps From cfdd10515a4bf6eb8f29409b0520ad4e6ddacc6c Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 21 Dec 2020 08:20:59 +0100 Subject: [PATCH 04/29] 4.0.1 --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index 72e27f60..7ab8bb5c 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -2,7 +2,7 @@ sonar.projectKey=aecu # this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1. sonar.projectName=AEM Easy Content Upgrade -sonar.projectVersion=3.4.0-SNAPSHOT +sonar.projectVersion=4.0.1-SNAPSHOT # Encoding of the source code. Default is default system encoding sonar.sourceEncoding=UTF-8 From 6726c4f637609975a06a42076d1d78d4276d5819 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 21 Dec 2020 08:29:15 +0100 Subject: [PATCH 05/29] fix run step --- .github/workflows/codeql-analysis.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 8c880f21..754ac3b0 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -49,8 +49,8 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v1 +# - name: Autobuild +# uses: github/codeql-action/autobuild@v1 # ℹ️ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -59,9 +59,8 @@ jobs: # and modify them (or add more) to build your code if your project # uses a compiled language - #- run: | - # make bootstrap - # make release + - run: | + mvn clean install - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v1 From 9ae6291080bf6f155adbf6fcfe5a6e76ca649b0d Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 21 Dec 2020 08:36:05 +0100 Subject: [PATCH 06/29] https --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 3befd7d7..e3615300 100644 --- a/pom.xml +++ b/pom.xml @@ -714,12 +714,12 @@ adobe Adobe Public Repository - http://repo.adobe.com/nexus/content/groups/public/ + https://repo.adobe.com/nexus/content/groups/public/ default central - http://repo1.maven.org/maven2 + https://repo1.maven.org/maven2 default false @@ -730,7 +730,7 @@ adobe Adobe Public Repository - http://repo.adobe.com/nexus/content/groups/public/ + https://repo.adobe.com/nexus/content/groups/public/ default From 314caca60ac7cdf0573465ccf6ffc1516f87db01 Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Thu, 14 Jan 2021 16:58:30 +0100 Subject: [PATCH 07/29] Wrap RuntimeException thrown by Actions to ease debugging This closes #147 --- .../console/bindings/traversers/TraversData.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/traversers/TraversData.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/traversers/TraversData.java index d9ddc58d..569a1f6c 100644 --- a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/traversers/TraversData.java +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/traversers/TraversData.java @@ -120,9 +120,14 @@ private void save(ResourceResolver resourceResolver) throws PersistenceException private void runActions(@Nonnull StringBuilder output, @Nonnull Resource resource, @Nonnull List actions) throws PersistenceException, AecuException { for (Action action : actions) { - String actionOutput = action.doAction(resource); - if (StringUtils.isNotBlank(actionOutput)) { - output.append(actionOutput + "\n"); + try { + String actionOutput = action.doAction(resource); + if (StringUtils.isNotBlank(actionOutput)) { + output.append(actionOutput + "\n"); + } + } catch (RuntimeException e) { + // wrap runtime exception to add the resource path (see also https://issues.apache.org/jira/browse/SLING-10063) + throw new AecuException("RuntimeException while performing action on resource '" + resource.getPath() + "'", e); } } } From 47206da5581e426c22f5172f2bc28374b547122a Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Thu, 14 Jan 2021 17:29:25 +0100 Subject: [PATCH 08/29] make loading scripts also work from non-JCR resource providers prevent leak in case of exceptions --- .../aecu/core/service/AecuServiceImpl.java | 19 +++++++------------ .../core/service/AecuServiceImplTest.java | 6 ++---- 2 files changed, 9 insertions(+), 16 deletions(-) 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 dd3f58b8..3c922242 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 @@ -26,10 +26,6 @@ import java.util.List; import java.util.Set; -import javax.jcr.Binary; -import javax.jcr.Node; -import javax.jcr.RepositoryException; - import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.jackrabbit.JcrConstants; @@ -222,14 +218,13 @@ private ExecutionResult executeScript(ResourceResolver resolver, String path) th */ private String loadScript(String path, ResourceResolver resolver) throws AecuException { Resource resource = resolver.getResource(path + "/" + JcrConstants.JCR_CONTENT); - Binary binary; - try { - binary = resource.adaptTo(Node.class).getProperty(JcrConstants.JCR_DATA).getBinary(); - InputStream inputStream = binary.getStream(); - String script = IOUtils.toString(inputStream, StandardCharsets.UTF_8.name()); - binary.dispose(); - return script; - } catch (RepositoryException | IOException e) { + // https://sling.apache.org/documentation/the-sling-engine/resources.html#binary-support + try (InputStream inputStream = resource.adaptTo(InputStream.class)){ + if (inputStream == null) { + throw new IOException("Resource at '" + path +"' cannot be adapted to InputStream, it doesn't seem to contain binary data"); + } + return IOUtils.toString(inputStream, StandardCharsets.UTF_8); + } catch (IOException e) { throw new AecuException("Unable to read script", e); } } diff --git a/core/src/test/java/de/valtech/aecu/core/service/AecuServiceImplTest.java b/core/src/test/java/de/valtech/aecu/core/service/AecuServiceImplTest.java index 0f90feaf..74cce0cf 100644 --- a/core/src/test/java/de/valtech/aecu/core/service/AecuServiceImplTest.java +++ b/core/src/test/java/de/valtech/aecu/core/service/AecuServiceImplTest.java @@ -29,6 +29,7 @@ import static org.mockito.Mockito.when; import java.io.ByteArrayInputStream; +import java.io.InputStream; import java.util.Arrays; import java.util.HashSet; import java.util.List; @@ -320,10 +321,7 @@ public void execute() throws AecuException, RepositoryException { when(resource.getName()).thenReturn(FILE1); when(scriptContext.getScript()).thenReturn(DIR); ByteArrayInputStream stream = new ByteArrayInputStream("test".getBytes()); - when(binary.getStream()).thenReturn(stream); - when(resource.adaptTo(Node.class)).thenReturn(node); - when(node.getProperty(JcrConstants.JCR_DATA)).thenReturn(property); - when(property.getBinary()).thenReturn(binary); + when(resource.adaptTo(InputStream.class)).thenReturn(stream); RunScriptResponse response = DefaultRunScriptResponse.fromResult(scriptContext, null, null, null); when(groovyConsoleService.runScript(Mockito.any())).thenReturn(response); From 531b8c3e035bb01fd4c8471fd2ef8e66f68be009 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Fri, 15 Jan 2021 08:57:43 +0100 Subject: [PATCH 09/29] removed obsolete code --- .../aecu/core/service/AecuServiceImplTest.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/core/src/test/java/de/valtech/aecu/core/service/AecuServiceImplTest.java b/core/src/test/java/de/valtech/aecu/core/service/AecuServiceImplTest.java index 74cce0cf..3732d1bb 100644 --- a/core/src/test/java/de/valtech/aecu/core/service/AecuServiceImplTest.java +++ b/core/src/test/java/de/valtech/aecu/core/service/AecuServiceImplTest.java @@ -35,9 +35,6 @@ import java.util.List; import java.util.Set; -import javax.jcr.Binary; -import javax.jcr.Node; -import javax.jcr.Property; import javax.jcr.RepositoryException; import org.apache.jackrabbit.JcrConstants; @@ -101,15 +98,6 @@ public class AecuServiceImplTest { @Mock private ScriptContext scriptContext = mock(ScriptContext.class); - @Mock - private Binary binary; - - @Mock - private Node node; - - @Mock - private Property property; - @Before public void setup() throws LoginException { Set runModes = new HashSet<>(); From 1bb62e27d7322bbde435d26afc3c8cfd7ca58697 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Tue, 19 Jan 2021 11:05:27 +0100 Subject: [PATCH 10/29] do not execute scripts with always flag when they have invalid path --- .../aecu/core/installhook/AecuTrackerListener.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/de/valtech/aecu/core/installhook/AecuTrackerListener.java b/core/src/main/java/de/valtech/aecu/core/installhook/AecuTrackerListener.java index 7d7cabdd..bc5ba2c9 100644 --- a/core/src/main/java/de/valtech/aecu/core/installhook/AecuTrackerListener.java +++ b/core/src/main/java/de/valtech/aecu/core/installhook/AecuTrackerListener.java @@ -28,6 +28,8 @@ import org.apache.commons.lang3.StringUtils; import org.apache.jackrabbit.vault.fs.api.ProgressTrackerListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import de.valtech.aecu.api.service.AecuService; @@ -39,6 +41,8 @@ */ public class AecuTrackerListener implements ProgressTrackerListener { + private static final Logger LOG = LoggerFactory.getLogger(AecuTrackerListener.class); + public static final String ALWAYS_SUFFIX = "always.groovy"; private static final Set ACTIONS = new HashSet<>(Arrays.asList("A", "M", "U")); @@ -91,14 +95,14 @@ public void onMessage(Mode mode, String action, String path) { return; } - if (StringUtils.endsWith(path, ALWAYS_SUFFIX)) { + if (StringUtils.endsWith(path, ALWAYS_SUFFIX) && isValid(path)) { logMessage(String.format("Adding %s due to having 'always' in name.", path)); paths.add(path); return; } if (!ACTIONS.contains(action) && isValid(path)) { - logMessage(String.format("Skipping %s due to non matching action '%s'", path, action)); + LOG.debug(String.format("Skipping %s due to non matching action '%s'", path, action)); return; } From e27bef9faa65c3e5a5c5c0b68a51acdfd842368c Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Thu, 11 Feb 2021 10:50:23 +0100 Subject: [PATCH 11/29] #151 added aecu-last-run tag --- .../de/valtech/aecu/core/healthcheck/LastRunHealthCheck.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/de/valtech/aecu/core/healthcheck/LastRunHealthCheck.java b/core/src/main/java/de/valtech/aecu/core/healthcheck/LastRunHealthCheck.java index 239caaeb..13dc9e5a 100644 --- a/core/src/main/java/de/valtech/aecu/core/healthcheck/LastRunHealthCheck.java +++ b/core/src/main/java/de/valtech/aecu/core/healthcheck/LastRunHealthCheck.java @@ -36,7 +36,7 @@ * @author Roland Gruber */ @Component(immediate = true, service = HealthCheck.class, property = {HealthCheck.TAGS + "=aecu", - HealthCheck.NAME + "=AECU Last Run", HealthCheck.MBEAN_NAME + "=aecuLastRunHCmBean"}) + HealthCheck.TAGS + "=aecu-last-run", HealthCheck.NAME + "=AECU Last Run", HealthCheck.MBEAN_NAME + "=aecuLastRunHCmBean"}) public class LastRunHealthCheck implements HealthCheck { @Reference From c0f3e1b2d7e348d1136584699ba754820ac9d242 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Thu, 11 Feb 2021 11:23:53 +0100 Subject: [PATCH 12/29] updated AEM version --- Readme.md | 2 +- .../console/bindings/servlet/AceAutocompleteServletTest.java | 5 +++-- pom.xml | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Readme.md b/Readme.md index c26ec1fb..de229ddd 100644 --- a/Readme.md +++ b/Readme.md @@ -58,7 +58,7 @@ AECU requires Java 8 and AEM 6.5 or above. For AEM 6.3/6.4 please see below. Gro | AEM Version | Groovy Console | AECU | | ------------- | -------------- | --------- | | AEM Cloud | 16.x
14.x, 13.x | 4.x
3.x, 2.x | -| 6.5 | 16.x
14.x, 13.x | 4.x
3.x, 2.x | +| 6.5 (>=6.5.3) | 16.x
14.x, 13.x | 4.x
3.x, 2.x | | 6.4 | 14.x, 13.x | 3.x, 2.x | | 6.3 | 12.x | 1.x | diff --git a/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/servlet/AceAutocompleteServletTest.java b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/servlet/AceAutocompleteServletTest.java index a52b2803..0e37a857 100644 --- a/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/servlet/AceAutocompleteServletTest.java +++ b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/servlet/AceAutocompleteServletTest.java @@ -62,8 +62,9 @@ public void test_getPublicMethodsOfClass_ofAecuBinding() assertNotNull(result); assertEquals(2, result.size()); - assertEquals("contentUpgradeBuilder", result.get(0).getName()); - assertEquals("validateAccessRights", result.get(1).getName()); + for (Method method : result) { + assertTrue("contentUpgradeBuilder".equals(method.getName()) || "validateAccessRights".equals(method.getName())); + } } @Test diff --git a/pom.xml b/pom.xml index e3615300..e16ca02a 100644 --- a/pom.xml +++ b/pom.xml @@ -501,7 +501,7 @@ com.adobe.aem uber-jar - 6.4.3 + 6.5.3 apis provided From 3ee6c6d0d5280b0a33a454f9beb4938537586963 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 15 Feb 2021 12:50:52 +0100 Subject: [PATCH 13/29] #146 Java 11 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dc007090..fd0c14da 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: java jdk: - - openjdk9 + - openjdk11 addons: sonarcloud: From 6ccf401257554d4d198c743fab9550dd3931703e Mon Sep 17 00:00:00 2001 From: Vugar Aghayev Date: Thu, 18 Feb 2021 10:09:34 +0100 Subject: [PATCH 14/29] add filterByNode & filterByNodeNotExist filters --- .../console/bindings/ContentUpgrade.java | 16 ++++ .../bindings/filters/FilterByNode.java | 68 +++++++++++++ .../filters/FilterByNodeNotExist.java | 67 +++++++++++++ .../filters/FilterByNodeNotExistTest.java | 96 +++++++++++++++++++ .../bindings/filters/FilterByNodeTest.java | 96 +++++++++++++++++++ .../bindings/impl/ContentUpgradeImpl.java | 14 +++ 6 files changed, 357 insertions(+) create mode 100644 api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNode.java create mode 100644 api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNodeNotExist.java create mode 100644 api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeNotExistTest.java create mode 100644 api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeTest.java 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 4b136ce0..8da09a8a 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 @@ -137,6 +137,22 @@ public interface ContentUpgrade { */ ContentUpgrade filterByNodeName(String nodeName); + /** + * Filters by node exist. + * + * @param path node path + * @return upgrade object + */ + ContentUpgrade filterByNode(String path); + + /** + * Filters by node not exist. + * + * @param path node path + * @return upgrade object + */ + ContentUpgrade filterByNodeNotExist(String path); + /** * Filters by node name using regular expression. * diff --git a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNode.java b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNode.java new file mode 100644 index 00000000..4fff5d63 --- /dev/null +++ b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNode.java @@ -0,0 +1,68 @@ +/* + * Copyright 2018 - 2019 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.commons.lang3.StringUtils; +import org.apache.sling.api.resource.Resource; + + +/** + * Filters resources by absolute or relative node path. Only resources that exist in the repository are accepted. + * + * @author Vugar Aghayev + */ +public class FilterByNode implements FilterBy { + + private String path; + + /** + * Constructor + * + * @param path node path + */ + public FilterByNode(@Nonnull String path) { + this.path = path; + } + + @Override + public boolean filter(@Nonnull Resource resource, StringBuilder output) { + if(StringUtils.isBlank(path)) + return true; + + if(isAbsolutePath(path)) { + return (null != resource.getResourceResolver().getResource(path)); + } else { + return (null != resource.getChild(path)); + } + } + + /** + * checks whether given path is absolute or not. + * + * @param path jcr path + * @return true if the given path is the absolute path. Otherwise + * false. + */ + private boolean isAbsolutePath(String path) { + return path.startsWith("/"); + } +} diff --git a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNodeNotExist.java b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNodeNotExist.java new file mode 100644 index 00000000..43ea87cd --- /dev/null +++ b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNodeNotExist.java @@ -0,0 +1,67 @@ +/* + * Copyright 2018 - 2019 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 org.apache.commons.lang3.StringUtils; +import org.apache.sling.api.resource.Resource; + +import javax.annotation.Nonnull; + + +/** + * Filters resources by node. Only resources that do not exist in the repository are accepted. + * + * @author Vugar Aghayev + */ +public class FilterByNodeNotExist implements FilterBy { + + private String path; + + /** + * Constructor + * + * @param path node path + */ + public FilterByNodeNotExist(@Nonnull String path) { + this.path = path; + } + + @Override + public boolean filter(@Nonnull Resource resource, StringBuilder output) { + if(StringUtils.isBlank(path)) + return true; + if(isAbsolutePath(path)) { + return (null == resource.getResourceResolver().getResource(path)); + } else { + return (null == resource.getChild(path)); + } + } + + /** + * checks whether given path is absolute or not. + * + * @param path jcr path + * @return true if the given path is the absolute path. Otherwise + * false. + */ + private boolean isAbsolutePath(String path) { + return path.startsWith("/"); + } +} diff --git a/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeNotExistTest.java b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeNotExistTest.java new file mode 100644 index 00000000..55fbbf02 --- /dev/null +++ b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeNotExistTest.java @@ -0,0 +1,96 @@ +/* + * 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 de.valtech.aecu.api.groovy.console.bindings.filters.FilterByNodeNotExist; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ResourceResolver; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +/** + * @author Vugar Aghayev + */ +@RunWith(MockitoJUnitRunner.class) +public class FilterByNodeNotExistTest { + + @Mock + private ResourceResolver resolver; + + @Mock + private Resource resource; + + @Mock + private Resource relativePathResource; + + @Mock + private Resource absolutePathResource; + + @Before + public void setup() { + when(resource.getResourceResolver()).thenReturn(resolver); + when(resource.getChild("climbing-on-kalymnos-island--greece/jcr:content")).thenReturn(relativePathResource); + } + + @Test + public void test_whenNodeNotFound_returnTrue() { + + assertTrue(new FilterByNodeNotExist("/content/we-retail/ca/climbing-on-kalymnos-island--greece/jcr:content").filter(resource, new StringBuilder())); + + assertTrue(new FilterByNodeNotExist("climbing-on-island--greece/jcr:content").filter(resource, new StringBuilder())); + } + + @Test + public void test_whenSubNodeFound_returnFalse() { + + assertFalse(new FilterByNodeNotExist("climbing-on-kalymnos-island--greece/jcr:content").filter(resource, new StringBuilder())); + + } + + @Test + public void test_whenAbsolutePathNodeFound_returnFalse() { + when(resource.getResourceResolver().getResource("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content")).thenReturn(absolutePathResource); + + assertFalse(new FilterByNodeNotExist("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content").filter(resource, new StringBuilder())); + + } + @Test + public void test_whenNodePathIsEmpty_returnTrue() { + + assertTrue(new FilterByNodeNotExist("").filter(resource, new StringBuilder())); + + assertTrue(new FilterByNodeNotExist(" ").filter(resource, new StringBuilder())); + + } + + @Test + public void test_whenNodePathIsNull_returnTrue() { + + assertTrue(new FilterByNodeNotExist(null).filter(resource, new StringBuilder())); + + } +} diff --git a/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeTest.java b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeTest.java new file mode 100644 index 00000000..417b463f --- /dev/null +++ b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeTest.java @@ -0,0 +1,96 @@ +/* + * 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 de.valtech.aecu.api.groovy.console.bindings.filters.FilterByNode; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ResourceResolver; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +/** + * @author Vugar Aghayev + */ +@RunWith(MockitoJUnitRunner.class) +public class FilterByNodeTest { + + @Mock + private ResourceResolver resolver; + + @Mock + private Resource resource; + + @Mock + private Resource relativePathResource; + + @Mock + private Resource absolutePathResource; + + @Before + public void setup() { + when(resource.getResourceResolver()).thenReturn(resolver); + when(resource.getChild("climbing-on-kalymnos-island--greece/jcr:content")).thenReturn(relativePathResource); + } + + @Test + public void test_whenNodeNotFound_returnFalse() { + + assertFalse(new FilterByNode("/content/we-retail/ca/climbing-on-kalymnos-island--greece/jcr:content").filter(resource, new StringBuilder())); + + assertFalse(new FilterByNode("climbing-on-island--greece/jcr:content").filter(resource, new StringBuilder())); + } + + @Test + public void test_whenSubNodeFound_returnTrue() { + + assertTrue(new FilterByNode("climbing-on-kalymnos-island--greece/jcr:content").filter(resource, new StringBuilder())); + + } + + @Test + public void test_whenAbsolutePathNodeFound_returnTrue() { + when(resource.getResourceResolver().getResource("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content")).thenReturn(absolutePathResource); + + assertTrue(new FilterByNode("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content").filter(resource, new StringBuilder())); + + } + @Test + public void test_whenNodePathIsEmpty_returnTrue() { + + assertTrue(new FilterByNode("").filter(resource, new StringBuilder())); + + assertTrue(new FilterByNode(" ").filter(resource, new StringBuilder())); + + } + + @Test + public void test_whenNodePathIsNull_returnTrue() { + + assertTrue(new FilterByNode(null).filter(resource, new StringBuilder())); + + } +} 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 5e4f96e0..f0a72f5b 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 @@ -44,6 +44,8 @@ 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.FilterByNode; +import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByNodeNotExist; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByNodeNameRegex; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByPathRegex; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByProperties; @@ -188,6 +190,18 @@ public ContentUpgrade filterByNodeName(@Nonnull String nodeName) { return this; } + @Override + public ContentUpgrade filterByNode(@Nonnull String path) { + addFilter(new FilterByNode(path)); + return this; + } + + @Override + public ContentUpgrade filterByNodeNotExist(@Nonnull String path) { + addFilter(new FilterByNodeNotExist(path)); + return this; + } + @Override public ContentUpgrade filterByNodeNameRegex(@Nonnull String regex) { addFilter(new FilterByNodeNameRegex(regex)); From cfe3455a3d929e652a196a0d0a2798e49404ae4d Mon Sep 17 00:00:00 2001 From: Vugar Aghayev Date: Thu, 18 Feb 2021 10:10:06 +0100 Subject: [PATCH 15/29] Update Readme file with new filter options --- Readme.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Readme.md b/Readme.md index de229ddd..392efa77 100644 --- a/Readme.md +++ b/Readme.md @@ -323,7 +323,29 @@ aecu.contentUpgradeBuilder() .run() ``` +#### Filter by Node | NodeNotExist +Filters resources by absolute or relative node path. + +* filterByNode(String path): process nodes if the given node or subnode exist in the repository +* filterByNodeNotExist(String path): process nodes if the given node or subnode do not exist in the repository + +Example filterByNode: +```java +aecu.contentUpgradeBuilder() + .forChildResourcesOf("/content/we-retail/ca/en") + .filterByNode("jcr:content/meta") + .doSetProperty("name", "value") + .run() +``` +Example filterByNodeNotExist: +```java +aecu.contentUpgradeBuilder() + .forChildResourcesOf("/content/we-retail/ca/en") + .filterByNodeNotExist("climbing-on-island--greece/jcr:content") + .printPath() + .run() +``` #### Combine Multiple Filters You can combine filters with AND and OR to build more complex filters. From 48847cf699d6f658feee395412d0a85e52e756a7 Mon Sep 17 00:00:00 2001 From: Vugar Aghayev Date: Thu, 18 Feb 2021 10:13:36 +0100 Subject: [PATCH 16/29] Update version numbers --- api/pom.xml | 2 +- .../api/groovy/console/bindings/filters/package-info.java | 2 +- .../aecu/api/groovy/console/bindings/package-info.java | 2 +- bundle/pom.xml | 2 +- core/pom.xml | 2 +- examples/pom.xml | 2 +- pom.xml | 4 ++-- sonar-project.properties | 2 +- ui.apps/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 6c1a82a6..c5becc90 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 4.0.1-SNAPSHOT + 4.1.0-SNAPSHOT aecu.api diff --git a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/package-info.java b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/package-info.java index 0f2e97c9..f239716c 100644 --- a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/package-info.java +++ b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/package-info.java @@ -22,7 +22,7 @@ * * @author Roxana Muresan */ -@Version("3.0.0") +@Version("3.1.0") package de.valtech.aecu.api.groovy.console.bindings.filters; import org.osgi.annotation.versioning.Version; diff --git a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/package-info.java b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/package-info.java index c2e153f1..9204a68f 100644 --- a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/package-info.java +++ b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/package-info.java @@ -22,7 +22,7 @@ * * @author Roxana Muresan */ -@Version("4.4.0") +@Version("4.5.0") package de.valtech.aecu.api.groovy.console.bindings; import org.osgi.annotation.versioning.Version; diff --git a/bundle/pom.xml b/bundle/pom.xml index 438e0415..1ee8acca 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.0.1-SNAPSHOT + 4.1.0-SNAPSHOT aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index d07a02d0..0091c180 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 4.0.1-SNAPSHOT + 4.1.0-SNAPSHOT aecu.core diff --git a/examples/pom.xml b/examples/pom.xml index 30af23e3..9cb010e0 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.0.1-SNAPSHOT + 4.1.0-SNAPSHOT aecu.examples diff --git a/pom.xml b/pom.xml index e16ca02a..6f5af92c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 4.0.1-SNAPSHOT + 4.1.0-SNAPSHOT AECU AEM Easy Content Upgrade https://github.com/valtech/aem-easy-content-upgrade @@ -19,7 +19,7 @@ localhost - 5602 + 6002 localhost 5705 admin diff --git a/sonar-project.properties b/sonar-project.properties index 7ab8bb5c..8a16db93 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -2,7 +2,7 @@ sonar.projectKey=aecu # this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1. sonar.projectName=AEM Easy Content Upgrade -sonar.projectVersion=4.0.1-SNAPSHOT +sonar.projectVersion=4.1.0-SNAPSHOT # Encoding of the source code. Default is default system encoding sonar.sourceEncoding=UTF-8 diff --git a/ui.apps/pom.xml b/ui.apps/pom.xml index 4dcc659e..fcdf4b15 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.0.1-SNAPSHOT + 4.1.0-SNAPSHOT aecu.ui.apps From 022e2190e257c3a4ebee2ab283fed850ad29394f Mon Sep 17 00:00:00 2001 From: Vugar Aghayev Date: Thu, 18 Feb 2021 10:20:44 +0100 Subject: [PATCH 17/29] Revert AEM default port number --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6f5af92c..859156b6 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ localhost - 6002 + 5602 localhost 5705 admin From b32e4f48edbb325d895894062b575e8c28f18cad Mon Sep 17 00:00:00 2001 From: Vugar Aghayev Date: Wed, 24 Feb 2021 09:55:36 +0100 Subject: [PATCH 18/29] Implement Code Review Suggestions --- Readme.md | 17 +--- .../console/bindings/ContentUpgrade.java | 57 ++++------- .../bindings/filters/FilterByNode.java | 23 +++-- .../filters/FilterByNodeNotExist.java | 67 ------------- .../filters/FilterByNodeNotExistTest.java | 96 ------------------- .../bindings/filters/FilterByNodeTest.java | 67 ++++++++++--- .../bindings/impl/ContentUpgradeImpl.java | 17 +--- 7 files changed, 97 insertions(+), 247 deletions(-) delete mode 100644 api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNodeNotExist.java delete mode 100644 api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeNotExistTest.java diff --git a/Readme.md b/Readme.md index 392efa77..5f9d6800 100644 --- a/Readme.md +++ b/Readme.md @@ -323,29 +323,22 @@ aecu.contentUpgradeBuilder() .run() ``` -#### Filter by Node | NodeNotExist +#### Filter by Node Filters resources by absolute or relative node path. -* filterByNode(String path): process nodes if the given node or subnode exist in the repository -* filterByNodeNotExist(String path): process nodes if the given node or subnode do not exist in the repository +* filterByNode(String path, boolean nodeExists): process nodes if the given node or subnode exist/not exist in the repository. +When “nodeExists” is set to true then filter will return true if the given node path found in the repository, otherwise false. When “nodeExists” is set to false then filter will return true if the given node path not found in the repository, otherwise false. Example filterByNode: ```java aecu.contentUpgradeBuilder() .forChildResourcesOf("/content/we-retail/ca/en") - .filterByNode("jcr:content/meta") + .filterByNode("jcr:content/meta",true) .doSetProperty("name", "value") .run() ``` -Example filterByNodeNotExist: -```java -aecu.contentUpgradeBuilder() - .forChildResourcesOf("/content/we-retail/ca/en") - .filterByNodeNotExist("climbing-on-island--greece/jcr:content") - .printPath() - .run() -``` + #### Combine Multiple Filters You can combine filters with AND and OR to build more complex filters. 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 8da09a8a..a579e277 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 @@ -94,8 +94,7 @@ public interface ContentUpgrade { ContentUpgrade filterByProperty(String name, Object value); /** - * Filters by a single property using a regular expression for the value. This is intended for - * single value properties. + * Filters by a single property using a regular expression for the value. This is intended for single value properties. * * @param name property name * @param regex regular expression to match value @@ -104,8 +103,8 @@ public interface ContentUpgrade { ContentUpgrade filterByPropertyRegex(String name, String regex); /** - * Filters by checking if any property matches the given regular expression for the value. This - * is intended for single value properties. + * Filters by checking if any property matches the given regular expression for the value. This is intended for single value + * properties. * * @param regex regular expression to match value * @return upgrade object @@ -138,20 +137,13 @@ public interface ContentUpgrade { ContentUpgrade filterByNodeName(String nodeName); /** - * Filters by node exist. - * - * @param path node path - * @return upgrade object - */ - ContentUpgrade filterByNode(String path); - - /** - * Filters by node not exist. + * Filters by node/subNode (not) exists. * - * @param path node path + * @param path absolute or relative resource path + * @param nodeExists node exists option * @return upgrade object */ - ContentUpgrade filterByNodeNotExist(String path); + ContentUpgrade filterByNode(String path, boolean nodeExists); /** * Filters by node name using regular expression. @@ -187,8 +179,7 @@ public interface ContentUpgrade { ContentUpgrade doSetProperty(String name, Object value); /** - * Joins a property value into a single value. Uses "," to join multiple values. Deletes - * properties with empty array values. + * Joins a property value into a single value. Uses "," to join multiple values. Deletes properties with empty array values. * * @param name property name * @return upgrade object @@ -280,8 +271,7 @@ public interface ContentUpgrade { ContentUpgrade doReplaceValuesOfMultiValueProperty(String name, String[] oldValues, String[] newValues); /** - * Replaces a substring in all properties of the matching resource. Only applies to String - * properties. + * Replaces a substring in all properties of the matching resource. Only applies to String properties. * * @param oldValue old value * @param newValue new value @@ -290,8 +280,7 @@ public interface ContentUpgrade { ContentUpgrade doReplaceValueInAllProperties(String oldValue, String newValue); /** - * Replaces a substring in specific properties of the matching resource. Only applies to String - * properties. + * Replaces a substring in specific properties of the matching resource. Only applies to String properties. * * @param oldValue old value * @param newValue new value @@ -301,8 +290,8 @@ public interface ContentUpgrade { ContentUpgrade doReplaceValueInProperties(String oldValue, String newValue, String[] propertyNames); /** - * Replaces a substring in all properties of the matching resource using a regular expression. - * Only applies to String properties. + * Replaces a substring in all properties of the matching resource using a regular expression. Only applies to String + * properties. * * @param searchRegex regex to match old value * @param replacement new value, may contain matcher groups (e.g. $1) @@ -311,8 +300,8 @@ public interface ContentUpgrade { ContentUpgrade doReplaceValueInAllPropertiesRegex(String searchRegex, String replacement); /** - * Replaces a substring in specific properties of the matching resource using a regular - * expression. Only applies to String properties. + * Replaces a substring in specific properties of the matching resource using a regular expression. Only applies to String + * properties. * * @param searchRegex regex to match old value * @param replacement new value, may contain matcher groups (e.g. $1) @@ -349,8 +338,7 @@ public interface ContentUpgrade { * Copies a resource to a relative path. * * @param relativePath path - * @param newName name for the new resource. If not provided the name of the source - * resource will be used. + * @param newName name for the new resource. If not provided the name of the source resource will be used. * @return upgrade object */ ContentUpgrade doCopyResourceToRelativePath(String relativePath, String newName); @@ -364,19 +352,16 @@ public interface ContentUpgrade { ContentUpgrade doMoveResourceToRelativePath(String relativePath); /** - * Moves a resource if its path matches the pattern to the path obtained by applying the - * replacement expression + * Moves a resource if its path matches the pattern to the path obtained by applying the replacement expression * * @param matchPattern regular expression for matching the resource path - * @param targetPathExpr expression to calculate the target path, can contain matched group - * references $1, $2, ... + * @param targetPathExpr expression to calculate the target path, can contain matched group references $1, $2, ... * @return upgrade object */ ContentUpgrade doMoveResourceToPathRegex(String matchPattern, String targetPathExpr); /** - * Deletes the child resources if supplied. If no children are specified it deletes the resource - * itself. + * Deletes the child resources if supplied. If no children are specified it deletes the resource itself. * * @return upgrade object */ @@ -474,8 +459,7 @@ public interface ContentUpgrade { ContentUpgrade doDeactivateContainingPage(); /** - * Deletes the page where the resource is located. This will not work if called multiple times - * for the same page. + * Deletes the page where the resource is located. This will not work if called multiple times for the same page. * * @return upgrade object */ @@ -490,8 +474,7 @@ public interface ContentUpgrade { ContentUpgrade doAddTagsToContainingPage(String... tags); /** - * Sets tags for the containing page of the matching resource. All existing tags are - * overwritten. + * Sets tags for the containing page of the matching resource. All existing tags are overwritten. * * @param tags tag IDs or paths * @return upgrade object diff --git a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNode.java b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNode.java index 4fff5d63..d5fbde1c 100644 --- a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNode.java +++ b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 - 2019 Valtech GmbH + * Copyright 2018 - 2021 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, @@ -33,34 +33,37 @@ public class FilterByNode implements FilterBy { private String path; + private boolean nodeExists; /** * Constructor * - * @param path node path + * @param path absolute or relative resource path + * @param nodeExists node exists option */ - public FilterByNode(@Nonnull String path) { + public FilterByNode(@Nonnull String path, boolean nodeExists) { this.path = path; + this.nodeExists = nodeExists; } @Override public boolean filter(@Nonnull Resource resource, StringBuilder output) { - if(StringUtils.isBlank(path)) + if (StringUtils.isBlank(path)) { return true; + } - if(isAbsolutePath(path)) { - return (null != resource.getResourceResolver().getResource(path)); + if (isAbsolutePath(path)) { + return (nodeExists && null != resource.getResourceResolver().getResource(path)) || (!nodeExists && null == resource.getResourceResolver().getResource(path)); } else { - return (null != resource.getChild(path)); + return (nodeExists && null != resource.getChild(path)) || (!nodeExists && null == resource.getChild(path)); } } /** * checks whether given path is absolute or not. * - * @param path jcr path - * @return true if the given path is the absolute path. Otherwise - * false. + * @param path jcr path + * @return true if the given path is the absolute path. Otherwise false. */ private boolean isAbsolutePath(String path) { return path.startsWith("/"); diff --git a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNodeNotExist.java b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNodeNotExist.java deleted file mode 100644 index 43ea87cd..00000000 --- a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNodeNotExist.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2018 - 2019 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 org.apache.commons.lang3.StringUtils; -import org.apache.sling.api.resource.Resource; - -import javax.annotation.Nonnull; - - -/** - * Filters resources by node. Only resources that do not exist in the repository are accepted. - * - * @author Vugar Aghayev - */ -public class FilterByNodeNotExist implements FilterBy { - - private String path; - - /** - * Constructor - * - * @param path node path - */ - public FilterByNodeNotExist(@Nonnull String path) { - this.path = path; - } - - @Override - public boolean filter(@Nonnull Resource resource, StringBuilder output) { - if(StringUtils.isBlank(path)) - return true; - if(isAbsolutePath(path)) { - return (null == resource.getResourceResolver().getResource(path)); - } else { - return (null == resource.getChild(path)); - } - } - - /** - * checks whether given path is absolute or not. - * - * @param path jcr path - * @return true if the given path is the absolute path. Otherwise - * false. - */ - private boolean isAbsolutePath(String path) { - return path.startsWith("/"); - } -} diff --git a/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeNotExistTest.java b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeNotExistTest.java deleted file mode 100644 index 55fbbf02..00000000 --- a/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeNotExistTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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 de.valtech.aecu.api.groovy.console.bindings.filters.FilterByNodeNotExist; -import org.apache.sling.api.resource.Resource; -import org.apache.sling.api.resource.ResourceResolver; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.when; - -/** - * @author Vugar Aghayev - */ -@RunWith(MockitoJUnitRunner.class) -public class FilterByNodeNotExistTest { - - @Mock - private ResourceResolver resolver; - - @Mock - private Resource resource; - - @Mock - private Resource relativePathResource; - - @Mock - private Resource absolutePathResource; - - @Before - public void setup() { - when(resource.getResourceResolver()).thenReturn(resolver); - when(resource.getChild("climbing-on-kalymnos-island--greece/jcr:content")).thenReturn(relativePathResource); - } - - @Test - public void test_whenNodeNotFound_returnTrue() { - - assertTrue(new FilterByNodeNotExist("/content/we-retail/ca/climbing-on-kalymnos-island--greece/jcr:content").filter(resource, new StringBuilder())); - - assertTrue(new FilterByNodeNotExist("climbing-on-island--greece/jcr:content").filter(resource, new StringBuilder())); - } - - @Test - public void test_whenSubNodeFound_returnFalse() { - - assertFalse(new FilterByNodeNotExist("climbing-on-kalymnos-island--greece/jcr:content").filter(resource, new StringBuilder())); - - } - - @Test - public void test_whenAbsolutePathNodeFound_returnFalse() { - when(resource.getResourceResolver().getResource("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content")).thenReturn(absolutePathResource); - - assertFalse(new FilterByNodeNotExist("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content").filter(resource, new StringBuilder())); - - } - @Test - public void test_whenNodePathIsEmpty_returnTrue() { - - assertTrue(new FilterByNodeNotExist("").filter(resource, new StringBuilder())); - - assertTrue(new FilterByNodeNotExist(" ").filter(resource, new StringBuilder())); - - } - - @Test - public void test_whenNodePathIsNull_returnTrue() { - - assertTrue(new FilterByNodeNotExist(null).filter(resource, new StringBuilder())); - - } -} diff --git a/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeTest.java b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeTest.java index 417b463f..3b0e2851 100644 --- a/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeTest.java +++ b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 Valtech GmbH + * Copyright 2021 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, @@ -20,6 +20,7 @@ package de.valtech.aecu.core.groovy.console.bindings.filters; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByNode; + import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; import org.junit.Before; @@ -57,40 +58,80 @@ public void setup() { } @Test - public void test_whenNodeNotFound_returnFalse() { + public void filterNodeExists_whenNodeNotFound_returnFalse() { - assertFalse(new FilterByNode("/content/we-retail/ca/climbing-on-kalymnos-island--greece/jcr:content").filter(resource, new StringBuilder())); + assertFalse(new FilterByNode("/content/we-retail/ca/climbing-on-kalymnos-island--greece/jcr:content", true).filter(resource, new StringBuilder())); - assertFalse(new FilterByNode("climbing-on-island--greece/jcr:content").filter(resource, new StringBuilder())); + assertFalse(new FilterByNode("climbing-on-island--greece/jcr:content", true).filter(resource, new StringBuilder())); } @Test - public void test_whenSubNodeFound_returnTrue() { + public void filterNodeExists_whenSubNodeFound_returnTrue() { - assertTrue(new FilterByNode("climbing-on-kalymnos-island--greece/jcr:content").filter(resource, new StringBuilder())); + assertTrue(new FilterByNode("climbing-on-kalymnos-island--greece/jcr:content", true).filter(resource, new StringBuilder())); } @Test - public void test_whenAbsolutePathNodeFound_returnTrue() { + public void filterNodeExists_whenAbsolutePathNodeFound_returnTrue() { when(resource.getResourceResolver().getResource("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content")).thenReturn(absolutePathResource); - assertTrue(new FilterByNode("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content").filter(resource, new StringBuilder())); + assertTrue(new FilterByNode("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content", true).filter(resource, new StringBuilder())); + + } + + @Test + public void filterNodeExists_whenNodePathIsEmpty_returnTrue() { + + assertTrue(new FilterByNode("", true).filter(resource, new StringBuilder())); + + assertTrue(new FilterByNode(" ", true).filter(resource, new StringBuilder())); } + + @Test + public void filterNodeExists_whenNodePathIsNull_returnTrue() { + + assertTrue(new FilterByNode(null, true).filter(resource, new StringBuilder())); + + } + + @Test + public void filterNodeNotExist_whenNodeNotFound_returnTrue() { + + assertTrue(new FilterByNode("/content/we-retail/ca/climbing-on-kalymnos-island--greece/jcr:content", false).filter(resource, new StringBuilder())); + + assertTrue(new FilterByNode("climbing-on-island--greece/jcr:content", false).filter(resource, new StringBuilder())); + } + + @Test + public void filterNodeNotExist_whenSubNodeFound_returnFalse() { + + assertFalse(new FilterByNode("climbing-on-kalymnos-island--greece/jcr:content", false).filter(resource, new StringBuilder())); + + } + + @Test + public void filterNodeNotExist_whenAbsolutePathNodeFound_returnFalse() { + when(resource.getResourceResolver().getResource("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content")).thenReturn(absolutePathResource); + + assertFalse(new FilterByNode("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content", false).filter(resource, new StringBuilder())); + + } + @Test - public void test_whenNodePathIsEmpty_returnTrue() { + public void filterNodeNotExist_whenNodePathIsEmpty_returnTrue() { - assertTrue(new FilterByNode("").filter(resource, new StringBuilder())); + assertTrue(new FilterByNode("", false).filter(resource, new StringBuilder())); - assertTrue(new FilterByNode(" ").filter(resource, new StringBuilder())); + assertTrue(new FilterByNode(" ", false).filter(resource, new StringBuilder())); } @Test - public void test_whenNodePathIsNull_returnTrue() { + public void filterNodeNotExist_whenNodePathIsNull_returnTrue() { - assertTrue(new FilterByNode(null).filter(resource, new StringBuilder())); + assertTrue(new FilterByNode(null, false).filter(resource, new StringBuilder())); } } 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 f0a72f5b..2096b731 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 @@ -45,7 +45,6 @@ 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.FilterByNode; -import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByNodeNotExist; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByNodeNameRegex; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByPathRegex; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByProperties; @@ -191,14 +190,8 @@ public ContentUpgrade filterByNodeName(@Nonnull String nodeName) { } @Override - public ContentUpgrade filterByNode(@Nonnull String path) { - addFilter(new FilterByNode(path)); - return this; - } - - @Override - public ContentUpgrade filterByNodeNotExist(@Nonnull String path) { - addFilter(new FilterByNodeNotExist(path)); + public ContentUpgrade filterByNode(@Nonnull String path, boolean nodeExists) { + addFilter(new FilterByNode(path, nodeExists)); return this; } @@ -275,14 +268,14 @@ public ContentUpgrade doRenameProperty(@Nonnull String oldName, @Nonnull String @Override public ContentUpgrade doCopyPropertyToRelativePath(@Nonnull String name, String newName, - @Nonnull String relativeResourcePath) { + @Nonnull String relativeResourcePath) { actions.add(new CopyPropertyToRelativePath(name, newName, context.getResolver(), relativeResourcePath)); return this; } @Override public ContentUpgrade doMovePropertyToRelativePath(@Nonnull String name, String newName, - @Nonnull String relativeResourcePath) { + @Nonnull String relativeResourcePath) { actions.add(new MovePropertyToRelativePath(name, newName, context.getResolver(), relativeResourcePath)); return this; } @@ -301,7 +294,7 @@ public ContentUpgrade doRemoveValuesOfMultiValueProperty(@Nonnull String name, @ @Override public ContentUpgrade doReplaceValuesOfMultiValueProperty(@Nonnull String name, @Nonnull String[] oldValues, - @Nonnull String[] newValues) { + @Nonnull String[] newValues) { actions.add(new ReplaceMultiValues(name, oldValues, newValues)); return this; } From 2f927ee1ed180f9f70b66b59229d3ecb7700cb55 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 24 Feb 2021 14:24:39 +0100 Subject: [PATCH 19/29] #145 small refactorings --- Readme.md | 12 ++-- .../console/bindings/ContentUpgrade.java | 57 ++++++++++++------- ...ByNode.java => FilterByNodeExistence.java} | 13 +++-- ...st.java => FilterByNodeExistenceTest.java} | 57 ++++++++++++------- .../bindings/impl/ContentUpgradeImpl.java | 18 ++++-- 5 files changed, 99 insertions(+), 58 deletions(-) rename api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/{FilterByNode.java => FilterByNodeExistence.java} (86%) rename api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/{FilterByNodeTest.java => FilterByNodeExistenceTest.java} (54%) diff --git a/Readme.md b/Readme.md index 5f9d6800..33684be1 100644 --- a/Readme.md +++ b/Readme.md @@ -323,18 +323,18 @@ aecu.contentUpgradeBuilder() .run() ``` -#### Filter by Node +#### Filter by Node Existence -Filters resources by absolute or relative node path. +Filters resources by the (non-)existence of relative or absolute node path. -* filterByNode(String path, boolean nodeExists): process nodes if the given node or subnode exist/not exist in the repository. -When “nodeExists” is set to true then filter will return true if the given node path found in the repository, otherwise false. When “nodeExists” is set to false then filter will return true if the given node path not found in the repository, otherwise false. +* filterByNodeExists(String path): process if the given subnode or absolute node exists +* filterByNodeNotExists(String path): process if the given subnode or absolute node does not exist -Example filterByNode: ```java aecu.contentUpgradeBuilder() .forChildResourcesOf("/content/we-retail/ca/en") - .filterByNode("jcr:content/meta",true) + .filterByNodeExists("jcr:content/meta") + .filterByNodeNotExists("jcr:content/meta") .doSetProperty("name", "value") .run() ``` 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 a579e277..f58daa0a 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 @@ -94,7 +94,8 @@ public interface ContentUpgrade { ContentUpgrade filterByProperty(String name, Object value); /** - * Filters by a single property using a regular expression for the value. This is intended for single value properties. + * Filters by a single property using a regular expression for the value. This is intended for + * single value properties. * * @param name property name * @param regex regular expression to match value @@ -103,8 +104,8 @@ public interface ContentUpgrade { ContentUpgrade filterByPropertyRegex(String name, String regex); /** - * Filters by checking if any property matches the given regular expression for the value. This is intended for single value - * properties. + * Filters by checking if any property matches the given regular expression for the value. This + * is intended for single value properties. * * @param regex regular expression to match value * @return upgrade object @@ -137,13 +138,20 @@ public interface ContentUpgrade { ContentUpgrade filterByNodeName(String nodeName); /** - * Filters by node/subNode (not) exists. + * Filters by node/subNode exists. + * + * @param path absolute or relative resource path + * @return upgrade object + */ + ContentUpgrade filterByNodeExists(String path); + + /** + * Filters by node/subNode not exists. * - * @param path absolute or relative resource path - * @param nodeExists node exists option + * @param path absolute or relative resource path * @return upgrade object */ - ContentUpgrade filterByNode(String path, boolean nodeExists); + ContentUpgrade filterByNodeNotExists(String path); /** * Filters by node name using regular expression. @@ -179,7 +187,8 @@ public interface ContentUpgrade { ContentUpgrade doSetProperty(String name, Object value); /** - * Joins a property value into a single value. Uses "," to join multiple values. Deletes properties with empty array values. + * Joins a property value into a single value. Uses "," to join multiple values. Deletes + * properties with empty array values. * * @param name property name * @return upgrade object @@ -271,7 +280,8 @@ public interface ContentUpgrade { ContentUpgrade doReplaceValuesOfMultiValueProperty(String name, String[] oldValues, String[] newValues); /** - * Replaces a substring in all properties of the matching resource. Only applies to String properties. + * Replaces a substring in all properties of the matching resource. Only applies to String + * properties. * * @param oldValue old value * @param newValue new value @@ -280,7 +290,8 @@ public interface ContentUpgrade { ContentUpgrade doReplaceValueInAllProperties(String oldValue, String newValue); /** - * Replaces a substring in specific properties of the matching resource. Only applies to String properties. + * Replaces a substring in specific properties of the matching resource. Only applies to String + * properties. * * @param oldValue old value * @param newValue new value @@ -290,8 +301,8 @@ public interface ContentUpgrade { ContentUpgrade doReplaceValueInProperties(String oldValue, String newValue, String[] propertyNames); /** - * Replaces a substring in all properties of the matching resource using a regular expression. Only applies to String - * properties. + * Replaces a substring in all properties of the matching resource using a regular expression. + * Only applies to String properties. * * @param searchRegex regex to match old value * @param replacement new value, may contain matcher groups (e.g. $1) @@ -300,8 +311,8 @@ public interface ContentUpgrade { ContentUpgrade doReplaceValueInAllPropertiesRegex(String searchRegex, String replacement); /** - * Replaces a substring in specific properties of the matching resource using a regular expression. Only applies to String - * properties. + * Replaces a substring in specific properties of the matching resource using a regular + * expression. Only applies to String properties. * * @param searchRegex regex to match old value * @param replacement new value, may contain matcher groups (e.g. $1) @@ -338,7 +349,8 @@ public interface ContentUpgrade { * Copies a resource to a relative path. * * @param relativePath path - * @param newName name for the new resource. If not provided the name of the source resource will be used. + * @param newName name for the new resource. If not provided the name of the source + * resource will be used. * @return upgrade object */ ContentUpgrade doCopyResourceToRelativePath(String relativePath, String newName); @@ -352,16 +364,19 @@ public interface ContentUpgrade { ContentUpgrade doMoveResourceToRelativePath(String relativePath); /** - * Moves a resource if its path matches the pattern to the path obtained by applying the replacement expression + * Moves a resource if its path matches the pattern to the path obtained by applying the + * replacement expression * * @param matchPattern regular expression for matching the resource path - * @param targetPathExpr expression to calculate the target path, can contain matched group references $1, $2, ... + * @param targetPathExpr expression to calculate the target path, can contain matched group + * references $1, $2, ... * @return upgrade object */ ContentUpgrade doMoveResourceToPathRegex(String matchPattern, String targetPathExpr); /** - * Deletes the child resources if supplied. If no children are specified it deletes the resource itself. + * Deletes the child resources if supplied. If no children are specified it deletes the resource + * itself. * * @return upgrade object */ @@ -459,7 +474,8 @@ public interface ContentUpgrade { ContentUpgrade doDeactivateContainingPage(); /** - * Deletes the page where the resource is located. This will not work if called multiple times for the same page. + * Deletes the page where the resource is located. This will not work if called multiple times + * for the same page. * * @return upgrade object */ @@ -474,7 +490,8 @@ public interface ContentUpgrade { ContentUpgrade doAddTagsToContainingPage(String... tags); /** - * Sets tags for the containing page of the matching resource. All existing tags are overwritten. + * Sets tags for the containing page of the matching resource. All existing tags are + * overwritten. * * @param tags tag IDs or paths * @return upgrade object diff --git a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNode.java b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNodeExistence.java similarity index 86% rename from api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNode.java rename to api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNodeExistence.java index d5fbde1c..4c1e7dc8 100644 --- a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNode.java +++ b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByNodeExistence.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 - 2021 Valtech GmbH + * Copyright 2021 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, @@ -26,11 +26,12 @@ /** - * Filters resources by absolute or relative node path. Only resources that exist in the repository are accepted. + * Filters resources by absolute or relative node path. Only resources that (not) exist in the + * repository are accepted. * * @author Vugar Aghayev */ -public class FilterByNode implements FilterBy { +public class FilterByNodeExistence implements FilterBy { private String path; private boolean nodeExists; @@ -41,7 +42,7 @@ public class FilterByNode implements FilterBy { * @param path absolute or relative resource path * @param nodeExists node exists option */ - public FilterByNode(@Nonnull String path, boolean nodeExists) { + public FilterByNodeExistence(@Nonnull String path, boolean nodeExists) { this.path = path; this.nodeExists = nodeExists; } @@ -53,7 +54,8 @@ public boolean filter(@Nonnull Resource resource, StringBuilder output) { } if (isAbsolutePath(path)) { - return (nodeExists && null != resource.getResourceResolver().getResource(path)) || (!nodeExists && null == resource.getResourceResolver().getResource(path)); + return (nodeExists && null != resource.getResourceResolver().getResource(path)) + || (!nodeExists && null == resource.getResourceResolver().getResource(path)); } else { return (nodeExists && null != resource.getChild(path)) || (!nodeExists && null == resource.getChild(path)); } @@ -68,4 +70,5 @@ public boolean filter(@Nonnull Resource resource, StringBuilder output) { private boolean isAbsolutePath(String path) { return path.startsWith("/"); } + } diff --git a/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeTest.java b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeExistenceTest.java similarity index 54% rename from api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeTest.java rename to api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeExistenceTest.java index 3b0e2851..5f4d1b88 100644 --- a/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeTest.java +++ b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByNodeExistenceTest.java @@ -19,7 +19,9 @@ package de.valtech.aecu.core.groovy.console.bindings.filters; -import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByNode; +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.ResourceResolver; @@ -29,15 +31,13 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.when; +import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByNodeExistence; /** * @author Vugar Aghayev */ @RunWith(MockitoJUnitRunner.class) -public class FilterByNodeTest { +public class FilterByNodeExistenceTest { @Mock private ResourceResolver resolver; @@ -60,78 +60,93 @@ public void setup() { @Test public void filterNodeExists_whenNodeNotFound_returnFalse() { - assertFalse(new FilterByNode("/content/we-retail/ca/climbing-on-kalymnos-island--greece/jcr:content", true).filter(resource, new StringBuilder())); + assertFalse(new FilterByNodeExistence("/content/we-retail/ca/climbing-on-kalymnos-island--greece/jcr:content", true) + .filter(resource, new StringBuilder())); - assertFalse(new FilterByNode("climbing-on-island--greece/jcr:content", true).filter(resource, new StringBuilder())); + assertFalse( + new FilterByNodeExistence("climbing-on-island--greece/jcr:content", true).filter(resource, new StringBuilder())); } @Test public void filterNodeExists_whenSubNodeFound_returnTrue() { - assertTrue(new FilterByNode("climbing-on-kalymnos-island--greece/jcr:content", true).filter(resource, new StringBuilder())); + assertTrue(new FilterByNodeExistence("climbing-on-kalymnos-island--greece/jcr:content", true).filter(resource, + new StringBuilder())); } @Test public void filterNodeExists_whenAbsolutePathNodeFound_returnTrue() { - when(resource.getResourceResolver().getResource("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content")).thenReturn(absolutePathResource); + when(resource.getResourceResolver() + .getResource("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content")) + .thenReturn(absolutePathResource); - assertTrue(new FilterByNode("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content", true).filter(resource, new StringBuilder())); + assertTrue( + new FilterByNodeExistence("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content", + true).filter(resource, new StringBuilder())); } @Test public void filterNodeExists_whenNodePathIsEmpty_returnTrue() { - assertTrue(new FilterByNode("", true).filter(resource, new StringBuilder())); + assertTrue(new FilterByNodeExistence("", true).filter(resource, new StringBuilder())); - assertTrue(new FilterByNode(" ", true).filter(resource, new StringBuilder())); + assertTrue(new FilterByNodeExistence(" ", true).filter(resource, new StringBuilder())); } @Test public void filterNodeExists_whenNodePathIsNull_returnTrue() { - assertTrue(new FilterByNode(null, true).filter(resource, new StringBuilder())); + assertTrue(new FilterByNodeExistence(null, true).filter(resource, new StringBuilder())); } @Test public void filterNodeNotExist_whenNodeNotFound_returnTrue() { - assertTrue(new FilterByNode("/content/we-retail/ca/climbing-on-kalymnos-island--greece/jcr:content", false).filter(resource, new StringBuilder())); + assertTrue(new FilterByNodeExistence("/content/we-retail/ca/climbing-on-kalymnos-island--greece/jcr:content", false) + .filter(resource, new StringBuilder())); - assertTrue(new FilterByNode("climbing-on-island--greece/jcr:content", false).filter(resource, new StringBuilder())); + assertTrue( + new FilterByNodeExistence("climbing-on-island--greece/jcr:content", false).filter(resource, new StringBuilder())); } @Test public void filterNodeNotExist_whenSubNodeFound_returnFalse() { - assertFalse(new FilterByNode("climbing-on-kalymnos-island--greece/jcr:content", false).filter(resource, new StringBuilder())); + assertFalse(new FilterByNodeExistence("climbing-on-kalymnos-island--greece/jcr:content", false).filter(resource, + new StringBuilder())); } @Test public void filterNodeNotExist_whenAbsolutePathNodeFound_returnFalse() { - when(resource.getResourceResolver().getResource("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content")).thenReturn(absolutePathResource); + when(resource.getResourceResolver() + .getResource("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content")) + .thenReturn(absolutePathResource); - assertFalse(new FilterByNode("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content", false).filter(resource, new StringBuilder())); + assertFalse( + new FilterByNodeExistence("/content/we-retail/ca/en/experience/climbing-on-kalymnos-island--greece/jcr:content", + false).filter(resource, new StringBuilder())); } @Test public void filterNodeNotExist_whenNodePathIsEmpty_returnTrue() { - assertTrue(new FilterByNode("", false).filter(resource, new StringBuilder())); + assertTrue(new FilterByNodeExistence("", false).filter(resource, new StringBuilder())); - assertTrue(new FilterByNode(" ", false).filter(resource, new StringBuilder())); + assertTrue(new FilterByNodeExistence(" ", false).filter(resource, new StringBuilder())); } @Test public void filterNodeNotExist_whenNodePathIsNull_returnTrue() { - assertTrue(new FilterByNode(null, false).filter(resource, new StringBuilder())); + assertTrue(new FilterByNodeExistence(null, false).filter(resource, new StringBuilder())); } + } 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 2096b731..40b0d7f0 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 @@ -43,8 +43,8 @@ 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.FilterByNodeExistence; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByNodeName; -import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByNode; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByNodeNameRegex; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByPathRegex; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByProperties; @@ -190,8 +190,14 @@ public ContentUpgrade filterByNodeName(@Nonnull String nodeName) { } @Override - public ContentUpgrade filterByNode(@Nonnull String path, boolean nodeExists) { - addFilter(new FilterByNode(path, nodeExists)); + public ContentUpgrade filterByNodeExists(@Nonnull String path) { + addFilter(new FilterByNodeExistence(path, true)); + return this; + } + + @Override + public ContentUpgrade filterByNodeNotExists(@Nonnull String path) { + addFilter(new FilterByNodeExistence(path, false)); return this; } @@ -268,14 +274,14 @@ public ContentUpgrade doRenameProperty(@Nonnull String oldName, @Nonnull String @Override public ContentUpgrade doCopyPropertyToRelativePath(@Nonnull String name, String newName, - @Nonnull String relativeResourcePath) { + @Nonnull String relativeResourcePath) { actions.add(new CopyPropertyToRelativePath(name, newName, context.getResolver(), relativeResourcePath)); return this; } @Override public ContentUpgrade doMovePropertyToRelativePath(@Nonnull String name, String newName, - @Nonnull String relativeResourcePath) { + @Nonnull String relativeResourcePath) { actions.add(new MovePropertyToRelativePath(name, newName, context.getResolver(), relativeResourcePath)); return this; } @@ -294,7 +300,7 @@ public ContentUpgrade doRemoveValuesOfMultiValueProperty(@Nonnull String name, @ @Override public ContentUpgrade doReplaceValuesOfMultiValueProperty(@Nonnull String name, @Nonnull String[] oldValues, - @Nonnull String[] newValues) { + @Nonnull String[] newValues) { actions.add(new ReplaceMultiValues(name, oldValues, newValues)); return this; } From 645f07478fb2618bbb12824681382c1e0119fb18 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 24 Feb 2021 14:26:24 +0100 Subject: [PATCH 20/29] #145 docs --- Readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Readme.md b/Readme.md index 33684be1..dfad741b 100644 --- a/Readme.md +++ b/Readme.md @@ -334,7 +334,9 @@ Filters resources by the (non-)existence of relative or absolute node path. aecu.contentUpgradeBuilder() .forChildResourcesOf("/content/we-retail/ca/en") .filterByNodeExists("jcr:content/meta") + .filterByNodeExists("/content") .filterByNodeNotExists("jcr:content/meta") + .filterByNodeNotExists("/content") .doSetProperty("name", "value") .run() ``` From 6c76bd5066d7cdc10c08dab5556aa3501e52e09d Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 24 Feb 2021 15:23:09 +0100 Subject: [PATCH 21/29] docs --- HISTORY | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/HISTORY b/HISTORY index 8d8f55a8..48476959 100644 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,7 @@ +??? 5.0.0 + - New filter methods: filterByNodeExists() and filterByNodeNotExists() + + 2020-12-21 4.0.0 - Update to Groovy Console 16 and require AEM 6.5 (#135) - Fix for AEM Cloud in manual execution tool From 92e756a7d73dbfe35450bcad7be1b72c9c8fc3dc Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Fri, 7 May 2021 14:12:41 +0200 Subject: [PATCH 22/29] plugin update --- pom.xml | 7 +-- ui.apps.structure/.gitignore | 1 + ui.apps.structure/pom.xml | 49 +++++++++++++++++++ ui.apps/pom.xml | 17 +++++++ .../jcr_root/var/aecu/_oak_index/.content.xml | 1 + 5 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 ui.apps.structure/.gitignore create mode 100644 ui.apps.structure/pom.xml diff --git a/pom.xml b/pom.xml index 859156b6..23e67b28 100644 --- a/pom.xml +++ b/pom.xml @@ -12,6 +12,7 @@ api core + ui.apps.structure ui.apps bundle examples @@ -237,7 +238,7 @@ com.day.jcr.vault content-package-maven-plugin - 1.0.2 + 1.0.4 http://${aem.host}:${aem.port}/crx/packmgr/service.jsp true @@ -249,7 +250,7 @@ org.apache.jackrabbit filevault-package-maven-plugin - 1.0.4 + 1.1.6 true @@ -341,7 +342,7 @@ org.owasp dependency-check-maven - 5.2.4 + 6.1.6 0 true diff --git a/ui.apps.structure/.gitignore b/ui.apps.structure/.gitignore new file mode 100644 index 00000000..b83d2226 --- /dev/null +++ b/ui.apps.structure/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/ui.apps.structure/pom.xml b/ui.apps.structure/pom.xml new file mode 100644 index 00000000..992383cd --- /dev/null +++ b/ui.apps.structure/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + + + de.valtech.aecu + aecu + 4.1.0-SNAPSHOT + + + aecu.ui.apps.structure + content-package + AECU - Repository Structure Package + + Empty package that defines the structure of the Adobe Experience Manager repository the Code packages in this project deploy into. + Any roots in the Code packages of this project should have their parent enumerated in the Filters list below. + + + + + + org.apache.jackrabbit + filevault-package-maven-plugin + true + + + none + + + /apps + /apps/sling + /apps/cq + /apps/dam + /apps/wcm + /apps/msm + /apps/settings + /home/users + /home/users/system + /var/workflow/models + /var/workflow/models/dam + /conf + /conf/global + /conf/global/settings + + + + + + diff --git a/ui.apps/pom.xml b/ui.apps/pom.xml index fcdf4b15..44b8051c 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -77,6 +77,17 @@ true true Valtech + + + de.valtech.aecu + aecu.ui.apps.structure + + + + + true + + merge_preserve /apps/valtech/aecu/(config|install)/.* @@ -126,5 +137,11 @@ aecu.api ${project.version} + + de.valtech.aecu + aecu.ui.apps.structure + ${project.version} + zip + diff --git a/ui.apps/src/main/content/jcr_root/var/aecu/_oak_index/.content.xml b/ui.apps/src/main/content/jcr_root/var/aecu/_oak_index/.content.xml index 72cb10b7..d680f4b6 100644 --- a/ui.apps/src/main/content/jcr_root/var/aecu/_oak_index/.content.xml +++ b/ui.apps/src/main/content/jcr_root/var/aecu/_oak_index/.content.xml @@ -1,4 +1,5 @@ \ No newline at end of file From 0f7fbb1da085d5f5df4392b4fa96f8f0dc8c27f3 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Thu, 10 Jun 2021 07:52:15 +0200 Subject: [PATCH 23/29] hint for subpackages --- Readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Readme.md b/Readme.md index dfad741b..4435b115 100644 --- a/Readme.md +++ b/Readme.md @@ -122,6 +122,8 @@ All migration scripts need to be located in /var/groovyconsole/scripts/aecu. The an unlimited number of folders and files. E.g. organize your files by project or deployment. The content of the scripts is plain Groovy code that can be run via [Groovy Console](https://github.com/OlsonDigital/aem-groovy-console). +If your package containing the scripts is bundled in another package please make sure that this is done using "subPackages" in pom.xml. + There are just a few naming conventions: From 7224ee74e6deef7dcb0d0cb3d810614981bb1a70 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Thu, 10 Jun 2021 14:20:00 +0200 Subject: [PATCH 24/29] #156 removed old fake request and response classes --- HISTORY | 4 +- .../aecu/core/service/AecuScriptContext.java | 12 +- .../aecu/core/service/AecuServiceImpl.java | 9 +- .../core/service/GroovyConsoleRequest.java | 488 ------------------ .../core/service/GroovyConsoleResponse.java | 225 -------- .../service/GroovyConsoleRequestTest.java | 159 ------ .../service/GroovyConsoleResponseTest.java | 92 ---- 7 files changed, 9 insertions(+), 980 deletions(-) delete mode 100644 core/src/main/java/de/valtech/aecu/core/service/GroovyConsoleRequest.java delete mode 100644 core/src/main/java/de/valtech/aecu/core/service/GroovyConsoleResponse.java delete mode 100644 core/src/test/java/de/valtech/aecu/core/service/GroovyConsoleRequestTest.java delete mode 100644 core/src/test/java/de/valtech/aecu/core/service/GroovyConsoleResponseTest.java diff --git a/HISTORY b/HISTORY index 48476959..1322b6b5 100644 --- a/HISTORY +++ b/HISTORY @@ -1,6 +1,6 @@ -??? 5.0.0 +2021-06-11 4.1.0 - New filter methods: filterByNodeExists() and filterByNodeNotExists() - + - Fixed Sonar issues (#156) 2020-12-21 4.0.0 - Update to Groovy Console 16 and require AEM 6.5 (#135) diff --git a/core/src/main/java/de/valtech/aecu/core/service/AecuScriptContext.java b/core/src/main/java/de/valtech/aecu/core/service/AecuScriptContext.java index cb38f1fd..1af6a41d 100644 --- a/core/src/main/java/de/valtech/aecu/core/service/AecuScriptContext.java +++ b/core/src/main/java/de/valtech/aecu/core/service/AecuScriptContext.java @@ -4,14 +4,12 @@ import java.io.PrintStream; import java.io.UnsupportedEncodingException; -import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.resource.ResourceResolver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.base.Charsets; import com.icfolson.aem.groovy.console.api.context.ScriptContext; -import com.icfolson.aem.groovy.console.constants.GroovyConsoleConstants; /** * Script context to run Groovy Console scripts. @@ -26,24 +24,20 @@ public class AecuScriptContext implements ScriptContext { private ResourceResolver resolver; private ByteArrayOutputStream out = new ByteArrayOutputStream(); - private SlingHttpServletRequest request; - /** * Constructor * * @param script script content * @param resolver resolver - * @param request request */ - public AecuScriptContext(String script, ResourceResolver resolver, SlingHttpServletRequest request) { + public AecuScriptContext(String script, ResourceResolver resolver) { this.script = script; this.resolver = resolver; - this.request = request; } @Override public String getData() { - return request.getParameter(GroovyConsoleConstants.DATA); + return null; } @Override @@ -73,7 +67,7 @@ public String getScript() { @Override public String getUserId() { - return request.getResourceResolver().getUserID(); + return resolver.getUserID(); } } 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 3c922242..03ad06b3 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 @@ -29,7 +29,6 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.jackrabbit.JcrConstants; -import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.resource.LoginException; import org.apache.sling.api.resource.PersistenceException; import org.apache.sling.api.resource.Resource; @@ -188,9 +187,8 @@ public ExecutionResult execute(String path) throws AecuException { * @throws AecuException error running script */ private ExecutionResult executeScript(ResourceResolver resolver, String path) throws AecuException { - SlingHttpServletRequest slingRequest = new GroovyConsoleRequest(resolver); LOG.info("Executing script " + path); - ScriptContext scriptContext = new AecuScriptContext(loadScript(path, resolver), resolver, slingRequest); + ScriptContext scriptContext = new AecuScriptContext(loadScript(path, resolver), resolver); RunScriptResponse response = groovyConsoleService.runScript(scriptContext); boolean success = StringUtils.isBlank(response.getExceptionStackTrace()); if (success) { @@ -219,9 +217,10 @@ private ExecutionResult executeScript(ResourceResolver resolver, String path) th private String loadScript(String path, ResourceResolver resolver) throws AecuException { Resource resource = resolver.getResource(path + "/" + JcrConstants.JCR_CONTENT); // https://sling.apache.org/documentation/the-sling-engine/resources.html#binary-support - try (InputStream inputStream = resource.adaptTo(InputStream.class)){ + try (InputStream inputStream = resource.adaptTo(InputStream.class)) { if (inputStream == null) { - throw new IOException("Resource at '" + path +"' cannot be adapted to InputStream, it doesn't seem to contain binary data"); + throw new IOException( + "Resource at '" + path + "' cannot be adapted to InputStream, it doesn't seem to contain binary data"); } return IOUtils.toString(inputStream, StandardCharsets.UTF_8); } catch (IOException e) { diff --git a/core/src/main/java/de/valtech/aecu/core/service/GroovyConsoleRequest.java b/core/src/main/java/de/valtech/aecu/core/service/GroovyConsoleRequest.java deleted file mode 100644 index 64b6456d..00000000 --- a/core/src/main/java/de/valtech/aecu/core/service/GroovyConsoleRequest.java +++ /dev/null @@ -1,488 +0,0 @@ -/* - * Copyright 2018 - 2019 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.service; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.security.Principal; -import java.util.Collection; -import java.util.Collections; -import java.util.Enumeration; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.ResourceBundle; - -import javax.servlet.AsyncContext; -import javax.servlet.DispatcherType; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletInputStream; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import javax.servlet.http.Part; - -import org.apache.sling.api.SlingHttpServletRequest; -import org.apache.sling.api.request.RequestDispatcherOptions; -import org.apache.sling.api.request.RequestParameter; -import org.apache.sling.api.request.RequestParameterMap; -import org.apache.sling.api.request.RequestPathInfo; -import org.apache.sling.api.request.RequestProgressTracker; -import org.apache.sling.api.resource.Resource; -import org.apache.sling.api.resource.ResourceResolver; - -/** - * Dummy request that is used to execute the script. - * - * @author Roland Gruber - */ -public class GroovyConsoleRequest implements SlingHttpServletRequest { - - private ResourceResolver resolver; - - /** - * Constructor - * - * @param resolver resource resolver - */ - public GroovyConsoleRequest(ResourceResolver resolver) { - this.resolver = resolver; - } - - @Override - public String getAuthType() { - return null; - } - - @Override - public String getContextPath() { - return null; - } - - @Override - public Cookie[] getCookies() { - return new Cookie[0]; - } - - @Override - public long getDateHeader(String arg0) { - return 0; - } - - @Override - public String getHeader(String arg0) { - return null; - } - - @Override - public Enumeration getHeaderNames() { - return null; - } - - @Override - public Enumeration getHeaders(String arg0) { - return null; - } - - @Override - public int getIntHeader(String arg0) { - return 0; - } - - @Override - public String getMethod() { - return null; - } - - @Override - public String getPathInfo() { - return null; - } - - @Override - public String getPathTranslated() { - return null; - } - - @Override - public String getQueryString() { - return null; - } - - @Override - public String getRemoteUser() { - return null; - } - - @Override - public String getRequestURI() { - return null; - } - - @Override - public StringBuffer getRequestURL() { - return null; - } - - @Override - public String getRequestedSessionId() { - return null; - } - - @Override - public String getServletPath() { - return null; - } - - @Override - public HttpSession getSession() { - return null; - } - - @Override - public HttpSession getSession(boolean arg0) { - return null; - } - - @Override - public Principal getUserPrincipal() { - return null; - } - - @Override - public boolean isRequestedSessionIdFromCookie() { - return false; - } - - @Override - public boolean isRequestedSessionIdFromURL() { - return false; - } - - @Override - public boolean isRequestedSessionIdFromUrl() { - return false; - } - - @Override - public boolean isRequestedSessionIdValid() { - return false; - } - - @Override - public boolean isUserInRole(String arg0) { - return false; - } - - @Override - public Object getAttribute(String arg0) { - return null; - } - - @Override - public Enumeration getAttributeNames() { - return null; - } - - @Override - public String getCharacterEncoding() { - return null; - } - - @Override - public int getContentLength() { - return 0; - } - - @Override - public String getContentType() { - return null; - } - - @Override - public ServletInputStream getInputStream() throws IOException { - return null; - } - - @Override - public String getLocalAddr() { - return null; - } - - @Override - public String getLocalName() { - return null; - } - - @Override - public int getLocalPort() { - return 0; - } - - @Override - public Locale getLocale() { - return null; - } - - @Override - public Enumeration getLocales() { - return null; - } - - @Override - public String getParameter(String arg0) { - return null; - } - - @Override - public Map getParameterMap() { - return null; - } - - @Override - public Enumeration getParameterNames() { - return null; - } - - @Override - public String[] getParameterValues(String arg0) { - return new String[0]; - } - - @Override - public String getProtocol() { - return null; - } - - @Override - public BufferedReader getReader() throws IOException { - return null; - } - - @Override - public String getRealPath(String arg0) { - return null; - } - - @Override - public String getRemoteAddr() { - return null; - } - - @Override - public String getRemoteHost() { - return null; - } - - @Override - public int getRemotePort() { - return 0; - } - - @Override - public RequestDispatcher getRequestDispatcher(String arg0) { - return null; - } - - @Override - public String getScheme() { - return null; - } - - @Override - public String getServerName() { - return null; - } - - @Override - public int getServerPort() { - return 0; - } - - @Override - public boolean isSecure() { - return false; - } - - @Override - public void removeAttribute(String arg0) { - throw new UnsupportedOperationException("removeAttribute not implemented"); - } - - @Override - public void setAttribute(String arg0, Object arg1) { - throw new UnsupportedOperationException("setAttribute not implemented"); - } - - @Override - public void setCharacterEncoding(String arg0) throws UnsupportedEncodingException { - throw new UnsupportedOperationException("setCharacterEncoding not implemented"); - } - - @Override - public T adaptTo(Class arg0) { - return null; - } - - @Override - public Cookie getCookie(String arg0) { - return null; - } - - @Override - public RequestDispatcher getRequestDispatcher(Resource arg0) { - return null; - } - - @Override - public RequestDispatcher getRequestDispatcher(String arg0, RequestDispatcherOptions arg1) { - return null; - } - - @Override - public RequestDispatcher getRequestDispatcher(Resource arg0, RequestDispatcherOptions arg1) { - return null; - } - - @Override - public RequestParameter getRequestParameter(String arg0) { - return null; - } - - @Override - public List getRequestParameterList() { - return Collections.emptyList(); - } - - @Override - public RequestParameterMap getRequestParameterMap() { - return null; - } - - @Override - public RequestParameter[] getRequestParameters(String arg0) { - return new RequestParameter[0]; - } - - @Override - public RequestPathInfo getRequestPathInfo() { - return null; - } - - @Override - public RequestProgressTracker getRequestProgressTracker() { - return null; - } - - @Override - public Resource getResource() { - return null; - } - - @Override - public ResourceBundle getResourceBundle(Locale arg0) { - return null; - } - - @Override - public ResourceBundle getResourceBundle(String arg0, Locale arg1) { - return null; - } - - @Override - public ResourceResolver getResourceResolver() { - return resolver; - } - - @Override - public String getResponseContentType() { - return null; - } - - @Override - public Enumeration getResponseContentTypes() { - return null; - } - - @Override - public boolean authenticate(HttpServletResponse response) throws IOException, ServletException { - return false; - } - - @Override - public void login(String username, String password) throws ServletException { - // ignore - } - - @Override - public void logout() throws ServletException { - // ignore - } - - @Override - public Collection getParts() throws IOException, ServletException { - return Collections.emptyList(); - } - - @Override - public Part getPart(String name) throws IOException, ServletException { - return null; - } - - @Override - public ServletContext getServletContext() { - return null; - } - - @Override - public AsyncContext startAsync() { - return null; - } - - @Override - public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) { - return null; - } - - @Override - public boolean isAsyncStarted() { - return false; - } - - @Override - public boolean isAsyncSupported() { - return false; - } - - @Override - public AsyncContext getAsyncContext() { - return null; - } - - @Override - public DispatcherType getDispatcherType() { - return null; - } - -} diff --git a/core/src/main/java/de/valtech/aecu/core/service/GroovyConsoleResponse.java b/core/src/main/java/de/valtech/aecu/core/service/GroovyConsoleResponse.java deleted file mode 100644 index e0a0209c..00000000 --- a/core/src/main/java/de/valtech/aecu/core/service/GroovyConsoleResponse.java +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright 2019 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.service; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Collection; -import java.util.Collections; -import java.util.Locale; - -import javax.servlet.ServletOutputStream; -import javax.servlet.http.Cookie; - -import org.apache.sling.api.SlingHttpServletResponse; - -/** - * Dummy response to execute the scripts. - * - * @author Roland Gruber - * - */ -public class GroovyConsoleResponse implements SlingHttpServletResponse { - - @Override - public void addCookie(Cookie cookie) { - // not used - } - - @Override - public boolean containsHeader(String name) { - return false; - } - - @Override - public String encodeURL(String url) { - return url; - } - - @Override - public String encodeRedirectURL(String url) { - return url; - } - - @Override - public String encodeUrl(String url) { - return url; - } - - @Override - public String encodeRedirectUrl(String url) { - return url; - } - - @Override - public void sendError(int sc, String msg) throws IOException { - // not used - } - - @Override - public void sendError(int sc) throws IOException { - // not used - } - - @Override - public void sendRedirect(String location) throws IOException { - // not used - } - - @Override - public void setDateHeader(String name, long date) { - // not used - } - - @Override - public void addDateHeader(String name, long date) { - // not used - } - - @Override - public void setHeader(String name, String value) { - // not used - } - - @Override - public void addHeader(String name, String value) { - // not used - } - - @Override - public void setIntHeader(String name, int value) { - // not used - } - - @Override - public void addIntHeader(String name, int value) { - // not used - } - - @Override - public void setStatus(int sc) { - // not used - } - - @Override - public void setStatus(int sc, String sm) { - // not used - } - - @Override - public int getStatus() { - return 200; - } - - @Override - public String getHeader(String name) { - return null; - } - - @Override - public Collection getHeaders(String name) { - return Collections.emptyList(); - } - - @Override - public Collection getHeaderNames() { - return Collections.emptyList(); - } - - @Override - public String getCharacterEncoding() { - return "UTF-8"; - } - - @Override - public String getContentType() { - return null; - } - - @Override - public ServletOutputStream getOutputStream() throws IOException { - return null; - } - - @Override - public PrintWriter getWriter() throws IOException { - return null; - } - - @Override - public void setCharacterEncoding(String charset) { - // not used - } - - @Override - public void setContentLength(int len) { - // not used - } - - @Override - public void setContentType(String type) { - // not used - } - - @Override - public void setBufferSize(int size) { - // not used - } - - @Override - public int getBufferSize() { - return 0; - } - - @Override - public void flushBuffer() throws IOException { - // not used - } - - @Override - public void resetBuffer() { - // not used - } - - @Override - public boolean isCommitted() { - return false; - } - - @Override - public void reset() { - // not used - } - - @Override - public void setLocale(Locale loc) { - // not used - } - - @Override - public Locale getLocale() { - return null; - } - - @Override - public T adaptTo(Class arg0) { - return null; - } - -} diff --git a/core/src/test/java/de/valtech/aecu/core/service/GroovyConsoleRequestTest.java b/core/src/test/java/de/valtech/aecu/core/service/GroovyConsoleRequestTest.java deleted file mode 100644 index 60169fe5..00000000 --- a/core/src/test/java/de/valtech/aecu/core/service/GroovyConsoleRequestTest.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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.service; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; - -import javax.servlet.ServletException; - -import org.apache.sling.api.resource.Resource; -import org.apache.sling.api.resource.ResourceResolver; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -/** - * Tests GroovyConsoleRequest - * - * @author Roland Gruber - * - */ -@RunWith(MockitoJUnitRunner.class) -public class GroovyConsoleRequestTest { - - @Mock - private ResourceResolver resolver; - - private GroovyConsoleRequest request; - - @Before - public void setup() { - request = new GroovyConsoleRequest(resolver); - } - - @Test - public void getResourceResolver() { - assertEquals(resolver, request.getResourceResolver()); - } - - @Test(expected = UnsupportedOperationException.class) - public void removeAttribute() { - request.removeAttribute(""); - } - - @Test(expected = UnsupportedOperationException.class) - public void setAttribute() { - request.setAttribute(null, ""); - } - - @Test(expected = UnsupportedOperationException.class) - public void setCharacterEncoding() throws UnsupportedEncodingException { - request.setCharacterEncoding(""); - } - - @Test - public void emptyMethods() throws IOException, ServletException { - assertNull(request.getAuthType()); - assertNull(request.getContextPath()); - assertEquals(0, request.getCookies().length); - assertEquals(0, request.getDateHeader("")); - assertNull(request.getHeader("")); - assertNull(request.getHeaderNames()); - assertNull(request.getHeaders("")); - assertEquals(0, request.getIntHeader("")); - assertNull(request.getMethod()); - assertNull(request.getPathInfo()); - assertNull(request.getPathTranslated()); - assertNull(request.getQueryString()); - assertNull(request.getRemoteUser()); - assertNull(request.getRequestURI()); - assertNull(request.getRequestURL()); - assertNull(request.getRequestedSessionId()); - assertNull(request.getServletPath()); - assertNull(request.getSession()); - assertNull(request.getSession(true)); - assertFalse(request.isRequestedSessionIdFromCookie()); - assertFalse(request.isRequestedSessionIdFromURL()); - assertFalse(request.isRequestedSessionIdFromUrl()); - assertFalse(request.isRequestedSessionIdValid()); - assertFalse(request.isUserInRole("")); - assertNull(request.getAttribute("")); - assertNull(request.getAttributeNames()); - assertNull(request.getCharacterEncoding()); - assertEquals(0, request.getContentLength()); - assertNull(request.getContentType()); - assertNull(request.getInputStream()); - assertNull(request.getLocalAddr()); - assertNull(request.getLocalName()); - assertEquals(0, request.getLocalPort()); - assertNull(request.getLocale()); - assertNull(request.getLocales()); - assertNull(request.getParameter("")); - assertNull(request.getParameterMap()); - assertNull(request.getParameterNames()); - assertEquals(0, request.getParameterValues("").length); - assertNull(request.getProtocol()); - assertNull(request.getReader()); - assertNull(request.getRealPath("")); - assertNull(request.getRemoteAddr()); - assertNull(request.getRemoteHost()); - assertEquals(0, request.getRemotePort()); - assertNull(request.getRequestDispatcher("")); - assertNull(request.getScheme()); - assertNull(request.getServerName()); - assertEquals(0, request.getServerPort()); - assertFalse(request.isSecure()); - assertNull(request.adaptTo(null)); - assertNull(request.getCookie("")); - assertNull(request.getRequestDispatcher((Resource) null)); - assertNull(request.getRequestDispatcher("", null)); - assertNull(request.getRequestDispatcher((Resource) null, null)); - assertNull(request.getRequestParameter("")); - assertEquals(0, request.getRequestParameterList().size()); - assertNull(request.getRequestParameterMap()); - assertEquals(0, request.getRequestParameters("").length); - assertNull(request.getRequestPathInfo()); - assertNull(request.getRequestProgressTracker()); - assertNull(request.getResource()); - assertNull(request.getResourceBundle(null)); - assertNull(request.getResourceBundle("", null)); - assertNull(request.getResponseContentType()); - assertNull(request.getResponseContentTypes()); - assertFalse(request.authenticate(null)); - request.login(null, null); - request.logout(); - assertEquals(0, request.getParts().size()); - assertNull(request.getPart(null)); - assertNull(request.getServletContext()); - assertNull(request.startAsync()); - assertNull(request.startAsync(null, null)); - assertFalse(request.isAsyncStarted()); - assertFalse(request.isAsyncSupported()); - assertNull(request.getAsyncContext()); - assertNull(request.getDispatcherType()); - } - -} diff --git a/core/src/test/java/de/valtech/aecu/core/service/GroovyConsoleResponseTest.java b/core/src/test/java/de/valtech/aecu/core/service/GroovyConsoleResponseTest.java deleted file mode 100644 index e1759fad..00000000 --- a/core/src/test/java/de/valtech/aecu/core/service/GroovyConsoleResponseTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2019 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.service; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; - -import org.junit.Before; -import org.junit.Test; - -/** - * Tests GroovyConsoleResponse - * - * @author Roland Gruber - */ -public class GroovyConsoleResponseTest { - - private static final String TEST = "testval"; - - private GroovyConsoleResponse response; - - @Before - public void setup() { - response = new GroovyConsoleResponse(); - } - - @Test - public void setters() throws IOException { - response.addCookie(null); - response.sendError(0); - response.sendError(0, TEST); - response.sendRedirect(TEST); - response.setDateHeader(TEST, 0); - response.addDateHeader(TEST, 0); - response.setHeader(TEST, TEST); - response.addHeader(TEST, TEST); - response.setIntHeader(TEST, 0); - response.addIntHeader(TEST, 0); - response.setStatus(0); - response.setStatus(0, TEST); - response.setCharacterEncoding(TEST); - response.setContentLength(0); - response.setContentType(TEST); - response.setBufferSize(0); - response.flushBuffer(); - response.resetBuffer(); - response.reset(); - response.setLocale(null); - } - - @Test - public void getters() throws IOException { - assertFalse(response.containsHeader(null)); - assertEquals(TEST, response.encodeURL(TEST)); - assertEquals(TEST, response.encodeUrl(TEST)); - assertEquals(TEST, response.encodeRedirectURL(TEST)); - assertEquals(TEST, response.encodeRedirectUrl(TEST)); - assertEquals(200, response.getStatus()); - assertNull(response.getHeader(TEST)); - assertTrue(response.getHeaders(TEST).isEmpty()); - assertTrue(response.getHeaderNames().isEmpty()); - assertEquals("UTF-8", response.getCharacterEncoding()); - assertNull(response.getContentType()); - assertNull(response.getOutputStream()); - assertNull(response.getWriter()); - assertEquals(0, response.getBufferSize()); - assertFalse(response.isCommitted()); - assertNull(response.getLocale()); - assertNull(response.adaptTo(null)); - } - -} From 8cbf9e67ae8036ae950157a9314072329b7f1ae0 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Thu, 10 Jun 2021 14:29:05 +0200 Subject: [PATCH 25/29] JavaDoc --- .../aecu/api/groovy/console/bindings/ContentUpgrade.java | 7 ++++--- .../api/groovy/console/bindings/ValidateAccessRights.java | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) 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 f58daa0a..77c3a783 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 @@ -207,9 +207,9 @@ public interface ContentUpgrade { /** * Joins a property value into a single value using the given separator. * - * @param name property name - * @param value property value fall back for empty arrays. Use null to delete the property. - * @param name separator (e.g. ",") + * @param name property name + * @param value property value fall back for empty arrays. Use null to delete the property. + * @param separator separator (e.g. ",") * @return upgrade object **/ ContentUpgrade doJoinProperty(String name, Object value, String separator); @@ -378,6 +378,7 @@ public interface ContentUpgrade { * Deletes the child resources if supplied. If no children are specified it deletes the resource * itself. * + * @param children names of child nodes * @return upgrade object */ ContentUpgrade doDeleteResource(String... children); diff --git a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ValidateAccessRights.java b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ValidateAccessRights.java index 75ae0ea2..f7f142a6 100644 --- a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ValidateAccessRights.java +++ b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ValidateAccessRights.java @@ -235,6 +235,8 @@ public interface ValidateAccessRights { /** * Fail whole script execution on error. Script will stop after current aecu block. Subsequent * code will no longer be executed. + * + * @return access right validation builder */ ValidateAccessRights failOnError(); @@ -243,6 +245,7 @@ public interface ValidateAccessRights { * code will no longer be executed. * * @param fail if true fail script execution + * @return access right validation builder */ ValidateAccessRights failOnError(boolean fail); From 86123b5c44ce27b9562a9d54875a4b97de36a63e Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Thu, 10 Jun 2021 14:43:19 +0200 Subject: [PATCH 26/29] JavaDoc --- pom.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 23e67b28..a845d4bc 100644 --- a/pom.xml +++ b/pom.xml @@ -129,7 +129,10 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.9.1 + 3.1.0 + + 8 + org.apache.maven.plugins From 342103a2f3e3e7fa4a9acc87f25c2a4c8c99af86 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Thu, 10 Jun 2021 14:50:59 +0200 Subject: [PATCH 27/29] build --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fd0c14da..d15e90a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ addons: secure: v0L2WG1NtMt4bXGRipEY9X23Glmz5ZldVCw7LaIUbUwKOB2AVghhUttZAsI0FBntsF0jRHJDk3L/4g45UZWSZOMRMl3lPm8NTHZLC4TmeDb00H/JXirh5ZghX+9KDiL1X8IF5xX6HRU8WO2XFnPhNR9kdh6JKSBwM2wEXADl8WNWLP7I8hB4hQ+gBdil1zOcT5vnyhc29zSU5EuBp4uZanlNhjry12tIOp/pZpdDO/pzF6m8T0DvGsgvlkZNWF16a0kazsLVWOYZ7QmjM8YDt6jVCNVQ+cImY/YPoq42OdvbIUfTazxiMS+P68Wel7ulH9FqzfHmz+SYPxQ1TfAQ2ltZO05ubQ5C2TScC+mipUkfbgqRr9RJUPkret+nUJ1WaQdf6+W3oZ6pTvn27s+XZFlWTbj6CcmgTPN8cCL5D+A9huvDOD2wWHkP7cquGSIuqh+Nc33K/EWR/BhY4ec2Xk/bjfoPTIE4tOuVyIZQLf64RxL0sRyitj4dZz+aRqhKiCaVKRtELqh8JoteYon+QPw/MF4UOalq+/QAFWvmgMeCouGxLwh2EPlK+3kXFO5tebRv67zLVesfVFCZgKWshTvUJ02kxKqy8HpocMTmoaIsRUHi2E5ucpbMxzKuJitpetrOHIjMNJQhfi0oW17zeB8i/oDwMIdNUGXPAU2MF1g= script: - - mvn test javadoc:javadoc -B + - mvn clean install javadoc:javadoc -B - sonar-scanner cache: From beb3b31d675f64ef7f29bca52e83a44aad321dc1 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Fri, 11 Jun 2021 10:07:19 +0200 Subject: [PATCH 28/29] updating poms for 4.1.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.structure/pom.xml | 2 +- ui.apps/pom.xml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index c5becc90..8332515c 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 4.1.0-SNAPSHOT + 4.1.0-rc-SNAPSHOT aecu.api diff --git a/bundle/pom.xml b/bundle/pom.xml index 1ee8acca..277489e2 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.1.0-SNAPSHOT + 4.1.0-rc-SNAPSHOT aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index 0091c180..fbc116e9 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 4.1.0-SNAPSHOT + 4.1.0-rc-SNAPSHOT aecu.core diff --git a/examples/pom.xml b/examples/pom.xml index 9cb010e0..95228286 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.1.0-SNAPSHOT + 4.1.0-rc-SNAPSHOT aecu.examples diff --git a/pom.xml b/pom.xml index a845d4bc..1bc298f1 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 4.1.0-SNAPSHOT + 4.1.0-rc-SNAPSHOT AECU AEM Easy Content Upgrade https://github.com/valtech/aem-easy-content-upgrade diff --git a/ui.apps.structure/pom.xml b/ui.apps.structure/pom.xml index 992383cd..7d37847f 100644 --- a/ui.apps.structure/pom.xml +++ b/ui.apps.structure/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.1.0-SNAPSHOT + 4.1.0-rc-SNAPSHOT aecu.ui.apps.structure diff --git a/ui.apps/pom.xml b/ui.apps/pom.xml index 44b8051c..cec12e5f 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.1.0-SNAPSHOT + 4.1.0-rc-SNAPSHOT aecu.ui.apps From c7add1c79698c2e372c841d719ed88538e8c20ff Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Fri, 11 Jun 2021 10:08:05 +0200 Subject: [PATCH 29/29] updating poms for branch'release/4.1.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.structure/pom.xml | 2 +- ui.apps/pom.xml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 8332515c..c2670f2e 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 4.1.0-rc-SNAPSHOT + 4.1.0 aecu.api diff --git a/bundle/pom.xml b/bundle/pom.xml index 277489e2..b5fd74e1 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.1.0-rc-SNAPSHOT + 4.1.0 aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index fbc116e9..1a63e123 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 4.1.0-rc-SNAPSHOT + 4.1.0 aecu.core diff --git a/examples/pom.xml b/examples/pom.xml index 95228286..7b0af755 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.1.0-rc-SNAPSHOT + 4.1.0 aecu.examples diff --git a/pom.xml b/pom.xml index 1bc298f1..ce49196a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 4.1.0-rc-SNAPSHOT + 4.1.0 AECU AEM Easy Content Upgrade https://github.com/valtech/aem-easy-content-upgrade diff --git a/ui.apps.structure/pom.xml b/ui.apps.structure/pom.xml index 7d37847f..e542f116 100644 --- a/ui.apps.structure/pom.xml +++ b/ui.apps.structure/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.1.0-rc-SNAPSHOT + 4.1.0 aecu.ui.apps.structure diff --git a/ui.apps/pom.xml b/ui.apps/pom.xml index cec12e5f..8f484ac1 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.1.0-rc-SNAPSHOT + 4.1.0 aecu.ui.apps