cancel
Showing results for 
Search instead for 
Did you mean: 

Timer Events based on task assignment

ruedesilva
Champ in-the-making
Champ in-the-making
Hi,

Our customer has a request where once a task is assigned it can only sit with a person for a certain amount of time and then goes back to the queue (As there is no queue concept here, I managed this by setting the Assignee to null). Then the task can be picked up again by the same user, new user or a manager re-assign to someone else.

The issue is a Timer event can be set on the task itself as a boundaryEvent. So the timer starts right away when the task gets created. This is no good as I need the timer to start only when the task gets assigned. Can this be achieved somehow thru a tasklistner or some other mechanism?


Thanks,
Rue
9 REPLIES 9

frederikherema1
Star Contributor
Star Contributor
I'm afraid not, that's just how the BPMN-spec works… you can, however, let the sequence-flow (when timer fires) go to a gateway that decides to go back to the user-task or do what the timer should do in case an assignee has been set. You can easilly set a variable 'wasAssigned' in a taskListener (event=assignee) and let the gateway act on that.

Other solution is to alter the dueDate in the JobEntity table for the timer, but that will require using Impl stuff and probabily some dodgy stuff as well Smiley Wink

ruedesilva
Champ in-the-making
Champ in-the-making
Well the gateway approach is not going to work. I was thinking of that at the beginning also. Because in order for that to work the user task has to be completed (so that it takes the next transition) But just getting an assignee cannot complete the task as the assignee has to do a unit of work and then complete the task.  So setting 'wasAssigned' in a taskListener will not really do anything.

The only way is to alter the dueDate in the JobEntity table for the timer in a tasklistener.  Can you assist me in some details as to the impl classes I need t use?

thanks,
Rue

frederikherema1
Star Contributor
Star Contributor
Don't tell my boss, Tom, that I said what I'm about to say Smiley Wink Again, at your own risk…

First, you should get hold of the command-context, in order to do stuff inside activiti-context, this can be done using the Process-engine (cast to ProcessEngineImpl).

Next, get hold of the ManagementSession using, get the JobEntity you need (using findById or something)…

Update the entity (set duedate), and save the entity using the DBSQLSessionFactory. No magic is performed, so mook at the way the ManagementSession works, that should get you a long way.

ruedesilva
Champ in-the-making
Champ in-the-making
Wow. It is my happy day. Thank you so much. Since I am updating just the due date of the timer I doubt I will affect anything else (and I promise not to touch anything else  Smiley Wink

In the taskListner I have only a DelegateTask in the notify method. From that I am not sure how to get a Command Context etc. How do I do that?

I could possibly get the processEngine directly and cast it as you say (as it is in the Weblogic JVM). But looking at the src for ProcessEngineImpl I do not see a way to get ManagementSession. If you can give some code snippets that would help a  lot.

thanks so much,
Rue

frederikherema1
Star Contributor
Star Contributor
You should call use the static methods on Context object (org.activiti.engine.impl.context.Context) to get hold of the commandContext

Just call getSession(SessionClassYouNeed.class) on CommandContext

ruedesilva
Champ in-the-making
Champ in-the-making
Thanks. Where do I find this ManagementSession that you describe above that I can take a look to see how DB updates are done?

- Rue

frederikherema1
Star Contributor
Star Contributor
Activiti sourcecode…
Public SVN

Our SVN repo has moved to codehaus!

URL: http://svn.codehaus.org/activiti

Public anonymous access to the Activiti codebase. No username or password necessary.

ruedesilva
Champ in-the-making
Champ in-the-making
There is a source.jar (activiti-engine-5.7-sources.jar)  file that gets installed in the lib directory . This seems to contain all the (or most of?) the source code? I just couldn't find the ManagementSession (if that is what it is actually named). Is that the correct name and what package could I find it?)

thanks,
Rue

frederikherema1
Star Contributor
Star Contributor
Sorry, that's the old name… Use the JobManager :

commandContext
      .getJobManager()