Quantcast
Channel: SCN : All Content - SAP Business Process Management
Viewing all articles
Browse latest Browse all 887

How to Delegate , Claim , Release & Nominate a Task of a BPM Process using BPM API as a rest full service.

$
0
0

This guide provides instructions on how to Delegate , Release & Nominate Task of a SAP BPM Process using BPM API as a Restful Service.


Applies to:

This Document Holds good for all CE 7.3 SP05 onwards. This service can be called from UI5 Screen as an Ajax call.


Summary:

This guide describes step-by-step how to Complete Task of a BPM Process using BPM API as a rest full service.


Prerequisites:

You should have read through the document :

How to Start a BPM Process using BPM API as a RESTful service.

How to Complete Task of a BPM Process using BPM API as a rest full service.

How to get Task Details of a BPM Process using BPM API as a rest full service.


We will be discussing following points in detail in this document -


  1. Adding Libraries.
  2. Setting up the foundation for using Libraries.
  3. Creating Deploy-able Object.
  4. Accessing the methods exposed.


Adding Libraries:


Step 1 : Refer the document to add libraries.


Setting up the foundation for using Library:


Step 1 to Step 4 is same as mentioned in the document.


Step 5 : Create a restful service class file and write a code as shown below or if you are continuing from the document then just copy past the methods only.


import java.io.StringReader;
import java.net.URI;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import bo.Material;
import bo.MaterialCreation;
import bo.TaskHeader;
import bo.TaskHeaders;
import com.sap.bpm.api.BPMFactory;
import com.sap.bpm.exception.api.BPMException;
import com.sap.bpm.pm.api.ProcessDefinition;
import com.sap.bpm.pm.api.ProcessDefinitionManager;
import com.sap.bpm.pm.api.ProcessStartEvent;
import com.sap.bpm.pm.api.ProcessStartManager;
import com.sap.bpm.tm.api.Status;
import com.sap.bpm.tm.api.TaskAbstract;
import com.sap.bpm.tm.api.TaskDetail;
import com.sap.bpm.tm.api.TaskInstanceManager;
import com.sap.security.api.IUser;
import com.sap.tc.logging.Location;
import commonj.sdo.DataObject;
import commonj.sdo.helper.XMLHelper;
@Path("/MaterialCreationService")
@Produces({MediaType.APPLICATION_XML})
public class MaterialCreationToRestService {  private static final Location location = Location.getLocation(MaterialCreationToRestService.class);  private final String PRE_TASK_URI = "bpm://bpm.sap.com/task-instance/";  @Path("/delegate/{task-id}")  @POST  @Consumes({MediaType.APPLICATION_JSON})  @Produces({MediaType.APPLICATION_JSON})  public String delegate(@PathParam("task-id") String taskInstanceId, IUser newOwner) throws Exception    {    String log = null;    try{    //Retrieve the TaskInstanceManager    TaskInstanceManager taskInstanceManager = BPMFactory.getTaskInstanceManager();    taskInstanceId = PRE_TASK_URI + taskInstanceId;    URI taskInstId = new URI(taskInstanceId);    //Claim the Task First    taskInstanceManager.claim(taskInstId);    taskInstanceManager.delegate(taskInstId, newOwner);        log = "Task delegated";    }    catch (Exception e)    {    e.printStackTrace();    System.err.println(e);    log = "Task in Exception "+e.getLocalizedMessage();    }    return log;    }  @Path("/claim/{task-id}")  @POST  @Consumes({MediaType.APPLICATION_JSON})  @Produces({MediaType.APPLICATION_JSON})  public String claim(@PathParam("task-id") String taskInstanceId) throws Exception    {    String log = null;    try{    //Retrieve the TaskInstanceManager    TaskInstanceManager taskInstanceManager = BPMFactory.getTaskInstanceManager();    taskInstanceId = PRE_TASK_URI + taskInstanceId;    URI taskInstId = new URI(taskInstanceId);    taskInstanceManager.claim(taskInstId);        log = "Task claimed";    }    catch (Exception e)    {    e.printStackTrace();    System.err.println(e);    log = "Task in Exception "+e.getLocalizedMessage();    }    return log;    }  @Path("/release/{task-id}")  @POST  @Consumes({MediaType.APPLICATION_JSON})  @Produces({MediaType.APPLICATION_JSON})  public String release(@PathParam("task-id") String taskInstanceId) throws Exception    {    String log = null;    try{    //Retrieve the TaskInstanceManager    TaskInstanceManager taskInstanceManager = BPMFactory.getTaskInstanceManager();    taskInstanceId = PRE_TASK_URI + taskInstanceId;    URI taskInstId = new URI(taskInstanceId);    taskInstanceManager.release(taskInstId);        log = "Task released";    }    catch (Exception e)    {    e.printStackTrace();    System.err.println(e);    log = "Task in Exception "+e.getLocalizedMessage();    }    return log;    }  @Path("/nominate/{task-id}")  @POST  @Consumes({MediaType.APPLICATION_JSON})  @Produces({MediaType.APPLICATION_JSON})  public String nominate(@PathParam("task-id") String taskInstanceId, IUser newOwner) throws Exception    {    String log = null;    try{    //Retrieve the TaskInstanceManager    TaskInstanceManager taskInstanceManager = BPMFactory.getTaskInstanceManager();    taskInstanceId = PRE_TASK_URI + taskInstanceId;    URI taskInstId = new URI(taskInstanceId);    //Claim the Task First    taskInstanceManager.claim(taskInstId);    taskInstanceManager.nominate(taskInstId, newOwner);        log = "Task delegated";    }    catch (Exception e)    {    e.printStackTrace();    System.err.println(e);    log = "Task in Exception "+e.getLocalizedMessage();    }    return log;    }
}


Step 6 & Step 7 is same as mentioned in the document. If you are continuing then you can ignore these steps.


Creating Deploy-able Object & Accessing the methods exposed.


Refer the document to "Creating Deploy-able Object" & "Accessing the methods exposed" as it is the same.



Viewing all articles
Browse latest Browse all 887

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>