April 2, 2020
Estimated Post Reading Time ~

How to Implement Custom CQ Rollout Action

A LiveAction is an action that is executed on each resource that is involved in the rollout. A rollout is an operation that copies the contents from the blueprint to its livecopies.

CQ supplies out of the box rollout configs live contentUpdate, contentCopy, contentDelete, referencesUpdate, orderChildren, markLiveRelationship etc.

Create the Example Rollout Configuration and edit rollout config

Create the MSM rollout configuration that uses the LiveAction that you are going to create.
In your web browser, open the Tools console. (http://localhost:4502/miscadmin#/etc)
Select the Tools/MSM/Rollout Configurations folder and click New > New Page and provide values for the Rollout Configuration properties:

Title: Example Rollout Configuration
Name: examplerolloutconfig
Select RolloutConfig Template.
Click Create.
Then

Open the rollout configuration that is created and then click Edit.
In the Rollout Config dialog, use the Sync-Trigger drop-down menu to select On Activation, and then click OK.

Add the custom Live Action(exampleLiveAction) to the Example Rollout Configuration

Configure the rollout configuration that you created in the previous procedure so that it uses the ExampleLiveActionFactory class.

Open CRXDE Lite. (http://localhost:4502/crx/de)

Select the jcr:content node below the /etc/msm/rolloutconfigs/examplerolloutconfig/jcr:content node.

Click Create > Create Node, configure the following node properties and click OK:
Name: exampleLiveAction
Type: cq:LiveSyncAction

Click Save All.

Select the exampleLiveAction node and add the following property:
Name: repLastModBy
Type: Boolean
Value: true

This property indicates to the ExampleLiveAction class that the cq:LastModifiedBy property should be replicated from the source to the target node.
Click Save All.

Create Example live-action that implements the custom live action.

package com.aaa.cq.rollout.actions;

import ...;

@Component(label = "Custom MSM Live Action", description = "Custom MSM Live Action", immediate = true, metatype = false, enabled = true)
@Properties({
@Property(label = "Vendor", name = Constants.SERVICE_VENDOR, value = "Vendor", propertyPrivate = true),
@Property(label = "Name", value = "exampleLiveAction", description = "Custom Live Action", name = "cq.wcm.msm.action.name", propertyPrivate = true),
@Property(label = "parameter", value = "msm:exampleLiveAction", description = "Parameter", name = "cq.wcm.msm.action.parameter", propertyPrivate = true),
@Property(label = "Title", value = "Custom MSM Live Action", description = "Custom MSM Live Action", name = "cq.wcm.msm.action.title", propertyPrivate = true),
@Property(label = "Rank", intValue = 10, name = "cq.wcm.msm.action.rank", description = "Custom LiveAction Rank"),
@Property(label = "Properties", value = { "enabled" }, cardinality = Integer.MAX_VALUE, name = "cq.wcm.msm.action.properties", description = "Custom LiveAction Properties") })
@Service
@lombok.Data
public class CustomLiveActionImpl implements LiveAction, CustomLiveAction {
private int rank;
private String name;
private String title;
private String[] parameterNames;
private Dictionary<String, Object> prop;

@Override
public void execute(Resource resource, Resource resource2, LiveRelationship liveRelationship,
boolean b, boolean b2)
throws WCMException {
}

@Override
public void execute(ResourceResolver resolver, LiveRelationship relation, ActionConfig config,
boolean autoSave) throws WCMException {
//execute(resolver, relation, config, autoSave, false);
}

@Override
public void execute(ResourceResolver resolver, LiveRelationship relation,ActionConfig config,
boolean autoSave, boolean isResetRollout)
throws WCMException {
customLiveActionImplementation();
}

@Override
public void customLiveActionImplementation() {
// custom live action implementation
}

@Override
public String getParameterName() {
return ACTION_PARAMETER;
}

@Override
public void write(JSONWriter jsonWriter) throws JSONException {
jsonWriter.object();
jsonWriter.key("name").value(getName());
jsonWriter.key("parameter").value(ACTION_PARAMETER);
jsonWriter.key("title").value(getTitle());
jsonWriter.key("rank").value(getRank());
jsonWriter.key("properites");
jsonWriter.array();
for (String prop : getPropertiesNames()) {
jsonWriter.value(prop);
}
jsonWriter.endArray();
jsonWriter.endObject();
}

public String[] getPropertiesNames() {
return parameterNames;
}

/**
* OSGi Component Methods
*/
@Activate
@Modified
protected void activate(ComponentContext context) {
Dictionary<String, Object> properties = context.getProperties();
name = PropertiesUtil.toString(
properties.get("cq.wcm.msm.action.name"), "exampleLiveAction");
title = PropertiesUtil.toString(
properties.get("cq.wcm.msm.action.title"), "Custom Live Action");
rank = PropertiesUtil.toInteger(
properties.get("cq.wcm.msm.action.rank"), Integer.MAX_VALUE);
parameterNames = PropertiesUtil.toStringArray(
properties.get("cq.wcm.msm.action.properties"), new String[0]);
}

@Deactivate
protected void deactivate(ComponentContext context) {
log.info("Deactivating Custom rollout action.");
}

private final static String ACTION_PARAMETER = "msm:exampleLiveAction";
}

public interface CustomLiveAction {
void customLiveActionImplementation();
}


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.