Arch2Arch Tab BEA.com
Syndicate this blog (XML)

Creating a Process using PAPI-WS

Bookmark Blog Post

del.icio.us del.icio.us
Digg Digg
DZone DZone
Furl Furl
Reddit Reddit

Clinton Davidson's Blog | August 17, 2006   4:07 PM | Comments (5)


PAPI-WS is very useful for creating a process remotely. Consider the use case of an existing web application that now needs to create a process instance in ALBPM. The existing web application does not need to be recoded to work in ALBPM; only the steps to create a process instance need to be added. In later posts, I will show how to execute an external task remotely. In this post I will walk through the process of creating a process instance by looking at process visibility, the method signature, the appropriate settings in Studio (Process Designer) and the required code using PAPI-WS for .NET and Java.

Determining the list of processes where the current user can create an instance

Unfortunately, there is no PAPI-WS call that gives a list of processes where the current user can create an instance. A user can create a process instance if they belong to any role in the process. This is in contrast to Global Applications- the activities used to create a process instance in ALBPM-, which are only in one role. Creating a process using PAPI-WS means executing the Begin activity, which belongs to the automatic handler role and not to a user-created role. Since no user belongs to the automatic handler role, PAPI-WS looks at all roles in the process, and then checks to see if the current user belongs to any of those roles.

Method signature to create a process instance

The method createInstance takes four parameters: a session id, a process id, the argument set name, and an array of arguments. It returns an InstanceInfo Let's look at each of these in turn.
A remote session is required to do anything with PAPI-WS. This is a call that takes a name and password and returns a String sessionId. Creating a session id is documented in PAPI Web Service.
The process id is the programmatic identifier for the process. The simplest way to find the process id is to right-click the process in Studio, click properties, and the id will be listed at the top. A "/" needs to be added to the process id for it to be used as the process id parameter. See the PAPI Web Service document for more details or if you will specifying a version or organizational unit.
To get the argument set name, go to Studio, right-click the Begin activity, and choose "Argument Mapping". The default argument set name is "BeginIn". However, note that it's possible to add additional argument set names. This is valuable when this process could be created through ALBPM (in a global activity) as well as remotely. If the input arguments for the BeginIn argument set contain arguments that can't be expressed remotely, such as FuegoObjects, the alternative is to create another argument set. In this case the arguments coulc be xml, and the Fuego objects could be created from values in the xml documents in the method window of the Begin activity.
The array of arguments parameter in the createInstance method are an array of KeyValuePairs, where each key corresponds to an argument in the ArgumentMapping window of the BeginActivity, and each value corresponds to the String value of the argument. The document PAPI-WS Extensions for Fuego 5.5 also details how the argument sets and argument names can be retrieved via PAPI-WS.

The InstanceInfo object contains the instance id, the description set in the Begin Activity, and the current activity name. For an external application, the instance id could be stored to retrieve the instance later. For example, an external activity takes an instance id. The description is useful to display to the end-user that the instance has been created. The activity name is the name of the current activity, which is usually the next interactive activity for this process instance. Keep in mind that the activity name could be outdated at any time.

Sample code in Java for creating a process instance

 try
{
	//endpoint defined in include page	
	URL endpoint = new URL(WEB_SERVICE_ENDPOINT);
	//basic auth username and password defined in include page
                //note that this is only required for ALIP, not ALBPM
	ProcessServiceServiceLocator locator = new ProcessServiceServiceLocator(BASIC_AUTH_USERNAME, BASIC_AUTH_PASSWORD);

	//get the process service
	fuego.papi.ws.ProcessService processService =  locator.getProcessService(endpoint);
	System.out.println("Created the process service");

	//get a session id to make further calls
	//credentials defined in include.jsp for this lab.
	//credentials could also provided through a user prompt, or supplied by other means.
	String sessionID = processService.createSessionWithTakeOver(PROCESS_SERVER_USERNAME, PROCESS_SERVER_PASSWORD, true);
	System.out.println("Got the session ID");
	//creates the instance, using the parameters from the previous page.
	//note that the arguments and process name need to be hard-coded
	//this could be simplified using java preferences

	//Get the process ID.
	//Either get the process ID (process name, not project name) in Studio,
	//or get the process name via Process Administator by clicking the link under history,
	//then the link under Processes,
	//and finally viewing the Process Name.
	String processID = "/NewEmployee";

	//create the key value pair array of arguments
	//here we have 4 arguments - ssn, first name, last name, and email
	KeyValuePair[] keyValues = new KeyValuePair[4];
	keyValues[0] = new KeyValuePair();
	keyValues[0].setKey("ssn_arg");
	keyValues[0].setValue(ssn);
	keyValues[1] = new KeyValuePair();
	keyValues[1].setKey("nameFirst_arg");
	keyValues[1].setValue(nameFirst);
	keyValues[2] = new KeyValuePair();
	keyValues[2].setKey("nameLast_arg");
	keyValues[2].setValue(nameLast);
	keyValues[3] = new KeyValuePair();
	keyValues[3].setKey("email_arg");
	keyValues[3].setValue(email);

	//argument set name. Unless you have created another argument set, the default name is "BeginIn"
	String argumentSetName = "BeginIn";

	//create the instance, and get back the instance info
	InstanceInfo instanceInfo = processService.createInstance(sessionID, processID, argumentSetName, keyValues );
	System.out.println("Created new instance");
}
catch (Throwable t)
{
	 t.printStackTrace();
}

Sample code in C# for creating a process instance

try
{
               //get the process service
	ProcessServiceService processService =  new ProcessServiceService();
	Console.WriteLine("Created the process service");

	//get a session id to make further calls
	//credentials are defined in PageBase.cs for this lab.
	//credentials could also provided through a user prompt, or supplied by other means.
	String sessionID = processService.createSession(PROCESS_SERVER_USERNAME, PROCESS_SERVER_PASSWORD);
	Console.WriteLine("Got the session ID");
	//creates the instance, using the parameters from the previous page.
	//note that the arguments and process name need to be hard-coded
	//this could be simplified using java preferences

	//Get the process ID.
	//Either get the process ID (process name, not project name) in Process Designer,
	//or get the process name via Process Administator by clicking the link under history,
	//then the link under Processes,
	//and finally viewing the Process Name.
	String processID = "/NewEmployee";;

	//create the key value pair array of arguments
	//here we have 4 arguments - ssn, first name, last name, and email
	KeyValuePair[] keyValues = new KeyValuePair[4];
	keyValues[0] = new KeyValuePair();
	keyValues[0].key = "ssn_arg";
	keyValues[0].value =  ssn;
	keyValues[1] = new KeyValuePair();
	keyValues[1].key = "nameFirst_arg";
	keyValues[1].value = nameFirst ;
	keyValues [2] = new KeyValuePair();
	keyValues [2].key = "nameLast_arg";
	keyValues [2].value = nameLast;
	keyValues[3] = new KeyValuePair();
	keyValues[3].key =  "email_arg";
	keyValues[3].value =  email ;
	//argument set name. Unless you have created another argument set, the default name is "BeginIn"
	String argumentSetName = "BeginIn";

	//create the instance, and get back the instance info
	InstanceInfo instanceInfo = processService.createInstance(sessionID, processID, argumentSetName, keyValues );
	Console.WriteLine("Created new instance");

}
catch (Exception ex)
{
	Console.WriteLine(ex.ToString());
}

Comments

Comments are listed in date ascending order (oldest first) | Post Comment

  • Great info, but i canīt find the ProcessServiceServiceLocator class in the fuego.papi.ws source package. Iīve included the ftpapi.jar library but it still doesnīt appear available. Any suggestion?

    Posted by: varriaga on October 27, 2006 at 11:26 AM

  • Same here. Cannot find ProcessServiceServiceLocator nor can I find KeyValuePair. Any help would be appreciated. Thanks!

    Posted by: pmele on October 29, 2006 at 7:08 AM

  • I believe the ProcessServiceServiceLocator is a generated class from the AXIS framework. It takes the name of the Web service and adds ServiceLocator to the end of the Java Class name.

    KeyValuePair is located inside the WSDL file used to generate the web service client files.

    You need to get yourself a hold of the PAPI-WS WSDL which is generated from the ALBPM HiPer WorkSpace in 5.7 The URL should look something like the following http://hostname:8585/workspace/webservices/ProcessService?WSDL

    Then use AXIS or some other Web Service Client generator to create the client classes.

    Hope this helps.

    Posted by: AndreJGlauser on October 31, 2006 at 2:44 AM

  • I know it's an old post, but I hope somebody can help me. My problem lies on this line:

    fuego.papi.ws.ProcessService processService = locator.getProcessService(endpoint);

    The problem is: my locator returns and instance of MyService_PortType (as generated by Axis) and this is not compatible with a fuego.papi.ws.ProcessService object. How can I solve this? Thanks and regards.

    Posted by: leonchaves on March 24, 2008 at 8:04 AM

  • Can PAPI or PAPI-WS can be used to complete a particular activity pending for a particular user using code? any help / guidance / code sample will very much appreciated. Reagrds, Sandeep

    Posted by: gautamsa on March 31, 2008 at 10:56 PM



Only logged in users may post comments. Login Here.

Powered by
Movable Type 3.31