From f00afb69f5e4b2f0a5a9f6a6e454153af9ec25b7 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Thu, 28 May 2020 15:32:52 +0200 Subject: [PATCH 01/25] update to latest Groovy Console --- core/pom.xml | 2 +- .../groovy/console/bindings/impl/AecuBindingImpl.java | 4 ++-- .../console/bindings/impl/ContentUpgradeImpl.java | 2 +- .../bindings/impl/ValidateAccessRightsImpl.java | 4 ++-- .../provider/AecuBindingExtensionProvider.java | 4 ++-- .../de/valtech/aecu/core/service/AecuServiceImpl.java | 7 +++++-- .../console/bindings/impl/AecuBindingImplTest.java | 2 +- .../bindings/impl/ValidateAccessRightsImplTest.java | 2 +- .../provider/AecuBindingExtensionProviderTest.java | 2 +- .../valtech/aecu/core/service/AecuServiceImplTest.java | 10 ++++++++-- pom.xml | 4 ++-- 11 files changed, 26 insertions(+), 17 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index d9629b77..c7e5b96c 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -43,7 +43,7 @@ !antlr.*, javax.annotation;version=0.0.0, - com.icfolson.aem.groovy.console.*;version="[13.0,15)", + com.icfolson.aem.groovy.console.*;version="[15.1,16)", * diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/AecuBindingImpl.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/AecuBindingImpl.java index 1bdfa1a5..1a6259b6 100644 --- a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/AecuBindingImpl.java +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/AecuBindingImpl.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, @@ -26,7 +26,7 @@ import org.slf4j.LoggerFactory; import com.day.cq.replication.Replicator; -import com.icfolson.aem.groovy.console.api.ScriptContext; +import com.icfolson.aem.groovy.console.api.context.ScriptContext; import de.valtech.aecu.api.groovy.console.bindings.AecuBinding; import de.valtech.aecu.api.groovy.console.bindings.ContentUpgrade; 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 a1a95da6..b5d36717 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 @@ -35,7 +35,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.icfolson.aem.groovy.console.api.ScriptContext; +import com.icfolson.aem.groovy.console.api.context.ScriptContext; import de.valtech.aecu.api.groovy.console.bindings.ContentUpgrade; import de.valtech.aecu.api.groovy.console.bindings.CustomResourceAction; diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/ValidateAccessRightsImpl.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/ValidateAccessRightsImpl.java index 5be170ba..c8ff4053 100644 --- a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/ValidateAccessRightsImpl.java +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/ValidateAccessRightsImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 Valtech GmbH + * Copyright 2019 - 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, @@ -37,7 +37,7 @@ import com.day.cq.replication.ReplicationActionType; import com.day.cq.replication.Replicator; -import com.icfolson.aem.groovy.console.api.ScriptContext; +import com.icfolson.aem.groovy.console.api.context.ScriptContext; import de.valtech.aecu.api.groovy.console.bindings.ValidateAccessRights; import de.valtech.aecu.api.groovy.console.bindings.accessrights.AccessRightValidator; diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/provider/AecuBindingExtensionProvider.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/provider/AecuBindingExtensionProvider.java index 71a03a3e..a1a09ff1 100644 --- a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/provider/AecuBindingExtensionProvider.java +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/provider/AecuBindingExtensionProvider.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, @@ -31,7 +31,7 @@ import com.day.cq.replication.Replicator; import com.icfolson.aem.groovy.console.api.BindingExtensionProvider; import com.icfolson.aem.groovy.console.api.BindingVariable; -import com.icfolson.aem.groovy.console.api.ScriptContext; +import com.icfolson.aem.groovy.console.api.context.ScriptContext; import de.valtech.aecu.api.groovy.console.bindings.AecuBinding; import de.valtech.aecu.core.groovy.console.bindings.impl.AecuBindingImpl; 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 3320bea1..60fd2140 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 @@ -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, @@ -40,6 +40,8 @@ import org.slf4j.LoggerFactory; import com.icfolson.aem.groovy.console.GroovyConsoleService; +import com.icfolson.aem.groovy.console.api.context.ScriptContext; +import com.icfolson.aem.groovy.console.api.impl.RequestScriptContext; import com.icfolson.aem.groovy.console.response.RunScriptResponse; import de.valtech.aecu.api.service.AecuException; @@ -186,7 +188,8 @@ private ExecutionResult executeScript(ResourceResolver resolver, String path) { SlingHttpServletRequest slingRequest = new GroovyConsoleRequest(resolver); SlingHttpServletResponse slingResponse = new GroovyConsoleResponse(); LOG.info("Executing script " + path); - RunScriptResponse response = groovyConsoleService.runScript(slingRequest, slingResponse, path); + ScriptContext scriptContext = new RequestScriptContext(slingRequest, slingResponse, null, null, path); + RunScriptResponse response = groovyConsoleService.runScript(scriptContext); boolean success = StringUtils.isBlank(response.getExceptionStackTrace()); if (success) { LOG.info("Executed script " + path + " with status OK"); diff --git a/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/impl/AecuBindingImplTest.java b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/impl/AecuBindingImplTest.java index 204a3c1b..398de8b9 100644 --- a/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/impl/AecuBindingImplTest.java +++ b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/impl/AecuBindingImplTest.java @@ -19,7 +19,7 @@ import org.mockito.junit.MockitoJUnitRunner; import com.day.cq.replication.Replicator; -import com.icfolson.aem.groovy.console.api.ScriptContext; +import com.icfolson.aem.groovy.console.api.context.ScriptContext; /** * Tests AecuBindingImpl diff --git a/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/impl/ValidateAccessRightsImplTest.java b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/impl/ValidateAccessRightsImplTest.java index f1c840c6..0fe81997 100644 --- a/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/impl/ValidateAccessRightsImplTest.java +++ b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/impl/ValidateAccessRightsImplTest.java @@ -32,7 +32,7 @@ import com.day.cq.replication.ReplicationActionType; import com.day.cq.replication.Replicator; -import com.icfolson.aem.groovy.console.api.ScriptContext; +import com.icfolson.aem.groovy.console.api.context.ScriptContext; /** * Tests ValidateAccessRightsImpl diff --git a/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/provider/AecuBindingExtensionProviderTest.java b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/provider/AecuBindingExtensionProviderTest.java index 47b1cbca..0bf1977d 100644 --- a/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/provider/AecuBindingExtensionProviderTest.java +++ b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/provider/AecuBindingExtensionProviderTest.java @@ -15,7 +15,7 @@ import com.day.cq.replication.Replicator; import com.icfolson.aem.groovy.console.api.BindingExtensionProvider; import com.icfolson.aem.groovy.console.api.BindingVariable; -import com.icfolson.aem.groovy.console.api.ScriptContext; +import com.icfolson.aem.groovy.console.api.context.ScriptContext; import de.valtech.aecu.api.groovy.console.bindings.AecuBinding; import de.valtech.aecu.core.serviceuser.ServiceResourceResolverService; 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 f559d9d5..5d7b3bee 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 @@ -50,7 +50,9 @@ import org.mockito.junit.MockitoJUnitRunner; import com.icfolson.aem.groovy.console.GroovyConsoleService; +import com.icfolson.aem.groovy.console.api.context.ScriptContext; import com.icfolson.aem.groovy.console.response.RunScriptResponse; +import com.icfolson.aem.groovy.console.response.impl.DefaultRunScriptResponse; import de.valtech.aecu.api.service.AecuException; import de.valtech.aecu.api.service.HistoryEntry; @@ -89,6 +91,9 @@ public class AecuServiceImplTest { @Mock private HistoryUtil historyUtil; + @Mock + private ScriptContext scriptContext = mock(ScriptContext.class); + @Before public void setup() throws LoginException { Set runModes = new HashSet<>(); @@ -297,9 +302,10 @@ public void execute() throws AecuException { Resource resource = mock(Resource.class); when(resolver.getResource(DIR)).thenReturn(resource); when(resource.getName()).thenReturn(FILE1); + when(scriptContext.getScript()).thenReturn(DIR); - RunScriptResponse response = new RunScriptResponse(); - when(groovyConsoleService.runScript(Mockito.any(), Mockito.any(), Mockito.eq(DIR))).thenReturn(response); + RunScriptResponse response = DefaultRunScriptResponse.fromResult(scriptContext, null, null, null); + when(groovyConsoleService.runScript(Mockito.any())).thenReturn(response); service.execute(DIR); } diff --git a/pom.xml b/pom.xml index fab71953..028c2b0c 100644 --- a/pom.xml +++ b/pom.xml @@ -544,7 +544,7 @@ com.icfolson.aem.groovy.console aem-groovy-console - 14.0.0 + 15.1.0 provided @@ -557,7 +557,7 @@ com.icfolson.aem.groovy.console aem-groovy-console - 14.0.0 + 15.1.0 zip From 836cbb26bb8a0340b983caacd60357d253c50677 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 7 Oct 2020 08:26:58 +0200 Subject: [PATCH 02/25] updating poms for 3.3.1-SNAPSHOT development --- api/pom.xml | 2 +- bundle/pom.xml | 2 +- core/pom.xml | 2 +- examples/pom.xml | 2 +- pom.xml | 2 +- ui.apps/pom.xml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 87f95a8c..a825efc1 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 3.3.0-SNAPSHOT + 3.3.1-SNAPSHOT aecu.api diff --git a/bundle/pom.xml b/bundle/pom.xml index 6d13a121..106f22d3 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.3.0-SNAPSHOT + 3.3.1-SNAPSHOT aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index 2211fb17..8b500382 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 3.3.0-SNAPSHOT + 3.3.1-SNAPSHOT aecu.core diff --git a/examples/pom.xml b/examples/pom.xml index 21df8da0..e326db15 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.3.0-SNAPSHOT + 3.3.1-SNAPSHOT aecu.examples diff --git a/pom.xml b/pom.xml index 96fd4f09..5a20538c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 3.3.0-SNAPSHOT + 3.3.1-SNAPSHOT AECU AEM Easy Content Upgrade https://github.com/valtech/aem-easy-content-upgrade diff --git a/ui.apps/pom.xml b/ui.apps/pom.xml index 59f35016..245b43f8 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.3.0-SNAPSHOT + 3.3.1-SNAPSHOT aecu.ui.apps From b1eb80150de06a35529b6a4b4ac25b496f1dc27b Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 7 Oct 2020 08:32:05 +0200 Subject: [PATCH 03/25] 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 a825efc1..39d6ba00 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 3.3.1-SNAPSHOT + 3.3.0 aecu.api diff --git a/bundle/pom.xml b/bundle/pom.xml index 106f22d3..7b4bbc2e 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.3.1-SNAPSHOT + 3.3.0 aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index 8b500382..98e8f940 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 3.3.1-SNAPSHOT + 3.3.0 aecu.core diff --git a/examples/pom.xml b/examples/pom.xml index e326db15..d2b796a7 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.3.1-SNAPSHOT + 3.3.0 aecu.examples diff --git a/pom.xml b/pom.xml index 5a20538c..8dccce28 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 3.3.1-SNAPSHOT + 3.3.0 AECU AEM Easy Content Upgrade https://github.com/valtech/aem-easy-content-upgrade diff --git a/ui.apps/pom.xml b/ui.apps/pom.xml index 245b43f8..87c25ab8 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.3.1-SNAPSHOT + 3.3.0 aecu.ui.apps From ffa94ad055e06b18fe3df18720e56fd732debd48 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 7 Oct 2020 08:32:05 +0200 Subject: [PATCH 04/25] 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 39d6ba00..a825efc1 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 3.3.0 + 3.3.1-SNAPSHOT aecu.api diff --git a/bundle/pom.xml b/bundle/pom.xml index 7b4bbc2e..106f22d3 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.3.0 + 3.3.1-SNAPSHOT aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index 98e8f940..8b500382 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 3.3.0 + 3.3.1-SNAPSHOT aecu.core diff --git a/examples/pom.xml b/examples/pom.xml index d2b796a7..e326db15 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.3.0 + 3.3.1-SNAPSHOT aecu.examples diff --git a/pom.xml b/pom.xml index 8dccce28..5a20538c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 3.3.0 + 3.3.1-SNAPSHOT AECU AEM Easy Content Upgrade https://github.com/valtech/aem-easy-content-upgrade diff --git a/ui.apps/pom.xml b/ui.apps/pom.xml index 87c25ab8..245b43f8 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.3.0 + 3.3.1-SNAPSHOT aecu.ui.apps From d96e945a1251a10aa10a3f83bc1126b0e367bd49 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 7 Oct 2020 08:37:38 +0200 Subject: [PATCH 05/25] 3.3.0 --- sonar-project.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index ba2202bd..72e27f60 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.3.0-SNAPSHOT +sonar.projectVersion=3.4.0-SNAPSHOT # Encoding of the source code. Default is default system encoding sonar.sourceEncoding=UTF-8 From 7fa6d63f74da0d75bc28288b1b7cef9be79c23e8 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Fri, 9 Oct 2020 08:34:25 +0200 Subject: [PATCH 06/25] better output --- .../actions/resource/ChangePrimaryType.java | 5 ++-- .../resource/ChangePrimaryTypeTest.java | 24 ++++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/ChangePrimaryType.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/ChangePrimaryType.java index d0bb98d4..436791ca 100644 --- a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/ChangePrimaryType.java +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/ChangePrimaryType.java @@ -33,10 +33,11 @@ public String doAction(@Nonnull Resource resource) throws PersistenceException { try { if (null != node) { node.setPrimaryType(newPrimaryType); - return "Updated jcr:primaryType to " + newPrimaryType; + return "Updated jcr:primaryType to " + newPrimaryType + " for resource " + resource.getPath(); } } catch (RepositoryException e) { - throw new PersistenceException("ERROR: could not update jcr:primaryType to " + newPrimaryType, e); + throw new PersistenceException( + "ERROR: could not update jcr:primaryType to " + newPrimaryType + " for resource " + resource.getPath(), e); } return "WARNING: could not update jcr:primaryType to " + newPrimaryType; } diff --git a/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/ChangePrimaryTypeTest.java b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/ChangePrimaryTypeTest.java index 5aed63fa..659864b8 100644 --- a/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/ChangePrimaryTypeTest.java +++ b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/ChangePrimaryTypeTest.java @@ -1,5 +1,14 @@ package de.valtech.aecu.core.groovy.console.bindings.actions.resource; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import javax.jcr.Node; +import javax.jcr.RepositoryException; + import org.apache.sling.api.resource.PersistenceException; import org.apache.sling.api.resource.Resource; import org.junit.Before; @@ -8,16 +17,6 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import javax.jcr.Node; -import javax.jcr.RepositoryException; -import javax.jcr.lock.LockException; -import javax.jcr.nodetype.ConstraintViolationException; -import javax.jcr.nodetype.NoSuchNodeTypeException; -import javax.jcr.version.VersionException; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; - /** * Tests ChangePrimaryTypeTest * @@ -27,6 +26,8 @@ @RunWith(MockitoJUnitRunner.class) public class ChangePrimaryTypeTest { + private static final String PATH = "path"; + private static final String newPrimaryType = "nt:unstructured"; @Mock @@ -38,6 +39,7 @@ public class ChangePrimaryTypeTest { @Before public void setup() { when(resource.adaptTo(Node.class)).thenReturn(node); + when(resource.getPath()).thenReturn(PATH); } @Test @@ -45,7 +47,7 @@ public void test_doAction_setPrimaryType() throws PersistenceException, Reposito ChangePrimaryType changePrimaryType = new ChangePrimaryType(newPrimaryType); String result = changePrimaryType.doAction(resource); verify(node, times(1)).setPrimaryType(newPrimaryType); - assertEquals("Updated jcr:primaryType to " + newPrimaryType, result); + assertEquals("Updated jcr:primaryType to " + newPrimaryType + " for resource " + PATH, result); } @Test From 806e608085ab7eed1a8414a10dfe7e6235c9b1d4 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Fri, 9 Oct 2020 08:44:16 +0200 Subject: [PATCH 07/25] NOT-filter example --- Readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Readme.md b/Readme.md index a9cc4d95..9e635771 100644 --- a/Readme.md +++ b/Readme.md @@ -345,6 +345,7 @@ def complexFilter = new ORFilter( aecu.contentUpgradeBuilder() .forDescendantResourcesOf("/content/we-retail/ca/en", false) .filterWith(complexFilter) + .filterWith(new NOTFilter(new FilterByPathRegex(".*jcr:content.*"))) .doSetProperty("name", "value") .run() ``` From 486c669b1cbe59edfe043eb764cebc70ad7feedb Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Fri, 9 Oct 2020 14:00:57 +0200 Subject: [PATCH 08/25] small fix for AEM cloud --- Readme.md | 1 + .../aecu/clientlibs/aecu.editor/js/executor.js | 17 ----------------- .../aecu/tools/execute/page/.content.xml | 1 + 3 files changed, 2 insertions(+), 17 deletions(-) diff --git a/Readme.md b/Readme.md index 9e635771..57bc9159 100644 --- a/Readme.md +++ b/Readme.md @@ -60,6 +60,7 @@ AECU requires Java 8 and AEM 6.4 or above. For AEM 6.3 please install the last 1 | 6.3 | 12.x | 1.x | | 6.4 | 14.x, 13.x | 3.x, 2.x | | 6.5 | 14.x, 13.x | 3.x, 2.x | +| AEM Cloud | 14.x | 3.x | diff --git a/ui.apps/src/main/content/jcr_root/apps/valtech/aecu/clientlibs/aecu.editor/js/executor.js b/ui.apps/src/main/content/jcr_root/apps/valtech/aecu/clientlibs/aecu.editor/js/executor.js index 21731aa2..0a4b2f86 100644 --- a/ui.apps/src/main/content/jcr_root/apps/valtech/aecu/clientlibs/aecu.editor/js/executor.js +++ b/ui.apps/src/main/content/jcr_root/apps/valtech/aecu/clientlibs/aecu.editor/js/executor.js @@ -161,21 +161,4 @@ $(document).ready(function () { AECU.Constants.Executor.HistoryEntryActions.single, null); }); - /* open rail tab */ - var button = $('coral-cyclebutton'); - var panel = $('coral-panel'); - if (button) { - Coral.commons.ready(button[0], function () { - if (panel) { - Coral.commons.ready(panel[0], function () { - var selected = panel.attr('aria-selected'); - if (!selected || (selected == "false")) { - button.find('button').click(); - setTimeout(function() {button.find('[tabindex="-1"]').click();}, 300); - } - }); - } - }); - } - }); \ No newline at end of file diff --git a/ui.apps/src/main/content/jcr_root/apps/valtech/aecu/tools/execute/page/.content.xml b/ui.apps/src/main/content/jcr_root/apps/valtech/aecu/tools/execute/page/.content.xml index 7bc0fc9b..064e32f3 100644 --- a/ui.apps/src/main/content/jcr_root/apps/valtech/aecu/tools/execute/page/.content.xml +++ b/ui.apps/src/main/content/jcr_root/apps/valtech/aecu/tools/execute/page/.content.xml @@ -31,6 +31,7 @@ jcr:primaryType="nt:unstructured" jcr:title="Search" sling:resourceType="granite/ui/components/coral/foundation/panel/railpanel" + active="{Boolean}true" > Date: Fri, 9 Oct 2020 14:44:32 +0200 Subject: [PATCH 09/25] cloud fix --- HISTORY | 3 +++ 1 file changed, 3 insertions(+) diff --git a/HISTORY b/HISTORY index 37b54c34..6d96e38b 100644 --- a/HISTORY +++ b/HISTORY @@ -1,3 +1,6 @@ +3.3.1 + - Fix for AEM Cloud in manual execution tool + 2020-10-07 3.3.0 - Allow to change primary type - Documentation and example updates From 1b3e37bb09985a6cb7f8b990280902888da269b5 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Fri, 9 Oct 2020 15:55:11 +0200 Subject: [PATCH 10/25] update to Groovy Console 16 --- core/pom.xml | 2 +- .../aecu/core/service/AecuScriptContext.java | 79 +++++++++++++++++++ .../aecu/core/service/AecuServiceImpl.java | 5 +- pom.xml | 4 +- ui.apps/pom.xml | 2 +- 5 files changed, 84 insertions(+), 8 deletions(-) create mode 100644 core/src/main/java/de/valtech/aecu/core/service/AecuScriptContext.java diff --git a/core/pom.xml b/core/pom.xml index 21156dba..4780793c 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -43,7 +43,7 @@ !antlr.*, javax.annotation;version=0.0.0, - com.icfolson.aem.groovy.console.*;version="[15.1,16)", + com.icfolson.aem.groovy.console.*;version="[15.1,17)", * 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 new file mode 100644 index 00000000..3576ef83 --- /dev/null +++ b/core/src/main/java/de/valtech/aecu/core/service/AecuScriptContext.java @@ -0,0 +1,79 @@ +package de.valtech.aecu.core.service; + +import java.io.ByteArrayOutputStream; +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. + * + * @author Roland Gruber + */ +public class AecuScriptContext implements ScriptContext { + + private static final Logger LOG = LoggerFactory.getLogger(AecuScriptContext.class); + + private String scriptPath; + private ResourceResolver resolver; + private ByteArrayOutputStream out = new ByteArrayOutputStream(); + + private SlingHttpServletRequest request; + + /** + * Constructor + * + * @param scriptPath script path + * @param resolver resolver + * @param request request + */ + public AecuScriptContext(String scriptPath, ResourceResolver resolver, SlingHttpServletRequest request) { + this.scriptPath = scriptPath; + this.resolver = resolver; + this.request = request; + } + + @Override + public String getData() { + return request.getParameter(GroovyConsoleConstants.DATA); + } + + @Override + public ByteArrayOutputStream getOutputStream() { + return out; + } + + @Override + public PrintStream getPrintStream() { + try { + return new PrintStream(out, true, Charsets.UTF_8.name()); + } catch (UnsupportedEncodingException e) { + LOG.error("Unable to create print stream", e); + } + return null; + } + + @Override + public ResourceResolver getResourceResolver() { + return resolver; + } + + @Override + public String getScript() { + return scriptPath; + } + + @Override + public String getUserId() { + return request.getResourceResolver().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 60fd2140..26ccd1ad 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,7 +26,6 @@ import org.apache.commons.lang3.StringUtils; import org.apache.jackrabbit.JcrConstants; import org.apache.sling.api.SlingHttpServletRequest; -import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.resource.LoginException; import org.apache.sling.api.resource.PersistenceException; import org.apache.sling.api.resource.Resource; @@ -41,7 +40,6 @@ import com.icfolson.aem.groovy.console.GroovyConsoleService; import com.icfolson.aem.groovy.console.api.context.ScriptContext; -import com.icfolson.aem.groovy.console.api.impl.RequestScriptContext; import com.icfolson.aem.groovy.console.response.RunScriptResponse; import de.valtech.aecu.api.service.AecuException; @@ -186,9 +184,8 @@ public ExecutionResult execute(String path) throws AecuException { */ private ExecutionResult executeScript(ResourceResolver resolver, String path) { SlingHttpServletRequest slingRequest = new GroovyConsoleRequest(resolver); - SlingHttpServletResponse slingResponse = new GroovyConsoleResponse(); LOG.info("Executing script " + path); - ScriptContext scriptContext = new RequestScriptContext(slingRequest, slingResponse, null, null, path); + ScriptContext scriptContext = new AecuScriptContext(path, slingRequest.getResourceResolver(), slingRequest); RunScriptResponse response = groovyConsoleService.runScript(scriptContext); boolean success = StringUtils.isBlank(response.getExceptionStackTrace()); if (success) { diff --git a/pom.xml b/pom.xml index b9430f23..bb79288b 100644 --- a/pom.xml +++ b/pom.xml @@ -544,7 +544,7 @@ com.icfolson.aem.groovy.console aem-groovy-console - 15.1.0 + 16.0.0 provided @@ -557,7 +557,7 @@ com.icfolson.aem.groovy.console aem-groovy-console - 15.1.0 + 16.0.0 zip diff --git a/ui.apps/pom.xml b/ui.apps/pom.xml index 245b43f8..fc597300 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -98,7 +98,7 @@ ICF Next aem-groovy-console - (13,15] + (16,17] From bc9099f6a3f2b3773262e0c6a2f2ed9e95db6722 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2020 22:57:50 +0000 Subject: [PATCH 11/25] Bump junit from 4.12 to 4.13.1 Bumps [junit](https://github.com/junit-team/junit4) from 4.12 to 4.13.1. - [Release notes](https://github.com/junit-team/junit4/releases) - [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.12.md) - [Commits](https://github.com/junit-team/junit4/compare/r4.12...r4.13.1) Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5a20538c..991ea01f 100644 --- a/pom.xml +++ b/pom.xml @@ -612,7 +612,7 @@ junit junit - 4.12 + 4.13.1 test From b2708f9ba14fc9074245107033d0e3a92507385d Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Tue, 20 Oct 2020 09:11:34 +0200 Subject: [PATCH 12/25] fixed script reading --- .../aecu/core/service/AecuScriptContext.java | 14 +++---- .../aecu/core/service/AecuServiceImpl.java | 37 +++++++++++++++++-- .../core/service/AecuServiceImplTest.java | 23 +++++++++++- 3 files changed, 63 insertions(+), 11 deletions(-) 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 3576ef83..cb38f1fd 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 @@ -22,7 +22,7 @@ public class AecuScriptContext implements ScriptContext { private static final Logger LOG = LoggerFactory.getLogger(AecuScriptContext.class); - private String scriptPath; + private String script; private ResourceResolver resolver; private ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -31,12 +31,12 @@ public class AecuScriptContext implements ScriptContext { /** * Constructor * - * @param scriptPath script path - * @param resolver resolver - * @param request request + * @param script script content + * @param resolver resolver + * @param request request */ - public AecuScriptContext(String scriptPath, ResourceResolver resolver, SlingHttpServletRequest request) { - this.scriptPath = scriptPath; + public AecuScriptContext(String script, ResourceResolver resolver, SlingHttpServletRequest request) { + this.script = script; this.resolver = resolver; this.request = request; } @@ -68,7 +68,7 @@ public ResourceResolver getResourceResolver() { @Override public String getScript() { - return scriptPath; + return script; } @Override 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 26ccd1ad..dd3f58b8 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 @@ -18,11 +18,19 @@ */ package de.valtech.aecu.core.service; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; 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; import org.apache.sling.api.SlingHttpServletRequest; @@ -180,12 +188,13 @@ public ExecutionResult execute(String path) throws AecuException { * * @param resolver resource resolver * @param path path - * @return result + * @return result execution result + * @throws AecuException error running script */ - private ExecutionResult executeScript(ResourceResolver resolver, String path) { + private ExecutionResult executeScript(ResourceResolver resolver, String path) throws AecuException { SlingHttpServletRequest slingRequest = new GroovyConsoleRequest(resolver); LOG.info("Executing script " + path); - ScriptContext scriptContext = new AecuScriptContext(path, slingRequest.getResourceResolver(), slingRequest); + ScriptContext scriptContext = new AecuScriptContext(loadScript(path, resolver), resolver, slingRequest); RunScriptResponse response = groovyConsoleService.runScript(scriptContext); boolean success = StringUtils.isBlank(response.getExceptionStackTrace()); if (success) { @@ -203,6 +212,28 @@ private ExecutionResult executeScript(ResourceResolver resolver, String path) { response.getOutput() + response.getExceptionStackTrace(), fallbackResult, path); } + /** + * Read script. + * + * @param path path + * @param resolver resource resolver + * @return script content + * @throws AecuException error reading script + */ + 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) { + throw new AecuException("Unable to read script", e); + } + } + /** * Returns the fallback script name if any exists. * 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 5d7b3bee..0f90feaf 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 @@ -28,11 +28,17 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.io.ByteArrayInputStream; import java.util.Arrays; import java.util.HashSet; 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; import org.apache.sling.api.resource.LoginException; import org.apache.sling.api.resource.Resource; @@ -94,6 +100,15 @@ 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<>(); @@ -298,11 +313,17 @@ public void execute_invalidFileName() throws AecuException { } @Test - public void execute() throws AecuException { + public void execute() throws AecuException, RepositoryException { Resource resource = mock(Resource.class); when(resolver.getResource(DIR)).thenReturn(resource); + when(resolver.getResource(DIR + "/" + JcrConstants.JCR_CONTENT)).thenReturn(resource); 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); RunScriptResponse response = DefaultRunScriptResponse.fromResult(scriptContext, null, null, null); when(groovyConsoleService.runScript(Mockito.any())).thenReturn(response); From c6a648e7578979540535234cf9e6f8d68ea25557 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Tue, 20 Oct 2020 11:14:31 +0200 Subject: [PATCH 13/25] version update --- HISTORY | 3 ++- Readme.md | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/HISTORY b/HISTORY index 6d96e38b..70fa5d29 100644 --- a/HISTORY +++ b/HISTORY @@ -1,4 +1,5 @@ -3.3.1 +4.0.0 + - Update to Groovy Console 16 and require AEM 6.5 - Fix for AEM Cloud in manual execution tool 2020-10-07 3.3.0 diff --git a/Readme.md b/Readme.md index 57bc9159..979d18a0 100644 --- a/Readme.md +++ b/Readme.md @@ -57,10 +57,10 @@ 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 | 14.x, 13.x | 3.x, 2.x | -| 6.5 | 14.x, 13.x | 3.x, 2.x | -| AEM Cloud | 14.x | 3.x | +| 6.3 | 12.x | 1.x | +| 6.4 | 14.x, 13.x | 3.x, 2.x | +| 6.5 | 16.x
14.x, 13.x | 4.x
3.x, 2.x | +| AEM Cloud | 16.x
14.x, 13.x | 4.x
3.x, 2.x | From 47201a0cf0c3116973bc44767ffcb073d86b9a96 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Tue, 20 Oct 2020 14:40:21 +0200 Subject: [PATCH 14/25] docs update --- Readme.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Readme.md b/Readme.md index 979d18a0..c26ec1fb 100644 --- a/Readme.md +++ b/Readme.md @@ -53,14 +53,14 @@ Table of contents # Requirements -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. +AECU requires Java 8 and AEM 6.5 or above. For AEM 6.3/6.4 please see below. 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 | 14.x, 13.x | 3.x, 2.x | -| 6.5 | 16.x
14.x, 13.x | 4.x
3.x, 2.x | | 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.4 | 14.x, 13.x | 3.x, 2.x | +| 6.3 | 12.x | 1.x | From 1634c595f92522e4603209bee220bc63ac2a9d6c Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 18 Nov 2020 11:20:55 +0100 Subject: [PATCH 15/25] better error message --- .../actions/resource/ReplaceResourcePropertyValues.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/ReplaceResourcePropertyValues.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/ReplaceResourcePropertyValues.java index c486a3e6..6a9d70db 100644 --- a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/ReplaceResourcePropertyValues.java +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/resource/ReplaceResourcePropertyValues.java @@ -82,7 +82,7 @@ public String doAction(@Nonnull Resource resource) throws PersistenceException { } } } catch (RepositoryException e) { - throw new PersistenceException("Rename failed", e); + throw new PersistenceException("Replace failed for " + resource.getPath(), e); } if (updated) { return "Updated values from " + oldValue + " to " + newValue + " in " + resource.getPath(); From 22b8f5c7e54cda229d758143727f6f2212646b5d Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Tue, 24 Nov 2020 13:58:12 +0100 Subject: [PATCH 16/25] #140 added conversions for GString --- api/pom.xml | 6 +- .../console/bindings/GStringConverter.java | 51 ++++++++ .../bindings/filters/FilterByProperties.java | 8 +- .../bindings/filters/FilterByProperty.java | 4 +- .../groovy/console/bindings/package-info.java | 2 +- .../filters/FilterByPropertiesTest.java | 123 ++++++++++++++++++ .../filters/FilterByPropertyTest.java | 11 ++ .../console/bindings/filters/TestFilters.java | 5 +- bundle/pom.xml | 2 +- core/pom.xml | 2 +- examples/pom.xml | 2 +- pom.xml | 2 +- ui.apps/pom.xml | 2 +- 13 files changed, 205 insertions(+), 15 deletions(-) create mode 100644 api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/GStringConverter.java create mode 100644 api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByPropertiesTest.java diff --git a/api/pom.xml b/api/pom.xml index a825efc1..6bab112c 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 3.3.1-SNAPSHOT + 4.0.0-SNAPSHOT aecu.api @@ -86,6 +86,10 @@ org.apache.commons commons-lang3
+ + org.codehaus.groovy + groovy-all + junit junit diff --git a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/GStringConverter.java b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/GStringConverter.java new file mode 100644 index 00000000..54b342d5 --- /dev/null +++ b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/GStringConverter.java @@ -0,0 +1,51 @@ +package de.valtech.aecu.api.groovy.console.bindings; + +import java.util.HashMap; +import java.util.Map; + +import groovy.lang.GString; + +/** + * Converts GString to String. + * + * @author Roland Gruber + */ +public class GStringConverter { + + private GStringConverter() { + // no instantiation + } + + /** + * Converts the input in case it is a GString. + * + * @param input input + * @return converted value + */ + public static Object convert(Object input) { + if (input instanceof GString) { + return ((GString) input).toString(); + } + return input; + } + + /** + * Converts the input in case it is a GString. + * + * @param input input + * @return converted value + */ + public static Map convert(Map input) { + if (input == null) { + return input; + } + Map output = new HashMap<>(input); + for (Map.Entry entry : input.entrySet()) { + if (entry.getValue() instanceof GString) { + output.put(entry.getKey(), convert(entry.getValue())); + } + } + return output; + } + +} diff --git a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByProperties.java b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByProperties.java index 62ff729e..b69440f7 100644 --- a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByProperties.java +++ b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByProperties.java @@ -24,8 +24,10 @@ import javax.annotation.Nonnull; -import org.apache.sling.api.resource.ModifiableValueMap; import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ValueMap; + +import de.valtech.aecu.api.groovy.console.bindings.GStringConverter; /** * Filters resources by properties. You can define multiple properties that all need an exact match. @@ -43,12 +45,12 @@ public class FilterByProperties implements FilterBy { * @param conditionProperties list of properties to match (property name, property value) */ public FilterByProperties(@Nonnull Map conditionProperties) { - this.conditionProperties.putAll(conditionProperties); + this.conditionProperties.putAll(GStringConverter.convert(conditionProperties)); } @Override public boolean filter(@Nonnull Resource resource, StringBuilder output) { - ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class); + ValueMap properties = resource.getValueMap(); if (properties == null) { output.append("WARNING: Could not get ModifiableValueMap of resource " + resource.getPath()); return false; diff --git a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByProperty.java b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByProperty.java index 121f0fe6..86c5dbe4 100644 --- a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByProperty.java +++ b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByProperty.java @@ -23,6 +23,8 @@ import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ValueMap; +import de.valtech.aecu.api.groovy.console.bindings.GStringConverter; + /** * Filters resources by a given property. The filter only matches if the attribute exists and has * the exact given value. @@ -42,7 +44,7 @@ public class FilterByProperty implements FilterBy { */ public FilterByProperty(@Nonnull String name, Object value) { this.name = name; - this.value = value; + this.value = GStringConverter.convert(value); } @Override 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 067546ac..c2e153f1 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.3.0") +@Version("4.4.0") package de.valtech.aecu.api.groovy.console.bindings; import org.osgi.annotation.versioning.Version; diff --git a/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByPropertiesTest.java b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByPropertiesTest.java new file mode 100644 index 00000000..7a5443cb --- /dev/null +++ b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByPropertiesTest.java @@ -0,0 +1,123 @@ +/* + * 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.filters; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ValueMap; +import org.codehaus.groovy.runtime.GStringImpl; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByProperties; +import groovy.lang.GString; + +/** + * Tests FilterByProperties + * + * @author Roland Gruber + */ +@RunWith(MockitoJUnitRunner.class) +public class FilterByPropertiesTest { + + private static final String NAME1 = "name"; + private static final String VALUE1 = "value"; + private static final String NAME2 = "name2"; + private static final String VALUE2 = "value2"; + private static final String NAME3 = "name3"; + private static final GString VALUE_G = new GStringImpl(new Object[] {2}, new String[] {"value"}); + + @Mock + private Resource resource; + + @Mock + ValueMap values; + + @Before + public void setup() { + when(resource.getValueMap()).thenReturn(values); + when(values.get(NAME1)).thenReturn(VALUE1); + when(values.get(NAME2)).thenReturn(VALUE2); + } + + @Test + public void filterAttributeNullValueNull() { + Map filterMap = new HashMap<>(); + filterMap.put(NAME3, null); + FilterByProperties filter = new FilterByProperties(filterMap); + + assertTrue(filter.filter(resource, new StringBuilder())); + } + + @Test + public void filterAttributeNullValueNonNull() { + Map filterMap = new HashMap<>(); + filterMap.put(NAME1, null); + FilterByProperties filter = new FilterByProperties(filterMap); + + assertFalse(filter.filter(resource, new StringBuilder())); + } + + @Test + public void filterAttributeNonNullValueNull() { + Map filterMap = new HashMap<>(); + filterMap.put(NAME3, VALUE1); + FilterByProperties filter = new FilterByProperties(filterMap); + + assertFalse(filter.filter(resource, new StringBuilder())); + } + + @Test + public void filterAttributeNonNullValueNonNull() { + Map filterMap = new HashMap<>(); + filterMap.put(NAME1, VALUE1); + FilterByProperties filter = new FilterByProperties(filterMap); + + assertTrue(filter.filter(resource, new StringBuilder())); + } + + @Test + public void filterAttributeNonNullValueMulti() { + Map filterMap = new HashMap<>(); + filterMap.put(NAME1, VALUE1); + filterMap.put(NAME2, VALUE2); + FilterByProperties filter = new FilterByProperties(filterMap); + + assertTrue(filter.filter(resource, new StringBuilder())); + } + + @Test + public void filterAttributeGString() { + Map filterMap = new HashMap<>(); + filterMap.put(NAME2, VALUE_G); + FilterByProperties filter = new FilterByProperties(filterMap); + + assertTrue(filter.filter(resource, new StringBuilder())); + } + +} diff --git a/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByPropertyTest.java b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByPropertyTest.java index d944c6e7..3f8e3f82 100644 --- a/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByPropertyTest.java +++ b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByPropertyTest.java @@ -24,6 +24,7 @@ import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ValueMap; +import org.codehaus.groovy.runtime.GStringImpl; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -31,6 +32,7 @@ import org.mockito.junit.MockitoJUnitRunner; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByProperty; +import groovy.lang.GString; /** * Tests FilterByProperty @@ -42,6 +44,7 @@ public class FilterByPropertyTest { private static final String NAME = "name"; private static final String VALUE = "value"; + private static final GString VALUE_G = new GStringImpl(new Object[] {3}, new String[] {"value"}); @Mock private Resource resource; @@ -86,4 +89,12 @@ public void filterAttributeNonNullValueNonNull() { assertTrue(filter.filter(resource, new StringBuilder())); } + @Test + public void filterAttributeGString() { + FilterByProperty filter = new FilterByProperty(NAME, VALUE_G); + when(values.get(NAME)).thenReturn(VALUE + "3"); + + assertTrue(filter.filter(resource, new StringBuilder())); + } + } diff --git a/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/TestFilters.java b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/TestFilters.java index 7595644b..b39447e7 100644 --- a/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/TestFilters.java +++ b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/TestFilters.java @@ -29,7 +29,6 @@ import java.util.LinkedHashMap; import java.util.Map; -import org.apache.sling.api.resource.ModifiableValueMap; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ValueMap; import org.apache.sling.api.wrappers.ValueMapDecorator; @@ -37,8 +36,6 @@ import org.junit.Test; import org.mockito.Mockito; -import com.adobe.granite.rest.utils.ModifiableMappedValueMapDecorator; - import de.valtech.aecu.api.groovy.console.bindings.filters.ANDFilter; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterBy; import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByMultiValuePropContains; @@ -297,7 +294,7 @@ private void testWithOneProp(Resource resource, String propName, Object propValu private Resource getMockResourceWithNameAndProperties(String name, Map proeprties) { Resource resourceMock = Mockito.mock(Resource.class); when(resourceMock.getName()).thenReturn(name); - when(resourceMock.adaptTo(ModifiableValueMap.class)).thenReturn(new ModifiableMappedValueMapDecorator(proeprties)); + when(resourceMock.getValueMap()).thenReturn(new ValueMapDecorator(proeprties)); when(resourceMock.adaptTo(ValueMap.class)).thenReturn(new ValueMapDecorator(proeprties)); return resourceMock; } diff --git a/bundle/pom.xml b/bundle/pom.xml index 106f22d3..fbca12d5 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.3.1-SNAPSHOT + 4.0.0-SNAPSHOT aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index 4780793c..f51a7581 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 3.3.1-SNAPSHOT + 4.0.0-SNAPSHOT aecu.core diff --git a/examples/pom.xml b/examples/pom.xml index e326db15..97f27856 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.3.1-SNAPSHOT + 4.0.0-SNAPSHOT aecu.examples diff --git a/pom.xml b/pom.xml index 94401741..8dac25d1 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 3.3.1-SNAPSHOT + 4.0.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 fc597300..48946725 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 3.3.1-SNAPSHOT + 4.0.0-SNAPSHOT aecu.ui.apps From 586b472eb70a36492bd2e1393cb23f44e899da8e Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 25 Nov 2020 15:58:48 +0100 Subject: [PATCH 17/25] #140 support GString --- .../console/bindings/GStringConverter.java | 18 +++ .../FilterByMultiValuePropContains.java | 8 +- .../FilterByMultiValuePropContainsTest.java | 106 ++++++++++++++++++ 3 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByMultiValuePropContainsTest.java diff --git a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/GStringConverter.java b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/GStringConverter.java index 54b342d5..547884b5 100644 --- a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/GStringConverter.java +++ b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/GStringConverter.java @@ -1,5 +1,6 @@ package de.valtech.aecu.api.groovy.console.bindings; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -48,4 +49,21 @@ public static Map convert(Map input) { return output; } + /** + * Converts the input in case it is a GString. + * + * @param input input + * @return converted value + */ + public static Object[] convert(Object[] input) { + if (input == null) { + return input; + } + Object[] output = Arrays.copyOf(input, input.length); + for (int i = 0; i < output.length; i++) { + output[i] = convert(output[i]); + } + return output; + } + } diff --git a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByMultiValuePropContains.java b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByMultiValuePropContains.java index 17df269f..639d218f 100644 --- a/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByMultiValuePropContains.java +++ b/api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/filters/FilterByMultiValuePropContains.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, @@ -25,6 +25,8 @@ import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ValueMap; +import de.valtech.aecu.api.groovy.console.bindings.GStringConverter; + /** * Filters resources by multi-value properties. It checks if the given values are contained in the * resource's multi-value field, no exact match. @@ -44,12 +46,12 @@ public class FilterByMultiValuePropContains implements FilterBy { */ public FilterByMultiValuePropContains(@Nonnull String name, @Nonnull Object[] values) { this.name = name; - this.values = values; + this.values = GStringConverter.convert(values); } @Override public boolean filter(@Nonnull Resource resource, StringBuilder output) { - ValueMap properties = resource.adaptTo(ValueMap.class); + ValueMap properties = resource.getValueMap(); if (properties != null) { Object value = properties.get(name); if (value != null && value.getClass().isArray()) { diff --git a/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByMultiValuePropContainsTest.java b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByMultiValuePropContainsTest.java new file mode 100644 index 00000000..47d39b35 --- /dev/null +++ b/api/src/test/java/de/valtech/aecu/core/groovy/console/bindings/filters/FilterByMultiValuePropContainsTest.java @@ -0,0 +1,106 @@ +/* + * 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.filters; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ValueMap; +import org.codehaus.groovy.runtime.GStringImpl; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import de.valtech.aecu.api.groovy.console.bindings.filters.FilterByMultiValuePropContains; +import groovy.lang.GString; + +/** + * Tests FilterByMultiValuePropContains + * + * @author Roland Gruber + * + */ +@RunWith(MockitoJUnitRunner.class) +public class FilterByMultiValuePropContainsTest { + + private static final String NAME1 = "name"; + private static final String VALUE1 = "value"; + private static final String NAME2 = "name2"; + private static final String VALUE2 = "value2"; + private static final String NAME3 = "name3"; + private static final GString VALUE_G = new GStringImpl(new Object[] {2}, new String[] {"value"}); + + @Mock + private Resource resource; + + @Mock + ValueMap values; + + @Before + public void setup() { + when(resource.getValueMap()).thenReturn(values); + when(values.get(NAME1)).thenReturn(new Object[] {VALUE1, VALUE2}); + when(values.get(NAME2)).thenReturn(new Object[] {VALUE2}); + } + + @Test + public void filterAttributeNull_filterValueEmpty() { + Object[] filterAttributes = new Object[0]; + FilterByMultiValuePropContains filter = new FilterByMultiValuePropContains(NAME1, filterAttributes); + + assertTrue(filter.filter(resource, new StringBuilder())); + } + + @Test + public void filterAttributeNull_filterValueNonNull() { + Object[] filterAttributes = new Object[] {VALUE1}; + FilterByMultiValuePropContains filter = new FilterByMultiValuePropContains(NAME3, filterAttributes); + + assertFalse(filter.filter(resource, new StringBuilder())); + } + + @Test + public void filterAttributeNonNull_filterValueNonNull() { + Object[] filterAttributes = new Object[] {VALUE1}; + FilterByMultiValuePropContains filter = new FilterByMultiValuePropContains(NAME1, filterAttributes); + + assertTrue(filter.filter(resource, new StringBuilder())); + } + + @Test + public void filterAttributeNonNull_filterValueMulti() { + Object[] filterAttributes = new Object[] {VALUE1, VALUE2}; + FilterByMultiValuePropContains filter = new FilterByMultiValuePropContains(NAME1, filterAttributes); + + assertTrue(filter.filter(resource, new StringBuilder())); + } + + @Test + public void filterAttributeGString() { + Object[] filterAttributes = new Object[] {VALUE_G}; + FilterByMultiValuePropContains filter = new FilterByMultiValuePropContains(NAME2, filterAttributes); + + assertTrue(filter.filter(resource, new StringBuilder())); + } + +} From 233d4639c3e04dd9da70cb40654fde92b26989c0 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 25 Nov 2020 16:10:52 +0100 Subject: [PATCH 18/25] #140 support GString --- .../bindings/actions/properties/SetProperty.java | 12 +++++++----- .../actions/properties/SetPropertyTest.java | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/properties/SetProperty.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/properties/SetProperty.java index 8083849b..64914dda 100644 --- a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/properties/SetProperty.java +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/properties/SetProperty.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,12 +18,13 @@ */ package de.valtech.aecu.core.groovy.console.bindings.actions.properties; -import de.valtech.aecu.core.groovy.console.bindings.actions.Action; +import javax.annotation.Nonnull; import org.apache.sling.api.resource.ModifiableValueMap; import org.apache.sling.api.resource.Resource; -import javax.annotation.Nonnull; +import de.valtech.aecu.api.groovy.console.bindings.GStringConverter; +import de.valtech.aecu.core.groovy.console.bindings.actions.Action; /** * @author Roxana Muresan @@ -35,7 +36,7 @@ public class SetProperty implements Action { public SetProperty(@Nonnull String name, Object value) { this.name = name; - this.value = value; + this.value = GStringConverter.convert(value); } @Override @@ -43,7 +44,8 @@ public String doAction(@Nonnull Resource resource) { ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class); if (properties != null) { properties.put(name, value); - return "Setting " + value.getClass().getSimpleName() + " property " + name + "=" + value + " for resource " + resource.getPath(); + return "Setting " + value.getClass().getSimpleName() + " property " + name + "=" + value + " for resource " + + resource.getPath(); } return "WARNING: could not get ModifiableValueMap for resource " + resource.getPath(); } diff --git a/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/properties/SetPropertyTest.java b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/properties/SetPropertyTest.java index 7c29bf0b..d7b25255 100644 --- a/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/properties/SetPropertyTest.java +++ b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/properties/SetPropertyTest.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,12 +25,15 @@ import org.apache.sling.api.resource.ModifiableValueMap; import org.apache.sling.api.resource.PersistenceException; import org.apache.sling.api.resource.Resource; +import org.codehaus.groovy.runtime.GStringImpl; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import groovy.lang.GString; + /** * Tests SetProperty * @@ -43,6 +46,8 @@ public class SetPropertyTest { private static final String ATTR = "attr"; + private static final GString VALUE_G = new GStringImpl(new Object[] {1}, new String[] {"val"}); + @Mock private Resource resource; @@ -63,4 +68,13 @@ public void doAction() throws PersistenceException { verify(valueMap, times(1)).put(ATTR, VAL1); } + @Test + public void doAction_gString() throws PersistenceException { + SetProperty action = new SetProperty(ATTR, VALUE_G); + + action.doAction(resource); + + verify(valueMap, times(1)).put(ATTR, VAL1); + } + } From b80a840427ddaae414f223bc6af09f203960277a Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 25 Nov 2020 16:22:53 +0100 Subject: [PATCH 19/25] #140 support GString --- .../actions/properties/JoinProperty.java | 3 ++- .../actions/properties/JoinPropertyTest.java | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/properties/JoinProperty.java b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/properties/JoinProperty.java index a1405e3c..7e98936c 100644 --- a/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/properties/JoinProperty.java +++ b/core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/actions/properties/JoinProperty.java @@ -27,6 +27,7 @@ import org.apache.sling.api.resource.PersistenceException; import org.apache.sling.api.resource.Resource; +import de.valtech.aecu.api.groovy.console.bindings.GStringConverter; import de.valtech.aecu.core.groovy.console.bindings.actions.Action; /** @@ -69,7 +70,7 @@ public JoinProperty(@Nonnull String name, Object emptyValue) { public JoinProperty(@Nonnull String name, Object emptyValue, @Nonnull String separator) { this.name = name; this.separator = separator; - this.emptyValue = emptyValue; + this.emptyValue = GStringConverter.convert(emptyValue); } @Override diff --git a/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/properties/JoinPropertyTest.java b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/properties/JoinPropertyTest.java index f4ce28f6..a1e42b13 100644 --- a/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/properties/JoinPropertyTest.java +++ b/core/src/test/java/de/valtech/aecu/core/groovy/console/bindings/actions/properties/JoinPropertyTest.java @@ -36,12 +36,15 @@ import org.apache.sling.api.resource.ModifiableValueMap; import org.apache.sling.api.resource.PersistenceException; import org.apache.sling.api.resource.Resource; +import org.codehaus.groovy.runtime.GStringImpl; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import groovy.lang.GString; + /** * Tests JoinProperty * @@ -52,6 +55,7 @@ public class JoinPropertyTest { private static final String VAL1 = "val1"; private static final String EMPTY_VALUE = "emptyValue"; + private static final GString EMPTY_VALUE_G = new GStringImpl(new Object[] {"Value"}, new String[] {"empty"}); private static final String ATTR = "attr"; public static final String SEPARATOR = ";|;"; @@ -124,6 +128,19 @@ public void doActionReplaceEmptyArray() throws PersistenceException { verify(valueMap, times(1)).put(ATTR, EMPTY_VALUE); } + @Test + public void doActionReplaceEmptyArrayGString() throws PersistenceException { + // setup test resource + when(valueMap.containsKey(ATTR)).thenReturn(true); + when(valueMap.get(ATTR)).thenReturn(new Boolean[] {}); + + JoinProperty action = new JoinProperty(ATTR, EMPTY_VALUE_G); + action.doAction(resource); + + verify(valueMap, times(1)).remove(ATTR); + verify(valueMap, times(1)).put(ATTR, EMPTY_VALUE); + } + @Test public void doActionNoArgs() throws PersistenceException { // setup test resource From 1bcd17e90c8a3629919e10b1ebc7c0ad0bbfde99 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Thu, 26 Nov 2020 13:24:11 +0100 Subject: [PATCH 20/25] #140 support GString --- .../actions/resource/CreateResource.java | 11 +++++----- .../actions/resource/CreateResourceTest.java | 22 ++++++++++++++++++- 2 files changed, 27 insertions(+), 6 deletions(-) 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 6842a2af..536aa527 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,16 +18,17 @@ */ package de.valtech.aecu.core.groovy.console.bindings.actions.resource; -import de.valtech.aecu.core.groovy.console.bindings.actions.Action; +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 java.util.Map; - -import javax.annotation.Nonnull; +import de.valtech.aecu.api.groovy.console.bindings.GStringConverter; +import de.valtech.aecu.core.groovy.console.bindings.actions.Action; /** * Creates a new node @@ -44,7 +45,7 @@ public class CreateResource implements Action { public CreateResource(@Nonnull String name, @Nonnull Map properties, String relativePath, @Nonnull ResourceResolver resourceResolver) { this.name = name; - this.properties = properties; + this.properties = GStringConverter.convert(properties); this.relativePath = relativePath; this.resourceResolver = resourceResolver; } 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 index 7446513b..51ecc9c5 100644 --- 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 @@ -35,12 +35,15 @@ import org.apache.sling.api.resource.PersistenceException; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; +import org.codehaus.groovy.runtime.GStringImpl; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import groovy.lang.GString; + /** * Tests CreateResource * @@ -49,6 +52,11 @@ @RunWith(MockitoJUnitRunner.class) public class CreateResourceTest { + private static final String NT_UNSTRUCTURED = "nt:unstructured"; + private static final GString NT_UNSTRUCTURED_G = new GStringImpl(new Object[] {"unstructured"}, new String[] {"nt:"}); + + private static final String JCR_PRIMARY_TYPE = "jcr:primaryType"; + private static final String INTERMEDIATE = "intermediate"; private static final String NEW_NAME = "newName"; @@ -71,7 +79,7 @@ public class CreateResourceTest { 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"); + properties.put(JCR_PRIMARY_TYPE, NT_UNSTRUCTURED); when(resolver.create(resource, NEW_NAME, properties)).thenReturn(newResource); when(resolver.create(intermediateResource, NEW_NAME, properties)).thenReturn(newResource); } @@ -96,4 +104,16 @@ public void doAction_Relative() throws PersistenceException, ItemExistsException verify(resolver, times(1)).create(intermediateResource, NEW_NAME, properties); } + @Test + public void doAction_noRelativeGString() throws PersistenceException, ItemExistsException, PathNotFoundException, + VersionException, ConstraintViolationException, LockException, RepositoryException { + Map propertiesInput = new HashMap<>(properties); + propertiesInput.put(JCR_PRIMARY_TYPE, NT_UNSTRUCTURED_G); + CreateResource action = new CreateResource(NEW_NAME, propertiesInput, null, resolver); + + action.doAction(resource); + + verify(resolver, times(1)).create(resource, NEW_NAME, properties); + } + } From 4b153e7d0f53f9705424a124719f145386cc7a06 Mon Sep 17 00:00:00 2001 From: gruberrolandvaltech <39398496+gruberrolandvaltech@users.noreply.github.com> Date: Thu, 26 Nov 2020 13:27:49 +0100 Subject: [PATCH 21/25] Create codeql-analysis.yml --- .github/workflows/codeql-analysis.yml | 67 +++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 00000000..8c880f21 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,67 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ develop, gh-pages, master ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ develop ] + schedule: + - cron: '41 1 * * 6' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + language: [ 'java', 'javascript' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more: + # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # 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 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 From 253e1c3b76e2d62eb6227feaba9dcd713abd0c79 Mon Sep 17 00:00:00 2001 From: gruberrolandvaltech <39398496+gruberrolandvaltech@users.noreply.github.com> Date: Thu, 26 Nov 2020 13:31:38 +0100 Subject: [PATCH 22/25] Create SECURITY.md --- SECURITY.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 00000000..85f97961 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,5 @@ +# Security Policy + +## Reporting a Vulnerability + +Please create an issue and provide details like the attack vector or examples for exploitation. From f45279aac49a746855dfda65f2264243f3266e89 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 21 Dec 2020 08:05:17 +0100 Subject: [PATCH 23/25] 4.0.0 --- HISTORY | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/HISTORY b/HISTORY index 70fa5d29..8d8f55a8 100644 --- a/HISTORY +++ b/HISTORY @@ -1,6 +1,7 @@ -4.0.0 - - Update to Groovy Console 16 and require AEM 6.5 +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 + - Convert GString values in binding methods (#140) 2020-10-07 3.3.0 - Allow to change primary type From b7903dd6f9b56aa488c6ac8b6375bca516a142bc Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 21 Dec 2020 08:06:20 +0100 Subject: [PATCH 24/25] updating poms for 4.0.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 6bab112c..a3997309 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 4.0.0-SNAPSHOT + 4.0.0-rc-SNAPSHOT aecu.api diff --git a/bundle/pom.xml b/bundle/pom.xml index fbca12d5..279f8929 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.0.0-SNAPSHOT + 4.0.0-rc-SNAPSHOT aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index f51a7581..4df0977d 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 4.0.0-SNAPSHOT + 4.0.0-rc-SNAPSHOT aecu.core diff --git a/examples/pom.xml b/examples/pom.xml index 97f27856..53fce5bb 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.0.0-SNAPSHOT + 4.0.0-rc-SNAPSHOT aecu.examples diff --git a/pom.xml b/pom.xml index 8dac25d1..1a6eedd1 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 4.0.0-SNAPSHOT + 4.0.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 48946725..027afbcd 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.0-rc-SNAPSHOT aecu.ui.apps From e5dc90ce772a48ad0e86f3e67ae524c564f73333 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 21 Dec 2020 08:06:44 +0100 Subject: [PATCH 25/25] updating poms for branch'release/4.0.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 a3997309..69b12203 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 4.0.0-rc-SNAPSHOT + 4.0.0 aecu.api diff --git a/bundle/pom.xml b/bundle/pom.xml index 279f8929..1cdcc80a 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.0.0-rc-SNAPSHOT + 4.0.0 aecu.bundle diff --git a/core/pom.xml b/core/pom.xml index 4df0977d..07294c1a 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu - 4.0.0-rc-SNAPSHOT + 4.0.0 aecu.core diff --git a/examples/pom.xml b/examples/pom.xml index 53fce5bb..54d98f96 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.0.0-rc-SNAPSHOT + 4.0.0 aecu.examples diff --git a/pom.xml b/pom.xml index 1a6eedd1..fb5f8e61 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ de.valtech.aecu aecu pom - 4.0.0-rc-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 027afbcd..c9248268 100644 --- a/ui.apps/pom.xml +++ b/ui.apps/pom.xml @@ -5,7 +5,7 @@ de.valtech.aecu aecu - 4.0.0-rc-SNAPSHOT + 4.0.0 aecu.ui.apps