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"

m
(Fetching user work-list)
Line 102: Line 102:
 
==== Fetching user work-list<br> ====
 
==== Fetching user work-list<br> ====
 
some text goes here
 
some text goes here
<source lang="Java">
+
<source lang="Java">{...
                String processID = "LeaveApplicationProcess";
+
                Map<String, String> initData = new HashMap<String, String>();
+
String processID = "LeaveApplicationProcess";
                boolean isSynchronous = true;
+
Map<String, String> initData = new HashMap<String, String>();
                ProcessInstance startedProcess = wfs.startProcess(processID, initData, isSynchronous);
+
boolean isSynchronous = true;
 +
ProcessInstance startedProcess = wfs.startProcess(processID, initData, isSynchronous);
 +
 +
...
 +
}
 
</source>
 
</source>

Revision as of 08:02, 9 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 started successfully, 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="default";
		Map<String, ?> outData =new HashMap<String, String>();
		int flags = WorkflowService.FLAG_ACTIVATE_NEXT_ACTIVITY_INSTANCE;
		ActivityCompletionLog activityCompletionLog = wfs.activateAndComplete(activityInstanceOID, context, outData, flags);


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

                activityInstance = wfs.activate(activityInstanceOID);
                activityInstance = wfs.activateNextActivityInstance(activityInstanceOID);
                activityCompletionLog = wfs.complete(activityInstanceOID, context, outData, flags);

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