Writing Adapter Methods

Adapter methods provide an interface between application layer functionality and BPM service calls.

The use of adapter methods is recommended, because they insulate the application layer from the implementation details of the service calls.

Note: Connection and security requirements can also be handled at this layer, as described in the preceding sections.

The Adapter class (in Adapter.cs) implements the following methods to call specific BPM service operations.

Method Description Invokes...
CancelWorkItem Cancels a work item cancelWorkItem operation from the WorkPresentationService
CloseWorkItem Closes a work item closeWorkItem operation from the WorkPresentationService
GetWorkList Gets the worklist of a user identified by their GUID getWorkListItems operation from the WorkListService
OpenItem Allocates and opens a selected work item openWorkItem operation from the WorkPresentationService
SubmitWorkItem Completes a work item completeWorkItem operation from the WorkPresentationService
GetGUID Gets the GUID for the username specified in the LoginForm dialog. (See Obtaining the Calling User’s GUID for more information about this method.) lookupUser operation from the EntityResolverService .

Each method uses a similar structure to provide its interface. For example, the GetWorkList method.

Procedure

  1. Creates an object from the class that represents the operation to be invoked - in this case, getWorkListItems.
    public WorkItem[] GetWorkList(string guid)
    {
          getWorkListItems getItems = new getWorkListItems();
  2. Populates the object with appropriate parameter values for the request message. In this case, the required values have been determined by referencing the getWorkListItemsRequest element.
          getItems.Item = new XmlModelEntityId();
          getItems.getTotalCount = true;
          getItems.numberOfItems = 100;
          getItems.startPosition = 0;
          getItems.Item.entitytype = OrganisationalEntityType.RESOURCE;
          getItems.Item.guid = guid;
          getItems.Item.modelversion = -1;
  3. Invokes the appropriate WCF client, calls the operation and stores the response - which in this case will be a getWorkListItemsResponse object.
          WorkListServiceClient wlSvcClient = _handler.GetWorkListServiceClient();
          getWorkListItemsResponse response = wlSvcClient.getWorkListItems(getItems);
  4. Processes the response and adds exception handling as required.

Result

      if (response != null)
      {
         if (response.workItems != null)
         {
            WorkItem[] items = response.workItems;
            return items;
         }
      }
     throw new Exception("Failed to get WorkList - call returned null");
}

The Adapter class also includes the GetBOMJSP, GetFormURL and GetJSURL methods. See Rendering a Form for a Work Item for more information about the use of these methods.