cancel
Showing results for 
Search instead for 
Did you mean: 

Business Rule task not updating Java object

mikepoole
Champ in-the-making
Champ in-the-making
I have a business rule task that uses a drl file to update a Java object which was created in a Java Service Task prior to the rule task

I have some printlns in the functions that the drl file triggers so I am confident that the rule task is firing AND evaluating correctly.

The next step in the process is a user task. When I retrieve the values form the Java object to display on the form, they are the pre business task/drools update values

ie:
1. Create Article (my Java object (which implements Serializable)) - set size to 5 and assign Article to process variable "pvArticle"
2. Business Rule task runs and sets size to 50 (Tomcat shows the setSize() method being triggered and this.size being set to 50)
3. User task form has #{pvArticle.getSize()} as the expression - returns 5

What am I doing wrong?

Many thanks

Mike
20 REPLIES 20

trademak
Star Contributor
Star Contributor
Hi,

That's strange indeed. I just did a small test myself and that worked as expected.
Can you share your test project?

Best regards,

mikepoole
Champ in-the-making
Champ in-the-making
Tijs

It is very strange indeed. I'm sure I am doing something fundamentally wrong and just not seeing it

Attached is a zip file with (hopefully) all the relevant info you need

Many thanks

Mike

trademak
Star Contributor
Star Contributor
Mike,

Your Drools example works fine with some changes.
In the code you only claim the user task, which means that the process instance doesn't even reach the business rule task, but still waits for the first user task to complete.
Also a better way to create the process engine would be:

ProcessEngine processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.test.xml").buildProcessEngine();
And then rename your config file to activiti.test.xml. This is to be sure that the Activiti Engine uses the right Activiti config.
Also the script task you included can be removed, because you also set the variable in the Java service task.
After making these changes the test runs fine and the Java article object is updated by the business rule task.

Best regards,

mikepoole
Champ in-the-making
Champ in-the-making
Tijs

Many thanks for the reply

I'm a little confused by your first comment - "In the code you only claim the user task, which means that the process instance doesn't even reach the business rule task, but still waits for the first user task to complete.". (I've done the other bits - improved the ProcessEngine creation and removed the script task) with no success.

When I create the process instance, do I have to claim ALL the tasks in the process? My example requires the user task to be completed before running the business rule task as it is dependant on user input values.

How do I claim the things other than the user task to allow the process instance to reach the business rule task?

My code is currently:

public class DroolsDemo {

public static void main(String[] args){

  ProcessEngine processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.test.xml").buildProcessEngine();
  RepositoryService repositoryService = processEngine.getRepositoryService();
  RuntimeService runtimeService = processEngine.getRuntimeService();

  // Deploy the process definition (and sub processes and rules)
  repositoryService.createDeployment()
  .addClasspathResource("DroolsExample.bpmn20.xml")
  .addClasspathResource("ArticleSize.drl")
  .deploy();

  // Start a process instance
  String procId = runtimeService.startProcessInstanceByKey("drools").getId();

  // Get the first task
  TaskService taskService = processEngine.getTaskService(); 
  List<Task> tasks = taskService.createTaskQuery().processDefinitionKey("drools").list();
  for (Task task : tasks) {
   System.out.println("ProcID: " + procId + " - Task ID: " + task.getId() + " created on " + task.getCreateTime());
   taskService.claim(task.getId(), "fozzie");
  }

  System.out.println("DROOLS DEMO FINISHED");
}
}

trademak
Star Contributor
Star Contributor
Hi Mike,

What I mean is that calling the claim method only changes the state of the task, it doesn't complete it.
So instead of claim, you should call the complete method and then the process instance will continue to the next activity.

Best regards,

mikepoole
Champ in-the-making
Champ in-the-making
Thanks Tijs

So does the user pressing the "Complete task" not do the same thing?

I want the user task to wait (having been claimed by fozzie) so that the user enters the one value, presses the "Complete task" button which will then continue the process.

Mike

trademak
Star Contributor
Star Contributor
Okay, maybe I didn't understand your test good enough.
In my version of the test, everything happens in that test, so you can get the feedback immediately.
When you use the Activiti Explorer to complete the task, the process instance will run on the Activiti Explorer, and that's a bit strange to my feeling.
You then only start the process instance in the test and complete it in the Activiti Explorer.

Best regards,

mikepoole
Champ in-the-making
Champ in-the-making
Tijs

I think I'm not doing a test, merely creating a new instance via Java then processing it all in Activiti Explorer.

Mike

trademak
Star Contributor
Star Contributor
Mike,

Yep. The only thing is that you then have to make sure that the service task classes used in the process definition are available in the Activiti Explorer classpath.
In addition make sure that the RulesDeployer is activated in the Activiti Engine Spring config of the Activiti Explorer.

Best regards,