Skip to content

Commit

Permalink
Merge branch 'release/1.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberrolandvaltech committed Sep 28, 2018
2 parents 8a2840d + 5562d82 commit 367c34b
Show file tree
Hide file tree
Showing 29 changed files with 707 additions and 77 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: java
9 changes: 9 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
2018-09-28 1.5.0
- Groovy Console binding:
- Run custom code as binding action (#28)
- Page actions: (de)activate and delete containing page
- Better logging (#25)
- Enhanced health check (#26)
- Fixed bugs:
- Exception in log for history page on AEM 6.4 (#24)

2018-08-29 1.4.0
- Groovy Console extension:
- added filterByProperty()
Expand Down
91 changes: 78 additions & 13 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@ Features:
* Service API
* Health Checks

The tool was presented at [adaptTo() conference in Berlin](https://adapt.to/2018/en/schedule/aem-easy-content-upgrade.html)

Table of contents
1. [Requirements](#requirements)
2. [Installation](#installation)
3. [Execution of Migration Scripts](#execution)
3. [File and Folder Structure](#structure)
4. [Execution of Migration Scripts](#execution)
1. [Install Hook](#installHook)
2. [Manual Execution](#manualExecution)
4. [History of Past Runs](#history)
5. [Extension to Groovy Console](#groovy)
6. [JMX Interface](#jmx)
7. [Health Checks](#healthchecks)
8. [API Documentation](#api)
9. [License](#license)
10. [Changelog](#changelog)
11. [Developers](#developers)
5. [History of Past Runs](#history)
6. [Extension to Groovy Console](#groovy)
7. [JMX Interface](#jmx)
8. [Health Checks](#healthchecks)
9. [API Documentation](#api)
10. [License](#license)
11. [Changelog](#changelog)
12. [Developers](#developers)


<a name="requirements"></a>
Expand Down Expand Up @@ -67,6 +70,25 @@ The package is also available on [Maven Central](http://repo1.maven.org/maven2/d
```


<a name="structure"></a>

# File and Folder Structure

All migration scripts need to be located in /etc/groovyconsole/scripts/aecu. There you can create
an unlimited number of folders and files. E.g. organize your files by project or deployment.
The content of the scripts is plain Groovy code that can be run via [Groovy Console](https://github.com/OlsonDigital/aem-groovy-console).

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

There are just a few naming conventions:

* Run modes: folders can contain run modes to limit the execution to a specific target environment. E.g. some scripts are for author only or for your local dev environment.
* Always selector: if a script name ends with ".always.groovy" then it will be executed by
[install hook](#installHook) on each package installation. There will be no more check if this script
was already executed before.
* Fallback selector: if a script name ends with ".fallback.groovy" then it will be executed only if
the corresponding script failed with an exception. E.g. if there is "script.groovy" and "script.fallback.groovy" then the fallback script only gets executed if "script.groovy" fails.

<a name="execution"></a>

# Execution of Migration Scripts
Expand Down Expand Up @@ -142,7 +164,8 @@ In the collect phase you define which nodes should be checked for a migration.

* forResources(String[] paths): use the given paths without any subnodes
* forChildResourcesOf(String path): use all direct childs of the given path (but no grandchilds)
* forDescendantResourcesOf(String path, boolean includeRootResource): use the whole subtree under this path including or not including the parent root node
* forDescendantResourcesOf(String path): use the whole subtree under this path excluding the parent root node
* forResourcesInSubtree(String path): use the whole subtree under this path including the parent root node

You can call these methods multiple times and combine them. They will be merged together.

Expand All @@ -152,7 +175,8 @@ Example:
println aecu.contentUpgradeBuilder()
.forResources((String[])["/content/we-retail/ca/en"])
.forChildResourcesOf("/content/we-retail/us/en")
.forDescendantResourcesOf("/content/we-retail/us/en/experience", false)
.forDescendantResourcesOf("/content/we-retail/us/en/experience")
.forResourcesInSubtree("/content/we-retail/us/en/experience")
.doSetProperty("name", "value")
.run()
```
Expand Down Expand Up @@ -305,7 +329,7 @@ println aecu.contentUpgradeBuilder()
.run()
```

### Delete nodes
### Delete Nodes

You can delete all nodes that match your collection and filter.

Expand All @@ -319,6 +343,25 @@ println aecu.contentUpgradeBuilder()
.run()
```

### Page Actions

AECU can run actions on the page that contains a filtered resource. This is e.g. helpful if you filter by page resource type.
Please note that there is no check for duplicate actions. If you run a page action for two resources in the same page then the action will be executed twice.

* doActivateContainingPage(): activates the page that contains the current resource
* doDeactivateContainingPage(): deactivates the page that contains the current resource
* doDeleteContainingPage(): deletes the page (incl. subpages) that contains the current resource

```java
println aecu.contentUpgradeBuilder()
.forChildResourcesOf("/content/we-retail/ca/en")
.filterByProperty("sling:resourceType", "weretail/components/structure/page")
.doActivateContainingPage()
.doDeactivateContainingPage()
.doDeleteContainingPage()
.run()
```

### Print Nodes

Sometimes, you only want to print the path of the matched nodes.
Expand All @@ -333,6 +376,28 @@ println aecu.contentUpgradeBuilder()
.run()
```

### Custom Actions

You can also hook in custom code to perform actions on resources. For this "doCustomResourceBasedAction()" can take a Lambda expression.

* doCustomResourceBasedAction(): run your custom code

```java
def myAction = {
resource ->
hasChildren = resource.hasChildren()
String output = resource.path + " has children: "
output += hasChildren ? "yes" : "no"
return output
}

println aecu.contentUpgradeBuilder()
.forChildResourcesOf("/content/we-retail/ca/en")
.doCustomResourceBasedAction(myAction)
.run()
```



## Run Options

Expand All @@ -351,7 +416,7 @@ AECU provides JMX methods for executing scripts and reading the history. You can

## Execute

This will execute the given script or folder. If a folder is specified then all files (incl. any subfolders) are executed. AECU will respect runmodes during execution.
This will execute the given script or folder. If a folder is specified then all files (incl. any subfolders) are executed. AECU will respect run modes during execution.

Parameters:
* Path: file or folder to execute
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>1.4.0</version>
<version>1.5.0</version>
</parent>

<artifactId>aecu.api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,36 @@ public interface ContentUpgrade {
*/
ContentUpgrade doDeleteResource();

/**
* Performs a custom action with providing a function.
*
* @param action action to perform on resource
* @return upgrade object
*/
ContentUpgrade doCustomResourceBasedAction(CustomResourceAction action);

/**
* Activates the page where the resource is located.
*
* @return upgrade object
*/
ContentUpgrade doActivateContainingPage();

/**
* Deactivates the page where the resource is located.
*
* @return upgrade object
*/
ContentUpgrade doDeactivateContainingPage();

/**
* Deletes the page where the resource is located. This will not work if called multiple times
* for the same page.
*
* @return upgrade object
*/
ContentUpgrade doDeleteContainingPage();

/**
* Print path
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2018 Valtech GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package de.valtech.aecu.api.groovy.console.bindings;

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

/**
* Functional interface to define custom action on content upgrade.
*
* @author Roland Gruber
*/
@FunctionalInterface
public interface CustomResourceAction {

/**
* Performs the provided action on the resource.
*
* @param resource resource
* @return log output
*/
String doAction(Resource resource);

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,14 @@ public boolean filter(@Nonnull Resource resource) {
return !foundFalse;

}

/**
* Adds a new filter to the AND condition.
*
* @param filter filter
*/
public void addFilter(@Nonnull FilterBy filter) {
filters.add(filter);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @author Roxana Muresan
*/
@Version("1.0")
@Version("1.1")
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>1.4.0</version>
<version>1.5.0</version>
</parent>

<artifactId>aecu.bundle</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>1.4.0</version>
<version>1.5.0</version>
</parent>

<artifactId>aecu.core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2018 Valtech GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package de.valtech.aecu.core.groovy.console.bindings.actions.page;

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

import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.WCMException;

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

/**
* Deletes the page of a given resource.
*
* @author Roland Gruber
*/
public class DeletePageAction implements Action {

private BindingContext context;

/**
* Constructor
*
* @param context binding context
*/
public DeletePageAction(BindingContext context) {
this.context = context;
}

@Override
public String doAction(Resource resource) throws PersistenceException {
Page page = context.getPageManager().getContainingPage(resource);
if (page == null) {
return "Unable to find a page for resource " + resource.getPath();
}
String successMessage = "Deleted page " + page.getPath();
if (context.isDryRun()) {
return successMessage;
}
try {
context.getPageManager().delete(page, false);
} catch (WCMException e) {
throw new PersistenceException("Unable to delete " + page.getPath());
}
return successMessage;
}

}
Loading

0 comments on commit 367c34b

Please sign in to comment.