Scanning the Audit Trail

You can use the scanAuditTrail() method on the engine to iterate through the audit trail and gather information about the events that have occurred. The engine also includes a separate method for scanning the audit trail by user (see the Javadoc for more details).

See below for an example of using the Java API to scan the audit trail.

//  Look up the engine – edit this code if your engine is not running
//  unsecured at the default location.
Engine engine = Factory.makeInstance().lookupRmiEngine("localhost", 1099, "Flux");

//  Dates will be used for searching the audit trail. This allows us to search
//  the audit trail for all events occurring within the last week.
        Date lastWeek = new Date();
        lastWeek.setDate(lastWeek.getDate() - 7);
        Date now = new Date();

//  A Set of event names that the search should match. Must include the full
//  class name and package of the events.
        Set eventNames = new HashSet();
        eventNames.add("flux.audittrail.server.EnteringActionEvent");
        eventNames.add("flux.audittrail.server.ExitingActionEvent");

//  Search the audit trail. In order, the parameters are:

//    Namespace: The namespace you want to search. This can be a namespace or
//      the full name (including namespace) of a workflow.

//    Lower bound: The starting date to search from.

//    Upper bound: The last date to be considered in the search.

//    Audit trail event names: A java.util.Set of Strings representing the
//      event names that should be considered. If the set is null or empty,
//      this will match all events. In this case the scan will only match the
//      entering action and exiting action events.

//    Message filter: Allows you to restrict results based on the contents
//      of the message for each audit trail event. In this case the wildcard
//      character matches all messages.
        AuditTrailIterator ait = engine.scanAuditTrail("/Folder/Workflow", lastWeek, now, eventNames, "*");

//  Now iterate through the results.
        while (ait.hasNext()) {
        AuditTrailEntry entry = ait.next();

//  Each entry has several values you can access.
        String eventName = entry.getAuditTrailEventName();
        String engineName = entry.getEngineName();
        String groupName = entry.getGroupname();
        String message = entry.getMessage();
        String namespace = entry.getNamespace();
        Date timestamp = entry.getTimestamp();
        String username = entry.getUsername();
        }