Friday, November 26, 2010

Human Workflow Java API Part 2

Continuing on from the previous post...

The payload I tested with is as follows -



Now I want to access the custName value in the payload.

Here's the code snippet(thanks to my colleaue Mireille) -

Element el= task.getPayloadAsElement();
String custName = null;
custName = getElementValue(el, "custName");
if(el != null){
System.out.println("Payload customer name = " + custName);


}
else{
System.out.println("Payload is null");
}

public static String getElementValue(Element pElement, String pElementName){
String value=null;
NodeList myNodeList = pElement.getElementsByTagName(pElementName);
Element myElement = (Element)myNodeList.item(0);
NodeList myChildNodeList = myElement.getChildNodes();
for (int i=0; i {
value = ((Node)myChildNodeList.item( i )).getNodeValue().trim();
if( value.equals("") value.equals("\r") ){
continue;
}
else{
break;
}
}
return value;
}

Testing...




The complete Java class is as follows -

package com.niall.hwclient;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import java.util.Map;

import oracle.bpel.services.workflow.client.IWorkflowServiceClient;
import oracle.bpel.services.workflow.client.IWorkflowServiceClientConstants;
import oracle.bpel.services.workflow.client.WorkflowServiceClientFactory;
import oracle.bpel.services.workflow.query.ITaskQueryService;
import oracle.bpel.services.workflow.task.ITaskService;
import oracle.bpel.services.workflow.task.model.Task;
import oracle.bpel.services.workflow.verification.IWorkflowContext;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;


public class HwTask {
public HwTask() {
super();
}

public String getTaskdetails(String user){

Map properties = new HashMap();
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL, "t3://localhost:8001");
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS, "welcome1");
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL, "weblogic");

try
{
//Create JAVA WorflowServiceClient
IWorkflowServiceClient wfSvcClient =
WorkflowServiceClientFactory.getWorkflowServiceClient(WorkflowServiceClientFactory.REMOTE_CLIENT, properties, null);

//Get the task query service
ITaskQueryService querySvc = wfSvcClient.getTaskQueryService();
//Login as jcooper
IWorkflowContext ctx = querySvc.authenticate("cdoyle","welcome1".toCharArray(),null);
//Set up list of columns to query
List queryColumns = new ArrayList();
queryColumns.add("TASKID");
queryColumns.add("TASKNUMBER");
queryColumns.add("TITLE");
queryColumns.add("OUTCOME");

// also get the payload
List optionalInfo = new ArrayList();
optionalInfo.add(ITaskQueryService.OptionalInfo.PAYLOAD);
//
//Query a list of tasks assigned to jcooper
List tasks = querySvc.queryTasks(ctx,
queryColumns,
optionalInfo, // Payload
ITaskQueryService.AssignmentFilter.MY,
null, //No keywords
null, //No custom predicate
null, //No special ordering
0, //Do not page the query result
0);
//Get the task service
ITaskService taskSvc = wfSvcClient.getTaskService();
//Loop over the tasks, outputting task information, and approving any
//tasks whose outcome has not been set...

for(int i = 0 ; i < tasks.size() ; i ++)
{
System.out.println("In task loop...");
Task task = (Task)tasks.get(i);
int taskNumber = task.getSystemAttributes().getTaskNumber();
String title = task.getTitle();
String taskId = task.getSystemAttributes().getTaskId();
String outcome = task.getSystemAttributes().getOutcome();

// Get the payload
Element el= task.getPayloadAsElement();
String custName = null;
custName = getElementValue(el, "custName");
if(el != null){
System.out.println("Payload customer name = " + custName);


}
else{
System.out.println("Payload is null");
}



/* if(outcome == null)
{
outcome = "APPROVED";
taskSvc.updateTaskOutcome(ctx,taskId,outcome);
}*/

System.out.println("Task #"+taskNumber+" ("+title+") is "+outcome);
}
}
catch (Exception e)
{
//Handle any exceptions raised here...
System.out.println("Caught workflow exception: "+e.getMessage());
}

return "done";
}
public static String getElementValue(Element pElement, String pElementName){
String value=null;
NodeList myNodeList = pElement.getElementsByTagName(pElementName);
Element myElement = (Element)myNodeList.item(0);
NodeList myChildNodeList = myElement.getChildNodes();
for (int i=0; i {
value = ((Node)myChildNodeList.item( i )).getNodeValue().trim();
if( value.equals("") value.equals("\r") ){
continue;
}
else{
break;
}
}
return value;
}
}

Monday, November 22, 2010

BPM Signal Events and EDN Part 2

Now we will create another Business Event at the composite level – OrderProcessedEvent







The new event surfaces in the Business Catalogue.



Return to the BPM Design editor and set the implementation type of the End Event to Signal.





Now we have no errors in our process.

Create the required process variables so that it is runnable.

Add a new Business Object of type Order.



Add a Process Data Object variable of this type



Set the Data Associations for Start and End




Ok, so now as soon as the order has been processed, a Mediator component will pick this up and write the order to a file. Here we will leverage the File Adapter(Write) we created earlier.



We then wire this to the File Adapter(Write)
Don't forget to create the required transformation in the Mediator.



Deploy and Test

Sample input file to be dropped into the /in directory



Result

BPM Signal Events and Oracle EDN

Simple scenario –

A new order arrives via file and kicks off the BPM Order process.
This can be easily modelled in Oracle SOA Suite 11g.
Our order has the following xsd –



Steps

Create a couple of directories on the file system




Create a BPM Application in JDeveloper



Go to the Composite view



Create a file adapter – (Read) based on the XSD – pointing to /in directory
Create a file adapter – (Write) based on the XSD – pointing to /out directory



Add a Mediator to pick up the read order



Add a routing rule to publish an event



Create the event definition





Switch to the BPM Project view

The event has been automatically added to the Business catalogue.



Right-mouse click on the Start icon and change the type to Signal






No we have EDN kicking off the BPM process via a Signal event.
I'll flesh this process out in the next post!

Friday, November 19, 2010

JCAPS - SOA Suite 11g Interoperability/Migration

Greetings from South Africa!

Just spent a couple of days around Capetown and am now up in Hermanus whale watching.
Certainly beats the November cold of southern Germany!

Regarding the above, apart from standard integration via web services and JMS, tighter integration can be achieved using the SOA Suite 11g Spring component described in the last post. Essentially we can wrap the JCAPS JCD as a Spring component and leverage it's functionality directly in our composite. Please ping me if you're interested in more details.