Skip to content

Commit

Permalink
Merge branch 'release/5.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberrolandvaltech committed Aug 27, 2021
2 parents e5578ac + e21d45a commit d37bb2a
Show file tree
Hide file tree
Showing 21 changed files with 159 additions and 15 deletions.
3 changes: 3 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2021-08-27 5.1.0
- Added doReorderNode() to binding

2021-07-30 5.0.0
- AEM Cloud compatibility improvements (separate package for AEM cloud!)
- Changed packages: no more bundle package, install always "complete" package (includes Groovy Console)
Expand Down
2 changes: 2 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ The matching nodes can be copied/moved to a new location. You can use ".." if yo
* doCopyResourceToRelativePath(String relativePath, String newName): copies the node to the given target path under the new name
* doMoveResourceToRelativePath(String relativePath): moves the node to the given target path
* doMoveResourceToPathRegex(String matchPattern, String replacementExpr): moves a resource if its path matches the pattern to the target path obtained by applying the replacement expression. You can use group references such as $1 (hint: "$" needs to be escaped with "\" in Groovy).
* doReorderNode(String nameOfNodeToMove, String newSuccessor) (since AECU 5.1.0): reorders subnode "nameOfNodeToMove" before subnode "newSuccessor". Set "newSuccessor" to null to order at the end.

```java
aecu.contentUpgradeBuilder()
Expand All @@ -512,6 +513,7 @@ aecu.contentUpgradeBuilder()
.doCopyResourceToRelativePath("../subNode", "newName")
.doMoveResourceToRelativePath("../subNode")
.doMoveResourceToPathRegex("/content/we-retail/(\\w+)/(\\w+)/(\\w+)", "/content/somewhere/\$1/and/\$2")
.doReorderNode("toMove", "successor")
.run()
```

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>5.0.0</version>
<version>5.1.0</version>
</parent>

<artifactId>aecu.api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,15 @@ public interface ContentUpgrade {
*/
ContentUpgrade doMoveResourceToPathRegex(String matchPattern, String targetPathExpr);

/**
* Reorders a resource.
*
* @param nameOfNodeToMove entry name to move
* @param newSuccessor entry will be put before this node (null to move at the end)
* @return upgrade object
*/
ContentUpgrade doReorderNode(String nameOfNodeToMove, String newSuccessor);

/**
* Deletes the child resources if supplied. If no children are specified it deletes the resource
* itself.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018 - 2019 Valtech GmbH
* Copyright 2018 - 2021 Valtech GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
Expand All @@ -22,7 +22,7 @@
*
* @author Roxana Muresan
*/
@Version("4.5.0")
@Version("4.6.0")
package de.valtech.aecu.api.groovy.console.bindings;

import org.osgi.annotation.versioning.Version;
2 changes: 1 addition & 1 deletion complete-cloud/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>5.0.0</version>
<version>5.1.0</version>
</parent>

<artifactId>aecu.complete.cloud</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion complete/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>5.0.0</version>
<version>5.1.0</version>
</parent>

<artifactId>aecu.complete</artifactId>
Expand Down
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>5.0.0</version>
<version>5.1.0</version>
</parent>

<artifactId>aecu.core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class CreateAccessValidator extends BaseAccessRightsValidator {
*
* @param group group
* @param resource resource to check
* @param context validation context
* @param checkAccessGranted checks if the access is granted or denied
*/
public CreateAccessValidator(Group group, Resource resource, AccessValidatorContext context, boolean checkAccessGranted) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package de.valtech.aecu.core.groovy.console.bindings.actions.resource;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
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;
import de.valtech.aecu.core.groovy.console.bindings.impl.BindingContext;

/**
* Reorders a subnode of a resource.
*
* @author Roland Gruber
*/
public class ReorderNode implements Action {

protected String nameOfNodeToMove;
protected String newSuccessor;
private BindingContext context;

/**
* Constructor
*
* @param nameOfNodeToMove node to move
* @param newSuccessor new successor node name
* @param context binding context
*/
public ReorderNode(@Nonnull String nameOfNodeToMove, @Nullable String newSuccessor, @Nonnull BindingContext context) {
this.nameOfNodeToMove = nameOfNodeToMove;
this.newSuccessor = newSuccessor;
this.context = context;
}

@Override
public String doAction(@Nonnull Resource resource) throws PersistenceException {
Node node = resource.adaptTo(Node.class);
try {
if (null != node) {
if (!context.isDryRun()) {
node.orderBefore(nameOfNodeToMove, newSuccessor);
}
return "Reordered " + nameOfNodeToMove + " on resource " + resource.getPath();
}
} catch (RepositoryException e) {
throw new PersistenceException("ERROR: could not reorder " + nameOfNodeToMove + " on resource " + resource.getPath(),
e);
}
return "WARNING: could not reorder " + nameOfNodeToMove;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import de.valtech.aecu.core.groovy.console.bindings.actions.resource.MoveResourceToPathRegex;
import de.valtech.aecu.core.groovy.console.bindings.actions.resource.MoveResourceToRelativePath;
import de.valtech.aecu.core.groovy.console.bindings.actions.resource.RenameResource;
import de.valtech.aecu.core.groovy.console.bindings.actions.resource.ReorderNode;
import de.valtech.aecu.core.groovy.console.bindings.actions.resource.ReplaceResourcePropertyValues;
import de.valtech.aecu.core.groovy.console.bindings.actions.resource.ReplaceResourcePropertyValuesRegex;
import de.valtech.aecu.core.groovy.console.bindings.actions.resource.ReplicateResourceAction;
Expand Down Expand Up @@ -365,6 +366,12 @@ public ContentUpgrade doMoveResourceToPathRegex(@Nonnull String matchPattern, @N
return this;
}

@Override
public ContentUpgrade doReorderNode(String nameOfNodeToMove, String newSuccessor) {
actions.add(new ReorderNode(nameOfNodeToMove, newSuccessor, context));
return this;
}

@Override
public ContentUpgrade doDeleteResource(String... children) {
actions.add(new DeleteResource(context.getResolver(), children));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ private List<Resource> resolveResources() {
for (String path : pathsToCheck) {
Resource resource = resolver.getResource(path);
if (resource == null) {
String message = "Unable to resolve path" + path;
String message = "Unable to resolve path " + path;
LOG.warn(message);
warnings.add(message);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package de.valtech.aecu.core.groovy.console.bindings.actions.resource;

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;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import de.valtech.aecu.core.groovy.console.bindings.impl.BindingContext;

/**
* Tests ReorderNode
*
* @author Roland Gruber
*/
@RunWith(MockitoJUnitRunner.class)
public class ReorderNodeTest {

private static final String NODE_TO_MOVE = "toMove";

private static final String NEW_SUCCESSOR = "newSuccessor";

@Mock
private Resource resource;

@Mock
private Node node;

@Mock
private BindingContext context;

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

@Test
public void test_doAction_dryRun() throws RepositoryException, PersistenceException {
when(context.isDryRun()).thenReturn(true);

ReorderNode action = new ReorderNode(NODE_TO_MOVE, NEW_SUCCESSOR, context);
action.doAction(resource);

verify(node, never()).orderBefore(NODE_TO_MOVE, NEW_SUCCESSOR);
}

@Test
public void test_doAction_run() throws RepositoryException, PersistenceException {
when(context.isDryRun()).thenReturn(false);

ReorderNode action = new ReorderNode(NODE_TO_MOVE, NEW_SUCCESSOR, context);
action.doAction(resource);

verify(node, times(1)).orderBefore(NODE_TO_MOVE, NEW_SUCCESSOR);
}

}
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>5.0.0</version>
<version>5.1.0</version>
</parent>

<artifactId>aecu.examples</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion oak.index/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>5.0.0</version>
<version>5.1.0</version>
</parent>

<artifactId>aecu.oak.index</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>de.valtech.aecu</groupId>
<artifactId>aecu</artifactId>
<packaging>pom</packaging>
<version>5.0.0</version>
<version>5.1.0</version>
<name>AECU</name>
<description>AEM Easy Content Upgrade</description>
<url>https://github.com/valtech/aem-easy-content-upgrade</url>
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
sonar.projectKey=aecu
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=AEM Easy Content Upgrade
sonar.projectVersion=4.2.0-SNAPSHOT
sonar.projectVersion=5.0.1-SNAPSHOT

# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
Expand Down
2 changes: 1 addition & 1 deletion ui.apps.groovyconsole/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>5.0.0</version>
<version>5.1.0</version>
</parent>

<artifactId>aecu.ui.apps.groovyconsole</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ui.apps.structure/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>5.0.0</version>
<version>5.1.0</version>
</parent>

<artifactId>aecu.ui.apps.structure</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ui.apps/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>5.0.0</version>
<version>5.1.0</version>
</parent>

<artifactId>aecu.ui.apps</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion ui.content/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>5.0.0</version>
<version>5.1.0</version>
</parent>

<artifactId>aecu.ui.content</artifactId>
Expand Down

0 comments on commit d37bb2a

Please sign in to comment.