Release 10.1A: OpenEdge Development:
Programming Interfaces

> ## 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 4GL 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 here */
>     {auditing/ttdefs/ _audpolicytt.i}
>     {auditing/ttdefs/_audfilepolicytt.i}
>     {auditing/ttdefs/_audfieldpolicytt.i}
>     {auditing/ttdefs/_audeventpolicytt.i}
>     /* you can call either registerAuditTableHandle for each table or
>     set-tt-hdls-for-dataset to pass all the 4 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 do:
>         Return error errorMsg.
>     End.
>     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 choice AS LOGICAL.
>         IF choice = TRUE 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.
>     /* 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:
>     /* lets reject everything ang get out */
>     RUN rejectChangesAuditDatabase IN hAuditCacheMgr.
>     Return error errorMsg.
>     End.
>     /* export changed policies to a XML file */
>     /* call the procedure in the auditUtils procedure do do the job */
>     RUN export-policies-to-xml IN hAuditCacheMgr
>             (INPUT cList,
>              INPUT cFileName,
>              OUTPUT errorMsg).
>     IF errorMsg <> "":U THEN
>        Return error errorMsg.
>     End.

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095