Document Manager API Sample

The Document Manager API sample is a small document manager that can store PDFs in binary fields and display them in a web browser by way of Data Explorer. This sample illustrates:
calac41
The Document Manager API sample is a small document manager that can store PDFs in binary fields and display them in a web browser by way of Data Explorer. This sample illustrates:
  • Non-persistent attributes (NPAs)
  • Formula rules
  • Custom endpoints
  • Accessing binary data
In this article:
 
 
Business Case
As a user, you want to see a list of documents and use the list to select which document to download or view in the browser. You want the list to show key information about the document and to be quickly searchable. In particular, since documents can be large, you want to view them before you download them.
Solution
The technical approach is to:
  1. Store the document (for example, PDF) in the 
    Docs_binary
     binary type field.
  2. Add data to the field using Data Explorer.
    For more information about how to add data to binary type fields using Data Explorer, see Author Mode.
  3. View the document in the browser:
    1. Create the 
      DownloadDoc
       NPA, as a hyperlink.
      The following code snippet shows the formula for the 
      DownloadDoc
       NPA:
      return 'http://localhost:8080/http/default/docs/ViewDoc?DocId=' + row.ident; // see the Viewdoc custom endpoint
      For more information about how to add NPAs, see Manage Non-Persistent Attributes.
    2. Implement the hyperlink with a custom endpoint called 
      ViewDoc
      .
      For more information about how to create a custom endpoint, see Manage Custom Endpoints.
      The following code snippet shows the code for the 
      ViewDoc
       custom endpoint:
      var docId = request.getParameter("DocId"); var settings = { headers: { Authorization: "CALiveAPICreator demo_full:1" }}; // TODO compute auth var params = null; // here we just compute the url var url = "http://localhost:8080/data/default/docs/v1/main:Docs/" + docId + "/Docs_binary"; var docData = SysUtility.restGetBinary(url, params, settings); // want binary data... // out.println("Doc Data: " + docData); responseHeaders.put('Content-Type', 'application/pdf'); responseHeaders.put('Content-Transfer-Encoding', 'binary'); responseHeaders.put('Content-Disposition', 'inline; filename="foo.pdf"'); return docData;
    3. In Data Explorer (in Author Mode), show the 
      DownloadDoc
       non-persistent attribute as an external link.
      For more information about how to add links in Data Explorer, see Author Mode.
Install the Document Manager API Sample
  1. Download the 
    Document Manager
     API from the  file. This ZIP file includes the 
    Doc Mgr.json
     and 
    DocDB.sql
     files.
  2. In MySQL Workbench, create the 
    docs
     MySQL schema by loading the schema/data from the 
    DocDB.sql
     file.
  3. In API Creator, complete the following:
    1. Import the API using the 
      Doc Mgr.json
       file.
    2. Fix your data source (Enter the password in the 
      Password
       field).
      For more information about how to import an API and fix the imported API, see Import and Export APIs.
  4. In Data Explorer, complete the following:
    1. (Optional) In the
       Docs Binary
       field, add data to this binary type field (a sample PDF is in the ZIP file).
    2. In the 
      Download Doc
       field, download and view the doc.
    The following image shows these fields in Data Explorer:
    Document Manager.png