Skip to content

Commit

Permalink
Merge branch 'release/6.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
nhirrle committed Mar 20, 2023
2 parents 7772c2a + 6b47346 commit dce5302
Show file tree
Hide file tree
Showing 24 changed files with 376 additions and 31 deletions.
6 changes: 5 additions & 1 deletion HISTORY
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
2023-02-23 6.2.1
2023-03-20 6.4.0
- Resource Action: New actions to add / remove mixins (#209)
- AEMaaCS doesn't start AECU Migration, due to wrong check in AecuCloudStartupService (#210)

2023-02-23 6.3.0
- Upgrade of Orbinson Groovy Console to version 19.0.3 (#205, #208)
- New filter method: filterByNodeRootPaths() (#204)
- AecuService: added new execute(String path, String data) method which accepts a JSON data string to be used within scipts (#204)
Expand Down
15 changes: 15 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,21 @@ aecu.contentUpgradeBuilder()
.run()
```

#### Update Mixins

* doAddMixin(String mixinName): adds a mixin to a node if the mixin is valid
* doRemoveMixin(String mixinName): removes a mixin from a node if the mixin is present

```java
aecu.contentUpgradeBuilder()
.forChildResourcesOf("/content/we-retail/ca/en")
.filterByNodeName("jcr:content")
.doAddMixin("mix:versionable")
.doAddMixin("mix:mymixin")
.doRemoveMixin("mix:lockable")
.run()
```

#### Copy and Move Properties

This will copy or move a property to a subnode. You can also change the property name.
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>6.3.0</version>
<version>6.4.0</version>
</parent>

<artifactId>aecu.api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,23 @@ public interface ContentUpgrade {
*/
ContentUpgrade doCheckPageRendering(String textPresent, String textNotPresent);


/**
* Adds a mixin
*
* @param mixinName valid mixin name
* @return upgrade object
*/
ContentUpgrade doAddMixin(String mixinName);

/**
* Removes a mixin
*
* @param mixinName valid mixin name present on the node
* @return upgrade object
*/
ContentUpgrade doRemoveMixin(String mixinName);

/**
* Print path
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @author Roxana Muresan
*/
@Version("4.9.0")
@Version("4.10.0")
package de.valtech.aecu.api.groovy.console.bindings;

import org.osgi.annotation.versioning.Version;
2 changes: 1 addition & 1 deletion cloud.startup.hook/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>6.3.0</version>
<version>6.4.0</version>
</parent>

<artifactId>aecu.cloud.startup.hook</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@
*/
package de.valtech.aecu.startuphook;

import de.valtech.aecu.api.service.AecuException;
import de.valtech.aecu.api.service.AecuService;
import de.valtech.aecu.api.service.HistoryEntry;
import de.valtech.aecu.api.service.HistoryEntry.STATE;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.jcr.Session;

import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
Expand All @@ -38,19 +41,13 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import be.orbinson.aem.groovy.console.api.BindingExtensionProvider;

import de.valtech.aecu.api.service.AecuException;
import de.valtech.aecu.api.service.AecuService;
import de.valtech.aecu.api.service.HistoryEntry;
import de.valtech.aecu.api.service.HistoryEntry.STATE;

/**
* Service that executes the AECU migration if the node store type is composite (AEM Cloud).
*/
@Component(service = AecuCloudStartupService.class, immediate = true, name = "AECU cloud startup hook")
public class AecuCloudStartupService {

private static final String GROOVY_CONSOLE_BUNDLE_SYMBOLIC_NAME = "aem-groovy-console-bundle";
private static final String STAR_IMPORT_EXTENSION_PROVIDER = "StarImportExtensionProvider";
private static final String BINDING_EXTENSION_PROVIDER = "BindingExtensionProvider";
private static final String DEFAULT_EXTENSION_SERVICE =
Expand All @@ -70,8 +67,11 @@ public class AecuCloudStartupService {
@Reference
private ServiceComponentRuntime serviceComponentRuntime;

private BundleContext bundleContext;

@Activate
public void activate() {
public void activate(final BundleContext bundleContext) {
this.bundleContext = bundleContext;
Runnable runnable = this::checkAndRunMigration;
Thread thread = new Thread(runnable);
thread.start();
Expand Down Expand Up @@ -101,7 +101,7 @@ protected void checkAndRunMigration() {
/**
* Checks if an AECU migration is already in progress. If AECU history tells migration is in
* progress then wait max. for MIGRATION_TIMEOUT.
*
*
* @return migration in progress
*/
protected boolean isMigrationInProgress() {
Expand All @@ -121,7 +121,7 @@ protected boolean isMigrationInProgress() {

/**
* Waits till Groovy Console took up our services.
*
*
* @return services are ok
* @throws InterruptedException sleep failed
*/
Expand All @@ -140,7 +140,12 @@ protected boolean waitForServices() throws InterruptedException {
* Checks if our services are already injected.
*/
private boolean servicesAreOk() {
Bundle bundle = FrameworkUtil.getBundle(BindingExtensionProvider.class);
Bundle bundle = Arrays.stream(bundleContext.getBundles())
.filter(b -> GROOVY_CONSOLE_BUNDLE_SYMBOLIC_NAME.equals(b.getSymbolicName()))
.findFirst().orElse(null);
if (bundle == null) {
return false;
}
ComponentDescriptionDTO componentDescription =
serviceComponentRuntime.getComponentDescriptionDTO(bundle, DEFAULT_EXTENSION_SERVICE);
if ((componentDescription == null) || !serviceComponentRuntime.isComponentEnabled(componentDescription)) {
Expand Down Expand Up @@ -176,7 +181,7 @@ void startAecuMigration() {

/**
* Returns the resource resolver to be used
*
*
* @return the resource resolver
*/
private ResourceResolver getResourceResolver() {
Expand Down
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>6.3.0</version>
<version>6.4.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>6.3.0</version>
<version>6.4.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>6.3.0</version>
<version>6.4.0</version>
</parent>

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

import de.valtech.aecu.core.groovy.console.bindings.actions.Action;
import de.valtech.aecu.core.groovy.console.bindings.actions.util.MixinUtil;
import javax.annotation.Nonnull;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.NoSuchNodeTypeException;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;

/**
* Adds a mixin to a resource/node if the mixin exists.
*
* @author Bart Thierens
* @author Eric Manzi
*/
public class AddMixin implements Action {

private final String mixinName;

public AddMixin(String mixinName) {
this.mixinName = mixinName;
}

@Override
public String doAction(@Nonnull Resource resource) throws PersistenceException {
if (StringUtils.isBlank(mixinName)) {
return "WARNING: mixin name is empty";
}

Node node = resource.adaptTo(Node.class);
if (node == null) {
return "WARNING: could not get node for " + resource.getPath();
}

try {
MixinUtil.ensureMixin(node, mixinName);
return String.format("Adding mixin %s to %s", mixinName, resource.getPath());
} catch (NoSuchNodeTypeException nsnte) {
return "WARNING: non-existing mixin: " + mixinName;
}
catch (RepositoryException re) {
throw new PersistenceException("Problem when adding mixin to node", re);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package de.valtech.aecu.core.groovy.console.bindings.actions.resource;

import de.valtech.aecu.core.groovy.console.bindings.actions.Action;
import de.valtech.aecu.core.groovy.console.bindings.actions.util.MixinUtil;
import javax.annotation.Nonnull;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.NoSuchNodeTypeException;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;

/**
* Removes a mixin from a resource/node if the mixin is present.
*
* @author Bart Thierens
* @author Eric Manzi
*/
public class RemoveMixin implements Action {

private final String mixinName;

public RemoveMixin(String mixinName) {
this.mixinName = mixinName;
}

@Override
public String doAction(@Nonnull Resource resource) throws PersistenceException {
if (StringUtils.isBlank(mixinName)) {
return "WARNING: mixin name is empty";
}
Node node = resource.adaptTo(Node.class);
if (node == null) {
return "WARNING: could not get node for " + resource.getPath();
}

try {
if (MixinUtil.hasMixin(node, mixinName)) {
node.removeMixin(mixinName);
return String.format("Removing mixin %s from %s", mixinName, resource.getPath());
}
return String.format("No mixin %s present on %s", mixinName, resource.getPath());
} catch (NoSuchNodeTypeException nsnte) {
return "WARNING: non-existing mixin: " + mixinName;
} catch (RepositoryException re) {
throw new PersistenceException("Problem when removing mixin from node", re);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package de.valtech.aecu.core.groovy.console.bindings.actions.util;

import java.util.Arrays;
import javax.annotation.Nonnull;
import javax.jcr.Node;
import javax.jcr.RepositoryException;

/**
* Utility class for mixin related actions
*
* @author Bart Thierens
*/
public class MixinUtil {

private MixinUtil() {
throw new UnsupportedOperationException("Cannot instantiate MixinUtil");
}

/**
* Checks if a mixin is present on a node
* @param node the non-null node to check
* @param mixin the non-null mixin to check (can be a non-existing mixin type)
* @return true if the mixin is present on the node, otherwise false
* @throws RepositoryException if an exception occurs while performing repository operations
*/
public static boolean hasMixin(@Nonnull Node node, @Nonnull String mixin) throws RepositoryException {
return Arrays.stream(node.getMixinNodeTypes())
.anyMatch(nodeType -> nodeType.isNodeType(mixin));
}

/**
* Ensures a mixin is set on a node if it wasn't already
* @param node the non-null node to add the mixin to
* @param mixin the non-null mixin to add
* @throws RepositoryException if an exception occurs while performing repository operations
*/
public static void ensureMixin(@Nonnull Node node, @Nonnull String mixin) throws RepositoryException {
if (!hasMixin(node, mixin) && node.canAddMixin(mixin)) {
node.addMixin(mixin);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@
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.AddMixin;
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;
import de.valtech.aecu.core.groovy.console.bindings.actions.resource.DeleteResource;
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.RemoveMixin;
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;
Expand Down Expand Up @@ -642,6 +644,18 @@ public ContentUpgrade doCheckPageRendering(String textPresent, String textNotPre
return this;
}

@Override
public ContentUpgrade doAddMixin(String mixinName) {
actions.add(new AddMixin(mixinName));
return this;
}

@Override
public ContentUpgrade doRemoveMixin(String mixinName) {
actions.add(new RemoveMixin(mixinName));
return this;
}

@Override
public ContentUpgrade printPath() {
LOG.debug("printPath");
Expand Down
Loading

0 comments on commit dce5302

Please sign in to comment.