Using secondary types (aspects) as cmis:items in Alfresco CMIS queries

CMIS Standard 1.1 defines a cmis:item object type as:

A new top level data model type that is an extension point for repositories that need to expose any other object types via CMIS that do not fit the model’s definition for document, folder, relationship or policy.

But it also stays that:

Please note that the following text and the BNF grammar are inconsistent. The text allows the use of secondary object types in FROM clauses and the BNF grammar does not. Because the BNF grammar is the formal description of the query language, it takes precedence over the text. That is, secondary object types MUST NOT be used in FROM clauses.

The next version of the CMIS specification will correct the BNF grammar and allow the use of secondary object types in FROM clauses.

As there will be no next version of the CMIS specification, according to specifications SQL Queries using secondary types (called aspects in Alfresco) should not be supported by CMIS implementations.

However in Alfresco this feature is implemented, so you can use aspects as cmis:item in your queries in the same way you use an object type.

For instance, to select every node having cm:titled aspect you can write:

SELECT * FROM cm:titled

I’ve been using this syntax for years (unknowing that it was outside the standard) and it works without issues. I guess that is safe to use this also in the future, so I’ll keep on using it.

Thanks to Axel Faust for letting me know about this.

Further reading

Cool things you can do in Alfresco with cmis:item support by Jeff Potts

Testing Alfresco from command line with CURL and CMIS Browser

Recently, I’ve been working to automate ALF_NODE_PROPERTIES table partition process in PostgreSQL for Alfresco. This process creates several partitions for the table, including older contents in the first partition and new contents in the last one. Once the table has been partitioned is required to test CRUD for properties belonging to nodes in every segment to ensure that every partition has been properly set up.

Using CMIS Browser protocol to access Alfresco, simple CURL sentences can perform such operations.

Modifying a property for an existing content

Alfresco provides the same sample files on every installation, so a property of one of this sample files can be created or modified to test CRUD in the first partition.

Following command will modify cmis:description property value to “test” at Data Dictionary > scripts > alfresco docs.js.sample file.

$ curl -X POST \
'http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser/root/Data%20Dictionary/scripts/alfresco%20docs.js.sample?cmisSelector=object' \
-H 'authorization: Basic YWRtaW46dGVtcG9yYWw= \
-H 'content-type: application/x-www-form-urlencoded' \
-d 'cmisaction=update&propertyId%5B0%5D=cmis%3Adescription&propertyValue%5B0%5D=testok&succinct=true'

Content for every intermediate partition can be selected to perform the same command.

Creating a new content

Every new content will be created in the last partition, so to test CRUD in this partition an upload command can be used.

Following command will create a file named “test.txt” at Shared repository folder.

$ curl -X POST \
  http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser/root/Shared \
  -H 'authorization: Basic YWRtaW46dGVtcG9yYWw=' \
  -H 'content-type: multipart/form-data' \
  -F cmisaction=createDocument \
  -F 'propertyId[0]=cmis:objectTypeId' \
  -F 'propertyValue[0]=cmis:document' \
  -F 'propertyId[1]=cmis:name' \
  -F 'propertyValue[1]=test.txt' \
  -F file=@/tmp/test.txt \
  -F succinct=true

Removing a content

Partition testing does not require this additional command, but it has been included to clear our operations in the server.

Following command will remove the file “test.txt” we’ve just created at Shared repository folder.

curl -X POST\
  http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser/root/Shared/test.txt \
  -H 'authorization: Basic YWRtaW46dGVtcG9yYWw=' \
  -H 'content-type: multipart/form-data' \
  -F cmisaction=delete \
  -F succinct=true 

Alfresco makes it so simple to automate our operations!