Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Error while creating a custom rollout option

Avatar

Level 3

Hi,

 

I am trying to update the reference to experience fragments in my live copy for which I want to create a custom rollout config, below is the code.

 

Just for testing I am adding this action in the default rollout configuration in libs even though I should override it in apps (that i can do later)

but this is not working what am I doing wrong?

 

shehjadk07_0-1645986175887.png

 

 

import javax.jcr.RepositoryException;

import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.msm.api.LiveRelationship;
import com.day.cq.wcm.msm.commons.BaseAction;
import com.day.cq.wcm.msm.commons.BaseActionFactory;

@Component(immediate = true, property = {"liveAction=" + UpdateReferenceFactory.LIVE_ACTION_CLASS_NAME,
		"liveAction=" + UpdateReferenceFactory.LIVE_ACTION_NAME })
public class UpdateReferenceFactory extends BaseActionFactory<BaseAction> {

	public static final String LIVE_ACTION_CLASS_NAME = "ReferencesUpdateAction";
	public static final String LIVE_ACTION_NAME = "expreferencesUpdate";
	
	@Override
	protected ReferencesUpdateAction newActionInstance(ValueMap config) throws WCMException {
		return new ReferencesUpdateAction(config, this);
	}

	@Override
	public String createsAction() {
		return LIVE_ACTION_CLASS_NAME;
	}

	private static final class ReferencesUpdateAction extends BaseAction {

		public ReferencesUpdateAction(ValueMap config, BaseActionFactory<BaseAction> factory) {
			super(config, factory);
		}

		protected boolean handles(Resource source, Resource target, LiveRelationship relation, boolean resetRollout)
				throws RepositoryException, WCMException {
			return (relation.getStatus().isPage() && source != null);
		}

		protected void doExecute(Resource source, Resource target, LiveRelationship relation, boolean resetRollout)
				throws RepositoryException, WCMException {
			System.out.print("I am custom rollout");

		}
	}
}

1 Accepted Solution

Avatar

Correct answer by
Level 3

Okay I was able to solve it, I had 2 issues on the code I posted in the question.

 

1. Inside the component Annotation property needs to be liveActionName and not liveAction

2. Also to associate to LiveAction I need to add the service property in component annotation pointing to om.day.cq.wcm.msm.api.LiveActionFactory

 

Below is the working code, enjoy coding

import javax.jcr.RepositoryException;

import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.osgi.service.component.annotations.Component;

import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.msm.api.LiveActionFactory;
import com.day.cq.wcm.msm.api.LiveRelationship;
import com.day.cq.wcm.msm.commons.BaseAction;
import com.day.cq.wcm.msm.commons.BaseActionFactory;

@Component(service = LiveActionFactory.class,immediate = true, property = {"liveActionName=" + UpdateReferenceFactory.LIVE_ACTION_CLASS_NAME,
		"liveActionName=" + UpdateReferenceFactory.LIVE_ACTION_NAME })
public class UpdateReferenceFactory extends BaseActionFactory<BaseAction> {

	public static final String LIVE_ACTION_CLASS_NAME = "ReferencesUpdateAction";
	public static final String LIVE_ACTION_NAME = "expreferencesUpdate";
	
	@Override
	protected ReferencesUpdateAction newActionInstance(ValueMap config) throws WCMException {
		return new ReferencesUpdateAction(config, this);
	}

	@Override
	public String createsAction() {
		return LIVE_ACTION_CLASS_NAME;
	}

	private static final class ReferencesUpdateAction extends BaseAction {

		public ReferencesUpdateAction(ValueMap config, BaseActionFactory<BaseAction> factory) {
			super(config, factory);
		}

		protected boolean handles(Resource source, Resource target, LiveRelationship relation, boolean resetRollout)
				throws RepositoryException, WCMException {
			return (relation.getStatus().isPage() && source != null);
		}

		protected void doExecute(Resource source, Resource target, LiveRelationship relation, boolean resetRollout)
				throws RepositoryException, WCMException {
			System.out.print("I am custom rollout");

		}
	}
}

 

View solution in original post

2 Replies

Avatar

Level 3

27.02.2022 12:31:53.024 *ERROR* [[0:0:0:0:0:0:0:1] [1645986712940] GET /mnt/overlay/wcm/core/content/sites/createlivecopywizard.html/content/ansysincprogram/en-us/home/academic/students HTTP/1.1] com.day.cq.wcm.msm.impl.RolloutConfigManagerFactoryImpl RolloutConfig /libs/msm/wcm/rolloutconfigs/default is invalid: Failed to resolve Factory with id expreferencesUpdate, maybe Service is uninstalled

 

Avatar

Correct answer by
Level 3

Okay I was able to solve it, I had 2 issues on the code I posted in the question.

 

1. Inside the component Annotation property needs to be liveActionName and not liveAction

2. Also to associate to LiveAction I need to add the service property in component annotation pointing to om.day.cq.wcm.msm.api.LiveActionFactory

 

Below is the working code, enjoy coding

import javax.jcr.RepositoryException;

import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.osgi.service.component.annotations.Component;

import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.msm.api.LiveActionFactory;
import com.day.cq.wcm.msm.api.LiveRelationship;
import com.day.cq.wcm.msm.commons.BaseAction;
import com.day.cq.wcm.msm.commons.BaseActionFactory;

@Component(service = LiveActionFactory.class,immediate = true, property = {"liveActionName=" + UpdateReferenceFactory.LIVE_ACTION_CLASS_NAME,
		"liveActionName=" + UpdateReferenceFactory.LIVE_ACTION_NAME })
public class UpdateReferenceFactory extends BaseActionFactory<BaseAction> {

	public static final String LIVE_ACTION_CLASS_NAME = "ReferencesUpdateAction";
	public static final String LIVE_ACTION_NAME = "expreferencesUpdate";
	
	@Override
	protected ReferencesUpdateAction newActionInstance(ValueMap config) throws WCMException {
		return new ReferencesUpdateAction(config, this);
	}

	@Override
	public String createsAction() {
		return LIVE_ACTION_CLASS_NAME;
	}

	private static final class ReferencesUpdateAction extends BaseAction {

		public ReferencesUpdateAction(ValueMap config, BaseActionFactory<BaseAction> factory) {
			super(config, factory);
		}

		protected boolean handles(Resource source, Resource target, LiveRelationship relation, boolean resetRollout)
				throws RepositoryException, WCMException {
			return (relation.getStatus().isPage() && source != null);
		}

		protected void doExecute(Resource source, Resource target, LiveRelationship relation, boolean resetRollout)
				throws RepositoryException, WCMException {
			System.out.print("I am custom rollout");

		}
	}
}