cancel
Showing results for 
Search instead for 
Did you mean: 

Using Java Classes for Decisions in a workflow

minalbhatte
Champ in-the-making
Champ in-the-making
Hi all,

I want to call a java class method form a workflow.
For that i have used a handler tag in decision  to point to a Java class that implements the DecisionHandler interface.
The decide() method of the handler class should performs the logic it needs to and then it should returns the name of the transition to take.

I have added the jar file of my java class at ..\Alfresco\tomcat\webapps\alfresco\WEB-INF\lib  folder.
But when workflow reach the decision state it is not calling the java class  decision() method.

The procesdefinition.xml file is as follows:

<?xml version="1.0" encoding="UTF-8"?>

<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="wf:adhoc">

   <swimlane name="initiator"/>

   <start-state name="start">
      <task name="wf:submitAdhocTask" swimlane="initiator"/>
      <transition name="" to="adhoc"/>
   </start-state>

   <swimlane name="assignee">
      <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
         <actor>#{bpm_assignee}</actor>
      </assignment>
   </swimlane>
  
   <task-node name="adhoc">
      <task name="wf:adhocTask" swimlane="assignee">
         <event type="task-create">
            <script>
               if (bpm_workflowDueDate != void) taskInstance.dueDate = bpm_workflowDueDate;
               if (bpm_workflowPriority != void) taskInstance.priority = bpm_workflowPriority;
            </script>
         </event>
      </task>
      <transition name="" to="CheckAvailability">
         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
           <script>
              if (wf_notifyMe)
              {
                 var mail = actions.create("mail");
                 mail.parameters.to = initiator.properties.email;
                 mail.parameters.subject = "Adhoc Task " + bpm_workflowDescription;
                 mail.parameters.from = bpm_assignee.properties.email;
                 mail.parameters.text = "It's done";
                 mail.execute(bpm_package);
              }
           </script>
         </action>
      </transition>
   </task-node>
  
  
   <decision name="CheckAvailability"> 
     <handler class="com.sample.decision.sampleDecisionHandler"></handler>   
     <transition name="trDeliver" to="completed"></transition>  
  </decision>
 
 
   <task-node name="completed">
      <task name="wf:completedAdhocTask" swimlane="initiator"/>
      <transition name="" to="end"/>
   </task-node>
     
   <end-state name="end"/>
  
</process-definition>



and my java class code:


package com.sample.decision;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.Writer;

import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.node.DecisionHandler;

public class sampleDecisionHandler  implements DecisionHandler{
   public String decide(ExecutionContext executionContext) throws Exception { 
      // Code to create a text file
      
      System.out.println("Hello Inside sampleDecisionHandler ");
      Writer output = null;
       String text = "Inside Workflow - This is a decision";
       File file = new File("C:\\Alfresco\\write.txt");
       output = new BufferedWriter(new FileWriter(file));
       output.write(text);
       output.close();
       System.out.println("Your file has been written");
       // Go to transition trDeliver
       return "trDeliver";
      
      }  

}
1 REPLY 1

hyperation
Champ on-the-rise
Champ on-the-rise
Hi MinalBhatte,

Have you been able to solve this problem yet?

Thanks
Smiley Happy