cancel
Showing results for 
Search instead for 
Did you mean: 

REST API/NXQL Children of a Collection

olaf_
Champ on-the-rise
Champ on-the-rise

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?

4 REPLIES 4

pibou_Bouvret
Elite Collaborator
Elite Collaborator

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

This seemed to work ok, but results in some oddities. Please see above.

Guillaume_Renar
Star Contributor
Star Contributor

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

olaf_
Champ on-the-rise
Champ on-the-rise

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?