//***************************************************************************** //* * //* "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. * //* * //***************************************************************************** /* * There are several administrative tasks the process administrator can do * on a process instance. * This sample does the following: * 1. Retrieves a process instance in state running. * 2. Suspends the process instance * 3. Resumes the process instance * 4. Terminates the process instance calling forceTerminate() * 5. Restarts the process instance * 6. Terminates and delete the process instance * * The caller must be an administrator of the associated process instance. */ import com.ibm.bpe.api.*; public class AdministerProcesses { public static void main(String[] args) { try { // initialize context and access the remote interface for the // BusinessFlowManager bean BusinessFlowManager bfm = ApiHelper.initializeBFM(); // retrieve a process instance of the OrderApprovalProcess // that are in the running state // and whose starter is the the current user String selectClause = "DISTINCT PROCESS_INSTANCE.PIID" ; String whereClause = null; String orderClause = null; Integer threshold = new Integer(1); whereClause = "PROCESS_INSTANCE.STATE = PROCESS_INSTANCE.STATE.STATE_RUNNING AND " + " ( WORK_ITEM.REASON = WORK_ITEM.REASON.REASON_STARTER OR " + " WORK_ITEM.REASON = WORK_ITEM.REASON.REASON_ADMINISTRATOR ) AND " + "PROCESS_TEMPLATE.NAME = 'OrderApprovalProcess' "; QueryResultSet result = bfm.query( selectClause, whereClause, orderClause, null, threshold, null ); System.out.println( "\n > query(), result size: " + result.size()); if ( result.size() == 0 ) { System.exit(0); } result.first(); PIID piid = (PIID)result.getOID(1); MyTrace.trace( piid, "process retrieved", bfm); // Suspend the process instance bfm.suspend( piid ); MyTrace.trace( piid, "process suspended", bfm); java.lang.Thread.sleep(1000); // Resume the process instance bfm.resume( piid ); MyTrace.trace( piid, "process resumed", bfm); java.lang.Thread.sleep(1000); // Terminate the process instance // Depending on the invokeCompensation flag, the process instance // is compensated or not. If compensation is to be ignored, the // process instance is immediately terminated. If compensation is // to be invoked, the process instance is compensated before it is // terminated provided that compensation is defined at all. Otherwise, // the process instance is terminated without compensation. bfm.forceTerminate( piid, CompensationBehaviour.IGNORE_COMPENSATION ); MyTrace.trace( piid, "process terminated", bfm); java.lang.Thread.sleep(1000); // Restart the process instance bfm.restart( piid ); MyTrace.trace( piid, "process restarted", bfm); java.lang.Thread.sleep(1000); // Terminate and delete the process instance bfm.forceTerminate( piid ); MyTrace.trace( piid, "process terminated", bfm); bfm.delete( piid ); 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); } } }