Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Stardust/Knowledge Base/Java API/Dynamic Event Binding"

(No difference)

Revision as of 01:24, 9 September 2013

Requirements

A process, let say, Main Process has to trigger a sub-process called Escalation Process, but it doesn't know when to trigger it (not known during design). It only knows that when certain data or indicator will be available at proces execution it would like to trigger the sub-process.

Approach

We will be modelling the Main Process by defining an Process level Event Handling, Timer, and will not bind it Automatically. We will use a process data that will be set somewhere during process execution and this data will be used to indicate the time when we would like the Timer event to get fired and trigger the Escalation Process.

TimerEventDefinition1.JPG


TimerEventDefinition2.JPG


Complete Process

BindActionTestModel MainProcess Default.jpg

We will use IPP WorkflowService's API bindProcessEventHandler to bind the event after a value is available to the data to which Timer is bound.

Code:

package com.sungard.cm.invo.ipp.training;
 
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
 
import org.eclipse.stardust.common.config.Parameters;
import org.eclipse.stardust.engine.api.query.ActivityInstanceQuery;
import org.eclipse.stardust.engine.api.query.ActivityInstances;
import org.eclipse.stardust.engine.api.query.ActivityStateFilter;
import org.eclipse.stardust.engine.api.runtime.ActivityInstance;
import org.eclipse.stardust.engine.api.runtime.ActivityInstanceState;
import org.eclipse.stardust.engine.api.runtime.AdministrationService;
import org.eclipse.stardust.engine.api.runtime.DocumentManagementService;
import org.eclipse.stardust.engine.api.runtime.QueryService;
import org.eclipse.stardust.engine.api.runtime.ServiceFactory;
import org.eclipse.stardust.engine.api.runtime.ServiceFactoryLocator;
import org.eclipse.stardust.engine.api.runtime.UserService;
import org.eclipse.stardust.engine.api.runtime.WorkflowService;
import org.eclipse.stardust.engine.core.runtime.beans.removethis.SecurityProperties;
 
public class PrioritySettler {
	private static ServiceFactory serviceFactory;
	private static QueryService queryService;
	private static WorkflowService workflowService;
	private static UserService userService;
	private static AdministrationService adminService;
	private static DocumentManagementService documentService;
 
	public PrioritySettler() {
 
	}
 
	@SuppressWarnings("deprecation")
	public void evaluateAndUpdatePriority(long pOID) {
 
		System.out.println("Process OID to change the priority: "+ pOID);
		try{
			init("motu", "motu");
 
			workflowService.bindProcessEventHandler(pOID, "SLA");
 
 
		}catch(Exception e){
			//Default thresholdMins to 10 minutes
			e.printStackTrace();
			thresholdValue = 1;
		}
		finally {
			uninit();
		}
			}
 
	static void init(String backdoorAccount, String backdoorKey) throws IOException {
 
		// Get the factory and provide login credentials
		Map <String, String> prop = new HashMap();
 
		serviceFactory = ServiceFactoryLocator
				.get("motu", "motu");
		// Get the service instances
		queryService = serviceFactory.getQueryService();
		workflowService = serviceFactory.getWorkflowService();
		userService = serviceFactory.getUserService();
		documentService = serviceFactory.getDocumentManagementService();
		adminService = serviceFactory.getAdministrationService();
 
 
	}
 
	static void uninit() {
		//System.out.println("In Uninit#############");
		if (serviceFactory != null) {
			// Release all resources
			serviceFactory.close();
		}
	}
}


Results


In this example case, when Main Process is started:

  1. User will input data (time in milliseconds since Jan 1, 1970) on first activity UI.
  2. User will see the entered time value on next screen, after completing this activity.
  3. The application activity "Bind Timer", will call the POJO method and bind the Timer Event named "SLA" and the process Escalation Process witll be triggered at the time the user entered on first activity.


For example, you started Main Process at 16:45 hours and input the value (in milliseconds since Jan1, 1970) of 16:50, the Escalation Process will be triggered at 16:50.

Artifacts

Please get the required artifacts from here

Back to the top