cancel
Showing results for 
Search instead for 
Did you mean: 

Get name of currently processed activity

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

I am trying to achieve what seems to be an easy task - get currently activity name being processed.
I have an UI which shows currently running process and a progress bar which shows the progress of a ServiceTask.
If activity is something different - eg ScriptTask or a UserTask - it does not show the progress bar but only spinning wheel.
I also want to show the current task name being processed.

Is there a simple way to achieve it ?

I thought I would set a variable "current-activity" with the name of the activity like so:


case ACTIVITY_STARTED:
   if (ActivitiActivityEvent.class.isAssignableFrom(event.getClass())) {
      ActivitiActivityEvent activitiEvent = (ActivitiActivityEvent) event;
      runtimeService.setVariable(event.getExecutionId(), "current-activity", activitiEvent.getActivityName());
   }
break;


That code is in a service layer which listens to ActivitiEvent.
Please keep in mind that UI might be opened by a user in a middle of processing the activiti process.

I have a piece of code on the UI that does:


(String) activitiService.getRuntimeService().getVariable(execution.getId(), "current-activity"));


but it seems to be picking up only the previous variable content. I suspect it has to do with the transactions management.


Thanks,
Adrian
2 REPLIES 2

warper
Star Contributor
Star Contributor
Is there a simple way to achieve it ?
Nope. Transactions, cancellations and multiple executions per process are ruining the whole idea.
You can send notifications to your UI-related in-memory (or DB) storage and persist current activity there. It's important that you send notifications, not use direct listeners, your store should be in different transaction context and/or out of transactions.
You should process events of activity/process cancellation, transitions to wait-states etc.

I see similar reporting in unit tests, sometimes activity sequence is wrong Smiley Sad

serid
Champ in-the-making
Champ in-the-making
Hi,

Many thanks for your response !
Yes - I have already modified my service class so I am buffering the name of currently running activity.
Wanted to avoid that on the service layer (don't like to have a state of any service) but cannot find any better way.


Thanks,
Adrian