cancel
Showing results for 
Search instead for 
Did you mean: 

CMIS - Get categories with java

fabiogomes_ti
Champ in-the-making
Champ in-the-making
Hi all,

I need to create a module that read a folder structure and import to Alfresco, i am using CMIS for this.

I need to list the categories and tags from repository to apply to the doc uploaded, but i don't know how i can make it.

I am using the CMIS query but it is not working yet.

See my code:


String queryString = "SELECT * FROM cmis:folder where contains('PATH:\"/cm:generalclassifiable//*\"')";
List<CmisObject> objList = new ArrayList<CmisObject>(); 
       // execute query
       ItemIterable<QueryResult> results = session.query(queryString, false);
       System.out.println("TOTAL DE RESULTADOS => "+results.getTotalNumItems());
       for (QueryResult qResult : results) {
          String objectId = "";
          PropertyData<?> propData = qResult.getPropertyById("cmis:objectId"); // Atom Pub binding
          if (propData != null) {
             objectId = (String) propData.getFirstValue();
          } else {
             objectId = qResult.getPropertyValueByQueryName("d.cmis:objectId"); // Web Services binding
          }
         CmisObject obj = session.getObject(session.createObjectId(objectId));
         objList.add(obj);
       }
      
      DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
        int iCount = 1;
        for (CmisObject result : objList) {
            System.out.println("———————-\r\nResult " + iCount + ":");
            System.out.println("id:" + result.getId());
            System.out.println("name:" + result.getName());
            System.out.println("created:" + dateFormat.format(result.getCreationDate().getTime()));
            iCount ++;
        }
2 REPLIES 2

jpotts
World-Class Innovator
World-Class Innovator
I don't think this will be a successful strategy for you. Categories don't inherit from cm:content and therefore are not visible to CMIS (which only knows how to see cmis:document and cmis:folder objects or their descendant types).

Jeff

fabiogomes_ti
Champ in-the-making
Champ in-the-making
Hi Jeff,

I solve this with:


String luceneQueryString = "PATH:\""+ROOT_CATEGORY+(categoryPath==null?"":encodeCategoryPath(categoryPath))+"\"";
          Query query = new Query(Constants.QUERY_LANG_LUCENE, luceneQueryString);

          QueryResult result = WebServiceFactory.getRepositoryService().query(STORE, query, true);


Thanks for your reply!