Book Image

Oracle BPM Suite 11g Developer's cookbook

By : Vivek Acharya
Book Image

Oracle BPM Suite 11g Developer's cookbook

By: Vivek Acharya

Overview of this book

Oracle Business Process Management Suite is a complete set of tools for creating, executing, and optimizing business processes.Oracle BPM Suite 11g offers the flexibility that business demands, hand-in-hand with the power IT requires. The result is an agile platform that brings together your existing applications, enabling you to react quickly to new business requirements.With this cookbook we will develop rich, interactive business processes using the Oracle Business Process Management suite.With Oracle BPM Suite 11g Developer's Cookbook, a common process model based on BPMN is presented to the specific role assigned to readers in each chapter. Explore Oracle BPM 11g with Modelling, Implementation, Simulation, Deployment, Exception Management, BPM and SOA in Concert, Advanced Rules and Human tasks, End User Interaction and Run-time.Oracle BPM Suite 11g Developer's Cookbook will help readers learn BPM 11g through a Real World Sample Process.This book is divided into four sections: the first section, Modeling, lays the foundation and demonstrates how to implement the Modeling of Business processes for a Use Case of a Fictitious Organization which needs BPM to be implemented at their site (with data objects and information handling). In the second section, Implementation, we learn about Process Implementation, Human Interaction, Business Rules, and much more. In the third section, Measuring, we learn about Post Process Development, Performance Analysis and Simulation Models. In the last section, Deployment, Migration and Run-Time, we learn deployment and migration, and Post Deployment Run-Time.
Table of Contents (20 chapters)
Oracle BPM Suite 11g Developer's Cookbook
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
Oracle BPM—Application Development Lifecycle

Implementing dynamic approval mechanisms


To implement dynamic approval mechanism, follow the ensuing steps:

  • Create a PL/SQL procedure in the DEV_SOAINFRA schema of the enterprise database. This schema comes as a part of SOA installation. However, any business-specified custom schema can be used for a similar operation.

  • Create a Java class that accepts task as a parameter and invokes this PL/SQL procedure by passing argument and receiving approvers list.

How to do it...

You will create a PL/SQL procedure in the enterprise database and a Java class in JDeveloper or any other java editor. You have to place the Java class at a globally known location specifying the classpath in SOA. Then you can create an Approval Group, and in this case you will create a Dynamic Approval Group:

  1. 1. Create a PL/SQL procedure (named GetApprovers) that accepts Industry as argument and returns Approvers list, in SOAINFRA schema:

    CREATE OR REPLACE
    PROCEDURE GetApprovers(
    INDUSTRY IN VARCHAR2,
    APPROVERS OUT VARCHAR2 ) AUTHID CURRENT_USER
    AS
    BEGIN
    IF INDUSTRY LIKE 'SALES' THEN
    APPROVERS := 'Salesbusinessanalyst1,Salesbusinessanalyst2';
    END IF;
    IF INDUSTRY LIKE 'IT' THEN
    APPROVERS := 'ITbusinessanalyst1,ITbusinessanalyst2';
    ELSE
    APPROVERS := 'businessanalyst,businessanalystmanager';
    END IF;
    END GetApprovers;
    COMMIT;
    
  2. 2. Create a Java class (named XXDynamicAG) that accepts Task as a parameter and invokes this PL/SQL procedure GetApprovers by passing Industry as argument and receiving Approvers list.

  3. 3. Develop a custom Dynamic Approval Group class.

  4. 4. Place the class file at a globally known directory, which is the path for the SOA classpath.

  5. 5. For custom classes and JAR, Oracle offers oracle.soa.ext_11.1.1 dir to place custom components, such as classes and JAR files. Place your custom class at $BEAHOME/Oracle_SOA/soa/modules/oracle.soa.ext_11.1.1/classes/oracle/apps/XXDynamicAG.class.

  6. 6. You would define an implementation class using the interface file IDynamicApprovalGroup.java, defined in the package oracle.bpel.services.workflow.task; this class contains only one public method that gets the Approval Group members, and the task object is the only input parameter:

    import java.sql.CallableStatement;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.List;
    import oracle.bpel.services.workflow.IWorkflowConstants;
    import oracle.bpel.services.workflow.runtimeconfig.impl.RuntimeConfigUtil;
    import oracle.bpel.services.workflow.runtimeconfig.model.ApprovalGroupMember;
    import oracle.bpel.services.workflow.task.IDynamicApprovalGroup;
    import oracle.bpel.services.workflow.task.model.Task;
    import org.w3c.dom.Element;
    import org.w3c.dom.NodeList;
    public class XXDynamicAG implements IDynamicApprovalGroup {
    public XXDynamicAG() {
    super();
    }
    public List getMembers(Task task) {
    Element payloadElem = task.getPayloadAsElement();
    String IndustryName = null;
    IndustryName = getElementValue(payloadElem, "Industry");
    String getStatus = "";
    String[] results = { };
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    System.out.println("========== class loaded");
    }
    catch (ClassNotFoundException ex) {
    System.out.println("========== class load error");
    ex.printStackTrace();
    }
    Connection connection = null;
    CallableStatement cstmt = null;
    try {
    connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/mydb", "DEV20_SOAINFRA", "Welcome1");
    System.out.println("========== connection=" + connection);
    // prepare call
    cstmt = connection.prepareCall("{call GetApprovers (?,?)}");
    cstmt.setString(1, IndustryName);
    //Register Output
    cstmt.registerOutParameter(2, java.sql.Types.VARCHAR);
    // Call the stored procedure
    cstmt.execute();
    System.out.println("========== procedure executed");
    //Get the output parameter array
    String Approverstr = cstmt.getString(2);
    results = Approverstr.split(",");
    System.out.println("done");
    System.out.println(getStatus);
    }
    catch (SQLException ex) {
    ex.printStackTrace();
    } finally {
    try {
    if (cstmt != null)
    // close the callable statement
    {
    cstmt.close();
    cstmt = null;
    }
    System.out.println("========== stmt closed");
    } catch (SQLException ex) {
    System.out.println("========== stmt close err");
    ex.printStackTrace();
    }
    try {
    if (connection != null)
    // close the connection
    {
    connection.close();
    connection = null;
    }
    System.out.println("========== conn closed");
    } catch (SQLException ex) {
    System.out.println("========== conn close err");
    ex.printStackTrace();
    }
    }
    List approversList;
    approversList = new ArrayList();
    for (int i = 0; i < results.length; i++) {
    ApprovalGroupMember taskAssignee =
    RuntimeConfigUtil.getFactory(). createApprovalGroupMember();
    taskAssignee.setMember(results[i]);
    taskAssignee.setType (IWorkflowConstants.IDENTITY_TYPE_USER);
    taskAssignee.setSequence(i);
    approversList.add(taskAssignee);
    }
    return approversList;
    }
    public static String getElementValue(Element payloadElem,
    String pElementName) {
    String value = null;
    NodeList myNodeList = payloadElem.getElementsByTagName (pElementName);
    Element myElement = (Element)myNodeList.item(0);
    NodeList myChildNodeList = myElement.getChildNodes();
    for (int i = 0; i < myChildNodeList.getLength(); i++) {
    value = (myChildNodeList.item(i)).getNodeValue(). trim();
    }
    return value;
    }
    }
    
  7. 7. Register the Dynamic Approval Group using the BPM workspace applications.

  8. 8. Create a Dynamic Approval Group in BPM Workspace with name DynamicAG, based on the Java class XXDynamicAG.

  9. 9. Log in to Oracle BPM workspace with weblogic as the Administration account.

  10. 10. Click on Administration.

  11. 11. Click on Administration Areas | Task Administration | Approval Groups.

  12. 12. Create a dynamic group by clicking on the Create Dynamic option and entering the name of the group as DynamicApprovalGroup:

  13. 13. Click on Apply.

There's more...

You can now test the BPM process. Initiate the SalesToContract process. Enter it as Industry.

Testing the process

  1. 1. Go to Oracle BPM Workspace.

  2. 2. Log in as salesrepresentative, to initiate the quote.

  3. 3. Enter it as Industry and enter other quote details.

  4. 4. Submit the quote.

  5. 5. Log in as itbusinessanalyst1, and you can verify that the task is assigned to it:

    When the process token reaches the BusinessAnalystReview Approval Task, the list of approvers is built through a call to Dynamic Approval Group, which would invoke a Java class that, in turn, calls the PL/SQL procedure to dynamically build the list of participants. These participants will be returned to the Rule and the task gets assigned to them. As the Industry type entered in quote was it, PL/SQL would return users itbusinessanalyst1 and itbusinessanalyst2, and you can verify the task assignment to these users from Oracle BPM Workspace.

    Note

    You can use Oracle BPM Worklist application to perform similar operations that you have performed using Oracle BPM Workspace applications.