Programming with Content Services ES > Invoking LiveCycle ES Services from Custom Actions > Defining your application logic > Implementing the action executor class > Implementing the custom action

Implementing the custom action
The executeImpl() method is where the custom action business logic resides. It receives an Action object and the NodeRef of the node on which the action is performed. In this example, the executeImpl() method adds the reviewer aspect to the node and uses the list to set the node’s reviewDescription property.
Because the executeImpl() method uses NodeService, PersonService, AuthenticationService, and UserManagerUtils, you must inject those services by using Spring dependency injection, as shown in the following code example.
Example: Writing Spring dependency injection setter methods
The following example shows how to inject services.
	private NodeService nodeService;
	private AuthenticationService authenticationService;
	private PersonService personService;
	private UserManagerUtils userManagerUtils = null;
 
	// Inject Node Service.
	public void setNodeService(NodeService nodeService) 
	{
		this.nodeService = nodeService;
	}
 
	// Inject Person Service.
	public void setPersonService(PersonService personService) 
	{
		this.personService = personService;
	}
 
	// Inject Authentication Service.
	public void setAuthenticationService(AuthenticationService aAuthenticationService)
	{
        		this.authenticationService = aAuthenticationService;
	}
 
	// Inject UserManagerUtils
	public void setUserManagerUtils(UserManagerUtils aUserManagerUtils)
	{
		this.userManagerUtils = aUserManagerUtils;
	}
In this case, the custom action invokes a LiveCycle ES process, so the ReviewProcessActionExecuter.executeImpl method contains logic to obtain the user context, create a service client factory, and invoke the LiveCycle ES process. To obtain the user context, invoke the AuthenticationService.getCurrentTicket method to obtain a ticket, and pass that ticket to the UserManagerUtils.getIDPContext method. To create the service client factory, pass the user context to the ServiceClientFactory.createInstance method, as shown in the following example.
Example: Obtaining the user context
This example shows how to obtain the user context and create a service client. For information about creating service clients, see Invoking a service using a Java client library.
String ticket = authenticationService.getCurrentTicket();
Context idpContext = userManagerUtils.getIDPContext(ticket);
ServiceClientFactory _scFactory = ServiceClientFactory.createInstance(idpContext);
For this example, the class defining the methods in which LiveCycle ES services and processes are invoked is called LiveCycleServiceInvoker. The ReviewProcessActionExecuter.executeImpl method invokes the process by using the methods in the LiveCycleServiceInvoker class, as shown in the following example.
Example: Invoking the LiveCycle ES process
This example contains the logic that is contained within the ReviewProcessActionExecuter.executeImpl method to create an instance of the LiveCycleInvoker class, set its client factory, and use the class to invoke a LiveCycle ES process.
LiveCycleServiceInvoker _lcServiceInvoker = new LiveCycleServiceInvoker();
_lcServiceInvoker.setServiceClientFactory(_scFactory);
try {
	_lcServiceInvoker.invokeLongLivedOrchestration(NAME_REVIEW_AND_APPROVAL_PROCESS, _processParamMap);
} catch (DSCException e) {
	e.printStackTrace();
	throw new ProcessExecutionException(e.getMessage());
}
Example: Defining the ReviewProcessActionExecuter implementation
This example shows the entire implementation of the ReviewProcessActionExecuter class, in which the business logic is contained in the executeImp method, and the parameters are added through the addParameterDefinitions method.
package com.adobe.livecycle.samples.cs.action;
 
import java.util.ArrayList;
import java.util.List;
 
 
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.namespace.QName;
 
import com.adobe.contentservices.authentication.UserManagerUtils;
import com.adobe.contentservices.common.ContentServicesConstants.CSContentModel;
import com.adobe.contentservices.logging.CSModulesLogger;
import com.adobe.idp.Context;
import com.adobe.idp.dsc.DSCException;
import com.adobe.idp.dsc.clientsdk.ServiceClientFactory;
import com.adobe.livecycle.samples.cs.util.LiveCycleServiceInvoker;
 
 
 
/**
 * This is an Action Executer class to define an action (invocable from Java Script) that
 * can be used to initiate a Review and Approval process. It can be used to execute a Review
 * and Approval action from the Office Plug-in.
 * 
 * @author Akhil Kumar Jain
 */
public class ReviewProcessActionExecuter extends ActionExecuterAbstractBase 
{
	// specify logger
	private static final CSModulesLogger s_csLogger = CSModulesLogger.getCSModuleLogger(ReviewProcessActionExecuter.class); 
	
	// process name - this will be used to refer to the action.
	public static final String NAME = "process-action";
	
	// action parameters
	// reviewer name
	public static final String PARAM_REVIEWER_ID = "reviewer-id";
	// assigner name
	public static final String PARAM_ASSIGNER_ID = "assigner-id";
	// review description
	public static final String PARAM_REVIEW_DESC = "review-desc";
	
	// LiveCycle service that will be invoked for this action.
	private static final String NAME_REVIEW_AND_APPROVAL_PROCESS    = "Samples - Content Services - ReviewAndApproval";
 
	// parameters for the "Samples - Content Services - ReviewAndApproval" service
	private static final String PARAMETER_IN_REVIEWER_OID           = "inReviewerOID";
	private static final String PARMATER_IN_REVIEW_DESCRIPTION      = "inReviewDescription";
	private static final String PARAMETER_IN_REVIEW_INITIATOR_OID   = "inReviewInitiatorOID";
	private static final String PARAMETER_IN_STORE_NAME             = "inStoreName";
	private static final String PARAMETER_IN_REVIEW_CONTENT_URLLIST = "inReviewContentURLList";
 
	
	private NodeService nodeService;
	private AuthenticationService authenticationService;
	private PersonService personService;
	private UserManagerUtils userManagerUtils = null;
 
	// Inject Node Service.
	public void setNodeService(NodeService nodeService) 
	{
		this.nodeService = nodeService;
	}
 
	// Inject Person Service.
	public void setPersonService(PersonService personService) 
	{
		this.personService = personService;
	}
 
	// Inject Authentication Service.
	public void setAuthenticationService(AuthenticationService aAuthenticationService)
	{
        	this.authenticationService = aAuthenticationService;
	}
 
	// Inject UserManagerUtils
	public void setUserManagerUtils(UserManagerUtils aUserManagerUtils)
	{
		this.userManagerUtils = aUserManagerUtils;
	}
 
   
	/**
	 * This method is used to specify the parameters for the action.
	 * @param The list that should be filled with all the parameters.
	 */
	protected void addParameterDefinitions(List<ParameterDefinition> paramList) 
	{
		paramList.add(new ParameterDefinitionImpl(PARAM_REVIEWER_ID, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_REVIEWER_ID)));
		paramList.add(new ParameterDefinitionImpl(PARAM_ASSIGNER_ID, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_ASSIGNER_ID)));
		paramList.add(new ParameterDefinitionImpl(PARAM_REVIEW_DESC, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_REVIEW_DESC)));
	}
 
	/**
	 * This method is used to define the flow when the action defined by this ActionExecuter is
	 * executed.
	 * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
	 */
	protected void executeImpl(
			Action ruleAction,
			NodeRef actionedUponNodeRef) 
	{
 
		s_csLogger.info("Invoking action ==> " + ReviewProcessActionExecuter.NAME, "");
		
		if (this.nodeService.exists(actionedUponNodeRef) == true)
		{
 
			// Get the parameter values
			String assigner = (String)ruleAction.getParameterValue(PARAM_ASSIGNER_ID);
			String reviewer = (String)ruleAction.getParameterValue(PARAM_REVIEWER_ID);
			String reviewDesc = (String)ruleAction.getParameterValue(PARAM_REVIEW_DESC);
 
			s_csLogger.info("Fetching action parameters ..." , "");
			
			
			// Step: Collect the process parameters
			java.util.Map<String, Object> _processParamMap = new java.util.HashMap<String, Object>();
	                
			// Get the Review Initiator OID
			String _reviewInitiatorOID = getUserOID(assigner);        
			s_csLogger.debug("ReviewerInitiatorName=" + assigner + ",OID=" + _reviewInitiatorOID, "");
			_processParamMap.put(PARAMETER_IN_REVIEW_INITIATOR_OID, _reviewInitiatorOID);
	        
			// Get the Review Description        
			s_csLogger.debug("ReviewDescription=" + reviewDesc);
			_processParamMap.put(PARMATER_IN_REVIEW_DESCRIPTION, reviewDesc);
	        
			// Get the Reviewer OID
			s_csLogger.debug("ReviewerName=" + reviewer + ",OID=" + getUserOID(reviewer), "");            
			_processParamMap.put(PARAMETER_IN_REVIEWER_OID, getUserOID(reviewer));
	        
			String nodeName = actionedUponNodeRef.toString();
	        
			// Get the Store name
			// Items are of the form: workspace://SpacesStore/bb090e72-bf94-11dc-af8e-7d7d65ccd02d
			String[] _itemWebURLSplit = nodeName.split("//");
			String _itemURL = _itemWebURLSplit[1];
			String[] _itemURLSplit = _itemURL.split("/");
			_processParamMap.put(PARAMETER_IN_STORE_NAME, _itemURLSplit[0]);
	        
			// Construct Review Content URL List
			java.util.List<String> _reviewContentURLList = new ArrayList<String>();
			int _idx = nodeName.lastIndexOf("/");
			if (_idx == -1 || ((_idx+1) == nodeName.length()))
			{
				throw new IllegalArgumentException("Illegal URL [" + nodeName + "]");
			}
			_reviewContentURLList.add(nodeName.substring(_idx+1));
	            
			s_csLogger.debug("Content URL List=" + _reviewContentURLList, "");
			_processParamMap.put(PARAMETER_IN_REVIEW_CONTENT_URLLIST, _reviewContentURLList);
	        
			// Step: Invoke "Samples - Content Services - ReviewAndApproval" service         
			// Get the User Context 
			String ticket = authenticationService.getCurrentTicket();
			Context idpContext = userManagerUtils.getIDPContext(ticket);
			ServiceClientFactory _scFactory = ServiceClientFactory.createInstance(idpContext);
			s_csLogger.info("Invoking Service " + NAME_REVIEW_AND_APPROVAL_PROCESS, "");
 
			// Invoke the process with the given parameters
			LiveCycleServiceInvoker _lcServiceInvoker = new LiveCycleServiceInvoker();
			_lcServiceInvoker.setServiceClientFactory(_scFactory);
			try {
				_lcServiceInvoker.invokeLongLivedOrchestration(NAME_REVIEW_AND_APPROVAL_PROCESS, _processParamMap);
			} catch (DSCException e) {
				e.printStackTrace();
				throw new ProcessExecutionException(e.getMessage());
			}
 
			s_csLogger.info("Process: ’" + NAME_REVIEW_AND_APPROVAL_PROCESS + "’ launch COMPLETED.", "");
			
		}
	}
 
	/** Gets the OID for the given user */
	private String getUserOID(String userName)
	{
		NodeRef _personNode = personService.getPerson(userName);
		return (String)nodeService.getProperty(_personNode, QName.createQName(CSContentModel.PROP_OID));
	}
 
}
 

Programming with Content Services ES > Invoking LiveCycle ES Services from Custom Actions > Defining your application logic > Implementing the action executor class > Implementing the custom action

Programming with LiveCycle ES (LiveDocs)
Adobe LiveCycle ES Update 1

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/livecycle/8.2/programLC/programmer/help/001568_2.html