REST API/NXQL Children of a Collection

Hi

Normally one follows the recipe of querying a folder, get the UID and next issue a startswith on the ecm:path to get the contents of a folder (Workspace, Section).

With Collections it is a different cookie: $query = “SELECT * FROM Document WHERE ecm:path = '/default-domain/workspaces/” . $workspace . “/” . $collection . “'” ; $filter = “ecm:currentLifeCycleState != 'deleted'“; `

follwed by: getDocumentUiD

and somthing like: $query = “SELECT * FROM Document WHERE ecm:path STARTSWITH '/default-domain/workspaces/” . $workspace . “/” . $collection . “' AND ecm:parentId='“.$parid.“'” ; $query .= " AND " . $filter;`

This does not work as a Collection is not a folder with Documents in it, but is a thing with links to Documents. So when using the above query you get an empty resultset. (“file not found”). This makes sense as the UID of the parent of an item in the collection is not the Collection itself, but the folder in which the Document resides (the location being linked to from the collection).

So this leaves the question: how to get the items in a collection using NXQL as @children is not an option?

0 votes

3 answers

2448 views

ANSWER



After extensive testing I came to the following conclusions:

  • grenard's solution did not work for me as I got an error on the query used. This might have to do that we use different versions of Nuxeo (v7.10 vs v8) ?
  • pibou Bouvret's solution worked fine, but results in some weird behavior:

The collection I used contains 4 documents:

  • document #1 version 0.1 Project (resides in a personal workspace)
  • document #2 version 0.1 Project (resides in a section)
  • document #3 version 0.2 Project (resides in a workspace)
  • document #4 version 0.1 Approved (resides in a section)

Documents #3 and #4 have the same title/name.

When I query Nuxeo to get the collection:documentIds I get:

  1. document #1 , but it is the last item in the array

  2. a document which is not listed above. It is a deleted document

    Are document residing in a section not listed by default? Why?

Why do I only get a single document, or does that has to do with versioning/approving? If so, the fact that the document resides in a different location is irrelevant?

0 votes



Have a look to the default_content_collection page provider. You can then use it with the query endpoint.

0 votes



The Ids of documents belonging to a collection can be accessed as a multi-valued property of the collection : collection:documentIds / documentId The Ids of the collections a document belongs to can be accessed as a multi-valued property of the document : collectionMember:collectionIds

0 votes



This seemed to work ok, but results in some oddities. Please see above.
06/15/2016