Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Oracle BPM Suite 11g Developer's cookbook

You're reading from   Oracle BPM Suite 11g Developer's cookbook Over 80 advanced recipes to develop rich, interactive business processes using the Oracle Business Process Management Suite with this book and ebook

Arrow left icon
Product type Paperback
Published in Apr 2012
Publisher Packt
ISBN-13 9781849684224
Length 512 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Vivek Acharya Vivek Acharya
Author Profile Icon Vivek Acharya
Vivek Acharya
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Oracle BPM Suite 11g Developer's Cookbook
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
1. Preface
1. Process Modeling FREE CHAPTER 2. Process Implementation 3. Process Deployment and Testing 4. Business Rules in the BPM Process 5. Human Workflow in BPM Process 6. Process Simulation 7. Developing UI using Oracle ADF 8. Exception Management 9. BPM and SOA in Concert 10. End User Interaction 11. Manage, Monitor and Administer BPM Process Oracle BPM—Application Development Lifecycle
Approval Management

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.

lock icon The rest of the chapter is locked
arrow left Previous Section
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime