Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Stardust/Knowledge Base/API/ExamplesofAPIUsage/ActivityEventHibernateInitially

Checking Activity Events, Hand to Hand activity, Hibernate Initially (Runtime)

Purpose

There are certain instances when you want to find out the following during process execution(Runtime):

  • If an Activity has configured events at design time.
  • If an Activity has "Hibernate Initially" checked during design time.
  • What are the closest activities from a certain activity. Following code would help you achieve this, You will have to retrieve the Model Object, retrieve a specific process definition, or get all the process within a model.

Please Note: How you retrieve the model object would depend from where you execute this function, client or server side.

Sample Model

Stardust Activity Event and Hibernate Initially
import java.io.File;
import java.util.Iterator;
import ag.carnot.bpm.client.common.ModelCache;
import ag.carnot.workflow.model.IModel;
import ag.carnot.workflow.model.IProcessDefinition;
import ag.carnot.workflow.model.IActivity;
import ag.carnot.workflow.model.IEventHandler;
import ag.carnot.workflow.model.ITransition;
import ag.carnot.workflow.model.xpdl.XpdlUtils;
import ag.carnot.workflow.runtime.QueryService;
import ag.carnot.workflow.runtime.ServiceFactory;
import ag.carnot.workflow.runtime.ServiceFactoryLocator;
import ag.carnot.workflow.runtime.WorkflowService;
 
	public class WorkList {
 
		static IModel model; // this should be cached / fetched from the ModelCache
		static String modelRBname;
 
		public void getWList(){
 
			 ServiceFactory sf = ServiceFactoryLocator.get("motu","motu");
			 WorkflowService wfs = sf.getWorkflowService();
			 QueryService qs = null;
 
			 qs = sf.getQueryService();
 
			//Get model if this routine runs server side.
			//IModel model = (IModel) ModelCache.findModelCache().getAllModels();
 
			//Get model if this routine runs client side. 
			//IModel model = XpdlUtils.loadXpdlModel(new File("E:\\Worklist.xpdl"));
 
			IModel model = ModelManagerFactory.getCurrent().findActiveModel();  
 
			for (int k=0; k <model.getProcessDefinitions().size(); k++)
			{
			    IProcessDefinition pDef = (IProcessDefinition) model.getProcessDefinitions().get(k);
 
			    for (int i=0; i<pDef.getActivities().size(); i++)
			    {
				IActivity activity = (IActivity) pDef.getActivities().get(i);
 
				System.out.println("Activity Name :"  + activity.getName());
 
				// checks is hibernate on creation flag is set
				boolean isHibernateOnCreattion = activity.isHibernateOnCreation();
 
				System.out.println("Hibernate: " + isHibernateOnCreattion);
				// retrieves all timer events
				for (Iterator _iterator = activity.getAllEventHandlers("timer"); _iterator.hasNext();)
				{
				  IEventHandler eventHandler = (IEventHandler) _iterator.next();
				  System.out.println("Handler: " + eventHandler.getName());
				 }
 
				// gets all possible to activities
				   for (int j=0; j<activity.getOutTransitions().size(); j++)
				   {
				       ITransition transition = (ITransition) activity.getOutTransitions().get(j);
				       IActivity toActivity = transition.getToActivity();
				       System.out.println("To Actvitiy: " + toActivity.getName());
				   }
				 }
			     }
 
			   sf.close();
		}
}

Above function will return the following:

  • Activity Names
  • Hibernate : true/false (if checked during activity creation)
  • Handler: Timer event Name
  • To Activity: The closest activities this activity can reach out to. Similar Iterations can be done for other event types.

Copyright © Eclipse Foundation, Inc. All Rights Reserved.