Skip to content

Commit dce5302

Browse files
committed
Merge branch 'release/6.4.0'
2 parents 7772c2a + 6b47346 commit dce5302

File tree

24 files changed

+376
-31
lines changed

24 files changed

+376
-31
lines changed

HISTORY

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
2023-02-23 6.2.1
1+
2023-03-20 6.4.0
2+
- Resource Action: New actions to add / remove mixins (#209)
3+
- AEMaaCS doesn't start AECU Migration, due to wrong check in AecuCloudStartupService (#210)
4+
5+
2023-02-23 6.3.0
26
- Upgrade of Orbinson Groovy Console to version 19.0.3 (#205, #208)
37
- New filter method: filterByNodeRootPaths() (#204)
48
- AecuService: added new execute(String path, String data) method which accepts a JSON data string to be used within scipts (#204)

Readme.md

+15
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,21 @@ aecu.contentUpgradeBuilder()
512512
.run()
513513
```
514514

515+
#### Update Mixins
516+
517+
* doAddMixin(String mixinName): adds a mixin to a node if the mixin is valid
518+
* doRemoveMixin(String mixinName): removes a mixin from a node if the mixin is present
519+
520+
```java
521+
aecu.contentUpgradeBuilder()
522+
.forChildResourcesOf("/content/we-retail/ca/en")
523+
.filterByNodeName("jcr:content")
524+
.doAddMixin("mix:versionable")
525+
.doAddMixin("mix:mymixin")
526+
.doRemoveMixin("mix:lockable")
527+
.run()
528+
```
529+
515530
#### Copy and Move Properties
516531

517532
This will copy or move a property to a subnode. You can also change the property name.

api/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>de.valtech.aecu</groupId>
66
<artifactId>aecu</artifactId>
7-
<version>6.3.0</version>
7+
<version>6.4.0</version>
88
</parent>
99

1010
<artifactId>aecu.api</artifactId>

api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/ContentUpgrade.java

+17
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,23 @@ public interface ContentUpgrade {
704704
*/
705705
ContentUpgrade doCheckPageRendering(String textPresent, String textNotPresent);
706706

707+
708+
/**
709+
* Adds a mixin
710+
*
711+
* @param mixinName valid mixin name
712+
* @return upgrade object
713+
*/
714+
ContentUpgrade doAddMixin(String mixinName);
715+
716+
/**
717+
* Removes a mixin
718+
*
719+
* @param mixinName valid mixin name present on the node
720+
* @return upgrade object
721+
*/
722+
ContentUpgrade doRemoveMixin(String mixinName);
723+
707724
/**
708725
* Print path
709726
*

api/src/main/java/de/valtech/aecu/api/groovy/console/bindings/package-info.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
* @author Roxana Muresan
2424
*/
25-
@Version("4.9.0")
25+
@Version("4.10.0")
2626
package de.valtech.aecu.api.groovy.console.bindings;
2727

2828
import org.osgi.annotation.versioning.Version;

cloud.startup.hook/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>de.valtech.aecu</groupId>
66
<artifactId>aecu</artifactId>
7-
<version>6.3.0</version>
7+
<version>6.4.0</version>
88
</parent>
99

1010
<artifactId>aecu.cloud.startup.hook</artifactId>

cloud.startup.hook/src/main/java/de/valtech/aecu/startuphook/AecuCloudStartupService.java

+20-15
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@
1818
*/
1919
package de.valtech.aecu.startuphook;
2020

21+
import de.valtech.aecu.api.service.AecuException;
22+
import de.valtech.aecu.api.service.AecuService;
23+
import de.valtech.aecu.api.service.HistoryEntry;
24+
import de.valtech.aecu.api.service.HistoryEntry.STATE;
25+
import java.util.Arrays;
2126
import java.util.Collection;
2227
import java.util.Date;
2328
import java.util.List;
24-
2529
import javax.jcr.Session;
26-
2730
import org.apache.sling.api.resource.LoginException;
2831
import org.apache.sling.api.resource.ResourceResolver;
2932
import org.osgi.framework.Bundle;
30-
import org.osgi.framework.FrameworkUtil;
33+
import org.osgi.framework.BundleContext;
3134
import org.osgi.service.component.annotations.Activate;
3235
import org.osgi.service.component.annotations.Component;
3336
import org.osgi.service.component.annotations.Reference;
@@ -38,19 +41,13 @@
3841
import org.slf4j.Logger;
3942
import org.slf4j.LoggerFactory;
4043

41-
import be.orbinson.aem.groovy.console.api.BindingExtensionProvider;
42-
43-
import de.valtech.aecu.api.service.AecuException;
44-
import de.valtech.aecu.api.service.AecuService;
45-
import de.valtech.aecu.api.service.HistoryEntry;
46-
import de.valtech.aecu.api.service.HistoryEntry.STATE;
47-
4844
/**
4945
* Service that executes the AECU migration if the node store type is composite (AEM Cloud).
5046
*/
5147
@Component(service = AecuCloudStartupService.class, immediate = true, name = "AECU cloud startup hook")
5248
public class AecuCloudStartupService {
5349

50+
private static final String GROOVY_CONSOLE_BUNDLE_SYMBOLIC_NAME = "aem-groovy-console-bundle";
5451
private static final String STAR_IMPORT_EXTENSION_PROVIDER = "StarImportExtensionProvider";
5552
private static final String BINDING_EXTENSION_PROVIDER = "BindingExtensionProvider";
5653
private static final String DEFAULT_EXTENSION_SERVICE =
@@ -70,8 +67,11 @@ public class AecuCloudStartupService {
7067
@Reference
7168
private ServiceComponentRuntime serviceComponentRuntime;
7269

70+
private BundleContext bundleContext;
71+
7372
@Activate
74-
public void activate() {
73+
public void activate(final BundleContext bundleContext) {
74+
this.bundleContext = bundleContext;
7575
Runnable runnable = this::checkAndRunMigration;
7676
Thread thread = new Thread(runnable);
7777
thread.start();
@@ -101,7 +101,7 @@ protected void checkAndRunMigration() {
101101
/**
102102
* Checks if an AECU migration is already in progress. If AECU history tells migration is in
103103
* progress then wait max. for MIGRATION_TIMEOUT.
104-
*
104+
*
105105
* @return migration in progress
106106
*/
107107
protected boolean isMigrationInProgress() {
@@ -121,7 +121,7 @@ protected boolean isMigrationInProgress() {
121121

122122
/**
123123
* Waits till Groovy Console took up our services.
124-
*
124+
*
125125
* @return services are ok
126126
* @throws InterruptedException sleep failed
127127
*/
@@ -140,7 +140,12 @@ protected boolean waitForServices() throws InterruptedException {
140140
* Checks if our services are already injected.
141141
*/
142142
private boolean servicesAreOk() {
143-
Bundle bundle = FrameworkUtil.getBundle(BindingExtensionProvider.class);
143+
Bundle bundle = Arrays.stream(bundleContext.getBundles())
144+
.filter(b -> GROOVY_CONSOLE_BUNDLE_SYMBOLIC_NAME.equals(b.getSymbolicName()))
145+
.findFirst().orElse(null);
146+
if (bundle == null) {
147+
return false;
148+
}
144149
ComponentDescriptionDTO componentDescription =
145150
serviceComponentRuntime.getComponentDescriptionDTO(bundle, DEFAULT_EXTENSION_SERVICE);
146151
if ((componentDescription == null) || !serviceComponentRuntime.isComponentEnabled(componentDescription)) {
@@ -176,7 +181,7 @@ void startAecuMigration() {
176181

177182
/**
178183
* Returns the resource resolver to be used
179-
*
184+
*
180185
* @return the resource resolver
181186
*/
182187
private ResourceResolver getResourceResolver() {

complete-cloud/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>de.valtech.aecu</groupId>
77
<artifactId>aecu</artifactId>
8-
<version>6.3.0</version>
8+
<version>6.4.0</version>
99
</parent>
1010

1111
<artifactId>aecu.complete.cloud</artifactId>

complete/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>de.valtech.aecu</groupId>
77
<artifactId>aecu</artifactId>
8-
<version>6.3.0</version>
8+
<version>6.4.0</version>
99
</parent>
1010

1111
<artifactId>aecu.complete</artifactId>

core/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>de.valtech.aecu</groupId>
66
<artifactId>aecu</artifactId>
7-
<version>6.3.0</version>
7+
<version>6.4.0</version>
88
</parent>
99

1010
<artifactId>aecu.core</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package de.valtech.aecu.core.groovy.console.bindings.actions.resource;
2+
3+
import de.valtech.aecu.core.groovy.console.bindings.actions.Action;
4+
import de.valtech.aecu.core.groovy.console.bindings.actions.util.MixinUtil;
5+
import javax.annotation.Nonnull;
6+
import javax.jcr.Node;
7+
import javax.jcr.RepositoryException;
8+
import javax.jcr.nodetype.NoSuchNodeTypeException;
9+
import org.apache.commons.lang3.StringUtils;
10+
import org.apache.sling.api.resource.PersistenceException;
11+
import org.apache.sling.api.resource.Resource;
12+
13+
/**
14+
* Adds a mixin to a resource/node if the mixin exists.
15+
*
16+
* @author Bart Thierens
17+
* @author Eric Manzi
18+
*/
19+
public class AddMixin implements Action {
20+
21+
private final String mixinName;
22+
23+
public AddMixin(String mixinName) {
24+
this.mixinName = mixinName;
25+
}
26+
27+
@Override
28+
public String doAction(@Nonnull Resource resource) throws PersistenceException {
29+
if (StringUtils.isBlank(mixinName)) {
30+
return "WARNING: mixin name is empty";
31+
}
32+
33+
Node node = resource.adaptTo(Node.class);
34+
if (node == null) {
35+
return "WARNING: could not get node for " + resource.getPath();
36+
}
37+
38+
try {
39+
MixinUtil.ensureMixin(node, mixinName);
40+
return String.format("Adding mixin %s to %s", mixinName, resource.getPath());
41+
} catch (NoSuchNodeTypeException nsnte) {
42+
return "WARNING: non-existing mixin: " + mixinName;
43+
}
44+
catch (RepositoryException re) {
45+
throw new PersistenceException("Problem when adding mixin to node", re);
46+
}
47+
}
48+
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package de.valtech.aecu.core.groovy.console.bindings.actions.resource;
2+
3+
import de.valtech.aecu.core.groovy.console.bindings.actions.Action;
4+
import de.valtech.aecu.core.groovy.console.bindings.actions.util.MixinUtil;
5+
import javax.annotation.Nonnull;
6+
import javax.jcr.Node;
7+
import javax.jcr.RepositoryException;
8+
import javax.jcr.nodetype.NoSuchNodeTypeException;
9+
import org.apache.commons.lang3.StringUtils;
10+
import org.apache.sling.api.resource.PersistenceException;
11+
import org.apache.sling.api.resource.Resource;
12+
13+
/**
14+
* Removes a mixin from a resource/node if the mixin is present.
15+
*
16+
* @author Bart Thierens
17+
* @author Eric Manzi
18+
*/
19+
public class RemoveMixin implements Action {
20+
21+
private final String mixinName;
22+
23+
public RemoveMixin(String mixinName) {
24+
this.mixinName = mixinName;
25+
}
26+
27+
@Override
28+
public String doAction(@Nonnull Resource resource) throws PersistenceException {
29+
if (StringUtils.isBlank(mixinName)) {
30+
return "WARNING: mixin name is empty";
31+
}
32+
Node node = resource.adaptTo(Node.class);
33+
if (node == null) {
34+
return "WARNING: could not get node for " + resource.getPath();
35+
}
36+
37+
try {
38+
if (MixinUtil.hasMixin(node, mixinName)) {
39+
node.removeMixin(mixinName);
40+
return String.format("Removing mixin %s from %s", mixinName, resource.getPath());
41+
}
42+
return String.format("No mixin %s present on %s", mixinName, resource.getPath());
43+
} catch (NoSuchNodeTypeException nsnte) {
44+
return "WARNING: non-existing mixin: " + mixinName;
45+
} catch (RepositoryException re) {
46+
throw new PersistenceException("Problem when removing mixin from node", re);
47+
}
48+
}
49+
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package de.valtech.aecu.core.groovy.console.bindings.actions.util;
2+
3+
import java.util.Arrays;
4+
import javax.annotation.Nonnull;
5+
import javax.jcr.Node;
6+
import javax.jcr.RepositoryException;
7+
8+
/**
9+
* Utility class for mixin related actions
10+
*
11+
* @author Bart Thierens
12+
*/
13+
public class MixinUtil {
14+
15+
private MixinUtil() {
16+
throw new UnsupportedOperationException("Cannot instantiate MixinUtil");
17+
}
18+
19+
/**
20+
* Checks if a mixin is present on a node
21+
* @param node the non-null node to check
22+
* @param mixin the non-null mixin to check (can be a non-existing mixin type)
23+
* @return true if the mixin is present on the node, otherwise false
24+
* @throws RepositoryException if an exception occurs while performing repository operations
25+
*/
26+
public static boolean hasMixin(@Nonnull Node node, @Nonnull String mixin) throws RepositoryException {
27+
return Arrays.stream(node.getMixinNodeTypes())
28+
.anyMatch(nodeType -> nodeType.isNodeType(mixin));
29+
}
30+
31+
/**
32+
* Ensures a mixin is set on a node if it wasn't already
33+
* @param node the non-null node to add the mixin to
34+
* @param mixin the non-null mixin to add
35+
* @throws RepositoryException if an exception occurs while performing repository operations
36+
*/
37+
public static void ensureMixin(@Nonnull Node node, @Nonnull String mixin) throws RepositoryException {
38+
if (!hasMixin(node, mixin) && node.canAddMixin(mixin)) {
39+
node.addMixin(mixin);
40+
}
41+
}
42+
43+
}

core/src/main/java/de/valtech/aecu/core/groovy/console/bindings/impl/ContentUpgradeImpl.java

+14
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,15 @@
7474
import de.valtech.aecu.core.groovy.console.bindings.actions.properties.MovePropertyToRelativePath;
7575
import de.valtech.aecu.core.groovy.console.bindings.actions.properties.RenameProperty;
7676
import de.valtech.aecu.core.groovy.console.bindings.actions.properties.SetProperty;
77+
import de.valtech.aecu.core.groovy.console.bindings.actions.resource.AddMixin;
7778
import de.valtech.aecu.core.groovy.console.bindings.actions.resource.ChangePrimaryType;
7879
import de.valtech.aecu.core.groovy.console.bindings.actions.resource.CopyResourceToRelativePath;
7980
import de.valtech.aecu.core.groovy.console.bindings.actions.resource.CreateResource;
8081
import de.valtech.aecu.core.groovy.console.bindings.actions.resource.CustomAction;
8182
import de.valtech.aecu.core.groovy.console.bindings.actions.resource.DeleteResource;
8283
import de.valtech.aecu.core.groovy.console.bindings.actions.resource.MoveResourceToPathRegex;
8384
import de.valtech.aecu.core.groovy.console.bindings.actions.resource.MoveResourceToRelativePath;
85+
import de.valtech.aecu.core.groovy.console.bindings.actions.resource.RemoveMixin;
8486
import de.valtech.aecu.core.groovy.console.bindings.actions.resource.RenameResource;
8587
import de.valtech.aecu.core.groovy.console.bindings.actions.resource.ReorderNode;
8688
import de.valtech.aecu.core.groovy.console.bindings.actions.resource.ReplaceResourcePropertyValues;
@@ -642,6 +644,18 @@ public ContentUpgrade doCheckPageRendering(String textPresent, String textNotPre
642644
return this;
643645
}
644646

647+
@Override
648+
public ContentUpgrade doAddMixin(String mixinName) {
649+
actions.add(new AddMixin(mixinName));
650+
return this;
651+
}
652+
653+
@Override
654+
public ContentUpgrade doRemoveMixin(String mixinName) {
655+
actions.add(new RemoveMixin(mixinName));
656+
return this;
657+
}
658+
645659
@Override
646660
public ContentUpgrade printPath() {
647661
LOG.debug("printPath");

0 commit comments

Comments
 (0)