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 -




















No comments: