AnsweredAssumed Answered

How to make a CMIS query

Question asked by pbertrand on Apr 6, 2009
Latest reply on Jul 13, 2011 by mrogers
I a making a post for those who search to make a CMIS query because i've had a lot of trouble to find this info.

- First you need to make the files tha will be used by alfresco :
Three file :
- index.get.desc.xml :

<webscript>
  <shortname>Test</shortname>
  <description>a webscript To test CMIS query</description> 
  <url>/searchTest</url>
   <authentication>guest</authentication>
   <transaction>required</transaction>   
</webscript>
In url you can put the name of the url you wish to use
- index.get.xml.ftl

<#import "/org/alfresco/webscripts.lib.html.ftl" as wsLib/>
<#import "/org/alfresco/cmis/atomentry.lib.atom.ftl" as entryLib/>
<classes xmlns:cmis="http://www.cmis.org/2008/05" xmlns:alf="http://www.alfresco.com">
<#assign rs = cmisresultset(resultset)>
<#list rs.rows as row>
<@entryLib.row row/>
</#list>
</classes>
- index.get.js
In the <cmis:statement> you have the request you can personalise it. Here you hav a request to get all documents that are not made by alfresco (System) and those who are not generated by Share ( "webpreview.swf" and "doclib.png")

script: {
model.resultset = nodes;
default xml namespace = 'http://www.cmis.org/2008/05';

var query="<cmis:query xmlns:cmis='http://www.cmis.org/2008/05'    xmlns:p='http://www.w3.org/1999/xhtml'    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'    xsi:schemaLocation='http://www.cmis.org/2008/05 CMIS.xsd '>  <cmis:statement>SELECT * FROM DOCUMENT  WHERE NOT((CreatedBy = 'System') OR (Name = 'doclib.png') OR (Name = 'webpreview.swf')) </cmis:statement>  <cmis:searchAllVersions>false</cmis:searchAllVersions>  <cmis:pageSize>0</cmis:pageSize>  <cmis:skipCount>0</cmis:skipCount>  <cmis:returnAllowableActions>false</cmis:returnAllowableActions></cmis:query>";
var cmisQuery = new XML(query);

    // extract query statement
    model.statement = cmisQuery.statement.toString();
    if (model.statement == null || model.statement.length == 0)
    {
        //status.setCode(status.STATUS_BAD_REQUEST, "Query statement must be provided");
        break script;
    }
   
    // process search all versions (NOTE: not supported)
    var searchAllVersions = cmisQuery.searchAllVersions;
    if (searchAllVersions != null && searchAllVersions === "true")
    {
        //status.setCode(status.STATUS_INTERNAL_SERVER_ERROR, "Search all versions not supported");
        break script;
    }
   
    // TODO: process allowableActions
   
    // process paging
    var skipCount = parseInt(cmisQuery.skipCount);
    var pageSize = parseInt(cmisQuery.pageSize);
    var page = paging.createPageOrWindow(null, null, isNaN(skipCount) ? null : skipCount, isNaN(pageSize) ? null : pageSize);
   
    // perform query
    var paged = cmis.query(model.statement, page);
    model.resultset = paged.result;
    model.cursor = paged.cursor;
   
}

When the files are created then put them in "my alfresco"\tomcat\webapps\alfresco\WEB-INF\classes\alfresco\webscripts\com\{a name as you wish}\
and refresh alfresco webscript.

Then if you go to : http://{my alfresco}:8080/alfresco/service/{url choosed in index.get.desc.xml }.xml you will have the result of you CMIS request.

Outcomes