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