Try OpenEdge Now
skip to main content
Programming Interfaces
Audit Policy Maintenance APIs : Importing policies from XML
 

Importing policies from XML

OpenEdge provides the persistent procedure, src/auditing/_imp-policies.p that provides an API to import an XML file containing audit policies into either a database or a ProDataSet. This procedure must be executed persistently and then the caller should execute the internal procedures depending on the target for the policies—a ProDataSet or a database. This procedure is used by both the Audit Policy Maintenance tool and the Data Administration tool when importing audit policies from an XML file.
For a database, call import-xml-dbprocedure and save-changes-to-dbprocedure. For a ProDataSet, call import-xml-fill-dsetprocedure and copy-changes-to-dsetprocedure. The cleanup internal procedure should be called before deleting the persistent procedure.
Note: Import procedure for loading audit policies from an XML file into an OpenEdge database does not refresh the database cache automatically. It's up to the caller to decide if the cache should be refreshed. You can either call refresh-db-cacheprocedure or directly call the AUDIT-POLICY:REFRESH-AUDIT-POLICY() method.
The following example is a combination of pseudo-code and ABL that shows how to use some of the procedures that are provided in _imp-policies.p and described in the sections that follow:
Example calls to the API for importing audit policies from XML
DEFINE VARIABLE cErrorMsg AS CHARACTER NO-UNDO.
DEFINE VARIABLE cList     AS CHARACTER NO-UNDO.
DEFINE VARIABLE hProc     AS HANDLE    NO-UNDO.

/* Start the importing procedure */
RUN auditing/_imp-policies.p PERSISTENT SET hProc.

/* Try to load the file and save the changes into the database */
RUN import-xml-db IN hProc (INPUT "text.xml", /* XML file name */
  INPUT "sports2000", /* logical db name */
  INPUT TRUE,         /* wait on lock */
  INPUT FALSE,        /* override existing policies */
  OUTPUT cList,       /* list of duplicate policies */
  OUTPUT cErrorMsg).

/* Check if there was an error */
IF cErrorMsg = "":U THEN DO:
  IF cList <> "":U THEN DO:
    MESSAGE "The following policies already exist: " cList SKIP
      "Do you want to override them? (If you answer yes, the tool will" SKIP
      "delete the listed policies before importing them)"
      VIEW-AS ALERT-BOX QUESTION BUTTON YES-NO UPDATE lChoice AS LOGICAL.
    /* If the user wants to override policies, need to call save-changes-to-db
       to get them saved */
    IF lChoice THEN DO:
      RUN save-changes-to-db IN hProc
        (INPUT "sports2000", /* logical db name */
         INPUT TRUE,         /* wait on lock */
         OUTPUT cErrorMsg).
      IF cErrorMsg <> "" THEN  /* an error occurred */
        MESSAGE cErrorMsg VIEW-AS ALERT-BOX.
    END.
  END.
END.

ELSE /* An error occurred */
  MESSAGE cErrorMsg VIEW-AS ALERT-BOX ERROR.

/* Clean up the procedure and delete it */
RUN cleanup IN hProc.
DELETE PROCEDURE hProc.
* copy-changes-to-dset procedure
* import-xml-db procedure
* import-xml-fill-dset procedure
* refresh-db-cache procedure
* save-changes-to-db procedure