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

Difference between revisions of "Stardust/Knowledge Base/API/JavaAPICookbook/Stardust Workflow Service in Action"

(Fetching user work-list)
m
Line 1: Line 1:
 
== Introduction  ==
 
== Introduction  ==
  
In this article, we will explain the capabilities of Stardust Workflow Service in details with examples. It is assumed that you are familiar with the modeling the processes with Stardust. If not please read the product documentation here first.<br>If you are using the Stardust in embedded mode, then it is likely that you will have to use this service extensively. The Workflow Service is the heart of Stardust Engine. Its core features include:<br>&nbsp; • Starting a process<br>&nbsp; •&nbsp;Executing an activities<br>&nbsp; • Activating, delegating, suspending and aborting activities<br>&nbsp; • Accessing workflow data<br>
+
In this article, we will explain the capabilities of Stardust Workflow Service in details with examples. It is assumed that you are familiar with the modeling the processes with Stardust. If not please read the product documentation here first.<br>If you are using the Stardust in embedded mode, then it is likely that you will have to use this service extensively. The Workflow Service is the heart of Stardust Engine. Its core features include:<br>
 +
*Starting a process<br>&nbsp;  
 +
*Executing an activities<br>
 +
*Activating, delegating, suspending and aborting activities
 +
*Accessing workflow data<br>
  
 
== Example process model  ==
 
== Example process model  ==
Line 15: Line 19:
 
*The above mentioned process model is already deployed.  
 
*The above mentioned process model is already deployed.  
 
*We have a user with account, john, associated with ‘Employee’ role.  
 
*We have a user with account, john, associated with ‘Employee’ role.  
*We have a user with account, smith, associated with ‘Manager’ role.<br>&nbsp;
+
*We have a user with account, smith, associated with ‘Manager’ role.
 +
 
  
 
== &nbsp;The workflow service operations  ==
 
== &nbsp;The workflow service operations  ==
Line 23: Line 28:
 
The following code snippet shows how to start a process. You may execute this snippet, in this case, when user chooses to apply for the leave.<br>
 
The following code snippet shows how to start a process. You may execute this snippet, in this case, when user chooses to apply for the leave.<br>
 
<source lang="Java">
 
<source lang="Java">
                String processID = "LeaveApplicationProcess";
+
String processID = "LeaveApplicationProcess";
                Map<String, String> initData = new HashMap<String, String>();
+
Map<String, String> initData = new HashMap<String, String>();
                boolean isSynchronous = true;
+
boolean isSynchronous = true;
                ProcessInstance startedProcess = wfs.startProcess(processID, initData, isSynchronous);
+
ProcessInstance startedProcess = wfs.startProcess(processID, initData, isSynchronous);
 +
 
 
</source>  
 
</source>  
  
<br>Where;<br>The first method parameter, processID, is ID of the process to be started. In the Stardust runtime there can be many different processes. A process is uniquely identified by the ID. <br>• The second parameter is contains the data to be passed for process being started. We will discuss this in details in a separate article ‘Handling In and Out Data with API’.<br>• The third Boolean parameter indicates whether to start a process in sync mode.<br>• If the process is started successfully, this method returns started process instance.  
+
<br>Where;<br>
 +
*The first method parameter, processID, is ID of the process to be started. In the Stardust runtime there can be many different processes. A process is uniquely identified by the ID.
 +
* The second parameter is contains the data to be passed for process being started. We will discuss this in details in a separate article ‘Handling In and Out Data with API’.
 +
* The third Boolean parameter indicates whether to start a process in sync mode.
 +
* If the process is successfully started, this method returns started process instance.  
  
 
This operation will start the process and execute all non-interactive activities on the way. As soon as it encounters non-interactive activity, it will create that activity instance and suspends to its role work basket.<br>In our process, the first activity itself is a manual activity. Hence, the Stardust will create its instance and assign it to the ‘Employee’ role. The instance will be in the suspended state. Now, any user belonging to the Employee can activate and complete it.<br>
 
This operation will start the process and execute all non-interactive activities on the way. As soon as it encounters non-interactive activity, it will create that activity instance and suspends to its role work basket.<br>In our process, the first activity itself is a manual activity. Hence, the Stardust will create its instance and assign it to the ‘Employee’ role. The instance will be in the suspended state. Now, any user belonging to the Employee can activate and complete it.<br>
Line 39: Line 49:
 
When an activity is created and assigned to a role, by default, it goes into suspended state. When a user belonging to the role chooses to work on the activity instance, it gets activated. So, you may say, activating an activity means choosing to work on it and the other way around. <br>The following code snippet shows how to activate and complete an activity instance in single operation.<br>
 
When an activity is created and assigned to a role, by default, it goes into suspended state. When a user belonging to the role chooses to work on the activity instance, it gets activated. So, you may say, activating an activity means choosing to work on it and the other way around. <br>The following code snippet shows how to activate and complete an activity instance in single operation.<br>
 
<source lang="Java">
 
<source lang="Java">
                long activityInstanceOID = 401L;
+
long activityInstanceOID = 401L;
String context="default";
+
String context = null;
Map<String, ?> outData =new HashMap<String, String>();
+
Map<String, ?> outData = new HashMap<String, String>();
int flags = WorkflowService.FLAG_ACTIVATE_NEXT_ACTIVITY_INSTANCE;
+
int activateNextActivityFlag = WorkflowService.FLAG_ACTIVATE_NEXT_ACTIVITY_INSTANCE;
ActivityCompletionLog activityCompletionLog = wfs.activateAndComplete(activityInstanceOID, context, outData, flags);
+
ActivityCompletionLog activityCompletionLog = wfs.activateAndComplete(activityInstanceOID, context, outData,
 +
                                                                                        activateNextActivityFlag);
 
 
</source>  
+
</source>
   
+
<br>Where;<br>
 +
*The first parameter, activityInstanceOID, is an OID of the activity which you want to activate and complete. I have hard-coded an activity OID. Normally, you will get this from user’s work-list or using query service or even may be cached by your embedding application.
 +
*Second parameter is the context on which data mapping will be performed. The value of null maps the data in ‘default’ context. We will see more on data mapping in separate section bellow.
 +
*Third parameter is the process data that activity will change.  
 +
*The last parameter is a flag that indicates whether to activate the activity immediately after completing the current one.
 +
 
 +
 
 +
Note that <big>activateAndComplete</big> method returns an instance of ActivityCompletionLog. This contains the completed activity and possibly, next activated activity details. The Stardust will activate the next activity only if the next interactive activity exists, and current user can activate it.
  
 
The following code snippet shows how to activate and then complete an activity instance in separate operations.
 
The following code snippet shows how to activate and then complete an activity instance in separate operations.
 +
 
<source lang="Java">
 
<source lang="Java">
                activityInstance = wfs.activate(activityInstanceOID);
+
ActivityInstance activityInstance = wfs.activate(activityInstanceOID);
                activityInstance = wfs.activateNextActivityInstance(activityInstanceOID);
+
ActivityCompletionLog activityCompletionLog = wfs.complete(activityInstance.getOID(), context, outData, activateNextActivityFlag);
                activityCompletionLog = wfs.complete(activityInstanceOID, context, outData, flags);
+
</source>
</source>  
+
 
The following code snippet shows how to activate the next activity instance of the given process instance.
 
The following code snippet shows how to activate the next activity instance of the given process instance.
 
<source lang="Java">
 
<source lang="Java">
ActivityInstance activityInstance = wfs.activateNextActivityInstanceForProcessInstance(startedProcess.getOID());
+
ActivityInstance activityInstance = wfs.activateNextActivityInstanceForProcessInstance(startedProcess.getOID());
+
 
</source>  
 
</source>  
  

Revision as of 08:06, 10 November 2011

Introduction

In this article, we will explain the capabilities of Stardust Workflow Service in details with examples. It is assumed that you are familiar with the modeling the processes with Stardust. If not please read the product documentation here first.
If you are using the Stardust in embedded mode, then it is likely that you will have to use this service extensively. The Workflow Service is the heart of Stardust Engine. Its core features include:

  • Starting a process
     
  • Executing an activities
  • Activating, delegating, suspending and aborting activities
  • Accessing workflow data

Example process model

We will use the following simple leave application process for this article.
<process img goes here>

Prerequisite

To reduce complexity, I assume following;

  •  The Stardust is being used in embedded mode and user interaction is performed via embedding application UI. That is, you may invoke methods like starting a process or completing an activity when user chooses a command or link, or when submitting a form in the application. The responsibility to collect required data from user or from given context belongs to the application.
  • We have reference to the initialized workflow service named, wfs.
  • The above mentioned process model is already deployed.
  • We have a user with account, john, associated with ‘Employee’ role.
  • We have a user with account, smith, associated with ‘Manager’ role.


 The workflow service operations

Starting a process

The following code snippet shows how to start a process. You may execute this snippet, in this case, when user chooses to apply for the leave.

String processID = "LeaveApplicationProcess";
Map<String, String> initData = new HashMap<String, String>();
boolean isSynchronous = true;
ProcessInstance startedProcess = wfs.startProcess(processID, initData, isSynchronous);


Where;

  • The first method parameter, processID, is ID of the process to be started. In the Stardust runtime there can be many different processes. A process is uniquely identified by the ID.
  • The second parameter is contains the data to be passed for process being started. We will discuss this in details in a separate article ‘Handling In and Out Data with API’.
  • The third Boolean parameter indicates whether to start a process in sync mode.
  • If the process is successfully started, this method returns started process instance.

This operation will start the process and execute all non-interactive activities on the way. As soon as it encounters non-interactive activity, it will create that activity instance and suspends to its role work basket.
In our process, the first activity itself is a manual activity. Hence, the Stardust will create its instance and assign it to the ‘Employee’ role. The instance will be in the suspended state. Now, any user belonging to the Employee can activate and complete it.

 

Activating and completing an activity

When an activity is created and assigned to a role, by default, it goes into suspended state. When a user belonging to the role chooses to work on the activity instance, it gets activated. So, you may say, activating an activity means choosing to work on it and the other way around.
The following code snippet shows how to activate and complete an activity instance in single operation.

long activityInstanceOID = 401L;
String context = null;
Map<String, ?> outData = new HashMap<String, String>();
int activateNextActivityFlag = WorkflowService.FLAG_ACTIVATE_NEXT_ACTIVITY_INSTANCE;
ActivityCompletionLog activityCompletionLog = wfs.activateAndComplete(activityInstanceOID, context, outData,
                                                                                         activateNextActivityFlag);


Where;

  • The first parameter, activityInstanceOID, is an OID of the activity which you want to activate and complete. I have hard-coded an activity OID. Normally, you will get this from user’s work-list or using query service or even may be cached by your embedding application.
  • Second parameter is the context on which data mapping will be performed. The value of null maps the data in ‘default’ context. We will see more on data mapping in separate section bellow.
  • Third parameter is the process data that activity will change.
  • The last parameter is a flag that indicates whether to activate the activity immediately after completing the current one.


Note that activateAndComplete method returns an instance of ActivityCompletionLog. This contains the completed activity and possibly, next activated activity details. The Stardust will activate the next activity only if the next interactive activity exists, and current user can activate it.

The following code snippet shows how to activate and then complete an activity instance in separate operations.

ActivityInstance activityInstance = wfs.activate(activityInstanceOID);
ActivityCompletionLog activityCompletionLog = wfs.complete(activityInstance.getOID(), context, outData, activateNextActivityFlag);

The following code snippet shows how to activate the next activity instance of the given process instance.

ActivityInstance activityInstance = wfs.activateNextActivityInstanceForProcessInstance(startedProcess.getOID());

Aborting an activity

Sometimes, you need to abort an activity and the process to which it belongs. This could be for reasons that this process instance is no more required for business.
The following code snippet shows how to abort an activity and effectively complete process instance.

                ActivityInstance abortedActivityInstance = wfs.abortActivityInstance(activityInstanceOID);


The following code snippet shows how to indicate the scope of process abortion.

                AbortScope abortScope = AbortScope.SubHierarchy;
		abortedActivityInstance = wfs.abortActivityInstance(activityInstanceOID, abortScope);

Delegating an activity

You may delegate an activity instance to a specific user or a participant.

		wfs.delegateToDefaultPerformer(activityInstanceOID);
		String performerID = "Project";
		wfs.delegateToParticipant(activityInstanceOID, performerID);
		long userOID = 233L; 
		wfs.delegateToUser(activityInstanceOID, userOID);



Suspending an activity

paragragh text

                ContextData contextData = null;
		wfs.suspend(activityInstanceOID, contextData);
		wfs.suspendToDefaultPerformer(activityInstanceOID);
		String participantID = "Project";
		wfs.suspendToParticipant(activityInstanceOID, participantID,context, outData);
		wfs.suspendToUser(activityInstanceOID);
		wfs.suspendToUser(activityInstanceOID, userOID);
		wfs.suspendToUser(activityInstanceOID, userOID, context, outData);

Fetching user work-list

some text goes here

{...
 
		String processID = "LeaveApplicationProcess";
		Map<String, String> initData = new HashMap<String, String>();
		boolean isSynchronous = true;
		ProcessInstance startedProcess = wfs.startProcess(processID, initData, isSynchronous);
 
...
}

Back to the top