1

I'm trying to create a workflow that have multiple assignees (done) and launch to them, a task. When I start the workflow, I want to run a java code that makes modifications on file that the task has been assigned. How can I run this java code on "Start Workflow"?

And then, I want that each assignee have a task to approve (this moment, the assignees don't have task to approve, appear task done, how can I do that?), and to approve I want to run other java code. How can I make this ? Assign this java codes to workflow?

I don't know how to define bpmn too, I think some problems are because of this.

PRVS
  • 1,502
  • 4
  • 28
  • 65
  • Where is de bpmn file? Have you looked at the default workflows and how they're made? – Tahir Malik Nov 17 '15 at 08:38
  • I use this tutorial http://ecmarchitect.com/alfresco-developer-series-tutorials/workflow/tutorial/tutorial.html and the helloWorldUI.bpmn, but I want to expand this to multiple assignees, because I put a field to select multiple assignees but the task for them appear completed and I want that remain pending to all assignees put "approve"/"reject". I look for the default workflows, but when I try to use the bpmn of them, but field assignees dissapear. You preferer that I post code of bpmn here? Both that I try and the problems that I have? Or you know a way to make this? – PRVS Nov 17 '15 at 08:47
  • Of course I know how to make this, but you need to dig in yourself if you want to learn anything. If I just post the solution for you you won't be able to learn :). So take a look at the Default review and Approve. It has an approve button and use that. – Tahir Malik Nov 17 '15 at 08:51
  • 1
    But I dont want that you make the Code for me. I only want to know, for exemple, I try to use the bpmn of the default but my button assignee dissapear. Why? It that things that i want to understand :/ and how to put this working. – PRVS Nov 17 '15 at 08:53
  • I'm already helping you but not giving you want you want, but what can help you learning bpmn. Take look here: https://www.youtube.com/watch?v=Hc9gZp7HNT0 and here http://docs.alfresco.com/4.2/topics/wf-howto.html and here: http://stackoverflow.com/questions/9733182/looking-for-activiti-alfresco-workflow-tutorial-step-by-step – Tahir Malik Nov 17 '15 at 10:13

1 Answers1

2

In order to run java code from your bpmn, you need to use java Listener classes. Listeners run on task events(create or complete ) or workflow events (start or end). These listeners need to be defined in your bpmn , and in your spring context file.

I ll give an example from my own code:

spring context file:

<bean id="StartTaskListener" class="com.crius.epub.wf.StartTaskListener" parent="activitiCreateTaskListener">
        </bean>
<bean id="StartTaskListener.activitiBeanRegistry" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean" depends-on="activitiBeanRegistry">
    <property name="targetObject">
        <ref bean="activitiBeanRegistry" />
    </property>
    <property name="targetMethod" value="put" />
    <property name="arguments">
        <list>
            <value>StartTaskListener</value>
            <ref bean="StartTaskListener" />
        </list>
    </property>
</bean>

Similarly, you have to define CompleteTaskListener (runs at end of task), and ExecutionFlowListener (runs at begin and end of workflow)

In my bpmn, it looks like this

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="epubcreate" name="Create epub" isExecutable="true">
    <extensionElements>
      <activiti:executionListener event="end" delegateExpression="${ExecutionFlowListener}"></activiti:executionListener>
      <activiti:executionListener event="start" delegateExpression="${ExecutionFlowListener}"></activiti:executionListener>
    </extensionElements>
    <startEvent id="start" name="Start" activiti:initiator="initiatorUserName" activiti:formKey="epubwf:start"></startEvent>
    <userTask id="create" name="Create proof" activiti:assignee="${epubwf_creator.properties.userName}" activiti:formKey="epubwf:create">
      <extensionElements>
        <activiti:taskListener event="create" delegateExpression="${StartTaskListener}"></activiti:taskListener>
        <activiti:taskListener event="complete" delegateExpression="${CompleteTaskListener}"></activiti:taskListener>
      </extensionElements>
    </userTask>

An example of a Executionlistener class looks like this:

 public class ExecutionFlowListener  extends DelegateExecutionScriptBase implements ExecutionListener{

public void notify(DelegateExecution execution){
  ExecutionEntity executionEntity = (ExecutionEntity)execution;
  if ("start".equals(executionEntity.getActivityId())){
      // workflow has started
      // get value of property mymodel:myproperty
      Object assignees =  execution.getVariable("mymodel_myproperty");
  }  else if ((executionEntity.getTransition() != null && "end".equals(executionEntity.getTransition().getDestination().getId())) || "end".equals(execution.getEventName())){ 
     // workflow has ended
   }
 }

Hopefully this will get you started...

Stefan De Laet
  • 1,368
  • 9
  • 19
  • Thank you so much! It was really what I needed. One more question, if I put a java class on the start of workflow and if I want to have the information of the field of the assignees that I select on the form, you know how can I do this? Or where I can find the API to see how can do this? Thank you so much, again!! – PRVS Nov 18 '15 at 11:01
  • Only one question about the code, the executionEntity on the java example is from where? ExecutionEntity executionEntity by parameter gives me error. – PRVS Nov 18 '15 at 15:02
  • right, there was a missing casting statement, I ve added it. – Stefan De Laet Nov 18 '15 at 16:02
  • One more question, only one, where I can see the bean names? I.e, the "parent="activitiCreateTaskListener">" for ExecutionListener, i'm not founding on the internet. – PRVS Nov 18 '15 at 16:11
  • They are in alfresco\tomcat\webapps\alfresco\WEB-INF\classes\alfresco\activiti-context.xml . I think you need activitiCreateTaskListener , activitiCompleteTaskListener . For the java classes I also have StartTaskListener extends TaskCreateListener and CompleteTaskListener extends TaskCompleteListener – Stefan De Laet Nov 18 '15 at 16:25
  • I only have a file called web-client-application-context.xml, and not have this tasks. And to workflow, you said "ExecutionFlowListener (runs at begin and end of workflow)" I can use activiti createTaskListener? I want on the start of the workflow. – PRVS Nov 18 '15 at 16:29
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/95469/discussion-between-prvs-and-stefan-de-laet). – PRVS Nov 18 '15 at 16:59