AnsweredAssumed Answered

SubmitTaskFormData (invoked via servicetask) throws error

Question asked by bbarani on Mar 4, 2013
Latest reply on Mar 11, 2013 by jbarrez
Hi,

I have a simple flow as below,

External system invokes a workflow process with values —> Activiti will create a user form with a enum form type (user can select 'Yes' or 'No') for submitting the form –> Whenever a user approves / rejects the task, I call a service task(Java class) to set the owner for this task and persist the form property in history detail table.

For some reason, I am getting the below error whenever I submit my form using submitTaskFormdata method. Can someone let me know where I am wrong?

<?xml version="1.0" encoding="UTF-8"?>
<definitions id="definitions" targetNamespace="http://activiti.org/bpmn20"
   xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:activiti="http://activiti.org/bpmn">

   <process id="SimplePictureRequest" name="Testing Approval process">
      <startEvent id="theStart" activiti:initiator="initiator" />
      <sequenceFlow id="flow1" sourceRef="theStart" targetRef="needsApprovalTask" />
      <serviceTask id="needsApprovalTask" name="Needs approval"
         activiti:class="com.picturerequest.NeedsApprovalDelegate" />

      <sequenceFlow id="flow2" sourceRef="needsApprovalTask"
         targetRef="gateway" />

      <exclusiveGateway id="gateway" name="Needs approval?" />

      <sequenceFlow id="flow3" sourceRef="gateway" targetRef="confirmApproval">
         <conditionExpression xsi:type="tFormalExpression">
            ${needsApproval}
         </conditionExpression>
      </sequenceFlow>

      <sequenceFlow id="flow4" sourceRef="gateway" targetRef="Email">
         <conditionExpression xsi:type="tFormalExpression">
            ${!needsApproval}
         </conditionExpression>
      </sequenceFlow>

      <userTask id="confirmApproval" name="Approve the picture request"
         activiti:candidateUsers="${user}" activiti:assignee="${user}">
         <extensionElements>
            <activiti:formProperty id="approvalFlag" name="Needs Approval:"
               expression="${needsApproval}" writable="false" type="boolean" />

            <activiti:formProperty id="initiatorName"
               name="Initiator:" expression="${initiator}" writable="false" type="string" />

            <activiti:formProperty id="descriptionValue"
               name="Description:" expression="${description}" readable="true"
               writable="false" type="string" />

            <activiti:formProperty id="user" name="user"
               expression="${user}" writable="false" type="string" />

            <activiti:formProperty id="imageName" name="Image:"
               expression="${imageName}" writable="false" type="string" />

            <activiti:formProperty id="approvalConfirmed"
                name="approvalConfirmed" type="enum" required="true">
               <activiti:value id="true" name="Yes"></activiti:value>
               <activiti:value id="false" name="No"></activiti:value>
            </activiti:formProperty>
         </extensionElements>
      </userTask>

      <sequenceFlow id="flow5" sourceRef="confirmApproval"
         targetRef="gateway2" />

      <exclusiveGateway id="gateway2" name="Is approval confirmed?" />

      <sequenceFlow id="flow6" sourceRef="gateway2" targetRef="chargeAccount">
         <conditionExpression xsi:type="tFormalExpression"><![CDATA[${approvalConfirmed == 'true'}]]></conditionExpression>
      </sequenceFlow>

      <sequenceFlow id="flow7" sourceRef="gateway2" targetRef="ArchiveTask">
         <conditionExpression xsi:type="tFormalExpression"><![CDATA[${approvalConfirmed == 'false'}]]></conditionExpression>
      </sequenceFlow>

      <serviceTask id="Email" name="Email Service"
         activiti:class="com.picturerequest.ChargeDelegate">
         <extensionElements>
            <activiti:field name="wsdl"
               expression="http://localhost:8521/mailService?wsdl" />
            <activiti:field name="operation" expression="chargeAccount" />
            <activiti:field name="parameters" expression="${user}, ${imageName}" />
            <activiti:field name="returnValue" expression="myReturn" />
         </extensionElements>
      </serviceTask>



      <serviceTask id="chargeAccount" name="Charge account"
         activiti:class="com.picturerequest.ChargeDelegate">
         <extensionElements>
            <activiti:field name="wsdl"
               expression="http://localhost:8291/chargeService?wsdl" />
            <activiti:field name="operation" expression="chargeAccount" />
            <activiti:field name="parameters" expression="${user}, ${imageName}" />
            <activiti:field name="returnValue" expression="myReturn" />
         </extensionElements>
      </serviceTask>



      <sequenceFlow id="flow10" sourceRef="chargeAccount"
         targetRef="ArchiveTask" />


      <sequenceFlow id="flow13" sourceRef="Email" targetRef="theEnd" />

      <serviceTask id="ArchiveTask" name="serviceTask"
         activiti:class="com.picturerequest.ArchiveTask">
      </serviceTask>


      <sequenceFlow id="flow8" sourceRef="ArchiveTask"
         targetRef="theEnd" />

      <endEvent id="theEnd" />

   </process>
</definitions>



My java class:


public class ArchiveTask implements org.activiti.engine.delegate.JavaDelegate

{
   public void execute(DelegateExecution execution) throws Exception {
      Map<String, String> properties = new HashMap<String, String>();
      String assigneeName = (String) execution.getVariable("user");
      FormService formService = execution.getEngineServices()
            .getFormService();
      TaskService taskService = execution.getEngineServices()
            .getTaskService();
      String procId = execution.getProcessInstanceId();
      Task task = taskService.createTaskQuery().processInstanceId(procId)
            .orderByTaskName().asc().singleResult();

      task.setOwner(assigneeName);
      TaskFormData formData = formService.getTaskFormData(task.getId());
            
      try {
         properties.put(formData.getFormProperties().get(0).getName(),
               formData.getFormProperties().get(0).getValue());
         properties.put(formData.getFormProperties().get(1).getName(),
               formData.getFormProperties().get(1).getValue());
         properties.put(formData.getFormProperties().get(2).getName(),
               formData.getFormProperties().get(2).getValue());
         properties.put(formData.getFormProperties().get(3).getName(),
               formData.getFormProperties().get(3).getValue());
         properties.put(formData.getFormProperties().get(4).getName(),
               formData.getFormProperties().get(4).getValue());
         properties.put(formData.getFormProperties().get(5).getName(),
               formData.getFormProperties().get(5).getValue());
         formService.submitTaskFormData(task.getId(), properties);
      } catch (ActivitiException e) {
         e.printStackTrace();
      }


I initially thought that this might be due to some data issue but I am able to get the values from the form without any issues,

   
          System.out.println(task.getName());
System.out.println(formData.getFormProperties().get(0).getName() +
       ":" + formData.getFormProperties().get(0).getValue());
       System.out.println(formData.getFormProperties().get(1).getName() +
       ":" + formData.getFormProperties().get(1).getValue());
       System.out.println(formData.getFormProperties().get(2).getName() +
       ":" + formData.getFormProperties().get(2).getValue());
       System.out.println(formData.getFormProperties().get(3).getName() +
       ":" + formData.getFormProperties().get(3).getValue());
       System.out.println(formData.getFormProperties().get(4).getName() +
       ":" + formData.getFormProperties().get(4).getValue());
       System.out.println(formData.getFormProperties().get(5).getName() +
       ":" + formData.getFormProperties().get(5).getValue());

Approve the picture request
Needs Approval::true
Initiator::kermit
Description::Invoking Activiti from Java 4
user:kermit
Image::mule2.jpg
approvalConfirmed:true


I am getting the below error whenever I submit my form using submitTaskFormData…

        at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyL
istenerTake.execute(AtomicOperationTransitionNotifyListenerTake.java:65)
        at org.activiti.engine.impl.interceptor.CommandContext.performOperation(
CommandContext.java:85)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOp
erationSync(ExecutionEntity.java:535)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOp
eration(ExecutionEntity.java:530)
        at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionDestroy
Scope.execute(AtomicOperationTransitionDestroyScope.java:115)
        at org.activiti.engine.impl.interceptor.CommandContext.performOperation(
CommandContext.java:85)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOp
erationSync(ExecutionEntity.java:535)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOp
eration(ExecutionEntity.java:530)
        at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyL
istenerEnd.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerEn
d.java:36)
        at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.exe
cute(AbstractEventAtomicOperation.java:56)
        at org.activiti.engine.impl.interceptor.CommandContext.performOperation(
CommandContext.java:85)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOp
erationSync(ExecutionEntity.java:535)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOp
eration(ExecutionEntity.java:530)
        at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.exe
cute(AbstractEventAtomicOperation.java:49)
        at org.activiti.engine.impl.interceptor.CommandContext.performOperation(
CommandContext.java:85)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOp
erationSync(ExecutionEntity.java:535)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOp
eration(ExecutionEntity.java:530)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.take(Exec
utionEntity.java:370)
        at org.activiti.engine.impl.bpmn.behavior.BpmnActivityBehavior.performOu
tgoingBehavior(BpmnActivityBehavior.java:102)
        at org.activiti.engine.impl.bpmn.behavior.BpmnActivityBehavior.performDe
faultOutgoingBehavior(BpmnActivityBehavior.java:51)
        at org.activiti.engine.impl.bpmn.behavior.FlowNodeActivityBehavior.leave
(FlowNodeActivityBehavior.java:44)
        at org.activiti.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior.l
eave(AbstractBpmnActivityBehavior.java:47)
        at org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior.signa
l(UserTaskActivityBehavior.java:98)
        at org.activiti.engine.impl.persistence.entity.ExecutionEntity.signal(Ex
ecutionEntity.java:353)
        at org.activiti.engine.impl.persistence.entity.TaskEntity.complete(TaskE
ntity.java:157)
        at org.activiti.engine.impl.cmd.SubmitTaskFormCmd.execute(SubmitTaskForm
Cmd.java:47)
        at org.activiti.engine.impl.cmd.NeedsActiveTaskCmd.execute(NeedsActiveTa
skCmd.java:58)
        at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(Comm
andExecutorImpl.java:24)
        at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execut
e(CommandContextInterceptor.java:60)
        at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterc
eptor.java:32)
        at org.activiti.engine.impl.FormServiceImpl.submitTaskFormData(FormServi
ceImpl.java:70)
        at org.activiti.explorer.ui.task.TaskDetailPanel$4.handleFormSubmit(Task
DetailPanel.java:315)
        at org.activiti.explorer.ui.form.FormPropertiesEventListener.componentEv
ent(FormPropertiesEventListener.java:39)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:490)


This standalone code works fine as expected:

public static void main(String[] args) {
      Map<String, String> properties = new HashMap<String, String>();

      // Create Activiti process engine
      ProcessEngine processEngine = ProcessEngineConfiguration
            .createStandaloneProcessEngineConfiguration()
            .setHistory(HistoryLevel.AUDIT.getKey())
            .setDatabaseSchemaUpdate(
                  ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
            .setJdbcUrl("jdbc:h2:tcp://localhost/activiti1")
            .setJobExecutorActivate(true).buildProcessEngine();

      RuntimeService runtimeService = processEngine.getRuntimeService();

      Map<String, Object> variables = new HashMap<String, Object>();
      variables.put("user", "kermit");
      variables.put("imageName", "mule2.jpg");
      variables.put("description", "Invoking Activiti from Java 4");

      org.activiti.engine.IdentityService identityService = processEngine
            .getIdentityService();

      try {
         identityService.setAuthenticatedUserId("kermit");
         runtimeService.startProcessInstanceByKey("SimplePictureRequest",
               variables);

      } finally {

         FormService formService = processEngine.getFormService();
         TaskService taskService = processEngine.getTaskService();

         ProcessDefinition definition = processEngine.getRepositoryService()
               .createProcessDefinitionQuery()
               .processDefinitionKey("SimplePictureRequest")
               .singleResult();

         System.out.println(definition.getId());

         ProcessInstance pi = processEngine.getRuntimeService()
               .createProcessInstanceQuery()
               .processDefinitionId(definition.getId()).singleResult();

         Task task = taskService.createTaskQuery()
               .processInstanceId(pi.getId()).singleResult();

         System.out.println(pi.getId());
         TaskFormData formData = formService.getTaskFormData(task.getId());

         properties.put(formData.getFormProperties().get(0).getName(),
               formData.getFormProperties().get(0).getValue());
         properties.put(formData.getFormProperties().get(1).getName(),
               formData.getFormProperties().get(1).getValue());
         properties.put(formData.getFormProperties().get(2).getName(),
               formData.getFormProperties().get(2).getValue());
         properties.put(formData.getFormProperties().get(3).getName(),
               formData.getFormProperties().get(3).getValue());
         properties.put(formData.getFormProperties().get(4).getName(),
               formData.getFormProperties().get(4).getValue());
         properties.put(formData.getFormProperties().get(5).getName(),
               "true");
         formService.submitTaskFormData(task.getId(), properties);
      }

   }

Thanks,
Barani

Outcomes