Fórum

Can you override a <whatever>LocalServiceImpl with a hook?

thumbnail
Cameron McBride, modificado 12 Anos atrás.

Can you override a <whatever>LocalServiceImpl with a hook?

Expert Postagens: 269 Data de Entrada: 08/02/11 Postagens Recentes
In particular I am looking to change some functionality in CalEventLocalServiceImpl.

I have created my class that extends CalEventLocalServiceImpl and placed this in the xml:
	<service>
    	<service-type>com.liferay.portlet.calendar.service.impl.CalEventLocalServiceImpl</service-type>
    	<service-impl>com.liferay.portlet.calendar.service.impl.HCACalEventLocalServiceImpl</service-impl>
	</service>


It bombs out when trying to register the hook. Is the only way to override functionality in a LocalServiceImpl through the ext environment?
thumbnail
Thiago Leão Moreira, modificado 12 Anos atrás.

RE: Can you override a <whatever>LocalServiceImpl with a hook?

Liferay Legend Postagens: 1449 Data de Entrada: 10/10/07 Postagens Recentes
You can use a hook to override any *ServiceImpl. You made almost everything right, the wrong part was extend CalEventLocalServiceImpl instead of CalEventLocalServiceWrapper
thumbnail
Cameron McBride, modificado 12 Anos atrás.

RE: Can you override a <whatever>LocalServiceImpl with a hook?

Expert Postagens: 269 Data de Entrada: 08/02/11 Postagens Recentes
So I have changed my xml to:
	<service>
    	<service-type>com.liferay.portlet.calendar.service.CalEventLocalServiceWrapper</service-type>
    	<service-impl>com.liferay.portlet.calendar.service.impl.HCACalEventLocalServiceImpl</service-impl>
	</service>


I have changed my class to extend CalEventLocalServiceWrapper. At this point I have not bothered to add any methods to the class except for the required constructor. When I deploy I get an error registering the hook:
Caused by: java.lang.NoSuchMethodException: com.liferay.portlet.calendar.service.impl.HCACalEventLocalServiceImpl.<init>(com.liferay.portlet.calendar.service.CalEventLocalServiceWrapper)</init>


I'm sure I'm overlooking something silly. Thanks for the help.
thumbnail
Thiago Leão Moreira, modificado 12 Anos atrás.

RE: Can you override a <whatever>LocalServiceImpl with a hook?

Liferay Legend Postagens: 1449 Data de Entrada: 10/10/07 Postagens Recentes
Yep, we are! Try this

<service>
        <service-type>[b]com.liferay.portlet.calendar.service.CalEventLocalService[/b]</service-type>
        <service-impl>com.liferay.portlet.calendar.service.impl.HCACalEventLocalServiceImpl</service-impl>
    </service>
thumbnail
Cameron McBride, modificado 12 Anos atrás.

RE: Can you override a <whatever>LocalServiceImpl with a hook?

Expert Postagens: 269 Data de Entrada: 08/02/11 Postagens Recentes
Ha, you beat me to it. I tried that as a wild guess and it indeed was the missing piece. I'm adding an option to notify the community/group about an event.

Now it's time to add some methods. My end goal is to change whats in the remindUser method of CalEventLocalServiceImpl. However that is a protected method and is not part of the Wrapper class. I assume that I am not going to be able to override that. The calling method is public, in the wrapper and is called checkEvents. I assume I'll have to copy this method and then also any private/protected methods that it may call, which would include the method I want to change. I have tested overriding checkEvents and it does get called when the event triggers, yay! I just want to make sure I go about it the best way...
thumbnail
Sandeep Nair, modificado 12 Anos atrás.

RE: Can you override a <whatever>LocalServiceImpl with a hook?

Liferay Legend Postagens: 1744 Data de Entrada: 06/11/08 Postagens Recentes
One limitation it has is while copying the code from <original>localserviceimpl, you have to make sure there is nothing in it, which is from portal-impl.jar or it will again give exception

Regards,
Sandeep
thumbnail
Cameron McBride, modificado 12 Anos atrás.

RE: Can you override a <whatever>LocalServiceImpl with a hook?

Expert Postagens: 269 Data de Entrada: 08/02/11 Postagens Recentes
Yeah that would be a bummer, I could use PortalClassInvoker if I had to.

What I've ran into currently is there are some other variables that checkEvent runs but don't seem available to me: calEventPersistence and userPersistence.

Update: This seems to be turning into a never ending task. If I went with an EXT plugin would I be able to copy the entire CalEventLocalServiceImpl class and include my changes? That may be way easier.

Update 2: Creating my own class that extends CalEventLocalServiceImpl, copying the one method and changing it only took a few minutes in the ext environment :-( I sure would like to use a hook for something!
thumbnail
Sandeep Nair, modificado 12 Anos atrás.

RE: Can you override a <whatever>LocalServiceImpl with a hook?

Liferay Legend Postagens: 1744 Data de Entrada: 06/11/08 Postagens Recentes
Yes true. Well i am eagerly waiting for Liferay 6.1 where i can create my Struts action hook. Then what we can do is create a custom service for the same table and call the same from our struts action

Regards,
Sandeep
Sindhu Varshini, modificado 8 Anos atrás.

RE: Can you override a <whatever>LocalServiceImpl with a hook?

New Member Postagens: 6 Data de Entrada: 19/04/13 Postagens Recentes
Hi,

Do you have any update on the above issue. I am facing similar issue.
My requirement is to add another definition of terms in message boards. so I am trying to extend to access notifySubscribers() method from com\liferay\portlet\messageboards\service\impl\MBMessageLocalServiceImpl.java service using hook. But variables companyPersistence, groupPersistence,portletPreferencesLocalService,serviceContext are not available to me. Do we have to use EXT plugin for modifying service class? Hook doesn't work?

Can anyone share your knowledge.



Thanks,
Sindhu
thumbnail
Sandeep Nair, modificado 8 Anos atrás.

RE: Can you override a <whatever>LocalServiceImpl with a hook?

Liferay Legend Postagens: 1744 Data de Entrada: 06/11/08 Postagens Recentes
Hi,

Since it is protected method, you need to write ext.

Regards,
Sandeep
thumbnail
Olaf Kock, modificado 8 Anos atrás.

RE: Can you override a <whatever>LocalServiceImpl with a hook?

Liferay Legend Postagens: 6403 Data de Entrada: 23/09/08 Postagens Recentes
well, you could use a hook to override every single method that calls notifySubscribers (with a copy of the original code) and change the notifySubscribers call to a new implementation. Just to provide one more option - sometimes this is prohibitive and sometimes it's a good option.
Sindhu Varshini, modificado 8 Anos atrás.

RE: Can you override a <whatever>LocalServiceImpl with a hook?

New Member Postagens: 6 Data de Entrada: 19/04/13 Postagens Recentes
Hi,

Thanks Everyone for your help.

Thanks,
Sindhu