cancel
Showing results for 
Search instead for 
Did you mean: 

workflow called by java

mythox
Champ on-the-rise
Champ on-the-rise
hi, i try to understand the concept of calling workflow by java, i made a simple class as below, but below nodeService.addChild i do not understand, and i cant find related document about it.  appreciate for any advice.

the workflow is a simple workflow with 1 parameter as a name, it will say hello to this name in the debug log 

thankyou.


public class TestCallWorkflowByJava extends ActionExecuterAbstractBase  {
   
   public static final String NAME = "test-workflow";
   public static final String PARAM_NAME = "hello-name";
   
   private NodeService nodeService;
   private WorkflowService workflowService;

   @Override
   protected void addParameterDefinitions(List<ParameterDefinition> paramList) {
      
      // Add definitions for action parameters
      paramList.add(new ParameterDefinitionImpl(          
            PARAM_NAME,             
            DataTypeDefinition.TEXT,          
            true,                   
            getParamDisplayLabel(PARAM_NAME)));    
   }

   @Override
   protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
      if (this.nodeService.exists(actionedUponNodeRef) == true) {
          String helloQName = (String) action.getParameterValue(PARAM_NAME);
         
          NodeRef workflowPackage = this.workflowService.createPackage(null);
          nodeService.addChild(workflowPackage, ?, ?, ?);      //  <–  i dunno know what should be add to these 3 question marks.
        
          Map<QName, Serializable> workflowProps = new HashMap<QName, Serializable>(16);
          workflowProps.put(WorkflowModel.ASSOC_PACKAGE, workflowPackage);
          QName PROP_QNAME_HELLO_NAME = QName.createQName(PeWorkflowModel.NAMESPACE_PE_CONTENT_MODEL, PeWorkflowModel.PROP_HELLO_NAME);
          workflowProps.put(PROP_QNAME_HELLO_NAME, helloQName);
          WorkflowDefinition workflowDefinition = this.workflowService.getDefinitionByName("activiti$helloWorld");
          this.workflowService.startWorkflow(workflowDefinition.getId(), workflowProps);
      }
   }
   
   //   Setter
   public void setNodeService(NodeService nodeService) {
      this.nodeService = nodeService;
   }
   
   public void setWorkflowService(WorkflowService workflowService) {
      this.workflowService = workflowService;
   }

}
3 REPLIES 3

kaynezhang
World-Class Innovator
World-Class Innovator
1.The first parameter is worklow package–workflow Package is used to hold the content that's routed through the workflow,generally the node that this work work action is placed into the workflow package.
2.The second parameter is the node that your workflow actions on
3.The third parameter is parent-childer assocTypeQName ,you can just use WorkflowModel.ASSOC_PACKAGE_CONTAINS
4.The fourth parameter is association qname,you can name it whatever you'd like
for example

nodeService.addChild(workflowPackage, actionedUponNodeRef, WorkflowModel.ASSOC_PACKAGE_CONTAINS, "cm:assoname");

mythox
Champ on-the-rise
Champ on-the-rise
thankyou kaynezhang, it works anyway although still not quite understand the details.  i cannot find such info on the net, do you have any source about it?  

kaynezhang
World-Class Innovator
World-Class Innovator
Please refer to the JavaDoc for Java Foundation API at

Data Model project : http://dev.alfresco.com/resource/docs/java/datamodel
The Alfresco Repository project :http://dev.alfresco.com/resource/docs/java/repository