cancel
Showing results for 
Search instead for 
Did you mean: 

Query folders containing documents filtered by custom metada

hanumeshm
Champ in-the-making
Champ in-the-making
Hi,
I am new to Alfresco.
I am associating custom metadata 'targetUser' for the document while uploading. This is to specify who can access the document.
Now user 'testUser' logins to application. Then I should display the folders which contain atleast one document whose custom metadata 'targetUser' matches his userId i.e. (testUser).
Can any help in this regard.  ( I am using Alfresco 3.3 Enterprise ).
Currenlty, I am displaying all folders as soon as user logs in.

ResultSet rs = getSearchService().query(storeRef, SearchService.LANGUAGE_XPATH, folderPath);
nodeRef = rs.getNodeRef(0);
List<FileInfo> foldersInfo = fileFolderService.listFolders(selectedFolderNodeRef);
if(null != foldersInfo && !foldersInfo.isEmpty()){
  for(FileInfo fileInfo : foldersInfo){
     Folder folder = new Folder();
    folder.setFolderName(fileInfo.getName());
   ….
    list.add(folder)
   …

something like to following might be helpful. but I am not sure what does this mean (Qname, namespacePrefixResolver…)

QueryParameterDefImpl paramDef = new QueryParameterDefImpl(QName.createQName("alf:lemur",  
                                  namespacePrefixResolver), (org.alfresco.service.cmr.dictionary.PropertyDefinition) null, true, "fox");
         
ResultSet results = getSearchService().query(storeRef, "lucene", "TEXT:\"${alf:lemur}\"",  new QueryParameterDefinition[] { paramDef });




Context: There may be 1000 folders(under folderPath), out of which the user has access to 3 documents only scattered across 3 folders. Then I need to avoid rest of folders for display as there will not be documents intended for him.

Its very urgent. If anybody come across such situation or have idea, please do share information.

Thanks in advance,
Hanumesh
1 REPLY 1

hanumeshm
Champ in-the-making
Champ in-the-making
Forget to tell, I am using this logic in a Websript, and copying this module jar to Alfresco lib.

—————————————————————————
I tried this:

   I created aspects, attached metadata (targetUser) document while uploading, able to see the custom metadata in Alfresco explorer.
Writen a servlet code to retrieve documents filtered by custom metadata able to get only documents whose meta data 'targetUser' is say 'xyz'.

I have a custome websricpts module where I defined the customized webscripts, and copied this module to Alfresco
(<alfrescohome>\tomcat\webapps\alfresco\WEB-INF\lib) as a jar. One of the webscript is getting all folders under specified path.
Now I customized this webscript further so that I will get only the folders which contain documents related to a specific user.(by firing lucene query on metadata 'targetUser').  But after copying the latest jar to alfresco, giving error as ' No classDef Found: org/alfresco/webservice/repository/RepositoryFault'
I am using repository api for this logic so copied alfresco-web-service-client-3.3g.jar in the module which will be copied to alfresco.

Can anybody help me in resolving this issues please?
Thanks in advance,
Hanumesh
utility method which gives me required folders only follows:

import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.webservice.repository.QueryResult;
import org.alfresco.webservice.repository.RepositoryFault;
import org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub;
import org.alfresco.webservice.types.NamedValue;
import org.alfresco.webservice.types.Query;
import org.alfresco.webservice.types.ResultSet;
import org.alfresco.webservice.types.ResultSetRow;
import org.alfresco.webservice.types.Store;
import org.alfresco.webservice.util.Constants;
import org.alfresco.webservice.util.WebServiceFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
==================================
   ArrayList<String> getMyFolders(String userId, String userType){
      
      userId="honey";
      userType="Client User";
      
      RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();
      
      String ss = "TYPE:\"{http://www.alfresco.org/model/content/1.0}content\" AND @\\{locatable.targetUser\\}targetUser:honey*";
       Query query1 =  new Query(Constants.QUERY_LANG_LUCENE,ss);
       Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
          QueryResult queryResult=null;
      try {
         queryResult = repositoryService.query(storeRef, query1,false);
      } catch (RepositoryFault e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } catch (RemoteException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
        
          ResultSet resultSet = queryResult.getResultSet();

          long totalRowCount = resultSet.getTotalRowCount();
      System.out.println("Total count  *****************"+totalRowCount);
         ResultSetRow[] rows = resultSet.getRows();

         DataLocation arrayLocation = new Paginator().calculateArrayLocation(rows.length, 1, rows.length);
      
      Set se=new HashSet();
      Set folderSet=new HashSet();
      ArrayList foldersList = new ArrayList();
        for (int i = arrayLocation.getStart() - 1; i < arrayLocation.getEnd(); i++) {
           System.out.println("—————————————————— Row: "+i);
                SearchResult sr = new SearchResult();
                sr.setSize(rows.length);
                //int docId = hitss.scoreDocs.doc;
                ResultSetRow row = rows;
                NamedValue[] columns = row.getColumns();
              
                for (int y = 0; y < columns.length; y++)
                {
                   System.out.println("***Metadata Name"+row.getColumns(y).getName());
                   System.out.println(" Value: "+row.getColumns(y).getValue());
                   
                   if(row.getColumns(y).getName().endsWith("name"))
                    {
                      //sr.setSetpath(row.getColumns(y).getValue());
                       sr.setFilename(row.getColumns(y).getValue());
                      // ls.add(sr);
                                
                    }
                   if(row.getColumns(y).getName().endsWith("path"))
                    {
                      sr.setSetpath(row.getColumns(y).getValue());
                      //get first level folders having documents only intended for user under root.
                      foldersList= FolderUtil.getFolderList(foldersList, row.getColumns(y).getValue());
                    }
                   se.add(sr);
                }
        }
       
        List list = new ArrayList(se);

/* For Testing Remove later */
        System.out.println("Folders to display====>"+foldersList.size());
        int i=0;
        if(foldersList!=null){
            while (foldersList.size()>0 && i<foldersList.size()){
               System.out.println("****"+foldersList.get(i));
               i++;
            }
        }
        //End
        long end=System.currentTimeMillis();
        return foldersList;
      
   }