AnsweredAssumed Answered

Want to use custom class by <activiti:taskListener

Question asked by rakesh.world86 on Apr 25, 2015
Latest reply on Apr 28, 2015 by jbarrez
This is a simple example , where custom assignment via task listner is working .
Find the word "testserlvet.testclass" , this is a custom class , that this is working..


XML code

<process id="messageProcess" name="My Message" isExecutable="true">
    <startEvent id="startevent1" name="Start">
    </startEvent>
    <userTask id="usertask1" name="Approve (I am in Kartarpur)" activiti:assignee="kermit">
      <documentation>I am in Kartarpur</documentation>
      <extensionElements>
       <activiti:taskListener event="create" class="testserlvet.testclass" />
     </extensionElements>
    </userTask>
    <sequenceFlow id="flow4" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <userTask id="usertask2" name="Approve (I am in Jalandhar)" activiti:assignee="kermit">
      <documentation>I am in jalandhar</documentation>
    </userTask>
    <sequenceFlow id="flow5" sourceRef="usertask1" targetRef="usertask2"></sequenceFlow>
    <userTask id="usertask3" name="Approve (I am in Amritsar)" activiti:assignee="kermit">
      <documentation>I am in Amritsar</documentation>
    </userTask>
    <sequenceFlow id="flow6" sourceRef="usertask2" targetRef="usertask3"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow8" sourceRef="usertask3" targetRef="endevent1"></sequenceFlow>
  </process>




// testserlvet.testclass

package testserlvet;
import java.io.File;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
public class testclass implements TaskListener {
   public void notify(DelegateTask delegateTask) {
      System.out.println("printed ***********************************************");
          delegateTask.setAssignee("fozzie");
        File f = null;
         boolean bool = false;

         try{
            f = new File("c:\\activiti.txt");
            bool = f.createNewFile();
            System.out.println("File created: "+bool);
            f.delete();
            bool = f.createNewFile();
            System.out.println("File created: "+bool);
         }catch(Exception e){
            e.printStackTrace();
         }
     }
}





now , this is second xml , where custom assignment via tasklistner is not working.
pls find in testserlvet.testclass, why this is not working ..  testserlvet.testclass is same class shown above.. i have tried a lot but unable to run.. pls help me..

<process id="ApplyForLicense" name="Apply for license" isExecutable="true">
    <startEvent id="request" activiti:initiator="employeeName">
      <extensionElements>
        <activiti:formProperty id="licenseHolderName" name="licenseHolderName" type="string" required="true"></activiti:formProperty>
      </extensionElements>
    </startEvent>
    <sequenceFlow id="flow1" sourceRef="request" targetRef="handleRequest"></sequenceFlow>
    <userTask id="handleRequest" name="Handle license request" activiti:candidateGroups="inbox,management">
      <documentation>${licenseHolderName} has applied for license.</documentation>
      <extensionElements>
        <activiti:formProperty id="licenseApproved" name="Do you approve this license" type="string" required="true"></activiti:formProperty>
        <activiti:formProperty id="Comments" name="Comments" type="string"></activiti:formProperty>
      </extensionElements>
    </userTask>
    <sequenceFlow id="flow2" sourceRef="handleRequest" targetRef="requestApprovedDecision"></sequenceFlow>
    <exclusiveGateway id="requestApprovedDecision" name="Request approved?"></exclusiveGateway>
    <sequenceFlow id="flow3" sourceRef="requestApprovedDecision" targetRef="sendApprovalMail">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${licenseApproved == 'true'}]]></conditionExpression>
     
    </sequenceFlow>
    <userTask id="sendApprovalMail" name="Send confirmation e-mail">
      <documentation>Your manager has approved your license.</documentation>
      <extensionElements>
        <activiti:taskListener event="assignment" class="testserlvet.testclass"></activiti:taskListener>
      </extensionElements>
    </userTask>
    <sequenceFlow id="flow4" sourceRef="sendApprovalMail" targetRef="theEnd1"></sequenceFlow>
    <endEvent id="theEnd1"></endEvent>
    <sequenceFlow id="flow5" sourceRef="requestApprovedDecision" targetRef="adjustLicenseRequestTask">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${licenseApproved == 'false'}]]></conditionExpression>
    </sequenceFlow>
    <userTask id="adjustLicenseRequestTask" name="Reject License Approval">
      <documentation>Your manager has disapproved your license request . Reason: ${Comments}</documentation>
    </userTask>
    <endEvent id="theEnd2"></endEvent>
    <sequenceFlow id="flow6" sourceRef="adjustLicenseRequestTask" targetRef="theEnd2"></sequenceFlow>
  </process>

Outcomes