Example handlers and steps implementation outline

The following code and pseudocode provide example implementations for fixed-workflow handlers and variable-workflow steps.

Protocol processing handler

This section provides an outline of a handler implementation for processing a fixed-inbound protocol, in this case, a handler to support CSV processing. You should add protocol-specific code.

public class MyCSVProtocolProcess implements BusinessProcessHandlerInterface {
 
 public boolean applies(BusinessDocumentInterface document) {
 // do quick scan of the file contents to determine if it is CSV file
 // if it is then set from_protocol = "CSV_PROTOCOL"
 if (from_protocol.equals("CSV_PROTOCOL")) 
 return true; 
 
 return false; 
 } 
 
 public BusinessDocumentInterface process(BusinessDocumentInterface document) {
 try {
 String[] params;
 
 // obtain the file contents in a String 
 StringTokenizer tokenizer = new StringTokenizer(fileContents, ","); 
 String fromBusinessId = tokenizer.nextToken(); 
 if (fromBusinessId == null) {
 params = new String[1];
 params[0] = "From business ID not available.";
 EventInfo event = new EventInfo("BCG240614", document, params);
 document.addEvent(event);
 } 
 String toBusinessId = tokenizer.nextToken(); 
 String customerId = tokenizer.nextToken(); 
 String customerName = tokenizer.nextToken();
 String documentType = tokenizer.nextToken(); 
 String documentVersion = tokenizer.nextToken(); 
 
 ... 
 // trace-obtained information 
 ... 
 
 document.setValue(BCGDocumentConstants.BCG_FRBUSINESSID, fromBusinessId);
 document.setValue(BCGDocumentConstants.BCG_TOBUSINESSID, toBusinessId);
 document.setValue(BCGDocumentConstants.BCG_FRPROTOCOLCD, "CSV_PROTOCOL ");
 document.setValue(BCGDocumentConstants.BCG_FRPROTOCOLVER, "1.0");
 document.setValue(BCGDocumentConstants.BCG_FRPROCESSCD, documentType); 
 document.setValue(DocumentConstant.BCG_FRPROCESSVER, documentVersion);
 
 ... 
 
 } catch (Exception e) {
 params = new String[1];
 params[0] = "Error in MyCSVProtocolProcess";
 EventInfo event = new EventInfo("BCG240615", document, params, e); 
 document.addEvent(event); 
 document.setDocumentState(BCGDocumentConstants.BCG_DOCSTATE_FAILED);
 } 
 return document; 
 }
 }

Protocol unpackaging handler

This section provides an outline of a fixed inbound protocol unpackaging handler implementation, in this case a handler to support custom XML packaging from WebSphere Commerce Business Edition. You should add protocol-specific code.

public class MyProtocolUnPackagingHandler
 implements BusinessProcessHandlerInterface {
 
 public boolean applies(BusinessDocumentInterface document) {
 // do quick scan of the file contents, transport headers to determine 
 // if it is "MY_PACKAGE". if it is then set from_package = "MY_PACKAGE"
 if (from_package.equals("MY_PACKAGE")) 
 return true; 
 
 return false;
 } 
 
 public BusinessDocumentInterface process(BusinessDocumentInterface document) {
 
 // from your packaging, obtain package level routing information 
 
 try {
 String[] params;
 
 // obtain routing information from your packaging
 ...
 
 // trace-obtained information 
 ... 
 
 // set routing information on the document
 document.setValue(BCGDocumentConstants.BCG_PKG_FRBUSINESSID, fromBusinessId);
 document.setValue(BCGDocumentConstants.BCG_PKG_TOBUSINESSID, toBusinessId);
 document.setValue(BCGDocumentConstants.BCG_PKG_INITBUSINESSID, customerId); 
 document.setValue(BCGDocumentConstants.BCG_FRPACKAGINGCD, "MY_PACKAGE");
 document.setValue(BCGDocumentConstants.BCG_FRPACKAGINGVER, "1.0");
 
 ... 
 
 } catch (Exception e) {
 params = new String[1];
 params[0] = "Error in MyProtocolUnPackagingHandler";
 EventInfo event = new EventInfo("BCG240610", document, params, e); 
 document.addEvent(event);
 document.setDocumentState(BCGDocumentConstants.BCG_DOCSTATE_FAILED);
 } 
 return document; 
 } 
 }

Transformation step

This section provides an outline of a variable workflow step implementation, in this case a step to transform a document from one format to another. The sample includes code and pseudocode for the BusinessProcessFactory and BusinessProcess implementation. You should add protocol-specific code.

Factory implementation:

public class MyTransformationBusinessProcessFactory implements
              BusinessProcessFactoryInterface {
 
    public BusinessDocumentInterface getBusinessProcess(Context context,
           Config config, BusinessDocumentInterface document) {
    // Can use any configuration values from config as necessary. These 
    // are set via the console. 
    MyTransformationBusinessProcess bp = new MyTransformationBusinessProcess(); 
 
    // Set any items in this class as specific to the implementation 
    // between the factory and the business process class. 
    return bp; 
    } 
 
    public void returnBusinessProcess(BusinessProcessInterface bp) {
    // if not reusing Business Processes then do nothing. 
    } 
 }

Business process implementation:

public class MyTransformationBusinessProcess implements BusinessProcessInterface {
  
    public BusinessDocumentInterface process (BusinessDocumentInterface document,
                                              Context context) {
    
    String[] params;
       try {
       // trace relevant information. log relevant events. 
       ...
      
       // obtain transformation map
       MapService mapService = BusinessProcessUtil.getMapService();
       byte[] transformationMap = mapService.getTransformationMap (bDoc, context); 
       
       // Get the Business document file.
       File sourceFile = document.getDocument(); 
       
       // create a new file to store your transformed document
       File targetFile = document.createFile();
   
       // read business data from the source. write your logic to transform
       // the source to target. store your target busines data into target file
  
       ...
     
       // store the transformed target file into business document. 
       document.setDocument(targetFile); 
     
       } catch(Exception ex) {
       params = new String[1];
       params[0] = "Error in MyTransformationBusinessProcess: " + ex.getMessage();
       EventInfo event = new EventInfo("BCG_200005", document, params, e); 
       document.addEvent(event); 
       document.setDocumentState(BCGDocumentConstants.BCG_DOCSTATE_FAILED);
       }
   
    return document;
    } 
  
    public boolean reset() {
    /* reset internal variables. */ 
    ...
    }
 }

Copyright IBM Corp. 2003, 2005