Try OpenEdge Now
skip to main content
Programming Interfaces
Audit Policy Maintenance APIs : Caching API
 

Caching API

The procedure src/auditing/_aud-cache.p contains the API for caching the auditing policies from a given database into a ProDataSet object. The defined procedures and functions can be used by other applications if you want to use this API, for example, to build a different UI.
The procedures take advantage of ProDataSets to read and write policies from and to databases. This procedure works as a sort of wrapper for the API defined in src/auditing/_aud-utils.p. This procedure creates a ProDataSet object (with temp-tables defined by the caller) and maintains it for the caller so the caller does not need to build one.
The following example is a combination of pseudo-code and ABL that shows how to use the caching API described in the following sections:
Example calls to the audit policy caching API
{auditing/include/_aud-cache.i}

/* Define the temp-tables */
{auditing/ttdefs/ _audpolicytt.i}
{auditing/ttdefs/_audfilepolicytt.i}
{auditing/ttdefs/_audfieldpolicytt.i}
{auditing/ttdefs/_audeventpolicytt.i}

/* Call either registerAuditTableHandle for each table or
   set-tt-hdls-for-dataset to pass the four table handles */

/*
RUN registerAuditTableHandle IN hAuditCacheMgr ("policy",
  TABLE ttAuditPolicy:HANDLE).
RUN registerAuditTableHandle IN hAuditCacheMgr ("file-policy",
  TABLE ttAuditFilePolicy:HANDLE).
RUN registerAuditTableHandle IN hAuditCacheMgr ("field-policy",
  TABLE ttAuditFieldPolicy:HANDLE).
RUN registerAuditTableHandle IN hAuditCacheMgr ("event-policy",
  TABLE ttAuditFieldPolicy:HANDLE).
*/

RUN set-tt-hdls-for-dataset IN hAuditCacheMgr(TABLE ttAuditPolicy:HANDLE,
  TABLE ttAuditFilePolicy:HANDLE, TABLE ttAuditFieldPolicy:HANDLE,
  TABLE ttAuditEvent Policy:HANDLE).

/* Populate temp-tables with policies from connected database */
RUN changeAuditDatabase IN hAuditCacheMgr (ldbname(1)).

/* load policies from XML file */
RUN import-policies-from-xml IN hAuditCacheMgr
  (INPUT cFileName, OUTPUT cDupList, OUTPUT errorMsg).

/* Either display error message or confirmation that the policies were
   imported */
IF errorMsg <> "":U THEN
  RETURN ERROR errorMsg.
ELSE DO:
/* Check if XML file has policies which already exist */
IF cDupList <> "" THEN DO:
  MESSAGE "The following policies already exist:" SKIP
    REPLACE(cDupList,",",CHR(10)) SKIP
    "Do you want to override them?" SKIP
    "(If Yes, the listed policies will be deleted and re-imported)"
    VIEW-AS ALERT-BOX QUESTION BUTTON YES-NO UPDATE lChoice AS LOGICAL.

  IF lChoice THEN DO:
    /* User confirmed that he wants to override existing policies, so let's
       pick up from where we left off. Keep the changes. */
    RUN setcursor ("WAIT":U).
    RUN resubmit-import-from-xml IN hAuditCacheMgr(OUTPUT errorMsg).
    RUN setcursor ("":U).
    IF errorMsg <> "" THEN
      RETURN ERROR errorMsg.
  END.

  ELSE DO:
    /* User doesn't want to override policies, so cancel the previous
       request */
    RUN cancel-import-from-xml IN hAuditCacheMgr.
    MESSAGE "Import canceled" VIEW-AS ALERT-BOX INFO.
  END.
END. /* cDupList <> "" */

/* Make some changes to the policies by updating the temp-tables. Check if
   there are pending changes and save them to the database */
RUN getDataModified IN hAuditCacheMgr (OUTPUT lMod).
IF lMod THEN DO: /* changes pending */
  RUN saveChangesAuditDatabase IN hAuditCacheMgr.
  ASSIGN errorMsg = RETURN-VALUE.
  IF errorMsg <> "":U THEN DO:
    /* Let's reject everything and get out */
    RUN rejectChangesAuditDatabase IN hAuditCacheMgr.
    RETURN ERROR errorMsg.
  END.

  /* Export changed policies to an XML file. Call the procedure in the
     auditUtils procedure to do the job */
  RUN export-policies-to-xml IN hAuditCacheMgr
    (INPUT cList, INPUT cFileName, OUTPUT errorMsg).
  IF errorMsg <> "":U THEN
    RETURN ERROR errorMsg.
END.
* changeAuditDatabase procedure
* export-cached-audit-events procedure
* export-policies-to-xml procedure
* get-audit-events procedure
* get-conflict-info procedure
* getDataModified procedure
* get-merge-info procedure
* getNextAppLevelEventID function
* hasApplEvents function
* import-audit-events procedure
* import-policies-from-xml procedure
* is-valid-event-id function
* registerAuditTableHandle procedure
* rejectChangesAuditDatabase procedure
* resubmit-import-from-xml procedure
* saveAuditEventChanges procedure
* saveChangesAuditDatabase procedure
* set-tt-hdls-for-dataset procedure