cancel
Showing results for 
Search instead for 
Did you mean: 

Action against many Nodes

mahdi
Champ in-the-making
Champ in-the-making
hi,
i need to develop an action against many nodes.
this action will search for all nodes with type "contrat" and then update the values of their properties from a Data Base.
here is a test class that didn't work:

package org.alfresco.synchro;

import java.io.Serializable;
import java.util.List;

import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.ResultSetRow;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.web.bean.BrowseBean;



public class SynchoNodeContrat extends ActionExecuterAbstractBase {
   
   private static final long serialVersionUID = 9123100108219370986L;   
   SearchService searchService=null;      
   private NodeService nodeService;
    /** The name of the action */
    public static final String NAME = "synchroContrat-action";
   
    ResultSet resultat;

       Contrat contract=new Contrat();

       protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
    {
                
   String spacesStore = "workspace://SpacesStore";
   StoreRef storeRef=new StoreRef(spacesStore);

resultat = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, "Type:\"{contrat.new.model}contrat\"");


actionedUponNodeRef = this.nodeService.getRootNode(storeRef);

if(this.nodeService.exists(actionedUponNodeRef)== true)
{
      for (ResultSetRow nodeI: resultat ) {
         NodeRef nod=nodeI.getNodeRef();
         Serializable numcontrat = this.nodeService.getProperty(nod, ContratModel.PROP_N_AFFAIRE );
         String numS = numcontrat.toString();
         int num = Integer.parseInt(numS);
         contract.importerSql(num);
            

            this.nodeService.setProperty(nod, ContratModel.PROP_CHEF_PROJET, contract.getChef_projet());
            this.nodeService.setProperty(nod, ContratModel.PROP_CLIENT_CONTRAT,  contract.getClient());
            this.nodeService.setProperty(nod, ContratModel.PROP_DATE_DEBUT, (Serializable) contract.getDate_depart());
            this.nodeService.setProperty(nod, ContratModel.PROP_DATE_FIN,  contract.getDate_fin());
            this.nodeService.setProperty(nod, ContratModel.PROP_DATE_SIGNATURE,  contract.getDatesign());
            this.nodeService.setProperty(nod, ContratModel.PROP_DESEIGNATION,  contract.getDesignation());
         
          
            this.nodeService.setProperty(nod, ContratModel.PROP_ETAT_PROJET,  contract.getEtat_projet());
            this.nodeService.setProperty(nod, ContratModel.PROP_MISSION_CONTRAT, contract.getMission());
           
            this.nodeService.setProperty(nod, ContratModel.PROP_NUM_AFFAIRE_AVENANT, contract.getNum_affaire_avenant());
            this.nodeService.setProperty(nod, ContratModel.PROP_NUM_AVENANT, contract.getNum_avenant());
            this.nodeService.setProperty(nod, ContratModel.PROP_PARTENAIRE_CONTRAT, contract.getPartenaire());
            this.nodeService.setProperty(nod, ContratModel.PROP_PAYS_CONTRAT, contract.getPays());
            this.nodeService.setProperty(nod, ContratModel.PROP_SECTEUR, contract.getSecteur_activ());
            this.nodeService.setProperty(nod, ContratModel.PROP_SERVICE_CONTRAT, contract.getService());
         this.nodeService.setProperty(nod, ContratModel.PROP_SITUATION_ST2I, contract.getSituation_St2i());
         this.nodeService.setProperty(nod, ContratModel.PROP_SOCIETE, contract.getCodes());
         this.nodeService.setProperty(nod, ContratModel.PROP_TITRE, contract.getTitre());
         this.nodeService.setProperty(nod, ContratModel.PROP_TYPE_AVENANT, contract.getType_avenant());
          
      }
               
      }
else {System.err.println("pb node");}
    }

   @Override
   protected void addParameterDefinitions(List<ParameterDefinition> paramList) {
      // TODO Auto-generated method stub
      
   }
   public NodeService getNodeService() {
      return nodeService;
   }

   public void setNodeService(NodeService nodeService) {
      this.nodeService = nodeService;
   }
}
here is file -context.xml :

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>
     
    <!– Logger Action Bean –>
    <bean id="synchroContrat-action" class="org.alfresco.synchro.SynchoNodeContrat" parent="action-executer">
      <property name="nodeService">
            <ref bean="nodeService"/>
        </property>
    </bean>
      <!– Load the Logger Action Messages –>  
      <bean id="synchroContrat-action-messages" class="org.alfresco.i18n.ResourceBundleBootstrapComponent">
       <property name="resourceBundles">
          <list>
             <value>org.alfresco.synchro.synchroContrat-action-messages</value>
          </list>
       </property>
      </bean>
     
</beans>
and there are the error messages :
11:26:44,250 User:admin ERROR [ui.common.Utils] Failed to run Actions due to error: null
java.lang.NullPointerException
        at org.alfresco.synchro.SynchoNodeContrat.executeImpl(SynchoNodeContrat.java:87)
        at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:127)
        at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(Acti
onServiceImpl.java:592)
        at org.alfresco.repo.action.ActionServiceImpl.executeActionImpl(ActionSe
rviceImpl.java:529)
        at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServic
eImpl.java:391)
        at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServic
eImpl.java:379)
        at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServic
eImpl.java:600)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflecti
on(AopUtils.java:296)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJo
inpoint(ReflectiveMethodInvocation.java:177)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:144)
        at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterc
eptor.invoke(AlwaysProceedMethodInterceptor.java:40)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:166)
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethod
Interceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:166)
        at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.j
ava:275)
        at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInte
rceptor.java:69)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:166)
        at org.springframework.transaction.interceptor.TransactionInterceptor.in
voke(TransactionInterceptor.java:107)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:166)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynami
cAopProxy.java:204)
        at $Proxy22.executeAction(Unknown Source)
        at org.alfresco.web.bean.actions.RunActionWizard.finishImpl(RunActionWiz
ard.java:101)
        at org.alfresco.web.bean.dialog.BaseDialogBean$1.execute(BaseDialogBean.
java:121)
        at org.alfresco.web.bean.dialog.BaseDialogBean$1.execute(BaseDialogBean.
java:118)
        at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransacti
on(RetryingTransactionHelper.java:320)
        at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransacti
on(RetryingTransactionHelper.java:227)
        at org.alfresco.web.bean.dialog.BaseDialogBean.finish(BaseDialogBean.jav
a:127)
        at org.alfresco.web.bean.wizard.WizardManager.finish(WizardManager.java:
580)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java
:132)
        at org.apache.myfaces.application.ActionListenerImpl.processAction(Actio
nListenerImpl.java:61)
        at javax.faces.component.UICommand.broadcast(UICommand.java:109)
        at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:9
7)
        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1
71)
        at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(Invoke
ApplicationExecutor.java:32)
        at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl
.java:95)
        at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java
:70)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
        at org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(Authentica
tionFilter.java:81)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:286)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:845)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
7)
        at java.lang.Thread.run(Thread.java:619)

any suggestions??
3 REPLIES 3

mahdi
Champ in-the-making
Champ in-the-making
can i use the search Service without using the ServiceRegistry ??

plz i need some help

mrogers
Star Contributor
Star Contributor
Yes.    The "normal" way to get the serarchService is to inject it via spring.   You need getSearchService and setSearchService methods similar to the way you have done the nodeService.   And in your bean definition you need to set the searchService property.

mahdi
Champ in-the-making
Champ in-the-making
thanks for your help
it works