Saturday, June 16, 2012

Inherit KM Workflow steps from parent folder


Following is the code through which KM Workflow can inherit steps from Parent Folder
public boolean enableWorkflow(ICollection parentFolder,IResource childResource ) throws StatemanagementException, WcmException{
private static String NAMESPACE = "namespace.com";
private static String APP_PROPERTY_NAME = "Enable_Workflow";
boolean isWorkflowEnabled;
IPropertyName pname = PropertyName.getPN(NAMESPACE, APP_PROPERTY_NAME);
IProperty property = parentFolder.getProperty(pname);
if(null!=property){
isWorkflowEnabled=property.getBooleanValue();
}
IStatemanagementManager parentStateMgr =null;
IStatemanagementResource parentStateRes =null;
IStatemanagementUtilsResource parentStateResUtils = null;
IStepList parentStepList = null;
IStatemanagementResource childStateRes = null;
IStatemanagementUtilsResource childStateResUtils = null;
IApplicationPropertiesService appPropService = null;

IRepositoryServiceFactory repServiceFactory = ResourceFactory.getInstance().getServiceFactory();
IStatemanagementManager stateMgr = (IStatemanagementManager) repServiceFactory.getRepositoryService(childResource,IWcmConst.STATEMANAGEMENT_SERVICE);

if (isWorkflowEnabled) {
if (childResource.isCollection()) {
//set custom metadata property for child
childResource.setProperty(property);
//instantiate the statemanagement manager for parent
parentStateMgr = (IStatemanagementManager) repServiceFactory.getRepositoryService(parentFolder,IWcmConst.STATEMANAGEMENT_SERVICE);
//get the statemanagement resource for parent
parentStateRes = parentStateMgr.getStatemangementResource(parentFolder);
//get the statemanagement utils for parent
parentStateResUtils = parentStateRes.getUtils();
if(null != parentStateResUtils && parentStateResUtils.isStatemanagementEnabled()){
//read approver list
parentStepList = parentStateResUtils.readApproverList();
//get the statemanagement resource for child
childStateRes = stateMgr.getStatemangementResource(childResource);
//get the statemanagement utils instance for child resource
childStateResUtils = childStateRes.getUtils();
//enable workflow for child
childStateResUtils.setStatemanagementEnabled(true);
//add and save approver list for child
childStateResUtils.saveApproverList(parentStepList);
}else{return false;}
} else {
// setps to submit a not collection child resource for approval automatically
IStatemanagementResource sResource = stateMgr.getStatemangementResource(childResource);
IResourceTransitionList transitionList = sResource.getAllowedTransitions();
if (sResource.getUtils().readState().toString().equalsIgnoreCase("in progress")) {
IResourceTransition transition = sResource.getTransition("lbl.submit");
if(null != transition){
transition.execute();
}else{return false;}
}else{return false;}
}
}else{
return false;
}
return true;
}

No comments:

Post a Comment