AnsweredAssumed Answered

Getting error while searching node by content mimetype.

Question asked by amit_wmw@yahoo.com on Feb 20, 2009
Hello,

Have written a simple example code to search nodes by there content type. But getting error while execution. Please suggest.

Example code
—————————

package org.alfresco.sample;

import java.sql.ResultSet;
import java.util.List;

import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.version.Version;
import javax.jcr.version.VersionHistory;
import javax.jcr.version.VersionIterator;

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.alfresco.service.namespace.DynamicNamespacePrefixResolver;
import org.alfresco.service.namespace.NamespaceService;
import org.springframework.context.ApplicationContext;  
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class FirstJCRClient
{
   
   private static final String String = null;
  
   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");
          NodeRef rootNodeRef = serviceRegistry.getNodeService().getRootNode(SR);
          SearchParameters sp = new SearchParameters();
           sp.addStore(SR);
           sp.setLanguage(SearchService.LANGUAGE_LUCENE);
           sp.setQuery("{http://www.alfresco.org/model/content/1.0}content.mimetype:text/plain");
        
           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();
      }
      
      
   }
   
      

}
————————————————————————————–

Error while executing
——————————–

18:44:45,577 INFO  [service.descriptor.DescriptorService] Alfresco started (Community Network): Current version 2.1.0 (482) schema 64 - Installed version 2.1.0 (482) schema 64
org.alfresco.repo.search.SearcherException: Failed to parse query: {http://www.alfresco.org/model/content/1.0}content.mimetype:text/plain Caught exception org.alfresco.repo.search.SearcherException: Failed to parse query: {http://www.alfresco.org/model/content/1.0}content.mimetype:text/plain

   at org.alfresco.repo.search.impl.lucene.ADMLuceneSearcherImpl.query(ADMLuceneSearcherImpl.java:286)
   at org.alfresco.repo.search.SearcherComponent.query(SearcherComponent.java:85)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
   at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:80)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.alfresco.repo.audit.AuditComponentImpl.auditImpl(AuditComponentImpl.java:256)
   at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:191)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
   at $Proxy17.query(Unknown Source)
   at org.alfresco.sample.FirstJCRClient.main(FirstJCRClient.java:58)
Caused by: org.alfresco.repo.search.impl.lucene.ParseException: Encountered "}" at line 1, column 42.
Was expecting one of:
    "TO" …
    <RANGEEX_QUOTED> …
    <RANGEEX_GOOP> …
   
   at org.alfresco.repo.search.impl.lucene.QueryParser.generateParseException(QueryParser.java:1243)
   at org.alfresco.repo.search.impl.lucene.QueryParser.jj_consume_token(QueryParser.java:1126)
   at org.alfresco.repo.search.impl.lucene.QueryParser.Term(QueryParser.java:956)
   at org.alfresco.repo.search.impl.lucene.QueryParser.Clause(QueryParser.java:758)
   at org.alfresco.repo.search.impl.lucene.QueryParser.Query(QueryParser.java:701)
   at org.alfresco.repo.search.impl.lucene.QueryParser.parse(QueryParser.java:139)
   at org.alfresco.repo.search.impl.lucene.LuceneQueryParser.parse(LuceneQueryParser.java:105)
   at org.alfresco.repo.search.impl.lucene.ADMLuceneSearcherImpl.query(ADMLuceneSearcherImpl.java:230)
   … 21 more
———————————————————————————————————————-

Outcomes