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/Java API/Support Case Example

< Stardust‎ | Knowledge Base‎ | Java API
Revision as of 03:50, 25 June 2014 by Simone.seurer.sungard.com (Talk | contribs) (Introduction)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Introduction

The Support Case example is a complete Stardust workflow that is described in detail in the product documentation. The reader can follow the steps described therein to design and execute the model end to end. This article illustrates the use of the Java API to execute this workflow thereby exposing the reader to the use of the various Stardust services and how they can be employed when designing a solution where Stardust is required to execute in embedded mode.

Note: All artifacts described in the following article including the model and Java POJOs can be downloaded from here.


Support Case example executed as Java application

Note: In the Java application shown below, it is assumed that the reader has already created two users with the following roles:

  • user "testagent" with password "123" in role "Callcenter Agent"
  • user "johndoe" with password "pqr" in role "Engineer"
package com.test;
 
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
 
import ag.carnot.workflow.model.ApplicationContext;
import ag.carnot.workflow.model.DataMapping;
import ag.carnot.workflow.runtime.ActivityInstance;
import ag.carnot.workflow.runtime.ProcessInstance;
import ag.carnot.workflow.runtime.ServiceFactory;
import ag.carnot.workflow.runtime.ServiceFactoryLocator;
import ag.carnot.workflow.runtime.WorkflowService;
import ag.carnot.workflow.runtime.beans.removethis.SecurityProperties;
import ag.carnot.workflow.runtime.details.ProcessDefinitionDetails;
 
public class TestWorkflow {
 
		public static void main(String args[]) {
			ServiceFactory sf = getTestService(null,null,null,"testagent","123");
			ServiceFactory sf1 = getTestService(null,null,null,"johndoe","pqr");
 
			WorkflowService wfs = sf.getWorkflowService();
			WorkflowService wfs1 = sf1.getWorkflowService();
 
			ProcessInstance pi = null;
			List l = wfs.getStartableProcessDefinitions();
			for(ProcessDefinitionDetails pdd: l){
				if(pdd.getId().equals("SupportCaseManagement")) {
					pi = wfs.startProcess("SupportCaseManagement", null, true);
					break;
				}
			}
 
			ActivityInstance ai = wfs.activateNextActivityInstanceForProcessInstance(pi.getOID());
			System.out.println("In mappings for activity " + ai.getActivity().getName());
			Map invalues = wfs.getInDataValues(ai.getOID(),null,null);
			Iterator iterator = invalues.keySet().iterator();  
			while (iterator.hasNext()) {  
				String key = iterator.next().toString();  
				String value = invalues.get(key)==null ? null: invalues.get(key).toString();  
				System.out.println(key + " " + value);  
			}
			System.out.println("Out mappings for activity " + ai.getActivity().getName());
			ApplicationContext ac  = ai.getActivity().getApplicationContext("default");
			List  outmappings = ac.getAllOutDataMappings();
			for(DataMapping mapping : outmappings) {
				System.out.println(mapping.getDataId()+ " " + mapping.getDataPath());
			}
			Map outmap = new HashMap();
			outmap.put("CustomerID", "2471");
			outmap.put("CustomerName", "Wiki Pedia");
			outmap.put("eMail", "wikipedia@knowledge.com");
			outmap.put("ProductName", "Motherboard Fan");
			outmap.put("Synopsis", "Works intermittently and system overheats");
			wfs.complete(ai.getOID(), null, outmap);
 
			ai = wfs1.activateNextActivityInstanceForProcessInstance(pi.getOID());
			System.out.println("In mappings for activity " + ai.getActivity().getName());
			invalues = wfs.getInDataValues(ai.getOID(),null,null);
			iterator = invalues.keySet().iterator();  
			while (iterator.hasNext()) {  
				String key = iterator.next().toString();  
				String value = invalues.get(key)==null ? null: invalues.get(key).toString();  
				System.out.println(key + " " + value);  
			}
			System.out.println("Out mappings for activity " + ai.getActivity().getName());
			ac  = ai.getActivity().getApplicationContext("default");
			outmappings = ac.getAllOutDataMappings();
			for(DataMapping mapping : outmappings) {
				System.out.println(mapping.getDataId()+ " " + mapping.getDataPath());
			}
			outmap = new HashMap();
			outmap.put("Analysis", "Problem has been resolved.");
			if(args[0].equals("C"))
				outmap.put("State", "C");
			else if(args[0].equals("R"))
				outmap.put("State", "R");
 
			wfs1.complete(ai.getOID(), null, outmap);
			ai = wfs1.activateNextActivityInstance(ai.getOID());
			if(ai!=null) {
				System.out.println("In mappings for activity " + ai.getActivity().getName());
				invalues = wfs.getInDataValues(ai.getOID(),null,null);
				iterator = invalues.keySet().iterator();  
				while (iterator.hasNext()) {  
					String key = iterator.next().toString();  
					String value = invalues.get(key)==null ? null: invalues.get(key).toString();  
					System.out.println(key + " " + value);  
				}
				System.out.println("Out mappings for activity " + ai.getActivity().getName());
				ac  = ai.getActivity().getApplicationContext("default");
				outmappings = ac.getAllOutDataMappings();
				for(DataMapping mapping : outmappings) {
					System.out.println(mapping.getDataId()+ " " + mapping.getDataPath());
				}
				wfs1.complete(ai.getOID(), null, null);
			}
			sf.release(wfs);
			sf1.release(wfs1);
		}
 
	    public static ServiceFactory getTestService(String partition, String domain, String realm, String user, String password)
	    {
	        Map properties = new HashMap();
	        properties.put(SecurityProperties.CRED_PARTITION, partition);
	        properties.put(SecurityProperties.CRED_DOMAIN, domain);
	        properties.put(SecurityProperties.CRED_REALM, realm);
	        return ServiceFactoryLocator.get(user, password, properties);
	    }
 
 
}

Back to the top