cancel
Showing results for 
Search instead for 
Did you mean: 

CMIS Query to get documents with a specific aspect property value

kartech11
Confirmed Champ
Confirmed Champ

I am trying to execute the following CMIS query that searches for all documents within a site that have the docStatus property set to 'Active' from defaultAspect type. The query errors out stating the below issue. Please can you let me know what is wrong with the query.

Error Content:
{"exception":"invalidArgument","message":"No selector for "}

Query

SELECT d.* FROM cmis:document AS d JOIN td:defaultAspect as p ON d.cmisSmiley SurprisedbjectId = p.cmisSmiley SurprisedbjectId WHERE td:docStatus ='Active' and CONTAINS('PATH:\"/app:company_home/st:sites/cm:testsite/cm:documentLibrary//*\"')

6 REPLIES 6

angelborroy
Community Manager Community Manager
Community Manager

Try the following sentence:

SELECT * FROM td:defaultAspect WHERE td:docStatus ='Active' and CONTAINS('PATH:\"/app:company_home/st:sites/cm:testsite/cm:documentLibrary//*\"')
Hyland Developer Evangelist

afaust
Legendary Innovator
Legendary Innovator

I believe you cannot select only on an aspect. You have to use a CMIS base type, even if that is just cmis:item, and then join with the aspect..

Axel, this query is working:

SELECT * FROM cm:titled

I've been writing queries by using only aspects many times. Am I wrong or I missed something?

Hyland Developer Evangelist

afaust
Legendary Innovator
Legendary Innovator

As discussed in the IRC channel, the spec explicitlely states that only primary object types are supported in the FROM clause, but Alfresco has implemented it in a way that aspects / secondary object types can also be used. The reason for this is that the text of the spec was not fully consistent with the BNF of the query language, and Alfresco apparently followed the text more closely than the formal definition.

jpotts
World-Class Innovator
World-Class Innovator

Here is how you do a join so that you can query aspect-based properties while simultaneously restricted the results to those in a certain path:

select D.cmis:name from cmis:document as D join sc:temp as T on D.cmisSmiley SurprisedbjectId = T.cmisSmiley SurprisedbjectId where T.scSmiley Tonguerop1 = 'value1' AND CONTAINS(D, 'PATH:\"/app:company_home/st:sites/cm:jtp-test-site-1/cm:documentLibrary//*\"')

The missing tidbit is that because you are doing a join, the selector ("D") has to be specified in the CONTAINS.

sepgs2004
Star Contributor
Star Contributor

I believe you got ample answers. I do like below, in case it helps in any way 

SELECT doc.*, slo.* FROM cmis:document AS doc JOIN slo:documentProperties AS slo ON doc.cmisSmiley SurprisedbjectId = slo.cmisSmiley SurprisedbjectId  WHERE  IN_FOLDER(doc, 'workspace://SpacesStore/3105f215-228e-4087-aef8-4a9399eb0b60') AND (slo.slo:m_link = 128) AND (slo.slo:m_category = 'Person')

m_link and m_category are the aspect properties

I have an aspect defined this way in our own custom model. Here is an extract of our custom model.

<types>
<!-- custom document type -->
<type name="slo:mdocument">
<title>SLO Document type</title>
<parent>cm:content</parent>

<!-- associations section - no associations as of now -->
<!-- aspect is defined to hold all the properties -->
<mandatory-aspects>
<aspect>slo:documentProperties</aspect>
</mandatory-aspects>
</type>

</types>

<aspects>
<!-- There is one aspect with all the custom properties defined -->
<aspect name="slo:documentProperties">
<title>m document properties</title>
<properties>

<property name="slo:m_category">
<title>Category</title>
<type>d:text</type>

</property>
<property name="slo:m_link">
<title>Link ID</title>
<type>d:int</type>
</property>

....

Gnanasekaran Sakthivel