Skip to content

Commit

Permalink
Merge branch 'release/3.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberrolandvaltech committed Oct 7, 2020
2 parents b11f5d2 + 6a18d29 commit 4fad352
Show file tree
Hide file tree
Showing 33 changed files with 261 additions and 49 deletions.
5 changes: 5 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2020-10-07 3.3.0
- Allow to change primary type
- Documentation and example updates
- Fixed issue with UnsupportedOperationException (#136)

2020-06-30 3.2.0
- Allow to limit access to AECU via group permissions. Attention: This requires configuration for non-admin users.
- Autocomplete added, all AECU methods are listed.
Expand Down
34 changes: 30 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ Table of contents
3. [Group Specification](#test_group_spec)
4. [Tests](#test_list)
5. [Execute Tests](#test_execution)
7. [Limit Access to AECU](#limitAccess)
7. [Security](#security)
1. [Limit Access to AECU](#limitAccess)
2. [Service Users](#serviceUsers)
8. [JMX Interface](#jmx)
9. [Health Checks](#healthchecks)
10. [API Documentation](#api)
Expand All @@ -63,7 +65,7 @@ AECU requires Java 8 and AEM 6.4 or above. For AEM 6.3 please install the last 1

# Installation

You can download the package from [Maven Central](http://repo1.maven.org/maven2/de/valtech/aecu/aecu.ui.apps/) or our [releases section](https://github.com/valtech/aem-easy-content-upgrade/releases). The aecu.ui.apps package will install the AECU software. It requires that you installed [Groovy Console](https://github.com/OlsonDigital/aem-groovy-console) before.
You can download the package from [Maven Central](https://repo1.maven.org/maven2/de/valtech/aecu/aecu.ui.apps/) or our [releases section](https://github.com/valtech/aem-easy-content-upgrade/releases). The aecu.ui.apps package will install the AECU software. It requires that you installed [Groovy Console](https://github.com/OlsonDigital/aem-groovy-console) before.

```xml
<dependency>
Expand All @@ -80,7 +82,7 @@ You can download the package from [Maven Central](http://repo1.maven.org/maven2/
## Bundle Installation

To simplify installation we provide a bundle package that already includes the Groovy Console. This makes sure there are no compatibility issues.
The package is also available on [Maven Central](http://repo1.maven.org/maven2/de/valtech/aecu/aecu.bundle/) or our [releases section](https://github.com/valtech/aem-easy-content-upgrade/releases).
The package is also available on [Maven Central](https://repo1.maven.org/maven2/de/valtech/aecu/aecu.bundle/) or our [releases section](https://github.com/valtech/aem-easy-content-upgrade/releases).

```xml
<dependency>
Expand Down Expand Up @@ -412,6 +414,7 @@ You can replace the content of String properties. This also supports multi-value
* doReplaceValueInProperties(String oldValue, String newValue, String[] propertyNames): replaces the substring "oldValue" with "newValue". Applies to all specified String properties
* doReplaceValueInAllPropertiesRegex(String searchRegex, String replacement): checks if the property value(s) match the search pattern and replaces it with "replacement". Applies to all String properties. You can use group references such as $1 (hint: "$" needs to be escaped with "\" in Groovy).
* doReplaceValueInPropertiesRegex(String searchRegex, String replacement, String[] propertyNames): checks if the property value(s) match the search pattern and replaces it with "replacement". Applies to specified String properties. You can use group references such as $1 (hint: "$" needs to be escaped with "\" in Groovy).
* doChangePrimaryType(String newPrimaryType) (since 3.3.0): changes primary type of the resource to the given primary type

```java
aecu.contentUpgradeBuilder()
Expand All @@ -421,6 +424,7 @@ aecu.contentUpgradeBuilder()
.doReplaceValueInProperties("old", "new", (String[]) ["propertyName1", "propertyName2"])
.doReplaceValueInAllPropertiesRegex("/content/([^/]+)/(.*)", "/content/newSub/\$2")
.doReplaceValueInPropertiesRegex("/content/([^/]+)/(.*)", "/content/newSub/\$2", (String[]) ["propertyName1", "propertyName2"])
.doChangePrimaryType("nt:unstructured")
.run()
```

Expand Down Expand Up @@ -855,9 +859,13 @@ aecu
```


<a name="security"></a>

# Security

<a name="limitAccess"></a>

# Limit Access to AECU (since 3.2)
## Limit Access to AECU (since 3.2)
For production systems it is recommended to limit the access to specific user groups.
This can be done via OSGI configuration. Here you can specify groups for read and execute access.

Expand All @@ -867,6 +875,18 @@ PID for OSGI config: de.valtech.aecu.core.security.AccessValidationService

<img src="docs/images/limitAccess.png">

<a name="serviceUsers"></a>

## Service Users
The following service users are installed by AECU:

| User | Rights | Description |
| ------------- | -------------- | --------- |
| aecu-admin | /: jcr:all | Validation of access rights, JMX executeWithHistory() to store script history |
| aecu-content-migrator | /: jcr:read <br /> /apps: jcr:all <br /> /conf: jcr:all <br /> /content: jcr:all <br /> /etc: jcr:all <br /> /home: jcr:all <br /> /var: jcr:all | Content changes using aecu binding |
| aecu-service | /: jcr:read <br /> /var/aecu: jcr:all | AECU execution history |



<a name="jmx"></a>

Expand All @@ -891,6 +911,12 @@ This will execute the given script or folder. If a folder is specified then all

Parameters:
* Path: file or folder to execute

Sample curl call:

```
curl -u admin:admin 'http://localhost:5902/system/console/jmx/de.valtech%3Atype%3DAECU/op/executeWithHistory/java.lang.String' --data-raw 'Path=/var/groovyconsole/scripts/aecu'
```

## GetHistory

Expand Down
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>3.2.0</version>
<version>3.3.0</version>
</parent>

<artifactId>aecu.api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,14 @@ public interface ContentUpgrade {
*/
ContentUpgrade doReplaceValueInPropertiesRegex(String searchRegex, String replacement, String[] propertyNames);

/**
* Changes jcr:primaryType.
*
* @param newPrimaryType jcr:primaryType value
* @return upgrade object
**/
ContentUpgrade doChangePrimaryType(String newPrimaryType);

/**
* Renames a resource to the given name.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @author Roxana Muresan
*/
@Version("4.2.0")
@Version("4.3.0")
package de.valtech.aecu.api.groovy.console.bindings;

import org.osgi.annotation.versioning.Version;
2 changes: 1 addition & 1 deletion bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>3.2.0</version>
<version>3.3.0</version>
</parent>

<artifactId>aecu.bundle</artifactId>
Expand Down
20 changes: 20 additions & 0 deletions bundle/src/main/content/META-INF/vault/definition/.content.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2012 Adobe Systems Incorporated
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<jcr:root xmlns:vlt="http://www.day.com/jcr/vault/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="vlt:PackageDefinition">
<thumbnail.png/>
</jcr:root>
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>3.2.0</version>
<version>3.3.0</version>
</parent>

<artifactId>aecu.core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package de.valtech.aecu.core.groovy.console.bindings.actions.resource;

import javax.annotation.Nonnull;
import javax.jcr.Node;
import javax.jcr.RepositoryException;

import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;

import de.valtech.aecu.core.groovy.console.bindings.actions.Action;

/**
* Changes the jcr:primaryType of a node.
*
* @author Sajith
*/
public class ChangePrimaryType implements Action {

protected String newPrimaryType;

/**
* Constructor
*
* @param newPrimaryType new type
*/
public ChangePrimaryType(@Nonnull String newPrimaryType) {
this.newPrimaryType = newPrimaryType;
}

@Override
public String doAction(@Nonnull Resource resource) throws PersistenceException {
Node node = resource.adaptTo(Node.class);
try {
if (null != node) {
node.setPrimaryType(newPrimaryType);
return "Updated jcr:primaryType to " + newPrimaryType;
}
} catch (RepositoryException e) {
throw new PersistenceException("ERROR: could not update jcr:primaryType to " + newPrimaryType, e);
}
return "WARNING: could not update jcr:primaryType to " + newPrimaryType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import de.valtech.aecu.core.groovy.console.bindings.actions.properties.MovePropertyToRelativePath;
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.ChangePrimaryType;
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;
Expand Down Expand Up @@ -218,7 +219,7 @@ private void addFilter(@Nonnull FilterBy filter) {
if (this.filter instanceof ANDFilter) {
((ANDFilter) this.filter).addFilter(filter);
}
ANDFilter newFilter = new ANDFilter(Arrays.asList(this.filter, filter));
ANDFilter newFilter = new ANDFilter(new ArrayList<FilterBy>(Arrays.asList(this.filter, filter)));
this.filter = newFilter;
}

Expand Down Expand Up @@ -315,6 +316,12 @@ public ContentUpgrade doReplaceValueInPropertiesRegex(String searchRegex, String
return this;
}

@Override
public ContentUpgrade doChangePrimaryType(@Nonnull String newPrimaryType) {
actions.add(new ChangePrimaryType(newPrimaryType));
return this;
}

@Override
public ContentUpgrade doRename(String newName) {
actions.add(new RenameResource(context.getResolver(), newName));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
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
*
* @author Sajith
*/

@RunWith(MockitoJUnitRunner.class)
public class ChangePrimaryTypeTest {

private static final String newPrimaryType = "nt:unstructured";

@Mock
private Resource resource;

@Mock
private Node node;

@Before
public void setup() {
when(resource.adaptTo(Node.class)).thenReturn(node);
}

@Test
public void test_doAction_setPrimaryType() throws PersistenceException, RepositoryException {
ChangePrimaryType changePrimaryType = new ChangePrimaryType(newPrimaryType);
String result = changePrimaryType.doAction(resource);
verify(node, times(1)).setPrimaryType(newPrimaryType);
assertEquals("Updated jcr:primaryType to " + newPrimaryType, result);
}

@Test
public void test_doAction_nodeIsNull() throws PersistenceException, RepositoryException {
when(resource.adaptTo(Node.class)).thenReturn(null);
ChangePrimaryType changePrimaryType = new ChangePrimaryType(newPrimaryType);
changePrimaryType.doAction(resource);
verify(node, never()).setPrimaryType(newPrimaryType);
}
}
2 changes: 1 addition & 1 deletion examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<version>3.2.0</version>
<version>3.3.0</version>
</parent>

<artifactId>aecu.examples</artifactId>
Expand Down
20 changes: 20 additions & 0 deletions examples/src/main/content/META-INF/vault/definition/.content.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2012 Adobe Systems Incorporated
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<jcr:root xmlns:vlt="http://www.day.com/jcr/vault/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="vlt:PackageDefinition">
<thumbnail.png/>
</jcr:root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def complexFilter = new ORFilter(
[ new FilterByProperty("sling:resourceType", "weretail/components/content/heroimage"),
new ANDFilter( [
new FilterByProperty("sling:resourceType", "weretail/components/content/image"),
new FilterByNodeName("image")
] )
])

aecu.contentUpgradeBuilder()
.forDescendantResourcesOf("/content/we-retail/us/en")
.filterWith(complexFilter)
.printPath()
.run()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
println "Sample script1"
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Scripts with extension ".fallback.groovy" will be executed if the non-fallback script fails
println "Executing fallback script for project1 - script2"
println "Executing fallback script for script2"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
println "Sample script2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// scripts with always flag are executed on each deployment
println "Sample script3"

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 4fad352

Please sign in to comment.