cancel
Showing results for 
Search instead for 
Did you mean: 

Problem using initiator

bhj2
Champ in-the-making
Champ in-the-making
Hello,

I created my own version of the explorer and my own bpmn2.0 process. The problem is about the initiator. I want the task to be assigned to the initiator of the process but that works… SOMETIMES!! It's random.

Here is my bpmn process:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
   xmlns:activiti="http://activiti.org/bpmn" targetNamespace="EGovRunnerProcesses">

   <process id="MyTestProcess" name="MyTest Process">
      <startEvent id="theStart" activiti:initiator="initiator">
         <extensionElements>
            <activiti:formProperty id="person" type="string" />
            <activiti:formProperty id="reason" type="string" />
         </extensionElements>
      </startEvent>

      <sequenceFlow id='flow1' sourceRef='theStart' targetRef='writeSomethingTask' />

      <userTask id="writeSomethingTask" name="Write something" activiti:formKey="ch/glue/egovrunner/processes/MyTestForm.form" activiti:assignee="${initiator}">
         <documentation>
            Write something.
            </documentation>
      <extensionElements>
      <activiti:taskListener event="create" class="ch.glue.egovrunner.explorer.listeners.OsisTaskCreateListener" />
        </extensionElements>
      </userTask>

      <sequenceFlow id='flow2' sourceRef='writeSomethingTask' targetRef='theEnd' />

      <endEvent id="theEnd" />
   </process>

</definitions>

and here is the java method I use to start the process:
/**
    * Start a instance which has a start form.
    *
    * @param processDefinition
    *            the process definition to start
    * @param formData
    *            the form data filled by the user
    */
   public void submitStartForm(ProcessDefinition processDefinition,
         Map<String, String> formData) {
      ProcessInstance pi = getFormService().submitStartFormData(
            processDefinition.getId(), generateBusinessKey(), formData);
      
      processLayout.showProcessStartSuccess(processDefinition);
   }

I tested with always the same process definition and always the same content in formData but the initiator is sometimes null and sometimes ok.

Do you have an idea?
10 REPLIES 10

bhj2
Champ in-the-making
Champ in-the-making
I think I resolved my problem. It came from the fact that I use "ProcessEngines.getDefaultProcessEngine()".The process engine I received was not always the same and not always the one I used with the method "setAuthenticatedUserId(…)".

The solution is to used a configurated process engine, is that correct?

frederikherema1
Star Contributor
Star Contributor
Strange… That means that, at runtime, new engines get registered under the name "default" in ProcessEngines. You should double-check the way you bootstrap/configure your engine.

bhj2
Champ in-the-making
Champ in-the-making
Strange… That means that, at runtime, new engines get registered under the name "default" in ProcessEngines. You should double-check the way you bootstrap/configure your engine.

here is my config file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="processEngineConfiguration"
  class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
  <property name="jdbcUrl" value="jdbc:mysql://localhost:5555/activiti" />
  <property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
  <property name="jdbcUsername" value="root" />
  <property name="jdbcPassword" value="password" />
  <property name="databaseSchemaUpdate" value="false" />
  <property name="jobExecutorActivate" value="false" />
</bean>
</beans>

according to the user guide, everything should be ok here.

When is a process instance created? During the execution of getDefaultProcessEngine()?

It is a static HashMap, thus, only one instance of a ProcessEngine should exist for the key default. Isn't it?

frederikherema1
Star Contributor
Star Contributor
Only one should exist for that key, right. But when another engine is created with that name afterwards, it's registered as the default -> previous value in map dissapears.

The first time you call getDefaultProcessEngine(), the init() will be called, and all process-engines on the classpath will be created. How do you know the engine isn't the same one as before?

bhj2
Champ in-the-making
Champ in-the-making
Only one should exist for that key, right. But when another engine is created with that name afterwards, it's registered as the default -> previous value in map dissapears.

The first time you call getDefaultProcessEngine(), the init() will be called, and all process-engines on the classpath will be created. How do you know the engine isn't the same one as before?

I do a setAuthenticate in the IdentityService and then use a process with an initiator. What is strange is that I sometimes receive the same engine with the user authenticated and sometimes not. If I start my process 10 times, the initiator could be 8 times null and 2 times the authenticated user. Should I only call the getDefaultProcessEngine() once in my whole application?

If the engine called "default" exists, it should not be created again? Do I miss something?

frederikherema1
Star Contributor
Star Contributor
The authenticated user is thread-local, so best, before EVERY call to the engine API, use the setCurrentAuth… call.

fredg
Champ in-the-making
Champ in-the-making
This is good information, i saw many questions on forum about setCurrentAuth()
in multi threaded environements, this can help.
Could be nice in user-guide.

sreeraamang
Champ in-the-making
Champ in-the-making
Hi All,

We start the process instance via a camel route
for eg:

from("direct:start")
.to("activiti:workflow-process-name")

In such a scenario, how do we ensure that the initiator's id is stored in the database (act_hi_procinst.start_user_id_)?

What we tried was a pre and post camel processor as shown below. Still couldn't achieve what we want.

from("direct:start")
.process(new Processor(){
   public void process(Exchange exchange){
        identityService.setAuthenticatedUserId((String)exchange.getProperty("invoker"));
   }
})
.to("activiti:workflow-process-name")
.process(new Processor(){
    public void process(Exchange exchange){
       identityService.setAuthenticatedUserId(null);
    }
});

Before starting a camel route, we populate all process variables (including the invoker variable) in a map and then set it on the body of the exchange.

Can somebody please let me know as to what is wrong here or is there an elegant approach to fix this issue?

best regards
Sriraman.

sreeraamang
Champ in-the-making
Champ in-the-making
Hi All,

Got it working. I had populated all process variables in a map and set it to the body of the camel exchange. However, while retrieving, i was trying to take it from the exchange properties. Inside the first processor after direct:start, I retrieved the body and cast it to a map and then try to find the object with key as invoker as shown below:

Map processVariables = (Map) exchange.getIn().getBody();
identityService.setAuthenticatedUserId((String)processVariables.get("invoker"));

What I want to know is whether the approach is correct ?

Thanks in advance.

best regards
Sriraman.