AnsweredAssumed Answered

How do I get the current ProcessInstance in SpringBean?

Question asked by mgriffith on Jul 8, 2011
Latest reply on Jul 19, 2011 by mgriffith
Hello all,

I have a ServiceTask in my workflow that resolves to a Spring Managed bean. It looks like this:

<serviceTask id="springTask1" name="BeanTest" activiti:expression="${taskBean.execute(contactName)}"></serviceTask>

I am not starting the process via code, but the process is either started via the activti-rest api or a form.  How can I get the context in which this task is executing from inside the bean that the task invokes, so that I might be able to add a process variable that could be referenced in a later task, such as an email.

My process engine is Spring enabled.   Here's a sample of what my managed bean looks like that is being invoked from the expression:

package org.psc.bpmn.examples;

import java.util.List;

import org.activiti.engine.RuntimeService;
import org.psc.bpmn.tasks.Contact;
import org.psc.service.ContactService;

public class GetBeanTest {
   
   public GetBeanTest() {
      super();
   }

   private ContactService contactService;
   private RuntimeService runtimeService;
   
   public void execute(String contactName) throws Exception {
      if(contactService == null){
         System.out.println("Bean was null!");
      }else{
         System.out.println("Bean is valid!");
         List<Contact> contacts= contactService.getContacts();
         System.out.println("There are " + contacts.size() +" in the contact list.");
         for (Contact contact : contacts) {
            if(contact.getName().equalsIgnoreCase(contactName)){
               System.out.println("Found the contact! " + contactName );
                                        // How do I get the current process so I can put some new process variable into it?
                                        // runtimeService.?????
            }
         }
      }

   }

   public void setRuntimeService(RuntimeService runtimeService) {
      this.runtimeService = runtimeService;
   }
   public void setContactService(ContactService contactService) {
      this.contactService = contactService;
   }   
}

I hope my question is clear. 

Thanks in advance for any replies.

Outcomes