cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to navigate till custom space.

amit_wmw
Champ in-the-making
Champ in-the-making
Hello

Below I wrote a simple program to get all workspace-id under my custom space(Amitspace). But I am unable to navigate till my custom space. Kindly let me know that with what should I replace query string (which I marked red in color in my program) to reach up to my custom space. Please get me out of this small issue.  Will be kind!
—————————————————————————————–
package org.alfresco.sample;

import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;

import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.ResultSetRow;
import org.alfresco.service.cmr.search.SearchParameters;
import org.alfresco.service.cmr.search.SearchService;

import org.springframework.context.ApplicationContext;  
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class FirstJCRClient
{
   
 
  
   public static void main(String[] args)      
   {
   
      try{
         
         
         
          ApplicationContext context = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml");
      
          Repository repository = (Repository)context.getBean("JCR.Repository");
         
          // login to workspace (here we rely on the default workspace defined by JCR.Repository bean)
          Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
          ServiceRegistry serviceRegistry = (ServiceRegistry)context.getBean("ServiceRegistry");
          StoreRef SR=new StoreRef("workspace://SpacesStore//app:companyHome//cm:Amitspace");
          SearchParameters sp = new SearchParameters();
           sp.addStore(SR);
           sp.setLanguage(SearchService.LANGUAGE_LUCENE);
           sp.setQuery("TYPE:\"{http://www.alfresco.org/model/content/1.0}content\"");

           //sp.setQuery("@cm\\:name:\"Amit2\"" );
        
           org.alfresco.service.cmr.search.ResultSet results = null;
           try
           {
            
              results = serviceRegistry.getSearchService().query(sp);
               for(ResultSetRow row : results)
               {
              
                   NodeRef currentNodeRef = row.getNodeRef();
                 
                   System.out.println(currentNodeRef.toString());
                  
               }
         
         
           }
          
           catch (Exception exp ){
            System.out.println (" Caught exception " + exp);
            exp.printStackTrace();
         }
           finally
           {
               if(results != null)
               {
                 results.close();
                 session.logout();
                 System.exit(0);
               }
           } 
         
      }catch (Exception exp ){
         System.out.println (" Caught exception " + exp);
         exp.printStackTrace();
      }
      
      
   }
   
      

}
————————————————————————————

Thanks
Amit
1 REPLY 1

amit_wmw
Champ in-the-making
Champ in-the-making
Dear all,

Finally got a solution here for this problem. Below I am sharing my code to navigate till my custom space Amit-2 and to get all contents from there.

——————————————————————————

public class FirstJCRClient
{
   
 
  
   public static void main(String[] args)      
   {
    
      try{
         
         
         
          ApplicationContext context = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml");
      
          Repository repository = (Repository)context.getBean("JCR.Repository");
          SearchService searchService1=(SearchService)context.getBean("SearchService");
          // login to workspace (here we rely on the default workspace defined by JCR.Repository bean)
          Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
       //getting StoreRef
          StoreRef SR=new StoreRef("workspace://SpacesStore");
         
       //Querying to go upto custom space
              ResultSet results = searchService1.query(SR, SearchService.LANGUAGE_LUCENE, "+PATH:\"/app:company_home/cm:Amitspace/cm:Amit-2/*\"");
                                                                       
              //iterating
               for(ResultSetRow row : results)
              
               {
                  //getting noderef of content and space
                   NodeRef currentNodeRef = row.getNodeRef();
                
                   System.out.println(currentNodeRef.toString());
                  
               }
             
               if(results != null)
               {
                 results.close();
                
                }
              
          
          session.logout(); 
          
         
      }catch (Exception exp ){
         System.out.println (" Caught exception " + exp);
         exp.printStackTrace();
      }
      
      finally
        {
           
           
            System.exit(0);
           
        } 
   }
   
      

}

—————————————————————————————

But at same time I want to take 1 more idea from you all that is there any way to get all contents inside a space, considering the parent space consists of child space and in a single shot is there any way to get all data from both parent and child space?

Please suggest.

Thanks

Amit
—————————————————————————————
[size=85]Please give appropriate rating if you find above post to be helpful[/size] Smiley Happy