Storing Document and Folder Meta Data into the Audit Trail

In some cases, e.g. a repository provider does not support meta data read and write, document meta data should be transparently saved and retrieved for each document or folder using the audit trail.

Class RepositoryAuditTrailUtils provides functionality to store, retrieve and delete document and folder beans as CLOB data bean in the audit trail using a JSON format. The entries are stored uniquely by document Id, revision Id and folder Id.

Storing a Document in the Audit Trail

To store a document in the audit trail, e.g. to supply repository providers in the audit trail that do not support write meta data, use method storeDocument(Document document). It stores the given document of type Document by its Id and also its revision Id if it exists and applies to the following:

   public static void storeDocument(Document document)
   {
      if (document != null)
      {
         storeResource(document.getId(), document, DmsDocumentBean.class);

         // store entry for revision
         if (document.getRevisionId() != null
               && !RepositoryConstants.VERSION_UNVERSIONED.equals(document.getRevisionId())
               && !RepositoryConstants.VERSION_VERSIONED.equals(document.getRevisionId()))
         {
            storeResource(document.getRevisionId(), document, DmsDocumentBean.class);
         }
      }
   }

Retrieving a Document from the Audit Trail

Use method retrieveDocument(String documentId) to fetch a document from the audit trail. Use the document Id or document revision Id as parameter to look up the document for.

   public static Document retrieveDocument(String documentId)
   {
      Map legoMap = retrieveResource(documentId, DmsDocumentBean.class);
      DmsDocumentBean dmsDocumentBean = legoMap == null ? null : new DmsDocumentBean(
            legoMap);
      return dmsDocumentBean;
   }

Example Usage

Document document;
...
Document retrievedDoc = RepositoryAuditTrailUtils.retrieveDocument(document.getId());

Deleting an Audit Trail Entry for a Document

Method removeDocument(String documentId) provides functionality to delete an entry for a document by a given document Id from the audit trail, in case it exists.

   public static void removeDocument(String documentId)
   {
      removeResource(documentId, DmsDocumentBean.class);
   }

Example Usage

The following example demonstrates how to remove a document entry from the audit trail by its revision Id:

   public void removeDocumentVersion(String documentId, String documentRevisionId)
         throws DocumentManagementServiceException
   {
      service.removeDocumentVersion(documentId, documentRevisionId);
      Document document = service.getDocument(documentId);

      if (document != null && !isMetaDataSupported(document.getRepositoryId()))
      {
         // update data for head
         storeMetaDataToAuditTrail(document);
         // remove data for revision
         RepositoryAuditTrailUtils.removeDocument(documentRevisionId);
      }

   }

Storing a Folder in the Audit Trail

To store a given folder in the audit trail, use method storeFolder(Folder folder).

   public static void storeFolder(Folder folder)
   {
      if (folder != null)
      {
         storeResource(folder.getId(), folder, DmsFolderBean.class);
      }
   }

Retrieving a Folder from the Audit Trail

Use method retrieveFolder(String folderId) to fetch a folder with a given folder Id from the audit trail.

   public static Folder retrieveFolder(String folderId)
   {
      Map legoMap = retrieveResource(folderId, DmsFolderBean.class);
      DmsFolderBean dmsFolderBean = new DmsFolderBean(legoMap);
      return dmsFolderBean;
   }

Deleting an Audit Trail Entry for a Folder

Method removeFolder(String folderId) deletes an entry for a folder with a given Id from the audit trail.

   public static void removeFolder(String folderId)
   {
      removeResource(folderId, DmsFolderBean.class);
   }