cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieve the categories assigned to a spezific document

robobot
Champ in-the-making
Champ in-the-making
Hi,
can please somebody help me with the following question. i have a simple query that finds a document in a spefic folder. i have assigend a category via the Web Interface to this document. when retrieving the document and it's properties, the value for categories is null. how can i retrieve the category?


Query query = new Query(Constants.QUERY_LANG_LUCENE, queryString );
     
      // Execute the query
      QueryResult queryResult = null;
      try {
        queryResult = WebServiceFactory.getRepositoryService().query(STORE, query,false);
      }catch (Exception ex){
        ex.printStackTrace();
      
      }
      //Display the results
      ResultSet resultSet = queryResult.getResultSet();
      ResultSetRow[] rows = resultSet.getRows();         
       
      //Get the information from the result set
      for(ResultSetRow row : rows) {      
        for (NamedValue namedValue : row.getColumns()) {         
          String name = namedValue.getName();
          String value = namedValue.getValue();      
          System.out.println(name + " - " +value);
        
        }       
      
      } 

the output is:

query: +@candidate\:Objid: 100001505500000 OwnerType: 8
{http://www.alfresco.org/model/content/1.0}name - pgadmin.log
{http://www.alfresco.org/model/system/1.0}node-dbid - 4358246
{http://www.alfresco.org/model/content/1.0}modified - 2009-01-29T10:42:00.674+01:00
{candidate.model}Objid - 100001505500000
{http://www.alfresco.org/model/content/1.0}description - test
{http://www.alfresco.org/model/system/1.0}node-uuid - d6a2d65b-0bb6-45df-a05a-1489b0382d57
{candidate.model}OwnerType - 8
{http://www.alfresco.org/model/system/1.0}store-protocol - workspace
{http://www.alfresco.org/model/content/1.0}modifier - admin
{http://www.alfresco.org/model/content/1.0}categories - null
{http://www.alfresco.org/model/content/1.0}title - -
{candidate.model}registrationDate - 2008-01-30T01:00:00.000+01:00
{http://www.alfresco.org/model/content/1.0}content - contentUrl=store://2009/1/29/10/42/66bd32da-d8eb-40ee-8034-40cc9a54f26a.bin|mimetype=application/octet-stream|size=7229|encoding=Base64|locale=en_US_
{http://www.alfresco.org/model/system/1.0}store-identifier - SpacesStore
{http://www.alfresco.org/model/content/1.0}created - 2009-01-28T18:22:34.940+01:00
{candidate.model}name - Schilling, Charles
{http://www.alfresco.org/model/content/1.0}creator - Admin, Super
{http://www.alfresco.org/model/content/1.0}path - /{http://www.alfresco.org/model/application/1.0}company_home/{http://www.alfresco.org/model/content/1....

Thank you very mutch.
1 REPLY 1

robobot
Champ in-the-making
Champ in-the-making
now i found out this little solution. don't know if this the straight forward way but for the first requirements it works:
referencepath is sth. like

/app:company_home/cm:Application/cm:Users/cm:Files/*[@cm:name="pgadmin.log"]


public String[] getAssignedCategories(String referencePath) {     
       
    Reference root = new Reference(STORE, null, referencePath);    
    String result [] = null;   
    try {
      CategoriesResult[] categories = categoryService.getCategories(new Predicate(new Reference[]{root}, STORE, null));
      if(categories != null)
       for (CategoriesResult categoriesResult : categories) {
        Reference [] reference = (Reference[])categoriesResult.getCategories(0).getCategories();
       
        if(reference != null){
          result = new String[reference.length];
          int i = 0;
          for (Reference category : reference) {            
             result[i++] = category.getPath();
          }
        }
       }
    }catch (Exception ex){
      return null;
    }
    return result;
  }