//***************************************************************************** //* * //* "This sample program is provided AS IS and may be used, executed, copied * //* and modified without royalty payment by customer * //* (a) for its own instruction and study, * //* (b) in order to develop applications designed to run with an * //* IBM WebSphere product, either for customer's own internal use or for * //* redistribution by customer, as part of such an application, in * //* customer's own products." * //* * //* Product 5655-FLW, * //* (C) COPYRIGHT International Business Machines Corp., 2006 * //* All Rights Reserved * Licensed Materials - Property of IBM * //* * //***************************************************************************** //* * //* DISCLAIMER * //* * //* This material contains programming source code for your consideration. * //* These examples have not been thoroughly tested under all conditions. * //* IBM, therefore, cannot guarantee or imply reliability, serviceability, * //* or function of these programs. * //* ALL PROGRAMS CONTAINED HEREIN ARE PROVIDED TO YOU "AS IS", WITHOUT ANY * //* WARRANTIES (EXPRESS OR IMPLIED) OR SUPPORT WHATSOEVER, INCLUDING BUT * //* NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS * //* FOR A PARTICULAR PURPOSE. * //* * //***************************************************************************** /* * This sample shows how you can implement 'claim next' functionality. * */ import com.ibm.websphere.bo.BOFactory; import commonj.sdo.DataObject; import commonj.sdo.Property; import com.ibm.websphere.sca.ServiceManager; import com.ibm.bpe.api.*; public class ClaimNext { public static void main(String[] args) { try { // initialize context and access the remote interface for the // BusinessFlowManager bean BusinessFlowManager bfm = ApiHelper.initializeBFM(); // work on the staff activities of the OrderApprovalProcess // that are in state ready and where the current user is the potential owner // Note: The conditions // ACTIVITY.STATE = ACTIVITY.STATE.STATE_READY AND // ACTIVITY.KIND = ACTIVITY.KIND.KIND_STAFF AND // WORK_ITEM.REASON = WORK_ITEM.REASON.REASON_POTENTIAL_OWNER AND // PROCESS_INSTANCE.STATE = PROCESS_INSTANCE.STATE.STATE_RUNNING // is added to your whereClause by the system. // Compare the sample: ClaimAndComplete.java String whereClause = "PROCESS_TEMPLATE.NAME = 'OrderApprovalProcess' "; String orderClause = "PROCESS_INSTANCE.STARTED"; for ( int indx = 0; indx < 2 ; indx++) { ActivityInstanceData activity = bfm.claim( whereClause, orderClause, null); if (activity == null) { System.out.println("\n no activity found that can be claimed.\n"); } if (activity != null) { MyTrace.trace( activity, "activity claimed" ); ClientObjectWrapper input = bfm.getInputMessage(activity.getID()); ClientObjectWrapper output = bfm.createMessage(activity.getID(), activity.getOutputMessageTypeName() ); DataObject inputMessage = null; DataObject outputMessage = null; if (input!=null && input.getObject()==null) { inputMessage = (DataObject)input.getObject(); MyTrace.trace(inputMessage); } if (output.getObject() != null && output.getObject() instanceof DataObject ) { outputMessage = (DataObject)output.getObject(); MyTrace.trace(outputMessage); } /* * Add the code snippet to read the input message * */ if ( outputMessage != null ) { // get the dataObject for the 'approvalResponse' String request = "approvalResponse"; DataObject dataObject = outputMessage.createDataObject( request ); MyTrace.trace(dataObject); // set the values in the output message // For instance: the decision is "accepted", the approver is "Smith" dataObject.setString("decision", "accepted"); dataObject.setString("approver", "Smith"); MyTrace.trace(dataObject); // complete the activity outputMessage.setDataObject(request, dataObject); } bfm.complete(activity.getID(), output); MyTrace.trace( activity.getID(),"activity completed", bfm ); } } System.out.println("\n successfully processed \n"); System.exit(0); } catch ( com.ibm.bpe.api.ProcessException xcpt) { System.out.println( xcpt ); } catch (java.lang.Exception xcpt ) { System.out.println( xcpt ); } catch (Throwable xcpt) { System.out.println( xcpt ); } finally { System.exit(0); } } }