The DMS provides options to access, i.e. read/write/create documents in your DMS directly. Most operations work through the API that the Nuxeo backend provides.

Please note that the below information is given as is with no liability taken by PI or Patrix. Do not proceed to use the below information against your repository unless you are well aware of what you do. 

For running the below commands, you can use gui tools, such as, e.g., Postman, or use the terminal's curl command. Commands are given as curl, however, you can easily determine the header and body values therefrom and translate that into Postman.

Accessing an existing document to open for editing/saving back to system

There is an option to post a URL to the DMS server which will invoke DocIntegrate to download the document and open it using the default document handler for that type. Once saved/closed, the document will be uploaded back to the DMS server with a new version for the document being created (this is the standard CaseBrowser behaviour).

Note: The behaviour of DocIntegrate is influenced by the <editableFileTypes> key in the settings.xml file in /Workspace/Settings/ of your repository.

Please check the information given here to access a document for editing.

Downloading an existing document from the DMS

To download a document from the DMS, you can use the following endpoint:

http://<nuxeoserverip>:<casebrowserport>/casebrowser/download/<caseRef>,<documentUID>/true

Note: This is a casebrowser endpoint so you need to use the casebrowser server IP and port.

To get the documentUID from the document's path, you can run a http POST against the Document.Query endpoint of the DMS:

curl -X POST \
  http://<nuxeoserverip>:<nuxeoport>/nuxeo/api/v1/automation/Document.Query \
  -H 'authorization: Basic <userAndPassEncoded>' \
  -H 'content-type: application/json' \
  -d '{"params":{"query":"SELECT * FROM Document WHERE dc:title='\''<documentName>'\'' AND ecm:path STARTSWITH '\''<casePath>'\''"}}'

Here, the <userAndPassEncoded> represents a Base64 encoded string of the format 'Username:Password'. So, 'Username:Password' would be represented as 'VXNlcm5hbWU6UGFzc3dvcmQ='.

To determine the <documentPath>, please see below. The <documentName> of a specific document can be found in PAT_DOC_LOG.DOC_FILE_NAME of the Patricia database.

The Document.Query endpoint returns an array of the documents in JSON format, for example:

{
    "entity-type": "documents",
    "isPaginable": true,
    "resultsCount": 1,
    "pageSize": 0,
    "maxPageSize": 1000,
    "currentPageSize": 1,
    "currentPageIndex": 0,
    "numberOfPages": 1,
    "isPreviousPageAvailable": false,
    "isNextPageAvailable": false,
    "isLastPageAvailable": false,
    "isSortable": true,
    "hasError": false,
    "errorMessage": null,
    "totalSize": 1,
    "pageIndex": 0,
    "pageCount": 1,
    "entries": [
        {
            "entity-type": "document",
            "repository": "default",
            "uid": "64acbaf8-c963-46a6-a5fc-a7e703826625",
            "path": "/default-domain/workspaces/Patricia/Documents/2/1000/DE/00/Sample.docx",
            "type": "File",
            "state": "project",
            "parentRef": "650d7a6c-9927-4485-85c4-4d2cc9b9f08f",
            "isCheckedOut": true,
            "changeToken": "1529682744601",
            "title": "Sample.docx",
            "lastModified": "2018-06-22T15:52:24.60Z",
            "facets": [
                "Versionable",
                "Publishable",
                "Commentable",
                "PiFileFacet",
                "PiFacet",
                "HasRelatedText",
                "Downloadable"
            ]
        }
    ]
}

From this, you can extract the "uid" value.

Since DMS version 1.9.8.2.3-3, the download endpoint allows downloading of multiple documents as follows:

http://<nuxeoserverip>:<nuxeoport>/casebrowser/download/<caseRef1>,<documentUID1>;<caseRef2>,<documentUID2>;<caseRef3>,<documentUID3>;.../true

Creating a document in the DMS

Creating a document in the DMS is a bit more complex. In Nuxeo, a document is made up of a document container, think of it as a shell with some metadata attached to it, and the binary/binaries. To create document in the DMS, you must thus first create a container and then add the binary to it.

a) Creating the "container"

http://<nuxeoserverip>:<nuxeoport>/nuxeo/api/v1/automation/Document.Create

This can be curled as http POST against the DMS as follows:

curl \
	-H "authorization: Basic <userAndPassEncoded>" \
	-H "Content-Type: application/json" \
	-d "{\"params\":{\"entity-type\":\"document\",\"type\":\"File\",\"name\":\"testdoc.txt\",\"properties\":{\"dc:title\":\"testdoc.txt\",\"pifile:docCategoryId\":\"1\"}},\"input\":\"/default-domain/workspaces/Patricia/<documentPath>\"}" \
	-X POST http://<nuxeoserverip>:<nuxeoport>/nuxeo/api/v1/automation/Document.Create

Again, the <userAndPassEncoded> represents a Base64 encoded string of the format 'Username:Password'. So, 'Username:Password' would be represented as 'VXNlcm5hbWU6UGFzc3dvcmQ='.

To determine the <documentPath>, please see below. The <docName> is the name that the new document should have. <categoryID> is the category that the document will be posted into; pleas take that from the Patricia database.

Following the document creation, the PAT_DOC_LOG of Patricia will also be updated to include the document.

b) Creating the document content

Following successful creation of the container (see above), the following endpoint is used to fill the container with content:

http://<nuxeoserverip>:<nuxeoport>/nuxeo/api/v1/automation/Blob.Attach

This can be curled as http POST against the DMS as follows:

curl \
	-H "authorization: Basic <userAndPassEncoded>" \
	-H "content-type: application/json" \
	-F "{\"params\":{\"mime-type\":\"<docMimeType>\",\"document\":\"/default-domain/workspaces/Patricia/<documentPath>/<docName>\",\"save\":\"true\",\"xpath\":\"file:content\"}}" \
	-F =@/<pathToSourceFile>
	-X POST http://<nuxeoserverip>:<nuxeoport>/nuxeo/api/v1/automation/Blob.Attach \

The <mimeType> should be set according to the document type (eg. "text/html" for a html document). <pathToSourceFile> is your local file path of the binary document to upload.

To determine the <documentPath>, please see below. The <docName> is the name that the new document has as per the creation of the container above.

Note:

For the above document creation to work, <documentPath> must exist. As the case may be, you may require creation of the folder path as follows:

curl \
	-H "authorization: Basic <...>" \
	-H "Content-Type: application/json" \
	-d "{\"params\":{\"entity-type\":\"document\",\"type\":\"Folder\",\"name\":\"<folderName>\",\"input\":\"/default-domain/workspaces/Patricia/<folderPath>\"}" \
	-X POST http://<nuxeoserverip>:<nuxeoport>/nuxeo/api/v1/automation/Document.Create

whereby <folderPath>/<folderName> will be created. Note that the folder tree needs to be build recursively (i.e. <folderPath> must also exist).

Deleting a document from the DMS

Please note that the term "deleting" in this context is misleading as the DMS does not delete any documents (unless the administrator follows a specific set of steps). All documents are kept in the DMS, however, when the user deletes a document, the document is merely marked deleted and thus removed from view and put in the trash. To terminally delete the document, the trash must be emptied.

The endpoint to mark an existing document as "deleted" is:

http://<nuxeoserverip>:<nuxeoport>/nuxeo/api/v1/automation/Document.SetLifeCycle

This can be curled as http POST against the DMS as follows:

curl -X POST \
  http://<nuxeoserverip>:<nuxeoport>/nuxeo/api/v1/automation/Document.SetLifeCycle \
  -H 'authorization: Basic <userAndPassEncoded>' \
  -H 'content-type: application/json' \
  -d '{"params":{"value":"delete"},"input":"/default-domain/workspaces/Patricia/<documentPath>/<documentName>"}'
 

Again, the <userAndPassEncoded> represents a Base64 encoded string of the format 'Username:Password'. So, 'Username:Password' would be represented as 'VXNlcm5hbWU6UGFzc3dvcmQ='.

To determine the <documentPath>, please see below. The <documentName> of a specific document can be found in PAT_DOC_LOG.DOC_FILE_NAME of the Patricia database.

Determining the document path

The document path always starts with “/default-domain/workspaces/Patricia/Documents/” but the remainder of the path is built using the components of the Patricia case reference, which can all be retrieved from the PAT_CASE table of the Patricia database along the following lines: <CASE_TYPE_ID>/<CASE_NUMBER>/<STATE_ID>/<CASE_NUMBER_EXTENSION>.

The below SQL Server function returns the path of a case for a specified case reference.

CREATE FUNCTION [dbo].[GetNuxeoPath]
(
         -- Add the parameters for the function here
         @CaseRef NVARCHAR(20)
)
RETURNS NVARCHAR(250)
AS
BEGIN
         -- Declare the return variable here
         DECLARE @NuxeoPath NVARCHAR(250)
 
         SET @NuxeoPath =
         (select CAST(CASE_TYPE_ID as NVARCHAR) + '/' + CAST(CASE_NUMBER as NVARCHAR)
                  + '/' + LTRIM(RTRIM(CAST(STATE_ID as nvarchar)))
                  + '/' + LTRIM(RTRIM(CAST(CASE_NUMBER_EXTENSION as nvarchar)))
         from dbo.PAT_CASE
         where dbo.fn_case_number(CASE_ID) = @CaseRef)
 
         -- Return the result of the function
         RETURN @NuxeoPath
END

Example at work

Torben Rees of Greaves Brewster deserves great kudos for having developed an integrating tool that uploads documents to the DMS and creating an excellent piece of documentation of which we used parts above. Please see his complete document here:

  • No labels