Error while creating a custom rollout option | Community
Skip to main content
Level 3
February 27, 2022
Solved

Error while creating a custom rollout option

  • February 27, 2022
  • 2 replies
  • 2313 views

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?

 

 

 

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"); } } }

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by shehjadk07

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");

		}
	}
}

 

2 replies

Level 3
February 27, 2022

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

 

shehjadk07AuthorAccepted solution
Level 3
February 27, 2022

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");

		}
	}
}