cancel
Showing results for 
Search instead for 
Did you mean: 

CDI BusinessProcessEvent @Observer, detecting ProcessInstance start

mason
Champ in-the-making
Champ in-the-making
Hello all.  I am using the Activiti-CDI module, a CDI observer, @Observes BusinessProcessEvent businessProcessEvent.  All of that is working perfectly.  I would like to be able to run some code when a ProcessInstance is started or before it's destroyed.  I've been trying to figure out a way to see what node type the BusinessProcessEvent is at, for example a Start Event or an End Event, but have been unable to do so.  Any pointers on how I can do that?

Thanks,
Mason
3 REPLIES 3

mason
Champ in-the-making
Champ in-the-making
I tried to inject the Task, as per the manual, using @Inject Task task, to see if I could get the current node from that,  Now I get the error
<code>
Servlet.service() for servlet Faces Servlet threw exception: org.activiti.cdi.ActivitiCdiException: Cannot work with tasks in an activiti command.
at org.activiti.cdi.impl.context.DefaultContextAssociationManager.getTask(DefaultContextAssociationManager.java:235) [activiti-cdi-5.13.jar:]
at org.activiti.cdi.BusinessProcess.getTask(BusinessProcess.java:467) [activiti-cdi-5.13.jar:]
at org.activiti.cdi.CurrentProcessInstance.getTask(CurrentProcessInstance.java:99) [activiti-cdi-5.13.jar:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_32]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_32]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_32]
</code>

mason
Champ in-the-making
Champ in-the-making
I found a way to do it, but it's a bit messy.  Please let me know if there is a cleaner way to do this.  Thanks!

<code>
public void onProcessEvent(@Observes BusinessProcessEvent businessProcessEvent, ProcessInstance pi) {
  ExecutionEntity ee = (ExecutionEntity) pi;
   if (null != ee) {
     ActivityImpl ai = ee.getActivity();
   if ("start".equals(businessProcessEvent.getType().getTypeName()) && ai.getActivityBehavior().getClass().equals(NoneStartEventActivityBehavior.class))
    createProcessInstance(businessProcessEvent, pi);
   if ("end".equals(businessProcessEvent.getType().getTypeName()) && ai.getActivityBehavior().getClass().equals(NoneEndEventActivityBehavior.class))
    endProcessInstance(businessProcessEvent, pi);
   }
}
</code>

paulo1
Champ in-the-making
Champ in-the-making
Does it work for tomcat7?
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.