0

I am extending a DbNodeServiceImpl class and try to Override a method named public void setProperty(NodeRef nodeRef, QName qname, Serializable value).

When I am trying to call the method with the help of nodeService interface its calling the default method that is present in DbNodeServiceImpl, not the custom one that i created. How can I implement the same thing? I just want to call my own method with the help of nodeservice Interface.

dambros
  • 4,252
  • 1
  • 23
  • 39
Sachin Singh
  • 99
  • 12

2 Answers2

1

You should define your own class like this:

   <bean id="newOwnService" class="MyNewServiceImpl" init-method="init" parent="org.alfresco.repo.node.db.DbNodeServiceImpl" >
         .... some needed properties....

       </bean>

Then where you call your method:

<bean id="newClass" class="NewClass">
        <property name="somethingName" ref="newOwnService"/>
       </bean>

In code:

private NodeService somethingName;

public setSomethingName(NodeService somethingName){
    this.somethingName = somethingName;
}
M.Diachenko
  • 198
  • 7
0

The interface calls overridden method with same signature. You cannot override a method two times in same implementor class.You should post some code for better explanations

Homo Filmens
  • 116
  • 7
  • actually i have a class that extend the DbNodeServiceImpl.class and DbNodeServiceImpl class implement nodeservice interface. i want override a method that defined in nodeservice and implemented in DbNodeServiceImpl but when i am calling that method its calling method that is present in DbNodeServiceImpl class not mine. – Sachin Singh Apr 20 '16 at 11:02
  • without seeing the code i think you are calling the method on a reference of type DbNodeServiceImpl , not on the other class that extends DbNodeServiceImpl. Show me the specific call instruction – Homo Filmens Apr 20 '16 at 11:13
  • public class CustomGetProperties extends DbNodeServiceImpl { public void setProperty(NodeRef nodeRef, QName qname, Serializable value) throws InvalidNodeRefException { if(dictionaryService.getType(qname).equals(DataTypeDefinition.ENCRYPTED)){ApplicationContext ctx =ApplicationContextHelper.getApplicationContext(); MetadataEncryptor metadataEncryptor = (MetadataEncryptor)ctx.getBean("metadataEncryptor"); Serializable encryptedValue=metadataEncryptor.encrypt(qname,value); super.setProperty(nodeRef,qname,encryptedValue); } else super.setProperty(nodeRef, qname, value); – Sachin Singh Apr 20 '16 at 11:23
  • i am not taking refrence here i am just extending – Sachin Singh Apr 20 '16 at 11:24
  • super.setProperty.... is a direct call to parent class, in this example DbNodeServiceImpl . Your method always returns a call to DbNodeServiceImpl setProperty method – Homo Filmens Apr 20 '16 at 11:27
  • yes i want to call that parent class method but before that i want to set encrypted value according to my requirment that thing i impplemented in my method – Sachin Singh Apr 20 '16 at 11:33
  • @SachinSingh read my comment on the question and show how you are calling instanciating the nodeService. – dambros Apr 20 '16 at 11:41