cancel
Showing results for 
Search instead for 
Did you mean: 

Overload Alfresco service

bch
Champ in-the-making
Champ in-the-making
Hi,

I want to overload an Alfresco service and more precisely NodeService. I want to add behavior so I must override methods like this :

    import org.alfresco.repo.version.NodeServiceImpl;
    import org.alfresco.service.cmr.repository.ChildAssociationRef;
    import org.alfresco.service.cmr.repository.InvalidNodeRefException;
    import org.alfresco.service.cmr.repository.NodeRef;
    import org.alfresco.service.namespace.QName;


    public class MyNodeService extends NodeServiceImpl {

       @Override
       public ChildAssociationRef createNode(NodeRef parentRef,
             QName assocTypeQName, QName assocQName, QName nodeTypeQName)
             throws InvalidNodeRefException {
          // Begin of my code
          …
          // End of my code
          return super.createNode(parentRef, assocTypeQName, assocQName, nodeTypeQName);
       }
    }

Now, I must add Spring configuration but I don't know how and where. Have you an idea ?

Thanks

Benjamin
2 REPLIES 2

cbosdonnat
Champ in-the-making
Champ in-the-making
Hi Benjamin,

First question before to start the answer: Why don't you use a Spring interceptor or JavaBehaviourPolicy  to add your feature ? To strictly answer your question, the nodeService bean spring configuration is defined in the WEB-INF/classes/alfresco/node-services-context.xml file and the NodeService configuration is in WEB-INF/classes/alfresco/public-services-context.xml file.

You should definately have a look at the OnCreateNodePolicy : this will be called after the node is created. Otherwise, you could add a Spring interceptor to the NodeService configuration. Have a look at the existing NodeService interceptors to see how it works.

HTH

bch
Champ in-the-making
Champ in-the-making
Hi,

Thanks for your response. Here is my solution :


public class NodeService extends DbNodeServiceImpl {

   private Map<String,String> synchronizedAssocs = new HashMap<String, String>();

   @Override
   public AssociationRef createAssociation(NodeRef sourceRef,
         NodeRef targetRef, QName assocTypeQName)
         throws InvalidNodeRefException, AssociationExistsException {
      …
      return super.createAssociation(sourceRef, targetRef, assocTypeQName);
   }
   
   @Override
   public void removeAssociation(NodeRef sourceRef, NodeRef targetRef,
         QName assocTypeQName) throws InvalidNodeRefException {
      …
      super.removeAssociation(sourceRef, targetRef, assocTypeQName);
   }
   
   public Map<String, String> getSynchronizedAssocs() {
      return synchronizedAssocs;
   }

   public void setSynchronizedAssocs(Map<String, String> synchronizedAssocs) {
      this.synchronizedAssocs = synchronizedAssocs;
   }
}

and my file synchro-context.xml located in the folder shared/classes/alfresco/extension :

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

<beans>
   <bean id="dbNodeServiceImpl" class="com.bluexml.alfresco.modules.associationSynchronization.NodeService" init-method="init" >
      <property name="dictionaryService">
         <ref bean="dictionaryService" />
      </property>
      <property name="nodeDaoService">
         <ref bean="nodeDaoService" />
      </property>
      <property name="policyComponent">
         <ref bean="policyComponent"/>
      </property>
      <property name="storeArchiveMap">
         <ref bean="storeArchiveMap"/>
      </property>
      <property name="avmNodeService">
         <ref bean="avmNodeService"/>
      </property>
      <property name="tenantService">
         <ref bean="tenantService"/>
      </property>
      <property name="synchronizedAssocs">
           <props>
           <prop key="{http://www.bluexml.com/model/content/test/1.0}test_Company_has_contact">{http://www.bluexml.com/model/content/test/1.0}test_Contact_has_contact</prop>
           </props>
      </property>
   </bean>
</beans>