Processing a single person workflow

Some workflows are performed by only one person, for example, ordering books from an online bookstore. This type of workflow has no parallel paths. The completeAndClaimSuccessor API supports the processing of this type of workflow.

Why and when to perform this task

In an online bookstore, the purchaser completes a sequence of actions to order a book. This sequence of actions can be implemented as a series of staff activities (participating tasks). If the purchaser decides to order several books, this is equivalent to claiming the next staff activity. This type of workflow is also known as page flow because user interface definitions are associated with the activities to control the flow of the dialogs in the user interface.

The completeAndClaimSuccessor API completes a staff activity and claims the next one in the same process instance for the logged-on person. It returns information about the next claimed activity, including the input message to be worked on. Because the next activity is made available within the same transaction of the activity that completed, the transactional boundaries must be set in the process model to participates.

Steps for this task

  1. Claim the first activity in the sequence of activities.
    //
    //Query the list of activities that can be claimed by the logged-on user
    //
    QueryResultSet result = 
         process.query("ACTIVITY.AIID", 
                       "PROCESS_INSTANCE.NAME = 'CustomerOrder' AND 
                        ACTIVITY.STATE = ACTIVITY.STATE.STATE_READY AND
                        ACTIVITY.KIND = ACTIVITY.KIND.KIND_STAFF AND
                        WORK_ITEM.REASON = 
                             WORK_ITEM.REASON.REASON_POTENTIAL_OWNER",
                        (String)null, (Integer)null, (TimeZone)null); 
    ...
    //
    //Claim the first activity
    //
    if (result.size() > 0)
    {
    	result.first();
    	AIID aiid = (AIID) result.getOID(1);
    	ClientObjectWrapper input = process.claim(aiid);
    	DataObject activityInput = null ;
      if ( input.getObject()!= null && input.getObject() instanceof DataObject )
      {
        activityInput = (DataObject)input.getObject();
        // read the values
        ...
      }  
    }
    When the activity is claimed, the input message of the activity is returned.
  2. When work on the activity is finished, complete the activity, and claim the next activity.

    To complete the activity, an output message is passed. When you create the output message, you must specify the message type name so that the message definition is contained.

    ActivityInstanceData activity = process.getActivityInstance(aiid);
    ClientObjectWrapper output = 
          process.createMessage(aiid, activity.getOutputMessageTypeName());
    DataObject myMessage = null ;
    if ( output.getObject()!= null && output.getObject() instanceof DataObject )
    {
      myMessage = (DataObject)output.getObject();
      //set the parts in your message, for example, an order number
      myMessage.setInt("OrderNo", 4711);
    }
    
    //complete the activity and claim the next one
    CompleteAndClaimSuccessorResult successor = 
       process.completeAndClaimSuccessor(aiid, output);
    This action sets an output message that contains the item number and claims the next activity in the sequence. If AutoClaim is set for successor activities, a random activity is returned as the next activity. If there are no more successor activities that can be assigned to this user, Null is returned. If AutoClaim is set for successor activities and if there are multiple paths that can be followed, all of the successor activities are claimed and a random activity is returned as the next activity.

    If the process contains parallel paths that can be followed and these paths contain staff activities for which the logged-on user is a potential owner of more than one of these activities, a random activity is claimed automatically and returned as the next activity.

  3. Work on the next activity.
    String name = successor.getActivityName();
    
    ClientObjectWrapper nextInput = successor.getInputMessage();
    if ( nextInput.getObject()!= 
                   null && nextInput.getObject() instanceof DataObject )
    {
      activityInput = (DataObject)input.getObject();
      // read the values
      ...
    }  
  4. Continue with step 2 to complete the activity.

Copyright IBM Corporation 2005, 2006.
This information center is powered by Eclipse technology (http://www.eclipse.org)