cancel
Showing results for 
Search instead for 
Did you mean: 

CMIS QL - get documents by path

iv0id
Champ in-the-making
Champ in-the-making
Hi ,

Is there a way to get all documents in a path like "/MyDocs/<strong>anything_here</strong>/Published/<strong>anything_here</strong>" using CMIS QL or passing it as an argument to the getObjectByPath of the Session class?

Thank you.


10 REPLIES 10

kaynezhang
World-Class Innovator
World-Class Innovator
You can use alfresco cmis path query ,like this

SELECT * FROM cmis:document D WHERE CONTAINS(D,'PATH: "/app:company_home//*"')

iv0id
Champ in-the-making
Champ in-the-making
I have already tried it and it's not working. In log console i got this error :
org.alfresco.scripts.ScriptException - 05090198 Failed to execute script 'classpath*:alfresco/templates/webscripts/org/alfresco/cmis/queries.post.cmisquery.js': 05090197 Unknown column/property PATH


any idea ?

kaynezhang
World-Class Innovator
World-Class Innovator
The query statement I pasted out should work.
Could you paste your code here?

iv0id
Champ in-the-making
Champ in-the-making
i'm using CMIS Workbench to test the queries (i get the error i posted) and here is the java Code :

public Session getSession(String repositoryUrl, String user, String password){
   Session session = cacheSession.getIfPresent(user);
   if (session == null) {
      Map<String, String> sessionParameters = new HashMap<String, String>();
      sessionParameters.put(SessionParameter.USER, user);
      sessionParameters.put(SessionParameter.PASSWORD, password);
      sessionParameters.put(SessionParameter.ATOMPUB_URL, repositoryUrl + "/service/cmis");
      sessionParameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
      sessionParameters.put(SessionParameter.OBJECT_FACTORY_CLASS,"org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");
      try {
         SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
         session = sessionFactory.getRepositories(sessionParameters).get(0).createSession();
      } catch (CmisBaseException e) {
          //TODO
      }
      cacheSession.put(user, session);
   }
   return session;
}

// somewhere in the code
ItemIterable<QueryResult> qrs = getSession("url","user","pwd").query("SELECT * FROM cmis:document D WHERE CONTAINS(D,'PATH: \"/app:company_home//*\"')", false);
for(QueryResult q : qrs) {
       System.out.println(q.getPropertyByQueryName("cmis:name"));
}


i get the error


org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException: Erreur Interne de Servlet
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.convertStatusCode(AbstractAtomPubService.java:452)
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.post(AbstractAtomPubService.java:570)
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.DiscoveryServiceImpl.query(DiscoveryServiceImpl.java:142)
   at org.apache.chemistry.opencmis.client.runtime.SessionImpl$3.fetchPage(SessionImpl.java:557)
   at org.apache.chemistry.opencmis.client.runtime.util.AbstractIterator.getCurrentPage(AbstractIterator.java:132)
   at org.apache.chemistry.opencmis.client.runtime.util.CollectionIterator.hasNext(CollectionIterator.java:48)
   at com.sqli.sante.ged.alfresco.document.service.AlfrescoDocumentServiceImpl.main(AlfrescoDocumentServiceImpl.java:729)

kaynezhang
World-Class Innovator
World-Class Innovator

iv0id
Champ in-the-making
Champ in-the-making
i'm using Alfresco 3.4.d and i can successfully get the session by using the URL provided in the java code (http://localhost:8080/alfresco/service/cmis). I installed a new instance of alfresco 3.4.d and i'm still getting the error

kaynezhang
World-Class Innovator
World-Class Innovator
I'm using 4.2 ,and the following code works fine ,you can test it in your environment

      String serverUrl= "http://localhost:8080/alfresco/cmisatom";
      String userName = "admin";
      String password = "admin";
      SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
      Map<String, String> params = new HashMap<String, String>();
      params.put(SessionParameter.USER, userName);
      params.put(SessionParameter.PASSWORD, password);
      params.put(SessionParameter.ATOMPUB_URL, serverUrl);
      params.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
      params.put(SessionParameter.OBJECT_FACTORY_CLASS,
            "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");
      List<Repository> repos = sessionFactory.getRepositories(params);
      if (repos.isEmpty()) {
         throw new RuntimeException("Server has no repositories!");
      }

      Session session =  repos.get(0).createSession();

      ItemIterable<QueryResult> qrs = session.query("SELECT * FROM cmis:document D WHERE CONTAINS(D,'PATH: \"/app:company_home//*\"')", false);

      for(QueryResult q : qrs) {
             System.out.println(q.getPropertyValueById(PropertyIds.OBJECT_ID));
             System.out.println(q.getPropertyValueById(PropertyIds.NAME));

      }

iv0id
Champ in-the-making
Champ in-the-making
I tested the query in 4.2 instance and its working fine, but for now upgrading from 3.4 to 4.2 is not possible. If there is any workaround i'll be very thankful.
thank you for your time.

kaynezhang
World-Class Innovator
World-Class Innovator
I'm sorry I don't have 3.4 environment.I can't recreate your problem.