2 Replies Latest reply on Feb 25, 2006 1:16 PM by tgullo

    Problem in invoking assignment handler using taskinstance.en

    prabuddha Newbie

      The method taskInstance.end() says it will end a task and might invoke the handler . what does that mean?
      Currently its not invoking the handler.
      Below is the code I'm using to assgn a task AssignTask.java
      The Handler class is ApproveAccount.java.

      The taskcontroller params are not accesible due the reason the signal is being done before assigning.

      So what is wrong here ? Please explain


      public class AssignTask {
      
       ProcessInstance processInstance = null;
       ContextInstance contextInstance = null;
       TaskMgmtInstance taskMgmtInstance = null;
       protected JbpmSession jbpmSession = null;
       protected GraphSession graphSession = null;
       protected TaskMgmtSession taskMgmtSession = null;
       protected ContextSession contextSession = null;
      
       static JbpmSessionFactory jbpmSessionFactory = JbpmSessionFactory
       .buildJbpmSessionFactory();
      
      
       static { jbpmSessionFactory.getJbpmSchema().createSchema(); }
      
      
       public AssignTask() {
      
       }
      
       public void buildProcessDefinition(String actor) {
       ProcessDefinition processDefinition = ProcessDefinition
       .parseXmlString("<process-definition name='AccountApproval'>"
       + " <start-state>"
       + " <transition name='submit' to='Approval' />"
       + " </start-state>"
       + " <controller>"
       + " <variable name='NAME'/>"
       + " <variable name='ADDRESS'/>"
       + " </controller>"
       + " <task-node name='Approval'>"
       + " <task name='Approve'>"
       + " <controller>"
       + " <variable name='NAME'/>"
       + " <variable name='ADDRESS'/>"
       + " <variable name='COMMENT'/>"
       + " </controller>"
       + " <assignment class='org.jbpm.tutorial.param.ApproveAccount' >"
       + " <assignee>" + actor + "</assignee> "
       + "</assignment>"
       + " </task>" + "<transition to='NewAccount' />"
       + " </task-node>" + " <end-state name='NewAccount' />"
       + "</process-definition>");
       JbpmSession jbpmSession = jbpmSessionFactory.openJbpmSession();
       jbpmSession.beginTransaction();
       graphSession = jbpmSession.getGraphSession();
       jbpmSession.getGraphSession().saveProcessDefinition(processDefinition);
      
       processInstance = new ProcessInstance(processDefinition);
       graphSession.saveProcessInstance(processInstance);
      
       processDefinition = graphSession
       .loadProcessDefinition(processDefinition.getId());
       processInstance = graphSession.loadProcessInstance(processInstance
       .getId());
       contextInstance = processInstance.getContextInstance();
      
       jbpmSession.commitTransaction();
       jbpmSession.close();
       }
      
       public void submitsApprovalTask(String actor) {
      
       buildProcessDefinition(actor);
      
       JbpmSession jbpmSession = jbpmSessionFactory.openJbpmSession();
       jbpmSession.beginTransaction();
       ProcessDefinition processDefinition = jbpmSession.getGraphSession()
       .findLatestProcessDefinition("AccountApproval");
       ProcessInstance processInstance = new ProcessInstance(processDefinition);
      
       Token token = processInstance.getRootToken();
      
       token.signal();
      
       TaskInstance taskInstance = (TaskInstance) processInstance
       .getTaskMgmtInstance().getTaskInstances().iterator().next();
      
       Map parameters = new HashMap();
       parameters.put("NAME", "JBPM");
       parameters.put("ADDRESS", "32,CTS");
       parameters.put("COMMENT", "One Billion Dollar Company");
      
       taskInstance.submitParameters(parameters);
      
      
       \\ testing the taskcontroller parameters submitted
      
       contextInstance = processInstance.getContextInstance();
      
       System.out.println(contextInstance.getVariable("NAME"));
       System.out.println(contextInstance.getVariable("ADDRESS"));
       System.out.println(contextInstance.getVariable("COMMENT"));
      
      
       jbpmSession.getGraphSession().saveProcessInstance(processInstance);
      
       jbpmSession.commitTransaction();
       jbpmSession.close();
       }
      
      }


      assigment handler

      public class ApproveAccount implements AssignmentHandler {
      
       private static final long serialVersionUID = 1L;
      
      String assignee;
      
       public void assign(Assignable assignable, ExecutionContext executionContext) {
       assignable.setActorId("CAG");
      
       ContextInstance contextInstance = executionContext.getContextInstance();
      
       TaskInstance taskInstance=executionContext.getTaskInstance();
      
       List taskFormParameters = taskInstance.getTaskFormParameters();
      
       \\ this is giving me the label names correctly but the values submitted are showing null.
      
       Iterator iter = taskFormParameters.iterator();
      
       while (iter.hasNext()) {
       TaskFormParameter tfp = (TaskFormParameter) iter.next();
       String label = tfp.getLabel();
       System.out.print(label);
       System.out.println(contextInstance.getVariable(label)); \\\ displays null
       }
      
      
       }
      }