From 0930103a0b64639e2540960a11bfde13b6757ed5 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 11 Dec 2019 10:35:32 +0100 Subject: [PATCH 01/27] updating poms for 3.0.2-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 b7ba85b7..03432b7f 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 3.0.1-SNAPSHOT + 3.0.2-SNAPSHOT aecu.api diff --git a/bundle/pom.xml b/bundle/pom.xml index f591347a..0bcf94fa 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.0.1-SNAPSHOT + 3.0.2-SNAPSHOT aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index 739eb54a..e7283cd7 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 3.0.1-SNAPSHOT + 3.0.2-SNAPSHOT aecu.core diff --git a/examples/pom.xml b/examples/pom.xml index 9a9139dd..e0f8ae71 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.0.1-SNAPSHOT + 3.0.2-SNAPSHOT aecu.examples diff --git a/pom.xml b/pom.xml index f0633b5b..cfd2ac02 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 3.0.1-SNAPSHOT + 3.0.2-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 a452298c..0c6b142d 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.0.1-SNAPSHOT + 3.0.2-SNAPSHOT aecu.ui.apps From e6858a3a001e6cd523fcc93507520a960f30a866 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 11 Dec 2019 10:39:22 +0100 Subject: [PATCH 02/27] 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 03432b7f..c7c81728 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 3.0.2-SNAPSHOT + 3.0.1 aecu.api diff --git a/bundle/pom.xml b/bundle/pom.xml index 0bcf94fa..b1f300b7 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.0.2-SNAPSHOT + 3.0.1 aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index e7283cd7..f2ee4761 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 3.0.2-SNAPSHOT + 3.0.1 aecu.core diff --git a/examples/pom.xml b/examples/pom.xml index e0f8ae71..d700e30a 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.0.2-SNAPSHOT + 3.0.1 aecu.examples diff --git a/pom.xml b/pom.xml index cfd2ac02..34f3f962 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 3.0.2-SNAPSHOT + 3.0.1 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 0c6b142d..014e60d2 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.0.2-SNAPSHOT + 3.0.1 aecu.ui.apps From cf2e295a82f05607fdcc0b5f3c15a73632f8c6e3 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 11 Dec 2019 10:39:22 +0100 Subject: [PATCH 03/27] 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 c7c81728..03432b7f 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 3.0.1 + 3.0.2-SNAPSHOT aecu.api diff --git a/bundle/pom.xml b/bundle/pom.xml index b1f300b7..0bcf94fa 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.0.1 + 3.0.2-SNAPSHOT aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index f2ee4761..e7283cd7 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 3.0.1 + 3.0.2-SNAPSHOT aecu.core diff --git a/examples/pom.xml b/examples/pom.xml index d700e30a..e0f8ae71 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.0.1 + 3.0.2-SNAPSHOT aecu.examples diff --git a/pom.xml b/pom.xml index 34f3f962..cfd2ac02 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 3.0.1 + 3.0.2-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 014e60d2..0c6b142d 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.0.1 + 3.0.2-SNAPSHOT aecu.ui.apps From 2f1e006b4e27c405f970325f82f3538cf0c0f3ea Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 11 Dec 2019 10:40:28 +0100 Subject: [PATCH 04/27] added 3.x --- Readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Readme.md b/Readme.md index 6bbe0886..80354034 100644 --- a/Readme.md +++ b/Readme.md @@ -52,11 +52,11 @@ Table of contents AECU requires Java 8 and AEM 6.4 or above. For AEM 6.3 please install the last 1.x version of AECU. Groovy Console can be installed manually if [bundle install](#bundleInstall) is not used. -| AEM Version | Groovy Console | AECU | -| ------------- | -------------- | ---- | -| 6.3 | 12.x | 1.x | -| 6.4 | 13.x, 14.x | 2.x | -| 6.5 | 13.x, 14.x | 2.x | +| AEM Version | Groovy Console | AECU | +| ------------- | -------------- | -------- | +| 6.3 | 12.x | 1.x | +| 6.4 | 13.x, 14.x | 3.x/2.x | +| 6.5 | 13.x, 14.x | 3.x/2.x | From ed2a882656caad9937f09f7c90cb2c7ef8b03d3d Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 11 Dec 2019 10:40:58 +0100 Subject: [PATCH 05/27] typo --- Readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Readme.md b/Readme.md index 80354034..acc72ce9 100644 --- a/Readme.md +++ b/Readme.md @@ -52,11 +52,11 @@ Table of contents AECU requires Java 8 and AEM 6.4 or above. For AEM 6.3 please install the last 1.x version of AECU. Groovy Console can be installed manually if [bundle install](#bundleInstall) is not used. -| AEM Version | Groovy Console | AECU | -| ------------- | -------------- | -------- | -| 6.3 | 12.x | 1.x | -| 6.4 | 13.x, 14.x | 3.x/2.x | -| 6.5 | 13.x, 14.x | 3.x/2.x | +| AEM Version | Groovy Console | AECU | +| ------------- | -------------- | --------- | +| 6.3 | 12.x | 1.x | +| 6.4 | 13.x, 14.x | 3.x, 2.x | +| 6.5 | 13.x, 14.x | 3.x, 2.x | From 4bfe09c1e2d819daaa6c030239c2595c9528b8e1 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 11 Dec 2019 10:41:31 +0100 Subject: [PATCH 06/27] typo --- Readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index acc72ce9..42aeff26 100644 --- a/Readme.md +++ b/Readme.md @@ -55,8 +55,8 @@ AECU requires Java 8 and AEM 6.4 or above. For AEM 6.3 please install the last 1 | AEM Version | Groovy Console | AECU | | ------------- | -------------- | --------- | | 6.3 | 12.x | 1.x | -| 6.4 | 13.x, 14.x | 3.x, 2.x | -| 6.5 | 13.x, 14.x | 3.x, 2.x | +| 6.4 | 14.x, 13.x | 3.x, 2.x | +| 6.5 | 14.x, 13.x | 3.x, 2.x | From bcec4e8cb45622e8f45e894c3d753b6a30a3c520 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 11 Dec 2019 10:49:26 +0100 Subject: [PATCH 07/27] 3.0.2 --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index 109ff878..f3c0c099 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.0.1-SNAPSHOT +sonar.projectVersion=3.0.2-SNAPSHOT # Encoding of the source code. Default is default system encoding sonar.sourceEncoding=UTF-8 From 77ca410e5737568e18106c791cbcda5bded01f1b Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Tue, 17 Dec 2019 13:24:15 +0100 Subject: [PATCH 08/27] added example --- Readme.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Readme.md b/Readme.md index 42aeff26..6eb0e150 100644 --- a/Readme.md +++ b/Readme.md @@ -460,6 +460,14 @@ Please note that this is for non-page resources such as commerce products. For p * doActivateResource(): activates the current resource * doDeactivateResource(): deactivates the current resource +```java +aecu.contentUpgradeBuilder() + .forChildResourcesOf("/content/we-retail/ca/en") + .doDeactivateResource() + .doActivateResource() + .run() +``` + #### Page Actions AECU can run actions on the page that contains a filtered resource. This is e.g. helpful if you filter by page resource type. From 72b2afddc542a455e52674b3f6640b63d44f39e6 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Tue, 4 Feb 2020 08:28:39 +0100 Subject: [PATCH 09/27] #89 createResource() --- api/pom.xml | 2 +- .../console/bindings/ContentUpgrade.java | 21 ++++++- .../groovy/console/bindings/package-info.java | 2 +- bundle/pom.xml | 2 +- core/pom.xml | 2 +- .../actions/resource/CreateResource.java | 63 +++++++++++++++++++ .../bindings/impl/ContentUpgradeImpl.java | 17 ++++- examples/pom.xml | 2 +- pom.xml | 2 +- ui.apps/pom.xml | 2 +- 10 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/CreateResource.java diff --git a/api/pom.xml b/api/pom.xml index 03432b7f..aa5628fd 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 3.0.2-SNAPSHOT + 3.1.0-SNAPSHOT aecu.api 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 32b134be..0afa59e8 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018 - 2019 Valtech GmbH + * Copyright 2018 - 2020 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, @@ -320,6 +320,25 @@ public interface ContentUpgrade { */ ContentUpgrade doDeleteResource(String... children); + /** + * Creates a new resource under the current one. + * + * @param name resource name + * @param properties properties incl. jcr:primaryTpye + * @return upgrade object + */ + ContentUpgrade doCreateResource(String name, Map properties); + + /** + * Creates a new resource under the current one. + * + * @param name resource name + * @param properties properties incl. jcr:primaryTpye + * @param relativePath relative path + * @return upgrade object + */ + ContentUpgrade doCreateResource(String name, Map properties, String relativePath); + /** * Activates the resource. * 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 2f01d73b..06f1d8f1 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.0.0") +@Version("4.1.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 0bcf94fa..c9a8219e 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.0.2-SNAPSHOT + 3.1.0-SNAPSHOT aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index e7283cd7..d9f6656d 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 3.0.2-SNAPSHOT + 3.1.0-SNAPSHOT aecu.core diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/CreateResource.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/CreateResource.java new file mode 100644 index 00000000..f29a5761 --- /dev/null +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/CreateResource.java @@ -0,0 +1,63 @@ +/* + * Copyright 2020 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.actions.resource; + +import java.util.Map; + +import javax.annotation.Nonnull; + +import org.apache.commons.lang3.StringUtils; +import org.apache.sling.api.resource.PersistenceException; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ResourceResolver; + +import de.valtech.aecu.core.groovy.console.bindings.actions.Action; + +/** + * @author Roland Gruber + */ +public class CreateResource implements Action { + + private String name; + private Map properties; + private String relativePath; + private ResourceResolver resourceResolver; + + public CreateResource(@Nonnull String name, @Nonnull Map properties, String relativePath, + @Nonnull ResourceResolver resourceResolver) { + this.name = name; + this.properties = properties; + this.relativePath = relativePath; + this.resourceResolver = resourceResolver; + } + + @Override + public String doAction(@Nonnull Resource resource) throws PersistenceException { + Resource destinationResource = resource; + if (StringUtils.isNotBlank(relativePath)) { + destinationResource = resourceResolver.getResource(resource, relativePath); + } + if (destinationResource != null) { + Resource newResource = resourceResolver.create(destinationResource, name, properties); + return "Created " + newResource.getPath(); + } + return "WARNING: could not read destination resource at " + relativePath; + } + +} 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 d0d3a4ee..628a893a 100644 --- a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/ContentUpgradeImpl.java +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/ContentUpgradeImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 - 2019 Valtech GmbH + * Copyright 2018 - 2020 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, @@ -68,6 +68,7 @@ import de.valtech.aecu.core.groovy.console.bindings.actions.properties.RenameProperty; import de.valtech.aecu.core.groovy.console.bindings.actions.properties.SetProperty; import de.valtech.aecu.core.groovy.console.bindings.actions.resource.CopyResourceToRelativePath; +import de.valtech.aecu.core.groovy.console.bindings.actions.resource.CreateResource; import de.valtech.aecu.core.groovy.console.bindings.actions.resource.CustomAction; import de.valtech.aecu.core.groovy.console.bindings.actions.resource.DeleteResource; import de.valtech.aecu.core.groovy.console.bindings.actions.resource.MoveResourceToPathRegex; @@ -104,7 +105,7 @@ public class ContentUpgradeImpl implements ContentUpgrade { * Constructor * * @param resourceResolver resolver - * @param scriptContext Groovy context + * @param scriptContext Groovy context */ public ContentUpgradeImpl(@Nonnull ResourceResolver resourceResolver, ScriptContext scriptContext) { this.context = new BindingContext(resourceResolver); @@ -323,6 +324,18 @@ public ContentUpgrade doDeleteResource(String... children) { return this; } + @Override + public ContentUpgrade doCreateResource(String name, Map properties) { + actions.add(new CreateResource(name, properties, null, context.getResolver())); + return this; + } + + @Override + public ContentUpgrade doCreateResource(String name, Map properties, String relativePath) { + actions.add(new CreateResource(name, properties, relativePath, context.getResolver())); + return this; + } + @Override public ContentUpgrade doActivateResource() { actions.add(new ReplicateResourceAction(true, context)); diff --git a/examples/pom.xml b/examples/pom.xml index e0f8ae71..fd6c6095 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.0.2-SNAPSHOT + 3.1.0-SNAPSHOT aecu.examples diff --git a/pom.xml b/pom.xml index cfd2ac02..cf59abd6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 3.0.2-SNAPSHOT + 3.1.0-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 0c6b142d..8dce711c 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.0.2-SNAPSHOT + 3.1.0-SNAPSHOT aecu.ui.apps From 19c6b63d12fb731ef56b669585e23355a3ace545 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Tue, 4 Feb 2020 08:45:38 +0100 Subject: [PATCH 10/27] #89 added test --- .../actions/resource/CreateResourceTest.java | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/CreateResourceTest.java diff --git a/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/CreateResourceTest.java b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/CreateResourceTest.java new file mode 100644 index 00000000..7446513b --- /dev/null +++ b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/CreateResourceTest.java @@ -0,0 +1,99 @@ +/* + * Copyright 2020 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.actions.resource; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.HashMap; +import java.util.Map; + +import javax.jcr.ItemExistsException; +import javax.jcr.PathNotFoundException; +import javax.jcr.RepositoryException; +import javax.jcr.lock.LockException; +import javax.jcr.nodetype.ConstraintViolationException; +import javax.jcr.version.VersionException; + +import org.apache.sling.api.resource.PersistenceException; +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 CreateResource + * + * @author Roland Gruber + */ +@RunWith(MockitoJUnitRunner.class) +public class CreateResourceTest { + + private static final String INTERMEDIATE = "intermediate"; + + private static final String NEW_NAME = "newName"; + + @Mock + private ResourceResolver resolver; + + @Mock + private Resource resource; + + @Mock + private Resource newResource; + + @Mock + private Resource intermediateResource; + + private Map properties = new HashMap<>(); + + @Before + public void setup() throws PersistenceException { + when(newResource.getPath()).thenReturn("/parent/node/nodeNew"); + when(resolver.getResource(resource, INTERMEDIATE)).thenReturn(intermediateResource); + properties.put("jcr:primaryType", "nt:unstructured"); + when(resolver.create(resource, NEW_NAME, properties)).thenReturn(newResource); + when(resolver.create(intermediateResource, NEW_NAME, properties)).thenReturn(newResource); + } + + @Test + public void doAction_noRelative() throws PersistenceException, ItemExistsException, PathNotFoundException, VersionException, + ConstraintViolationException, LockException, RepositoryException { + CreateResource action = new CreateResource(NEW_NAME, properties, null, resolver); + + action.doAction(resource); + + verify(resolver, times(1)).create(resource, NEW_NAME, properties); + } + + @Test + public void doAction_Relative() throws PersistenceException, ItemExistsException, PathNotFoundException, VersionException, + ConstraintViolationException, LockException, RepositoryException { + CreateResource action = new CreateResource(NEW_NAME, properties, INTERMEDIATE, resolver); + + action.doAction(resource); + + verify(resolver, times(1)).create(intermediateResource, NEW_NAME, properties); + } + +} From 922c5e32f9f8189e8052ae2b4d19e8581e293a12 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Tue, 4 Feb 2020 10:39:30 +0100 Subject: [PATCH 11/27] use new decorator --- .../de/valtech/aecu/core/model/history/HistoryDataSource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/de/valtech/aecu/core/model/history/HistoryDataSource.java b/core/src/main/java/de/valtech/aecu/core/model/history/HistoryDataSource.java index 5e7bf035..470c1a5e 100644 --- a/core/src/main/java/de/valtech/aecu/core/model/history/HistoryDataSource.java +++ b/core/src/main/java/de/valtech/aecu/core/model/history/HistoryDataSource.java @@ -28,13 +28,13 @@ import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ValueMap; +import org.apache.sling.api.wrappers.ValueMapDecorator; import org.apache.sling.models.annotations.Model; import org.apache.sling.models.annotations.injectorspecific.OSGiService; import org.apache.sling.models.annotations.injectorspecific.SlingObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.adobe.cq.commerce.common.ValueMapDecorator; import com.adobe.granite.ui.components.ds.AbstractDataSource; import com.adobe.granite.ui.components.ds.DataSource; import com.adobe.granite.ui.components.ds.ValueMapResource; From 997c28a7562b5aba015f95376bad67caa1c5599f Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Tue, 4 Feb 2020 11:07:28 +0100 Subject: [PATCH 12/27] #89 docs --- Readme.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Readme.md b/Readme.md index 6eb0e150..f9a963ac 100644 --- a/Readme.md +++ b/Readme.md @@ -437,6 +437,26 @@ aecu.contentUpgradeBuilder() .run() ``` +#### Create Nodes + +Sometimes a new node needs to be created e.g. to add or configure a component. + +* doCreateResource(String name, Map properties): creates a new node using the name and properties (do not forget to set "jcr:primaryType") +* doCreateResource(String name, Map properties, String relativePath): same as above but creates the node under the relative path + +```java +def map = [ + "jcr:primaryType": "nt:unstructured", + "testval": "test" +] + +aecu.contentUpgradeBuilder() + .forResources((String[]) ["/content/we-retail/jcr:content"]) + .doCreateResource("mynode", map) + .doCreateResource("mynode2", map, "mynode") + .run() +``` + #### Delete Nodes You can delete nodes that match your collection and filter. From debf157d60456edd3517c7dd8460c306ed9540b1 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Tue, 4 Feb 2020 12:02:08 +0100 Subject: [PATCH 13/27] #118 fixed JDK 11 issues --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index cf59abd6..c376ed3d 100644 --- a/pom.xml +++ b/pom.xml @@ -145,12 +145,12 @@ org.apache.maven.plugins maven-surefire-plugin - 2.20 + 2.22.2 org.jacoco jacoco-maven-plugin - 0.8.1 + 0.8.5 org.apache.maven.plugins @@ -621,7 +621,7 @@ org.mockito mockito-core - 2.7.22 + 2.28.2 test From a64f0815e0665046ab0c7d2dbaf1e9e26364d4b7 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 5 Feb 2020 13:53:33 +0100 Subject: [PATCH 14/27] #105 fixed issue when copying a page --- .../resource/CopyResourceToRelativePath.java | 23 ++++- .../bindings/actions/util/PageUtil.java | 54 +++++++++++ .../bindings/actions/util/PageUtilTest.java | 91 +++++++++++++++++++ 3 files changed, 164 insertions(+), 4 deletions(-) create mode 100644 core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/util/PageUtil.java create mode 100644 core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/util/PageUtilTest.java diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/CopyResourceToRelativePath.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/CopyResourceToRelativePath.java index 994b98a8..9e289f88 100644 --- a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/CopyResourceToRelativePath.java +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/CopyResourceToRelativePath.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 Valtech GmbH + * Copyright 2018 - 2020 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, @@ -18,13 +18,17 @@ */ package de.valtech.aecu.core.groovy.console.bindings.actions.resource; -import de.valtech.aecu.core.groovy.console.bindings.actions.Action; +import javax.annotation.Nonnull; import org.apache.sling.api.resource.PersistenceException; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; -import javax.annotation.Nonnull; +import com.day.cq.wcm.api.PageManager; +import com.day.cq.wcm.api.WCMException; + +import de.valtech.aecu.core.groovy.console.bindings.actions.Action; +import de.valtech.aecu.core.groovy.console.bindings.actions.util.PageUtil; /** * @author Roxana Muresan @@ -45,10 +49,21 @@ public String doAction(@Nonnull Resource resource) throws PersistenceException { if (destinationResource != null) { String sourceAbsPAth = resource.getPath(); String destinationAsPath = destinationResource.getPath(); - resourceResolver.copy(sourceAbsPAth, destinationAsPath); + PageUtil pageUtil = new PageUtil(); + if (pageUtil.isPageResource(resource)) { + PageManager pageManager = resourceResolver.adaptTo(PageManager.class); + try { + pageManager.copy(resource, destinationAsPath + "/" + resource.getName(), null, false, false); + } catch (WCMException | IllegalArgumentException e) { + throw new PersistenceException("Unable to copy " + sourceAbsPAth + ": " + e.getMessage()); + } + } else { + resourceResolver.copy(sourceAbsPAth, destinationAsPath); + } return "Copied " + sourceAbsPAth + " to path " + destinationAsPath; } return "WARNING: could not read copy destination resource " + relativePath; } + } diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/util/PageUtil.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/util/PageUtil.java new file mode 100644 index 00000000..5950a644 --- /dev/null +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/util/PageUtil.java @@ -0,0 +1,54 @@ +/* + * Copyright 2020 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.actions.util; + +import org.apache.jackrabbit.JcrConstants; +import org.apache.sling.api.resource.Resource; + +import com.day.cq.wcm.api.NameConstants; + +/** + * Util functions for pages. + * + * @author Roland Gruber + */ +public class PageUtil { + + private static final String CONTENT = "/content"; + + /** + * Returns if the given resource is a page. This will return false for any subnodes of a page + * incl. jcr:content. + * + * @param resource resource + * @return is page + */ + public boolean isPageResource(Resource resource) { + if (resource == null) { + return false; + } + String path = resource.getPath(); + if (!path.startsWith(CONTENT) || path.contains(JcrConstants.JCR_CONTENT)) { + return false; + } + String primaryType = resource.getValueMap().get(JcrConstants.JCR_PRIMARYTYPE, String.class); + return NameConstants.NT_PAGE.equals(primaryType); + } + +} diff --git a/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/util/PageUtilTest.java b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/util/PageUtilTest.java new file mode 100644 index 00000000..48444f49 --- /dev/null +++ b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/util/PageUtilTest.java @@ -0,0 +1,91 @@ +/* + * Copyright 2020 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.actions.util; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +import org.apache.jackrabbit.JcrConstants; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ValueMap; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import com.day.cq.wcm.api.NameConstants; + +/** + * Tests PageUtil + * + * @author Roland Gruber + */ +@RunWith(MockitoJUnitRunner.class) +public class PageUtilTest { + + @Mock + private Resource resource; + + @Mock + private ValueMap valueMap; + + @Before + public void setup() { + when(resource.getPath()).thenReturn("/content/project/something"); + when(resource.getValueMap()).thenReturn(valueMap); + when(valueMap.get(JcrConstants.JCR_PRIMARYTYPE, String.class)).thenReturn(NameConstants.NT_PAGE); + } + + @Test + public void isPageResource() { + PageUtil util = new PageUtil(); + + assertTrue(util.isPageResource(resource)); + } + + @Test + public void isPageResource_noContent() { + when(resource.getPath()).thenReturn("/var/project/something"); + + PageUtil util = new PageUtil(); + + assertFalse(util.isPageResource(resource)); + } + + @Test + public void isPageResource_subnode() { + when(resource.getPath()).thenReturn("/content/project/something/jcr:content/node"); + + PageUtil util = new PageUtil(); + + assertFalse(util.isPageResource(resource)); + } + + @Test + public void isPageResource_wrongPrimaryType() { + when(valueMap.get(JcrConstants.JCR_PRIMARYTYPE, String.class)).thenReturn(JcrConstants.NT_FOLDER); + + PageUtil util = new PageUtil(); + + assertFalse(util.isPageResource(resource)); + } + +} From 081b4f4195f084cc0d775d4328e67bf1fce38cb7 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 5 Feb 2020 14:09:36 +0100 Subject: [PATCH 15/27] #105 move with page manager if needed --- .../resource/MoveResourceToPathRegex.java | 18 +++++++++++-- .../resource/MoveResourceToRelativePath.java | 23 +++++++++++++--- .../resource/MoveResourceToPathRegexTest.java | 27 +++++++++++++------ 3 files changed, 54 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToPathRegex.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToPathRegex.java index bd459269..9d584fe3 100644 --- a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToPathRegex.java +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToPathRegex.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 Valtech GmbH + * Copyright 2018 - 2020 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, @@ -25,7 +25,11 @@ import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; +import com.day.cq.wcm.api.PageManager; +import com.day.cq.wcm.api.WCMException; + import de.valtech.aecu.core.groovy.console.bindings.actions.Action; +import de.valtech.aecu.core.groovy.console.bindings.actions.util.PageUtil; /** * Action class for moving resources via regex @@ -60,7 +64,17 @@ public String doAction(@Nonnull Resource resource) throws PersistenceException { Resource destinationResource = resourceResolver.getResource(targetPath); if (destinationResource != null) { - resourceResolver.move(resourcePath, targetPath); + PageUtil pageUtil = new PageUtil(); + if (pageUtil.isPageResource(resource)) { + PageManager pageManager = resourceResolver.adaptTo(PageManager.class); + try { + pageManager.move(resource, targetPath + "/" + resource.getName(), null, false, false, null); + } catch (WCMException | IllegalArgumentException e) { + throw new PersistenceException("Unable to move " + resourcePath + ": " + e.getMessage()); + } + } else { + resourceResolver.move(resourcePath, targetPath); + } return "Moved " + resourcePath + " to path " + targetPath; } diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToRelativePath.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToRelativePath.java index 2cd72cea..9a9a998c 100644 --- a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToRelativePath.java +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToRelativePath.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 Valtech GmbH + * Copyright 2018 - 2020 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, @@ -18,13 +18,17 @@ */ package de.valtech.aecu.core.groovy.console.bindings.actions.resource; -import de.valtech.aecu.core.groovy.console.bindings.actions.Action; +import javax.annotation.Nonnull; import org.apache.sling.api.resource.PersistenceException; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; -import javax.annotation.Nonnull; +import com.day.cq.wcm.api.PageManager; +import com.day.cq.wcm.api.WCMException; + +import de.valtech.aecu.core.groovy.console.bindings.actions.Action; +import de.valtech.aecu.core.groovy.console.bindings.actions.util.PageUtil; /** * @author Roxana Muresan @@ -45,10 +49,21 @@ public String doAction(@Nonnull Resource resource) throws PersistenceException { if (destinationResource != null) { String sourceAbsPAth = resource.getPath(); String destinationAsPath = destinationResource.getPath(); - resourceResolver.move(sourceAbsPAth, destinationAsPath); + PageUtil pageUtil = new PageUtil(); + if (pageUtil.isPageResource(resource)) { + PageManager pageManager = resourceResolver.adaptTo(PageManager.class); + try { + pageManager.move(resource, destinationAsPath + "/" + resource.getName(), null, false, false, null); + } catch (WCMException | IllegalArgumentException e) { + throw new PersistenceException("Unable to move " + sourceAbsPAth + ": " + e.getMessage()); + } + } else { + resourceResolver.move(sourceAbsPAth, destinationAsPath); + } return "Moved " + sourceAbsPAth + " to path " + destinationAsPath; } return "WARNING: could not read move destination resource " + relativePath; } + } diff --git a/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToPathRegexTest.java b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToPathRegexTest.java index 9d51f649..452a0617 100644 --- a/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToPathRegexTest.java +++ b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToPathRegexTest.java @@ -19,14 +19,6 @@ package de.valtech.aecu.core.groovy.console.bindings.actions.resource; -import org.apache.sling.api.resource.PersistenceException; -import org.apache.sling.api.resource.Resource; -import org.apache.sling.api.resource.ResourceResolver; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.anyString; @@ -37,6 +29,17 @@ import static org.mockito.Mockito.when; import static org.mockito.internal.verification.VerificationModeFactory.times; +import org.apache.jackrabbit.JcrConstants; +import org.apache.sling.api.resource.PersistenceException; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ResourceResolver; +import org.apache.sling.api.resource.ValueMap; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + /** * Tests MoveResourceToPathRegex * @@ -49,7 +52,15 @@ public class MoveResourceToPathRegexTest { private ResourceResolver resourceResolver; @Mock private Resource resource; + @Mock + private ValueMap valueMap; + @Before + public void setup() { + when(resource.getPath()).thenReturn("/content/project/something"); + when(resource.getValueMap()).thenReturn(valueMap); + when(valueMap.get(JcrConstants.JCR_PRIMARYTYPE, String.class)).thenReturn(JcrConstants.NT_FOLDER); + } @Test public void testDoAction_noMatch() { From e722b15faa1e7370a133cc91353df38a1a7aa666 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Fri, 7 Feb 2020 09:08:28 +0100 Subject: [PATCH 16/27] #89 made primaryType mandatory --- Readme.md | 13 ++++---- .../console/bindings/ContentUpgrade.java | 29 +++++++++++++++--- .../bindings/impl/ContentUpgradeImpl.java | 30 ++++++++++++++++--- 3 files changed, 59 insertions(+), 13 deletions(-) diff --git a/Readme.md b/Readme.md index f9a963ac..a1678fbb 100644 --- a/Readme.md +++ b/Readme.md @@ -441,19 +441,22 @@ aecu.contentUpgradeBuilder() Sometimes a new node needs to be created e.g. to add or configure a component. -* doCreateResource(String name, Map properties): creates a new node using the name and properties (do not forget to set "jcr:primaryType") -* doCreateResource(String name, Map properties, String relativePath): same as above but creates the node under the relative path +* doCreateResource(String name, String primaryType, Map properties): creates a new node using additional properties +* doCreateResource(String name, String primaryType, String relativePath): same as above but creates the node under the relative path +* doCreateResource(String name, String primaryType, Map properties, String relativePath): same as above but creates the node under the relative path ```java def map = [ - "jcr:primaryType": "nt:unstructured", "testval": "test" ] aecu.contentUpgradeBuilder() .forResources((String[]) ["/content/we-retail/jcr:content"]) - .doCreateResource("mynode", map) - .doCreateResource("mynode2", map, "mynode") + .doCreateResource("mynode1", "nt:unstructured") + .doCreateResource("mynode2", "nt:unstructured", map) + .doCreateResource("mysubnode1", "nt:unstructured", "mynode1") + .doCreateResource("mysubnode2", "nt:unstructured", map, "mynode2") .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 0afa59e8..cd5a3b6b 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 @@ -323,21 +323,42 @@ public interface ContentUpgrade { /** * Creates a new resource under the current one. * - * @param name resource name - * @param properties properties incl. jcr:primaryTpye + * @param name resource name + * @param primaryType jcr:primaryTpye * @return upgrade object */ - ContentUpgrade doCreateResource(String name, Map properties); + ContentUpgrade doCreateResource(String name, String primaryType); + + /** + * Creates a new resource under the current one. + * + * @param name resource name + * @param primaryType jcr:primaryTpye + * @param properties properties excl. jcr:primaryTpye + * @return upgrade object + */ + ContentUpgrade doCreateResource(String name, String primaryType, Map properties); + + /** + * Creates a new resource under the current one. + * + * @param name resource name + * @param primaryType jcr:primaryTpye + * @param relativePath relative path + * @return upgrade object + */ + ContentUpgrade doCreateResource(String name, String primaryType, String relativePath); /** * Creates a new resource under the current one. * * @param name resource name + * @param primaryType jcr:primaryTpye * @param properties properties incl. jcr:primaryTpye * @param relativePath relative path * @return upgrade object */ - ContentUpgrade doCreateResource(String name, Map properties, String relativePath); + ContentUpgrade doCreateResource(String name, String primaryType, Map properties, String relativePath); /** * Activates the resource. diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/ContentUpgradeImpl.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/ContentUpgradeImpl.java index 628a893a..9411e4cd 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 @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -28,6 +29,7 @@ import javax.jcr.query.Query; import javax.servlet.http.HttpServletResponse; +import org.apache.jackrabbit.JcrConstants; import org.apache.sling.api.resource.PersistenceException; import org.apache.sling.api.resource.ResourceResolver; import org.slf4j.Logger; @@ -325,14 +327,34 @@ public ContentUpgrade doDeleteResource(String... children) { } @Override - public ContentUpgrade doCreateResource(String name, Map properties) { - actions.add(new CreateResource(name, properties, null, context.getResolver())); + public ContentUpgrade doCreateResource(String name, String primaryType) { + Map propertyMap = new HashMap<>(); + propertyMap.put(JcrConstants.JCR_PRIMARYTYPE, primaryType); + actions.add(new CreateResource(name, propertyMap, null, context.getResolver())); return this; } @Override - public ContentUpgrade doCreateResource(String name, Map properties, String relativePath) { - actions.add(new CreateResource(name, properties, relativePath, context.getResolver())); + public ContentUpgrade doCreateResource(String name, String primaryType, Map properties) { + Map propertyMap = (properties == null) ? new HashMap<>() : properties; + propertyMap.put(JcrConstants.JCR_PRIMARYTYPE, primaryType); + actions.add(new CreateResource(name, propertyMap, null, context.getResolver())); + return this; + } + + @Override + public ContentUpgrade doCreateResource(String name, String primaryType, String relativePath) { + Map propertyMap = new HashMap<>(); + propertyMap.put(JcrConstants.JCR_PRIMARYTYPE, primaryType); + actions.add(new CreateResource(name, propertyMap, relativePath, context.getResolver())); + return this; + } + + @Override + public ContentUpgrade doCreateResource(String name, String primaryType, Map properties, String relativePath) { + Map propertyMap = (properties == null) ? new HashMap<>() : properties; + propertyMap.put(JcrConstants.JCR_PRIMARYTYPE, primaryType); + actions.add(new CreateResource(name, propertyMap, relativePath, context.getResolver())); return this; } From 32bf89dab5335805e43121a1ef7dd4167548adbb Mon Sep 17 00:00:00 2001 From: Roxana Muresan Date: Fri, 14 Feb 2020 11:33:00 +0100 Subject: [PATCH 17/27] feature/89_createNode: corrections in readme and javadoc --- Readme.md | 2 +- .../console/bindings/ContentUpgrade.java | 18 +++++++++--------- .../actions/resource/CreateResource.java | 10 ++++++---- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Readme.md b/Readme.md index a1678fbb..0886c898 100644 --- a/Readme.md +++ b/Readme.md @@ -441,7 +441,7 @@ aecu.contentUpgradeBuilder() Sometimes a new node needs to be created e.g. to add or configure a component. -* doCreateResource(String name, String primaryType, Map properties): creates a new node using additional properties * doCreateResource(String name, String primaryType, String relativePath): same as above but creates the node under the relative path * doCreateResource(String name, String primaryType, Map properties, String relativePath): same as above but creates the node under the relative path 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 cd5a3b6b..0abea3af 100644 --- a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ContentUpgrade.java +++ b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ContentUpgrade.java @@ -18,13 +18,13 @@ */ package de.valtech.aecu.api.groovy.console.bindings; -import java.util.Map; +import de.valtech.aecu.api.groovy.console.bindings.filters.FilterBy; +import de.valtech.aecu.api.service.AecuException; import org.apache.sling.api.resource.PersistenceException; import org.osgi.annotation.versioning.ProviderType; -import de.valtech.aecu.api.groovy.console.bindings.filters.FilterBy; -import de.valtech.aecu.api.service.AecuException; +import java.util.Map; /** * This class provides the builder methods to perform a content upgrade. @@ -324,7 +324,7 @@ public interface ContentUpgrade { * Creates a new resource under the current one. * * @param name resource name - * @param primaryType jcr:primaryTpye + * @param primaryType jcr:primaryType * @return upgrade object */ ContentUpgrade doCreateResource(String name, String primaryType); @@ -333,8 +333,8 @@ public interface ContentUpgrade { * Creates a new resource under the current one. * * @param name resource name - * @param primaryType jcr:primaryTpye - * @param properties properties excl. jcr:primaryTpye + * @param primaryType jcr:primaryType + * @param properties properties excl. jcr:primaryType * @return upgrade object */ ContentUpgrade doCreateResource(String name, String primaryType, Map properties); @@ -343,7 +343,7 @@ public interface ContentUpgrade { * Creates a new resource under the current one. * * @param name resource name - * @param primaryType jcr:primaryTpye + * @param primaryType jcr:primaryType * @param relativePath relative path * @return upgrade object */ @@ -353,8 +353,8 @@ public interface ContentUpgrade { * Creates a new resource under the current one. * * @param name resource name - * @param primaryType jcr:primaryTpye - * @param properties properties incl. jcr:primaryTpye + * @param primaryType jcr:primaryType + * @param properties properties excl. jcr:primaryType * @param relativePath relative path * @return upgrade object */ diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/CreateResource.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/CreateResource.java index f29a5761..6842a2af 100644 --- a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/CreateResource.java +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/CreateResource.java @@ -18,18 +18,20 @@ */ package de.valtech.aecu.core.groovy.console.bindings.actions.resource; -import java.util.Map; - -import javax.annotation.Nonnull; +import de.valtech.aecu.core.groovy.console.bindings.actions.Action; import org.apache.commons.lang3.StringUtils; import org.apache.sling.api.resource.PersistenceException; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; -import de.valtech.aecu.core.groovy.console.bindings.actions.Action; +import java.util.Map; + +import javax.annotation.Nonnull; /** + * Creates a new node + * * @author Roland Gruber */ public class CreateResource implements Action { From d9625ff8f3f7ad6eb6650ec4701185cc27d44583 Mon Sep 17 00:00:00 2001 From: Roxana Muresan Date: Fri, 14 Feb 2020 13:34:25 +0100 Subject: [PATCH 18/27] feature/89_createNode: added test script to examples --- .../testing/89_createNode_test.groovy | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/testing/89_createNode_test.groovy diff --git a/examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/testing/89_createNode_test.groovy b/examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/testing/89_createNode_test.groovy new file mode 100644 index 00000000..3d77cbab --- /dev/null +++ b/examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/testing/89_createNode_test.groovy @@ -0,0 +1,14 @@ +def propertiesMap = [:] +propertiesMap['test_with_props'] = "Test with properties" + +def propertiesMap2 = [:] +propertiesMap2['test_with_props_and_relative'] = "Test with properties and relative path" +propertiesMap2['another_property'] = "Another property value here" + +println aecu.contentUpgradeBuilder() + .forResources((String[])["/content/we-retail/ca/en/experience/jcr:content"]) + .doCreateResource("parent", "nt:unstructured") + .doCreateResource("parent_props", "nt:unstructured", propertiesMap) + .doCreateResource("relative_path", "nt:unstructured", "parent") + .doCreateResource("relative_path_props", "nt:unstructured", propertiesMap2, "parent/relative_path") + .run() \ No newline at end of file From 9e94945b631ac0f21ea7e5ab0031df028ca38e57 Mon Sep 17 00:00:00 2001 From: Roxana Muresan Date: Fri, 14 Feb 2020 13:52:14 +0100 Subject: [PATCH 19/27] feature/89_createNode: changed to dryRun() in example scripts and moved createNode script --- .../{testing/89_createNode_test.groovy => createNodes.groovy} | 3 +-- .../aecu-examples/project1/migrations.author/script3.groovy | 2 +- .../aecu-examples/project1/migrations.author/script4.groovy | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) rename examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/{testing/89_createNode_test.groovy => createNodes.groovy} (97%) diff --git a/examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/testing/89_createNode_test.groovy b/examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/createNodes.groovy similarity index 97% rename from examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/testing/89_createNode_test.groovy rename to examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/createNodes.groovy index 3d77cbab..6b78cb7d 100644 --- a/examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/testing/89_createNode_test.groovy +++ b/examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/createNodes.groovy @@ -1,6 +1,5 @@ def propertiesMap = [:] propertiesMap['test_with_props'] = "Test with properties" - def propertiesMap2 = [:] propertiesMap2['test_with_props_and_relative'] = "Test with properties and relative path" propertiesMap2['another_property'] = "Another property value here" @@ -11,4 +10,4 @@ println aecu.contentUpgradeBuilder() .doCreateResource("parent_props", "nt:unstructured", propertiesMap) .doCreateResource("relative_path", "nt:unstructured", "parent") .doCreateResource("relative_path_props", "nt:unstructured", propertiesMap2, "parent/relative_path") - .run() \ No newline at end of file + .dryRun() \ No newline at end of file diff --git a/examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/project1/migrations.author/script3.groovy b/examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/project1/migrations.author/script3.groovy index 99e6fde0..46bd8366 100644 --- a/examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/project1/migrations.author/script3.groovy +++ b/examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/project1/migrations.author/script3.groovy @@ -10,4 +10,4 @@ aecu.contentUpgradeBuilder() // actions .printPath() .doSetProperty("useFullWidth", false) - .run() \ No newline at end of file + .dryRun() \ No newline at end of file diff --git a/examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/project1/migrations.author/script4.groovy b/examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/project1/migrations.author/script4.groovy index 80862ad0..9d4759bf 100644 --- a/examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/project1/migrations.author/script4.groovy +++ b/examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/project1/migrations.author/script4.groovy @@ -7,4 +7,4 @@ aecu.contentUpgradeBuilder() // actions .printPath() .doMoveResourceToRelativePath("../experience") - .run() \ No newline at end of file + .dryRun() \ No newline at end of file From 819786404b25c39e3a11742b421274764577d206 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Fri, 14 Feb 2020 14:07:47 +0100 Subject: [PATCH 20/27] #89 removed println --- .../groovyconsole/scripts/aecu/aecu-examples/createNodes.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/createNodes.groovy b/examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/createNodes.groovy index 6b78cb7d..230a709a 100644 --- a/examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/createNodes.groovy +++ b/examples/src/main/content/jcr_root/var/groovyconsole/scripts/aecu/aecu-examples/createNodes.groovy @@ -4,7 +4,7 @@ def propertiesMap2 = [:] propertiesMap2['test_with_props_and_relative'] = "Test with properties and relative path" propertiesMap2['another_property'] = "Another property value here" -println aecu.contentUpgradeBuilder() +aecu.contentUpgradeBuilder() .forResources((String[])["/content/we-retail/ca/en/experience/jcr:content"]) .doCreateResource("parent", "nt:unstructured") .doCreateResource("parent_props", "nt:unstructured", propertiesMap) From 5301d9cd8e7c7a730f0052e2e3836a753a2d250e Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Fri, 14 Feb 2020 14:15:26 +0100 Subject: [PATCH 21/27] #105 history update --- HISTORY | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/HISTORY b/HISTORY index ae4890d7..bd1ee08e 100644 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,8 @@ +2020-02-14 3.1.0 + - Allow node creation + - JDK 11 support + - Fixes issues when a page with version history is copied + 2019-12-11 3.0.1 - Fixed installation issues on new instances From 12dea4258bcc251f0852abd7b65d92a725840112 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 17 Feb 2020 11:40:42 +0100 Subject: [PATCH 22/27] doc for multiple run mode combinations --- Readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 0886c898..ed1aab84 100644 --- a/Readme.md +++ b/Readme.md @@ -122,7 +122,8 @@ The content of the scripts is plain Groovy code that can be run via [Groovy Cons There are just a few naming conventions: -* Run modes: folders can contain run modes to limit the execution to a specific target environment. E.g. some scripts are for author only or for your local dev environment. +* Run modes: folders can contain run modes to limit the execution to a specific target environment. E.g. some scripts are for author only or for your local dev environment. Multiple +run mode combinations can be separated with ";" (e.g. "folder.author.test;author.stage" will be executed on test+stage author but not on prod author). * Always selector: if a script name ends with ".always.groovy" then it will be executed by [install hook](#installHook) on each package installation. There will be no more check if this script was already executed before. From f96d0fcf13686165a1c57680c95541abea1042c1 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 17 Feb 2020 12:00:14 +0100 Subject: [PATCH 23/27] #105 fixed issues with dry run --- Readme.md | 2 +- .../resource/CopyResourceToRelativePath.java | 8 +++++++- .../resource/MoveResourceToPathRegex.java | 17 +++++++++++------ .../resource/MoveResourceToRelativePath.java | 17 ++++++++++++++--- .../bindings/impl/ContentUpgradeImpl.java | 4 ++-- .../resource/MoveResourceToPathRegexTest.java | 7 +++++-- 6 files changed, 40 insertions(+), 15 deletions(-) diff --git a/Readme.md b/Readme.md index 0886c898..6a409ebd 100644 --- a/Readme.md +++ b/Readme.md @@ -432,7 +432,7 @@ aecu.contentUpgradeBuilder() .doRename("newNodeName") .doCopyResourceToRelativePath("subNode") .doCopyResourceToRelativePath("../subNode") - .doMoveResourceToRelativePath("subNode") + .doMoveResourceToRelativePath("../subNode") .doMoveResourceToPathRegex("/content/we-retail/(\\w+)/(\\w+)/(\\w+)", "/content/somewhere/\$1/and/\$2") .run() ``` diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/CopyResourceToRelativePath.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/CopyResourceToRelativePath.java index 9e289f88..6f303f05 100644 --- a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/CopyResourceToRelativePath.java +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/CopyResourceToRelativePath.java @@ -38,6 +38,12 @@ public class CopyResourceToRelativePath implements Action { private String relativePath; private ResourceResolver resourceResolver; + /** + * Constructor + * + * @param relativePath relative path + * @param resourceResolver resource resolver + */ public CopyResourceToRelativePath(@Nonnull String relativePath, @Nonnull ResourceResolver resourceResolver) { this.relativePath = relativePath; this.resourceResolver = resourceResolver; @@ -53,7 +59,7 @@ public String doAction(@Nonnull Resource resource) throws PersistenceException { if (pageUtil.isPageResource(resource)) { PageManager pageManager = resourceResolver.adaptTo(PageManager.class); try { - pageManager.copy(resource, destinationAsPath + "/" + resource.getName(), null, false, false); + pageManager.copy(resource, destinationAsPath + "/" + resource.getName(), null, false, false, false); } catch (WCMException | IllegalArgumentException e) { throw new PersistenceException("Unable to copy " + sourceAbsPAth + ": " + e.getMessage()); } diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToPathRegex.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToPathRegex.java index 9d584fe3..134ea490 100644 --- a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToPathRegex.java +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToPathRegex.java @@ -30,6 +30,7 @@ import de.valtech.aecu.core.groovy.console.bindings.actions.Action; import de.valtech.aecu.core.groovy.console.bindings.actions.util.PageUtil; +import de.valtech.aecu.core.groovy.console.bindings.impl.BindingContext; /** * Action class for moving resources via regex @@ -39,19 +40,21 @@ public class MoveResourceToPathRegex implements Action { private ResourceResolver resourceResolver; + private boolean dryRun; private String matchPattern; private String targetPathExpr; /** * Constructor * - * @param matchPattern regex pattern - * @param targetPathExpr target regex - * @param resourceResolver resolver + * @param matchPattern regex pattern + * @param targetPathExpr target regex + * @param context binding context */ public MoveResourceToPathRegex(@Nonnull String matchPattern, @Nonnull String targetPathExpr, - @Nonnull ResourceResolver resourceResolver) { - this.resourceResolver = resourceResolver; + @Nonnull BindingContext context) { + this.resourceResolver = context.getResolver(); + dryRun = context.isDryRun(); this.matchPattern = matchPattern; this.targetPathExpr = targetPathExpr; } @@ -68,7 +71,9 @@ public String doAction(@Nonnull Resource resource) throws PersistenceException { if (pageUtil.isPageResource(resource)) { PageManager pageManager = resourceResolver.adaptTo(PageManager.class); try { - pageManager.move(resource, targetPath + "/" + resource.getName(), null, false, false, null); + if (!dryRun) { + pageManager.move(resource, targetPath + "/" + resource.getName(), null, false, false, null); + } } catch (WCMException | IllegalArgumentException e) { throw new PersistenceException("Unable to move " + resourcePath + ": " + e.getMessage()); } diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToRelativePath.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToRelativePath.java index 9a9a998c..10c7e0c0 100644 --- a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToRelativePath.java +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToRelativePath.java @@ -29,6 +29,7 @@ import de.valtech.aecu.core.groovy.console.bindings.actions.Action; import de.valtech.aecu.core.groovy.console.bindings.actions.util.PageUtil; +import de.valtech.aecu.core.groovy.console.bindings.impl.BindingContext; /** * @author Roxana Muresan @@ -37,10 +38,18 @@ public class MoveResourceToRelativePath implements Action { private String relativePath; private ResourceResolver resourceResolver; + private boolean dryRun; - public MoveResourceToRelativePath(@Nonnull String relativePath, @Nonnull ResourceResolver resourceResolver) { + /** + * Constructor + * + * @param relativePath relative path + * @param context binding context + */ + public MoveResourceToRelativePath(@Nonnull String relativePath, @Nonnull BindingContext context) { this.relativePath = relativePath; - this.resourceResolver = resourceResolver; + this.resourceResolver = context.getResolver(); + dryRun = context.isDryRun(); } @Override @@ -53,7 +62,9 @@ public String doAction(@Nonnull Resource resource) throws PersistenceException { if (pageUtil.isPageResource(resource)) { PageManager pageManager = resourceResolver.adaptTo(PageManager.class); try { - pageManager.move(resource, destinationAsPath + "/" + resource.getName(), null, false, false, null); + if (!dryRun) { + pageManager.move(resource, destinationAsPath + "/" + resource.getName(), null, false, false, null); + } } catch (WCMException | IllegalArgumentException e) { throw new PersistenceException("Unable to move " + sourceAbsPAth + ": " + e.getMessage()); } 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 9411e4cd..792f32dc 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 @@ -310,13 +310,13 @@ public ContentUpgrade doCopyResourceToRelativePath(@Nonnull String relativePath) @Override public ContentUpgrade doMoveResourceToRelativePath(@Nonnull String relativePath) { - actions.add(new MoveResourceToRelativePath(relativePath, context.getResolver())); + actions.add(new MoveResourceToRelativePath(relativePath, context)); return this; } @Override public ContentUpgrade doMoveResourceToPathRegex(@Nonnull String matchPattern, @Nonnull String targetPathExpr) { - actions.add(new MoveResourceToPathRegex(matchPattern, targetPathExpr, context.getResolver())); + actions.add(new MoveResourceToPathRegex(matchPattern, targetPathExpr, context)); return this; } diff --git a/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToPathRegexTest.java b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToPathRegexTest.java index 452a0617..c7885fa7 100644 --- a/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToPathRegexTest.java +++ b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToPathRegexTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 Valtech GmbH + * Copyright 2018 - 2020 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, @@ -40,6 +40,8 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import de.valtech.aecu.core.groovy.console.bindings.impl.BindingContext; + /** * Tests MoveResourceToPathRegex * @@ -116,7 +118,8 @@ public void testDoAction_match_validDestination() { } private MoveResourceToPathRegex createObjectUnderTest(String matchPattern, String replaceExpr) { - return new MoveResourceToPathRegex(matchPattern, replaceExpr, resourceResolver); + BindingContext context = new BindingContext(resourceResolver); + return new MoveResourceToPathRegex(matchPattern, replaceExpr, context); } private void mockWithValues(String resourcePath, String targetPath, boolean destinationExists) { From 40a5547a49a1b5edf042469cfa7fdb6fa11caaf1 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Tue, 18 Feb 2020 14:59:58 +0100 Subject: [PATCH 24/27] #105 fixed dryRun issue --- .../actions/resource/MoveResourceToPathRegex.java | 9 ++++----- .../actions/resource/MoveResourceToRelativePath.java | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToPathRegex.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToPathRegex.java index 134ea490..35b80968 100644 --- a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToPathRegex.java +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToPathRegex.java @@ -39,8 +39,7 @@ */ public class MoveResourceToPathRegex implements Action { - private ResourceResolver resourceResolver; - private boolean dryRun; + private BindingContext context; private String matchPattern; private String targetPathExpr; @@ -53,14 +52,14 @@ public class MoveResourceToPathRegex implements Action { */ public MoveResourceToPathRegex(@Nonnull String matchPattern, @Nonnull String targetPathExpr, @Nonnull BindingContext context) { - this.resourceResolver = context.getResolver(); - dryRun = context.isDryRun(); + this.context = context; this.matchPattern = matchPattern; this.targetPathExpr = targetPathExpr; } @Override public String doAction(@Nonnull Resource resource) throws PersistenceException { + ResourceResolver resourceResolver = context.getResolver(); String resourcePath = resource.getPath(); if (resourcePath.matches(matchPattern)) { String targetPath = resourcePath.replaceAll(matchPattern, targetPathExpr); @@ -71,7 +70,7 @@ public String doAction(@Nonnull Resource resource) throws PersistenceException { if (pageUtil.isPageResource(resource)) { PageManager pageManager = resourceResolver.adaptTo(PageManager.class); try { - if (!dryRun) { + if (!context.isDryRun()) { pageManager.move(resource, targetPath + "/" + resource.getName(), null, false, false, null); } } catch (WCMException | IllegalArgumentException e) { diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToRelativePath.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToRelativePath.java index 10c7e0c0..65d52ee1 100644 --- a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToRelativePath.java +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/MoveResourceToRelativePath.java @@ -37,8 +37,7 @@ public class MoveResourceToRelativePath implements Action { private String relativePath; - private ResourceResolver resourceResolver; - private boolean dryRun; + private BindingContext context; /** * Constructor @@ -48,12 +47,12 @@ public class MoveResourceToRelativePath implements Action { */ public MoveResourceToRelativePath(@Nonnull String relativePath, @Nonnull BindingContext context) { this.relativePath = relativePath; - this.resourceResolver = context.getResolver(); - dryRun = context.isDryRun(); + this.context = context; } @Override public String doAction(@Nonnull Resource resource) throws PersistenceException { + ResourceResolver resourceResolver = context.getResolver(); Resource destinationResource = resourceResolver.getResource(resource, relativePath); if (destinationResource != null) { String sourceAbsPAth = resource.getPath(); @@ -62,7 +61,7 @@ public String doAction(@Nonnull Resource resource) throws PersistenceException { if (pageUtil.isPageResource(resource)) { PageManager pageManager = resourceResolver.adaptTo(PageManager.class); try { - if (!dryRun) { + if (!context.isDryRun()) { pageManager.move(resource, destinationAsPath + "/" + resource.getName(), null, false, false, null); } } catch (WCMException | IllegalArgumentException e) { From a6941d6cc386d6f07a3e40143a2a0abc467e35c0 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 19 Feb 2020 09:23:20 +0100 Subject: [PATCH 25/27] 3.1.0 --- HISTORY | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HISTORY b/HISTORY index bd1ee08e..51e8a78d 100644 --- a/HISTORY +++ b/HISTORY @@ -1,4 +1,4 @@ -2020-02-14 3.1.0 +2020-02-19 3.1.0 - Allow node creation - JDK 11 support - Fixes issues when a page with version history is copied From f0ea5d80c0eba49c8fed8f5d502b33afd65147a0 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 19 Feb 2020 09:32:16 +0100 Subject: [PATCH 26/27] updating poms for 3.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/pom.xml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index aa5628fd..cb5ffcc2 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 3.1.0-SNAPSHOT + 3.1.0-rc-SNAPSHOT aecu.api diff --git a/bundle/pom.xml b/bundle/pom.xml index c9a8219e..8481a38a 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.1.0-SNAPSHOT + 3.1.0-rc-SNAPSHOT aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index d9f6656d..169ab8bf 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 3.1.0-SNAPSHOT + 3.1.0-rc-SNAPSHOT aecu.core diff --git a/examples/pom.xml b/examples/pom.xml index fd6c6095..34cbdf54 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.1.0-SNAPSHOT + 3.1.0-rc-SNAPSHOT aecu.examples diff --git a/pom.xml b/pom.xml index c376ed3d..b316ff2a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 3.1.0-SNAPSHOT + 3.1.0-rc-SNAPSHOT AECU AEM Easy Content Upgrade https://github.com/valtech/aem-easy-content-upgrade diff --git a/ui.apps/pom.xml b/ui.apps/pom.xml index 8dce711c..980821e1 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.1.0-SNAPSHOT + 3.1.0-rc-SNAPSHOT aecu.ui.apps From c1d763cfdcf3efbd43819b47f1055a18789591b8 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 19 Feb 2020 09:32:40 +0100 Subject: [PATCH 27/27] updating poms for branch'release/3.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/pom.xml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index cb5ffcc2..44e45f28 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 3.1.0-rc-SNAPSHOT + 3.1.0 aecu.api diff --git a/bundle/pom.xml b/bundle/pom.xml index 8481a38a..af8b09c5 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.1.0-rc-SNAPSHOT + 3.1.0 aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index 169ab8bf..c3adaa98 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 3.1.0-rc-SNAPSHOT + 3.1.0 aecu.core diff --git a/examples/pom.xml b/examples/pom.xml index 34cbdf54..7b741d47 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.1.0-rc-SNAPSHOT + 3.1.0 aecu.examples diff --git a/pom.xml b/pom.xml index b316ff2a..f199550a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 3.1.0-rc-SNAPSHOT + 3.1.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 980821e1..538d1327 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.1.0-rc-SNAPSHOT + 3.1.0 aecu.ui.apps