Tuesday, February 11, 2014
#309 Adaptive Case Management API - part 6 - archiving the audit trail to Biz DB ++
As you can see, the audit table now includes a comments column.
now to the format of the comments -
*** comments are generated by my auditing utility.
auto... are comments from Oracle Business Rules
The rest are comments entered by the case worker via the UI.
The code -
Now we can further refine this to get the following output for all event types -
JDev project Here
Monday, February 10, 2014
#308 Adaptive Case Management API - part 5 - archiving the audit trail to Biz DB
Leading on from the previous post -
I now detail a basic example of archiving the case audit trail to a Biz DB.
I created the following table in my Biz schema
AUDIT_TIME is defined as TIMESTAMP the rest are varchars.
I now create a utility class to do the DB insert -
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;
public class AuditBizDB {
public AuditBizDB() {
super();
}
public String writeAudit2DB(String caseId, Date auditDate, String msgType, String msg) {
Connection conn = null;
Timestamp auditDateTime = getTimestamp(auditDate);
try {
conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe",
"niall", "niall");
PreparedStatement insertAudit = null;
String insertSQL =
"INSERT INTO NIALL.AUDIT4CASE (CASE_ID, AUDIT_TIME, AUDIT_MSG, AUDIT_MSG_TYPE) VALUES (?, ?, ?, ? )";
insertAudit = conn.prepareStatement(insertSQL);
insertAudit.setString(1, caseId);
insertAudit.setTimestamp(2, auditDateTime );
insertAudit.setString(3, msg);
insertAudit.setString(4, msgType);
insertAudit.execute();
conn.commit();
conn.close();
} catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
}
return "success";
}
private static java.sql.Timestamp getTimestamp(java.util.Date today) {
return new java.sql.Timestamp(today.getTime());
}
}
etc.
I re-run my tester and see the following output in my DB.
I now detail a basic example of archiving the case audit trail to a Biz DB.
I created the following table in my Biz schema
AUDIT_TIME is defined as TIMESTAMP the rest are varchars.
I now create a utility class to do the DB insert -
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;
public class AuditBizDB {
public AuditBizDB() {
super();
}
public String writeAudit2DB(String caseId, Date auditDate, String msgType, String msg) {
Connection conn = null;
Timestamp auditDateTime = getTimestamp(auditDate);
try {
conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe",
"niall", "niall");
PreparedStatement insertAudit = null;
String insertSQL =
"INSERT INTO NIALL.AUDIT4CASE (CASE_ID, AUDIT_TIME, AUDIT_MSG, AUDIT_MSG_TYPE) VALUES (?, ?, ?, ? )";
insertAudit = conn.prepareStatement(insertSQL);
insertAudit.setString(1, caseId);
insertAudit.setTimestamp(2, auditDateTime );
insertAudit.setString(3, msg);
insertAudit.setString(4, msgType);
insertAudit.execute();
conn.commit();
conn.close();
} catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
}
return "success";
}
private static java.sql.Timestamp getTimestamp(java.util.Date today) {
return new java.sql.Timestamp(today.getTime());
}
}
I call this from the existing auditing methods of my CaseAPI client -
etc.
I re-run my tester and see the following output in my DB.
Thursday, February 6, 2014
# 307 Adaptive Case Management API - Part 4- Getting the audit trail
Building on from the previous examples -
Here is the code -
public static boolean getAudit4Case(ICaseService caseService,
IBPMContext context,
String caseId) throws CaseServiceException {
System.out.println("CaseMgtAPI.getAudit4Case() for caseId: " + caseId);
CaseIdentifier caseIdentifier =
CaseIdentifier.getCaseIdentifierBasedOnCaseId(caseId);
System.out.println("Case identifier = " +caseIdentifier.toString());
TEventType eventType = null;
// event types is one of the following
/*eventType = TEventType.ACTIVITY_EVENT;
eventType = TEventType.DOCUMENT_EVENT;
eventType = TEventType.COMMENT_EVENT;
eventType = TEventType.USER_DEFINED_EVENT;
eventType = TEventType.LIFECYCLE_EVENT;
eventType = TEventType.ACTIVITY_EVENT;*/
eventType = TEventType.LIFECYCLE_EVENT;
int pageNum = 1;
int pageSize = 10;
String updatedBy = "System";
CaseObjectsList caseObjectsList =
caseService.getAudit(context, caseIdentifier, eventType, null,
pageSize, pageNum);
List persistedEvents = caseObjectsList.getCaseObjects();
System.out.println("### Lifecycle Events ###");
getAudit4CaseLifecycleEvents(persistedEvents, caseId);
// Milestone
System.out.println("### Milestone Events ###");
eventType = TEventType.MILESTONE_EVENT;
caseObjectsList =
caseService.getAudit(context, caseIdentifier, eventType, null,
pageSize, pageNum);
persistedEvents = caseObjectsList.getCaseObjects();
getAudit4CaseMilestoneEvents(persistedEvents, caseId);
// Activity
System.out.println("### Activity Events ###");
eventType = TEventType.ACTIVITY_EVENT;
caseObjectsList =
caseService.getAudit(context, caseIdentifier, eventType, null,
pageSize, pageNum);
persistedEvents = caseObjectsList.getCaseObjects();
getAudit4CaseActivityEvents(persistedEvents, caseId);
//
return true;
}
public static boolean getAudit4CaseLifecycleEvents(List persistedEvents,String caseId) throws CaseServiceException {
// System.out.println("CaseMgtAPI.getAudit4CaseLifecycleEvents for caseId: " + caseId);
String updatedBy = "";
for (CaseEvent ce : persistedEvents) {
updatedBy = ce.getUpdatedBy();
String displayName = ce.getUpdatedByDisplayName();
System.out.println("updated by " + displayName);
String myEventType = ce.getEventType().toString();
System.out.println("Lifecycle state " + ce.getLifecycleState());
System.out.println("eventType " + myEventType);
Calendar cal = ce.getUpdatedDate();
System.out.println("Timestamp: " + cal.getTime());
}
return true;
}
public static boolean getAudit4CaseActivityEvents(List persistedEvents,String caseId) throws CaseServiceException {
// System.out.println("CaseMgtAPI.getAudit4CaseActivityEvents for caseId: " + caseId);
String updatedBy = "";
for (CaseEvent ce : persistedEvents) {
updatedBy = ce.getUpdatedBy();
String displayName = ce.getUpdatedByDisplayName();
System.out.println("updated by " + displayName);
String myEventType = ce.getEventType().toString();
System.out.println("eventType " + myEventType);
System.out.println("Activity name " + ce.getActivityName());
System.out.println("Activity Type " + ce.getActivityType());
System.out.println("Activity Event " + ce.getActivityEvent().toString());
Calendar cal = ce.getUpdatedDate();
System.out.println("Timestamp: " + cal.getTime());
}
return true;
}
public static boolean getAudit4CaseMilestoneEvents(List persistedEvents,String caseId) throws CaseServiceException {
// System.out.println("CaseMgtAPI.getAudit4CaseMilestoneEvents for caseId: " + caseId);
String updatedBy = "";
for (CaseEvent ce : persistedEvents) {
updatedBy = ce.getUpdatedBy();
String displayName = ce.getUpdatedByDisplayName();
System.out.println("updated by " + displayName);
String myEventType = ce.getEventType().toString();
System.out.println("eventType " + myEventType);
System.out.println("Milestone " + ce.getMilestone());
System.out.println("Milestone Event " + ce.getMilestoneEvent());
Calendar cal = ce.getUpdatedDate();
System.out.println("Timestamp: " + cal.getTime());
}
return true;
}
Here is the code -
public static boolean getAudit4Case(ICaseService caseService,
IBPMContext context,
String caseId) throws CaseServiceException {
System.out.println("CaseMgtAPI.getAudit4Case() for caseId: " + caseId);
CaseIdentifier caseIdentifier =
CaseIdentifier.getCaseIdentifierBasedOnCaseId(caseId);
System.out.println("Case identifier = " +caseIdentifier.toString());
TEventType eventType = null;
// event types is one of the following
/*eventType = TEventType.ACTIVITY_EVENT;
eventType = TEventType.DOCUMENT_EVENT;
eventType = TEventType.COMMENT_EVENT;
eventType = TEventType.USER_DEFINED_EVENT;
eventType = TEventType.LIFECYCLE_EVENT;
eventType = TEventType.ACTIVITY_EVENT;*/
eventType = TEventType.LIFECYCLE_EVENT;
int pageNum = 1;
int pageSize = 10;
String updatedBy = "System";
CaseObjectsList caseObjectsList =
caseService.getAudit(context, caseIdentifier, eventType, null,
pageSize, pageNum);
List
System.out.println("### Lifecycle Events ###");
getAudit4CaseLifecycleEvents(persistedEvents, caseId);
// Milestone
System.out.println("### Milestone Events ###");
eventType = TEventType.MILESTONE_EVENT;
caseObjectsList =
caseService.getAudit(context, caseIdentifier, eventType, null,
pageSize, pageNum);
persistedEvents = caseObjectsList.getCaseObjects();
getAudit4CaseMilestoneEvents(persistedEvents, caseId);
// Activity
System.out.println("### Activity Events ###");
eventType = TEventType.ACTIVITY_EVENT;
caseObjectsList =
caseService.getAudit(context, caseIdentifier, eventType, null,
pageSize, pageNum);
persistedEvents = caseObjectsList.getCaseObjects();
getAudit4CaseActivityEvents(persistedEvents, caseId);
//
return true;
}
public static boolean getAudit4CaseLifecycleEvents(List
// System.out.println("CaseMgtAPI.getAudit4CaseLifecycleEvents for caseId: " + caseId);
String updatedBy = "";
for (CaseEvent ce : persistedEvents) {
updatedBy = ce.getUpdatedBy();
String displayName = ce.getUpdatedByDisplayName();
System.out.println("updated by " + displayName);
String myEventType = ce.getEventType().toString();
System.out.println("Lifecycle state " + ce.getLifecycleState());
System.out.println("eventType " + myEventType);
Calendar cal = ce.getUpdatedDate();
System.out.println("Timestamp: " + cal.getTime());
}
return true;
}
public static boolean getAudit4CaseActivityEvents(List
// System.out.println("CaseMgtAPI.getAudit4CaseActivityEvents for caseId: " + caseId);
String updatedBy = "";
for (CaseEvent ce : persistedEvents) {
updatedBy = ce.getUpdatedBy();
String displayName = ce.getUpdatedByDisplayName();
System.out.println("updated by " + displayName);
String myEventType = ce.getEventType().toString();
System.out.println("eventType " + myEventType);
System.out.println("Activity name " + ce.getActivityName());
System.out.println("Activity Type " + ce.getActivityType());
System.out.println("Activity Event " + ce.getActivityEvent().toString());
Calendar cal = ce.getUpdatedDate();
System.out.println("Timestamp: " + cal.getTime());
}
return true;
}
public static boolean getAudit4CaseMilestoneEvents(List
// System.out.println("CaseMgtAPI.getAudit4CaseMilestoneEvents for caseId: " + caseId);
String updatedBy = "";
for (CaseEvent ce : persistedEvents) {
updatedBy = ce.getUpdatedBy();
String displayName = ce.getUpdatedByDisplayName();
System.out.println("updated by " + displayName);
String myEventType = ce.getEventType().toString();
System.out.println("eventType " + myEventType);
System.out.println("Milestone " + ce.getMilestone());
System.out.println("Milestone Event " + ce.getMilestoneEvent());
Calendar cal = ce.getUpdatedDate();
System.out.println("Timestamp: " + cal.getTime());
}
return true;
}
Test output for my demo case -
Note the project libraries -
Monday, February 3, 2014
#306 Adaptive Case Management API Part 3
Monday, January 20, 2014
# 305 Adaptive Case Management Java API Part 2
Building on from the previous post - let's get some more information -
Case myCase = new Case();
List caseInfo =
new ArrayList();
caseInfo.add(ICaseConstants.CaseInfo.ALL);
Note the additional line above -
This gives us access to more case related info such as Activities, Data, Milestones, Comments etc.
// 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 Data
List cd_l = myCase.getCaseData();
System.out.println("Case Data list size " + cd_l.size());
for (int b = 0; b < cd_l.size(); b++) {
CaseData cd = cd_l.get(b);
System.out.println("Case Data = " + cd.getData());
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("");
// Case Comments
List c_l = myCase.getComments();
System.out.println("Comment list size " + c_l.size());
for (int d = 0; d < c_l.size(); d++) {
Comment comment = c_l.get(d);
System.out.println("Comment :" + comment.getCaseObjectComment());
}
System.out.println("");
List caseDataList = myCase.getCaseData();
System.out.println("Case Data List size = " + caseDataList.size());
for (int e = 0; e < caseDataList.size(); e++) {
CaseData caseData = caseDataList.get(e);
System.out.println("Case Data Name :" + caseData.caseDataName);
}
System.out.println("");
List caseMilestoneList = myCase.getCaseMilestones();
System.out.println("Case Milestone List size = " +
caseMilestoneList.size());
for (int f = 0; f < caseMilestoneList.size(); f++) {
CaseMilestone caseMilestone = caseMilestoneList.get(f);
System.out.println("Case Milestone :" +
caseMilestone.getObjectDisplayName());
System.out.println("Case Milestone state :" +
caseMilestone.getState());
}
System.out.println("");
FYI - here is one of my case composites -
I have a test instance running - the case is configured with a rule to automatically reach the milestone ApproveOrderStarted. The Case data below contains my input
I run the above code - and get the following output -
### Case Header Info ...
Composite Name = default/SimpleOrderProcessingCase!1.0*soa_9f7e0a57-cfea-4ce1-8f91-5ca2280c4a13
Case Def. = SimpleOrderProcessingCase
ECM Folder = MyOrders/123
Id Key = 123
Case Definition Name = SimpleOrderProcessingCase
Application Name = default
Component Name = SimpleOrderProcessingCase
Case Number = 42
Case Definition Id = default/SimpleOrderProcessingCase!1.0/SimpleOrderProcessingCase
### Nr of Case Activities Completed for this instance =0
### End of Case Header Info ...
Case Data list size 1
Case Data =123 iBike A1234 Niall C Main St IE N
+++ Actions : abortCase
+++ Actions : updateCaseHeader
+++ Actions : closeCase
+++ Actions : suspendCase
+++ Actions : getCase
+++ Actions : queryCase
Comment list size 1
Comment :auto-start
Case Data List size = 1
Case Data Name :caseDataName
Case Milestone List size = 4
Case Milestone :OrderApprovalCompleted
Case Milestone state :NOT_ATTAINED
Case Milestone :OrderApprovalStarted
Case Milestone state :ATTAINED
Case Milestone :OrderShippingCompleted
Case Milestone state :NOT_ATTAINED
Case Milestone :OrderShippingStarted
Case Milestone state :NOT_ATTAINED
Case StakeHolder List size = 1
Case StakeHolder Name :CSR
+++ Case StakeHolder Member Name :James Cooper
+++ Case StakeHolder Member Name :John Steinbeck
Revised JDeveloper project available here
Case myCase = new Case();
List
new ArrayList
caseInfo.add(ICaseConstants.CaseInfo.ALL);
Note the additional line above -
This gives us access to more case related info such as Activities, Data, Milestones, Comments etc.
// Case Activities
CompletedCaseActivityList ccal =
myCase.getCaseHeader().getCompletedCaseActivityList();
List
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 Data
List
System.out.println("Case Data list size " + cd_l.size());
for (int b = 0; b < cd_l.size(); b++) {
CaseData cd = cd_l.get(b);
System.out.println("Case Data = " + cd.getData());
System.out.println("");
}
// Case Actions
List
for (int c = 0; c < myActions.size(); c++) {
System.out.println("+++ Actions : " +
myActions.get(c).toString());
}
System.out.println("");
// Case Comments
List
System.out.println("Comment list size " + c_l.size());
for (int d = 0; d < c_l.size(); d++) {
Comment comment = c_l.get(d);
System.out.println("Comment :" + comment.getCaseObjectComment());
}
System.out.println("");
List
System.out.println("Case Data List size = " + caseDataList.size());
for (int e = 0; e < caseDataList.size(); e++) {
CaseData caseData = caseDataList.get(e);
System.out.println("Case Data Name :" + caseData.caseDataName);
}
System.out.println("");
List
System.out.println("Case Milestone List size = " +
caseMilestoneList.size());
for (int f = 0; f < caseMilestoneList.size(); f++) {
CaseMilestone caseMilestone = caseMilestoneList.get(f);
System.out.println("Case Milestone :" +
caseMilestone.getObjectDisplayName());
System.out.println("Case Milestone state :" +
caseMilestone.getState());
}
System.out.println("");
FYI - here is one of my case composites -
I have a test instance running - the case is configured with a rule to automatically reach the milestone ApproveOrderStarted. The Case data below contains my input
I run the above code - and get the following output -
### Case Header Info ...
Composite Name = default/SimpleOrderProcessingCase!1.0*soa_9f7e0a57-cfea-4ce1-8f91-5ca2280c4a13
Case Def. = SimpleOrderProcessingCase
ECM Folder = MyOrders/123
Id Key = 123
Case Definition Name = SimpleOrderProcessingCase
Application Name = default
Component Name = SimpleOrderProcessingCase
Case Number = 42
Case Definition Id = default/SimpleOrderProcessingCase!1.0/SimpleOrderProcessingCase
### Nr of Case Activities Completed for this instance =0
### End of Case Header Info ...
Case Data list size 1
Case Data =
+++ Actions : abortCase
+++ Actions : updateCaseHeader
+++ Actions : closeCase
+++ Actions : suspendCase
+++ Actions : getCase
+++ Actions : queryCase
Comment list size 1
Comment :auto-start
Case Data List size = 1
Case Data Name :caseDataName
Case Milestone List size = 4
Case Milestone :OrderApprovalCompleted
Case Milestone state :NOT_ATTAINED
Case Milestone :OrderApprovalStarted
Case Milestone state :ATTAINED
Case Milestone :OrderShippingCompleted
Case Milestone state :NOT_ATTAINED
Case Milestone :OrderShippingStarted
Case Milestone state :NOT_ATTAINED
Case StakeHolder List size = 1
Case StakeHolder Name :CSR
+++ Case StakeHolder Member Name :James Cooper
+++ Case StakeHolder Member Name :John Steinbeck
# 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
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
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
new ArrayList
CaseList caseList =
caseService.queryCase(bpmContext, caseInfo, null, null, 10, 1);
System.out.println("Total Nr of Case Instances = " +
caseList.getTotalNumberOfCases());
List
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
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
for (int c = 0; c < myActions.size(); c++) {
System.out.println("+++ Actions : " +
myActions.get(c).toString());
}
System.out.println("");
// stakeholders
List
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
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
Subscribe to:
Posts (Atom)