cancel
Showing results for 
Search instead for 
Did you mean: 

callActivity not setting the start user in second execution

iblanco
Confirmed Champ
Confirmed Champ
I'm using Activiti 5.19 embeded in Alfresco.
I'm doing some test to check if calling activities dynamically could solve one of our use cases.

So I defined a workflow that simply takes a process name from a config variable and calls that activity. The activity itself executes a little script task and then starts an Alfresco User Task. When the task is completed the activity ends and it goes back to the parent process. Then the parent process checks the config again and executes the next activity and so on…

The first time the callActivity is used everything works fine but the second time the callActivity starts the subprocess without setting an owner (start_user_id in table ACT_HI_PROCINST is null in the DB ) for child process.

This is the process XML (without the graphical part for brevity):


<?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://activiti.org/bpmn">
  <process id="testProcessChooseProcess" name="Proceso selector de trámites" isExecutable="true">
    <startEvent id="chooserStartEvent" name="Process chooser start event" activiti:formKey="twf:submitChooseProcess"></startEvent>
    <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
    <callActivity id="callNextActivity" name="Call next activity" calledElement="${nextActivity}">
      <extensionElements>
        <activiti:in source="bpm_sendEMailNotifications" target="bpm_sendEMailNotifications"></activiti:in>
        <activiti:in source="bpm_workflowDueDate" target="bpm_workflowDueDate"></activiti:in>
        <activiti:in source="bpm_assignee" target="bpm_assignee"></activiti:in>
        <activiti:in source="bpm_workflowPriority" target="bpm_workflowPriority"></activiti:in>
        <activiti:in source="bpm_workflowDescription" target="bpm_workflowDescription"></activiti:in>
        <activiti:in source="initiator" target="initiator"></activiti:in>
      </extensionElements>
    </callActivity>
    <sequenceFlow id="nextProcessSequence" name="Call next process" sourceRef="exclusivegateway1" targetRef="callNextActivity">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${nextActivity != null}]]></conditionExpression>
    </sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="noMoreProcessesSequence" name="No more processes" sourceRef="exclusivegateway1" targetRef="finalTaskAssigment">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${nextActivity == null}]]></conditionExpression>
    </sequenceFlow>
    <serviceTask id="alfrescoScripttask1" name="Get next activiti" activiti:class="org.alfresco.repo.workflow.activiti.script.AlfrescoScriptDelegate">
      <extensionElements>
        <activiti:field name="script">
          <activiti:string><![CDATA[logger.log("Parsing twf_processConfig v17…");
var nextActivity = 'dummyUserProcess';
execution.setVariable('nextActivity', nextActivity);
logger.log("Next activity will be: " + nextActivity);]></activiti:string>
        </activiti:field>
      </extensionElements>
    </serviceTask>
    <sequenceFlow id="flow1" sourceRef="chooserStartEvent" targetRef="alfrescoScripttask1"></sequenceFlow>
    <sequenceFlow id="flow2" sourceRef="alfrescoScripttask1" targetRef="exclusivegateway1"></sequenceFlow>
    <userTask id="finalTaskAssigment" name="Final user task" activiti:assignee="${initiator.properties.userName}" activiti:formKey="wf:adhocTask"></userTask>
    <sequenceFlow id="flow4" sourceRef="finalTaskAssigment" targetRef="endevent1"></sequenceFlow>
    <sequenceFlow id="flow6" sourceRef="callNextActivity" targetRef="alfrescoScripttask1"></sequenceFlow>
  </process>


5 REPLIES 5

jbarrez
Star Contributor
Star Contributor
What do you mean with 'second time'? I only see one call activity? Or does it loop back (That's what I assume)?

iblanco
Confirmed Champ
Confirmed Champ
Hi Joram:

Yes, it does loop back after executing each activity. The called activity is just a process with a single user task so whenever the user task is completed the parent process is resumed and calls the activity again.

I execute my process as user "admin". When the activity is called for the first time the called activity has the start_user_id set as "admin" as expected (both processes, the "parent" process and the called process, both have the user set correctly).

When I end the user task, once more with user "admin", the execution of the parent process resumes as expected and the callActivity is called once more but this time the child process has no "start_user_id" set at all.

It seems to me like if "resuming the parent" would cause the loss of the authentication.

I've tried to debug the issue across Activiti code and saw that the current authenticated user is saved in a ThreadLocal variable. Maybe there is some kind of thread when resuming the execution or something like that?

Thanks

jbarrez
Star Contributor
Star Contributor
> I've tried to debug the issue across Activiti code and saw that the current authenticated user is saved in a ThreadLocal variable.

That is correct.

How are you running this? Via Explorer? Unit test?

iblanco
Confirmed Champ
Confirmed Champ
I'm deploying and running it in Alfresco 5.1g.

jbarrez
Star Contributor
Star Contributor
I've added a unit test for it here, but I cannot reproduce it on the Activiti engine: https://github.com/Activiti/Activiti/commit/a6c8fda1e64497f50e76bb1ada77044d4a77cdaf

Would be interesting to see what the differences are between this and your case.