Monday, March 17, 2014

#311 Happy St. Patrick's Day from Maui

Off for the month of March for some well deserved R&R.
Spend today on the well worn road to Hana, instead of parading like the rest of the Irish diaspora.


So until April!

Tuesday, February 11, 2014

#310 Oracle Bold Data Project

Check it out on YouTube here

#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());
     
    }




}

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;
    }

Test output for my demo case -
















Note the project libraries -




















Monday, February 3, 2014

#306 Adaptive Case Management API Part 3

Firstly kudos to my colleague Venugopal -

In this lab we look at the Java API and how you can use it to -

  • query cases
  • update cases
  • start cases
  • close cases

JDeveloper Project – Libraries Required
















A starter project is available  -Here

Full lab - Here

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  = 123iBikeA1234NiallCMain StIEN
         

+++ 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