//***************************************************************************** //* * //* "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, 2008 * //* 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. * //* * //***************************************************************************** /* * If an error is encountered inside a staff activity and the corresponding * fault is not caught on the enclosing scope, the activity is put into the * stopped state if the associated activity template specifies that * the activity stops when an error occurs. * In this situation, you can force the completion of the activity. * You can also pass parameters in the force-complete call, * such as the message that should have been computed or the fault that should * have been raised. * The caller must be an administrator of the associated process instance. */ import java.util.TimeZone; import com.ibm.bpe.api.*; import commonj.sdo.DataObject; public class ForceComplete { public static void main(String[] args) { try { // initialize context and access the remote interface for the // BusinessFlowManager bean BusinessFlowManager bfm = ApiHelper.initializeBFM(); String processTemplateName = "OrderApprovalProcess"; // retrieve all stopped staff activities that belong to the OrderApproval process. String selectClause = "DISTINCT ACTIVITY.AIID "; String whereClause = "ACTIVITY.STATE = ACTIVITY.STATE.STATE_STOPPED AND " + "ACTIVITY.KIND = ACTIVITY.KIND.KIND_STAFF AND " + "PROCESS_INSTANCE.STATE = PROCESS_INSTANCE.STATE.STATE_RUNNING AND " + "PROCESS_TEMPLATE.NAME = '" + processTemplateName + "'"; QueryResultSet result = bfm.query( selectClause, whereClause, (String)null, (Integer)null, (TimeZone)null ); System.out.println( "\n > query(), result size: " + result.size()); if ( result.size() == 0 ) { System.exit(0); } AIID aiid = null; while (result.next()) { aiid = (AIID) result.getOID(1); // get the output message of the activity ActivityInstanceData activity = bfm.getActivityInstance(aiid); MyTrace.trace( activity, "activity retrieved"); ClientObjectWrapper output = bfm.createMessage( aiid, activity.getOutputMessageTypeName() ); DataObject outputMessage = null; if (output.getObject() != null && output.getObject() instanceof DataObject) { outputMessage = (DataObject)output.getObject(); /* * fill in the code snippet to set the content the of output message */ } // complete the activity. // If you specify continueOnError == false, // the activity stays in the stopped execution state // if an error occurs. // If you specify continueOnError == true // the activity is put into the failed execution state // if an error occurs. The navigation continues. boolean continueOnError = true; bfm.forceComplete( aiid, output, continueOnError ); MyTrace.trace( aiid, "activity after calling forceComplete", bfm); } System.out.println("\n successfully processed \n"); System.exit(0); } catch ( com.ibm.bpe.api.ProcessException xcpt) { System.out.println(" " + xcpt.getMessage()); } catch ( java.rmi.RemoteException xcpt ) { System.out.println(" " + xcpt.getMessage()); } finally { System.exit(0); } } }