Monday, January 20, 2014

# 304 Adaptive Case Management Java API Part 1

Here is the stakeholders definition of my demo order approvals case -















Here is an instance of that case -




















Test API Output


















API code to query the case -

package com.niall;


import java.io.StringWriter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import javax.xml.bind.JAXB;
import javax.xml.bind.JAXBElement;

import oracle.bpel.services.bpm.common.IBPMContext;
import oracle.bpel.services.workflow.client.IWorkflowServiceClientConstants;
import oracle.bpel.services.workflow.query.ITaskQueryService;
import oracle.bpel.services.workflow.task.ITaskService;

import oracle.bpel.services.workflow.verification.IWorkflowContext;
import oracle.bpel.services.workflow.WorkflowException;

import oracle.bpm.casemgmt.CaseIdentifier;
import oracle.bpm.casemgmt.CaseList;
import oracle.bpm.casemgmt.CaseServiceException;
import oracle.bpm.casemgmt.ICaseService;
import oracle.bpm.casemgmt.persistence.model.Case;
import oracle.bpm.casemgmt.persistence.model.CaseData;
import oracle.bpm.casemgmt.persistence.model.CaseHeader;
import oracle.bpm.casemgmt.persistence.model.CaseMilestone;
import oracle.bpm.casemgmt.persistence.model.CaseStakeHolder;
import oracle.bpm.casemgmt.persistence.model.CaseStakeHolderMember;
import oracle.bpm.casemgmt.persistence.model.Comment;
import oracle.bpm.casemgmt.persistence.model.CompletedCaseActivity;
import oracle.bpm.casemgmt.persistence.model.CompletedCaseActivityList;
import oracle.bpm.casemgmt.persistence.model.ICaseConstants;
import oracle.bpm.client.BPMServiceClientFactory;
import oracle.bpm.services.authentication.IBPMUserAuthenticationService;
import oracle.bpm.services.common.exception.BPMException;
import oracle.bpm.training.acm.apilab.model.Complaint.ObjectFactory;
import oracle.bpm.training.acm.apilab.model.Complaint.TComplaint;
import oracle.bpm.training.acm.apilab.util.CaseHelper;


public class CaseMgtAPI {

    private BPMServiceClientFactory mServiceClientFactory = null;
    private ICaseService mCaseService = null;
    private IBPMContext mBPMUserContext = null;

    private static final String WLS_ADMIN_PASSWORD = "welcome1";
    private static final String WLS_ADMIN_USERID = "jcooper";

    public CaseMgtAPI() {
        super();
    }


    public static CaseMgtAPI getAllCases4User(String cUser,
                                              String cPwd) throws Exception {
        CaseMgtAPI caseMgtAPI = new CaseMgtAPI();

        Map properties =
            new HashMap();
        properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.CLIENT_TYPE,
                       BPMServiceClientFactory.REMOTE_CLIENT);
        properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL,
                       "t3://localhost:7001");
        properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS,
                       cPwd);
        properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL,
                       cUser);
        caseMgtAPI.mServiceClientFactory =
                BPMServiceClientFactory.getInstance(properties, "default",
                                                    null);
        /* Get Task Query Service */
        ITaskQueryService service =
            caseMgtAPI.mServiceClientFactory.getWorkflowServiceClient().getTaskQueryService();

        /* Get Case Mgt Service */
        caseMgtAPI.mCaseService =
                caseMgtAPI.mServiceClientFactory.getCaseManagementServiceClient().getCaseService();

        caseMgtAPI.mBPMUserContext =
                (IBPMContext)service.authenticate(cUser, cPwd.toCharArray(),
                                                  null);


        if (caseMgtAPI.mBPMUserContext != null) {
            System.out.println("CaseMgtAPI.getAllCases4User() Returning context for:" +
                               caseMgtAPI.mBPMUserContext.getUser());
            // list Case instances
            listCases(caseMgtAPI.mCaseService, caseMgtAPI.mBPMUserContext);

        } else {
            System.out.println("CaseMgtAPI.getAllCases4User()  invalid context");
        }

        return caseMgtAPI;
    }

    public static void listCases(ICaseService caseService,
                                 IBPMContext bpmContext) throws CaseServiceException {
        System.out.println("CaseMgtAPI.listCases()");
        System.out.println("");

        Case myCase = new Case();
        List caseInfo =
            new ArrayList();

        CaseList caseList =
            caseService.queryCase(bpmContext, caseInfo, null, null, 10, 1);
        System.out.println("Total Nr of Case Instances = " +
                           caseList.getTotalNumberOfCases());
        List myCaseList = caseList.getCases();
        System.out.println("Case list size " + myCaseList.size());
        for (int i = 0; i < myCaseList.size(); i++) {
            myCase = myCaseList.get(i);
            System.out.println("");
            System.out.println("Info for Case Instance " + i);
            //
            // Case Header
            System.out.println("");

            System.out.println("### Case Header Info ...");
            System.out.println("Composite Name = " +
                               myCase.getCaseHeader().getCompositeDn());
            System.out.println("Case Def. = " +
                               myCase.getCaseHeader().getCaseDefinitionName());
            System.out.println("ECM Folder = " +
                               myCase.getCaseHeader().getEcmFolder());
            System.out.println("Id Key = " +
                               myCase.getCaseHeader().getIdentificationKey());
            System.out.println("Case Definition Name = " +
                               myCase.getCaseHeader().getCaseDefinitionName());
            System.out.println("Application Name = " +
                               myCase.getCaseHeader().getApplicationName());
            System.out.println("Component Name = " +
                               myCase.getCaseHeader().getComponentName());
            System.out.println("Case Number = " +
                               myCase.getCaseHeader().getCaseNumber());
            System.out.println("Case Definition Id = " +
                               myCase.getCaseHeader().getCaseDefinitionId());
            // Case Activities
            CompletedCaseActivityList ccal =
                myCase.getCaseHeader().getCompletedCaseActivityList();
            List cca_l =
                ccal.getCompletedCaseActivity();
            System.out.println("### Nr of Case Activities Completed for this instance =" +
                               cca_l.size());

            for (int a = 0; a < cca_l.size(); a++) {
                CompletedCaseActivity cca = cca_l.get(a);
                String name = cca.getName();
                System.out.println("Completed Case Activity name = " + name);
            }

            System.out.println("### End of Case Header Info ...");
            System.out.println("");


          
            // Case Actions
            List myActions = myCase.getActions();
            for (int c = 0; c < myActions.size(); c++) {
                System.out.println("+++ Actions : " +
                                   myActions.get(c).toString());
                

            }
            System.out.println("");
            
      
          
            
            // stakeholders
            List caseStakeholderList =
                myCase.getCaseStakeHolders();
            System.out.println("Case StakeHolder List size = " +
                               caseStakeholderList.size());

            for (int f = 0; f < caseStakeholderList.size(); f++) {
                CaseStakeHolder caseStakeholder = caseStakeholderList.get(f);
                System.out.println("Case StakeHolder Name :" +
                                   caseStakeholder.getObjectDisplayName());
                List l_csm =
                    caseStakeholder.getCaseStakeHolderMembers();
                for (int g = 0; g < l_csm.size(); g++) {
                    CaseStakeHolderMember csm = l_csm.get(g);
                    System.out.println("+++ Case StakeHolder Member Name :" +
                                       csm.getStakeHolderDisplayName());
                }


            }

            System.out.println("");
            
        }
    }

    public IBPMContext getBPMContext() {
        return this.mBPMUserContext;
    }


    public BPMServiceClientFactory getServiceClientFactory() {
        return mServiceClientFactory;
    }

    public ICaseService getCaseService() {
        return mCaseService;
    }

    public ITaskService getTaskService() {
        return this.mServiceClientFactory.getWorkflowServiceClient().getTaskService();
    }


}


JDeveloper Project Libraries




















JDev Project download













Available here 

Useful resources/docs:

https://blogs.oracle.com/VenugopalMangipudi/entry/obpm_case_management_api_s


http://docs.oracle.com/cd/E28280_01/apirefs.1111/e25378/oracle/bpm/casemgmt/ICaseInstanceService.html


No comments:

Post a Comment