Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Call a custom rollout config

Avatar

Level 1

Hi All,

 

I need to call my Custom rollout config from a custom workflow process step.

Can someone help me with this?

 

Thanks in Advance

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Bimmi__Soi, you can use one of below implementations inside your workflow step. Below solutions assume that you already have live copy, and that you have below information on workflow step level:

  1. path to blueprint
  2. path to target - live copy
  3. path to custom rollout configuration

First option simply sets new rollout configuration using Sling API, and runs rollout via RolloutManager.

import com.day.cq.wcm.msm.api.LiveRelationshipManager;
import com.day.cq.wcm.msm.api.LiveRelationship;
import com.day.cq.wcm.msm.api.RolloutManager;

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

import org.osgi.service.component.annotations.Reference;

@Reference
private LiveRelationshipManager liveRelationshipManager;

@Reference
private RolloutManager rolloutManager;

// setting string array that will keep path to rollout configuration    
String [] cqRolloutConfigs = new String[1];
cqRolloutConfigs[0] = "/path/to/rollout/config";

// get target resource by path - live copy
Resource targetResource = resourceResolver.getResource("/content/path/to/target/resource");

// get resource that includes cq:rolloutConfigs property
Resource cqLiveSyncConfigResource = resourceResolver.getResource(targetResource.getPath() + "/jcr:content/cq:LiveSyncConfig");

// setting new custom rollout configuration    
ModifiableValueMap valueMap = cqLiveSyncConfigResource.adaptTo(ModifiableValueMap.class);
valueMap.put("cq:rolloutConfigs", cqRolloutConfigs);
resourceResolver.commit();

// running rollout
if (liveRelationshipManager.hasLiveRelationship(targetResource)) {
     LiveRelationship liveRelationship = liveRelationshipManager.getLiveRelationship(targetResource, true)
    
    if (liveRelationship != null) {
        rolloutManager.rollout(resourceResolver, liveRelationship, true, true);
    }
}

Second option use MSM API to handle all needed actions.

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

import com.day.cq.wcm.msm.api.LiveRelationshipManager;
import com.day.cq.wcm.msm.api.LiveRelationship;
import com.day.cq.wcm.msm.api.RolloutConfig;
import com.day.cq.wcm.msm.api.RolloutManager;

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

import org.osgi.service.component.annotations.Reference;

@Reference
private LiveRelationshipManager liveRelationshipManager;

@Reference
private RolloutManager rolloutManager;

RolloutConfigManager rolloutConfigManager = resourceResolver.adaptTo(RolloutConfigManager.class);

// getting rollout config that shuld be used for rollout
RolloutConfig rolloutConfig = rolloutConfigManager.getRolloutConfig("/path/to/rollout/config");

// live copy target
Resource targetResource = resourceResolver.getResource("/content/path/to/target");

// blueprint
Resource sourceResource = resourceResolver.getResource("/content/path/to/source");

LiveRelationship liveRelationship = null;
if (sourceResource != null && targetResource != null && rolloutConfig != null) {
    Page sourcePage = sourceResource.adaptTo(Page.class);
    Page targetPage = targetResource.adaptTo(Page.class);
    if (sourcePage != null && targetPage != null) {
        if (liveRelationshipManager.hasLiveRelationship(targetResource)) {
            // to modify existing rollout config, current live copy/relationship needs to be removed
            liveRelationshipManager.endRelationship(targetResource, true);
        }
        // creating new live copy to use new rollout config
        liveRelationship =  liveRelationshipManager
            .establishRelationship(sourcePage, targetPage, true, true, rolloutConfig);
        
        if (liveRelationship != null) {
            rolloutManager.rollout(resourceResolver, liveRelationship, true, true);
        }
    }
}

I hope that it will be good starting point for you.

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hi @Bimmi__Soi, you can use one of below implementations inside your workflow step. Below solutions assume that you already have live copy, and that you have below information on workflow step level:

  1. path to blueprint
  2. path to target - live copy
  3. path to custom rollout configuration

First option simply sets new rollout configuration using Sling API, and runs rollout via RolloutManager.

import com.day.cq.wcm.msm.api.LiveRelationshipManager;
import com.day.cq.wcm.msm.api.LiveRelationship;
import com.day.cq.wcm.msm.api.RolloutManager;

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

import org.osgi.service.component.annotations.Reference;

@Reference
private LiveRelationshipManager liveRelationshipManager;

@Reference
private RolloutManager rolloutManager;

// setting string array that will keep path to rollout configuration    
String [] cqRolloutConfigs = new String[1];
cqRolloutConfigs[0] = "/path/to/rollout/config";

// get target resource by path - live copy
Resource targetResource = resourceResolver.getResource("/content/path/to/target/resource");

// get resource that includes cq:rolloutConfigs property
Resource cqLiveSyncConfigResource = resourceResolver.getResource(targetResource.getPath() + "/jcr:content/cq:LiveSyncConfig");

// setting new custom rollout configuration    
ModifiableValueMap valueMap = cqLiveSyncConfigResource.adaptTo(ModifiableValueMap.class);
valueMap.put("cq:rolloutConfigs", cqRolloutConfigs);
resourceResolver.commit();

// running rollout
if (liveRelationshipManager.hasLiveRelationship(targetResource)) {
     LiveRelationship liveRelationship = liveRelationshipManager.getLiveRelationship(targetResource, true)
    
    if (liveRelationship != null) {
        rolloutManager.rollout(resourceResolver, liveRelationship, true, true);
    }
}

Second option use MSM API to handle all needed actions.

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

import com.day.cq.wcm.msm.api.LiveRelationshipManager;
import com.day.cq.wcm.msm.api.LiveRelationship;
import com.day.cq.wcm.msm.api.RolloutConfig;
import com.day.cq.wcm.msm.api.RolloutManager;

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

import org.osgi.service.component.annotations.Reference;

@Reference
private LiveRelationshipManager liveRelationshipManager;

@Reference
private RolloutManager rolloutManager;

RolloutConfigManager rolloutConfigManager = resourceResolver.adaptTo(RolloutConfigManager.class);

// getting rollout config that shuld be used for rollout
RolloutConfig rolloutConfig = rolloutConfigManager.getRolloutConfig("/path/to/rollout/config");

// live copy target
Resource targetResource = resourceResolver.getResource("/content/path/to/target");

// blueprint
Resource sourceResource = resourceResolver.getResource("/content/path/to/source");

LiveRelationship liveRelationship = null;
if (sourceResource != null && targetResource != null && rolloutConfig != null) {
    Page sourcePage = sourceResource.adaptTo(Page.class);
    Page targetPage = targetResource.adaptTo(Page.class);
    if (sourcePage != null && targetPage != null) {
        if (liveRelationshipManager.hasLiveRelationship(targetResource)) {
            // to modify existing rollout config, current live copy/relationship needs to be removed
            liveRelationshipManager.endRelationship(targetResource, true);
        }
        // creating new live copy to use new rollout config
        liveRelationship =  liveRelationshipManager
            .establishRelationship(sourcePage, targetPage, true, true, rolloutConfig);
        
        if (liveRelationship != null) {
            rolloutManager.rollout(resourceResolver, liveRelationship, true, true);
        }
    }
}

I hope that it will be good starting point for you.