RE: RE: How to customize DLAppServiceUtil?

Jamie Sammons, modified 2 Years ago. New Member Posts: 3 Join Date: 4/11/23 Recent Posts

Hello,

following the tutorial Creating a Custom OSGi Service I have been able to customize references to DlAppService. If a component asks for a reference to DlAppService it gets a reference to my customized class DlAppCustomServiceImpl.

I would like to do the same for ServiceUtil classes. But when a jsp calls any method of DlAppServiceUtil the internal method that obtains the service (GetService) returns a reference to the original DlAppServiceImpl instead of a reference to DlAppCustomServiceImpl and my customized code is not invoked. I think it is related to ServiceUtil classes using Spring instead of OSGI to locate the implementation service class but I can't see how to fix it.

What steps should I take so DlAppServiceUtil gets a reference to my DlAppCustomServiceImpl instead of DlAppServiceImpl?

Thanks

Antonio

thumbnail
Mohammed Yasin, modified 2 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts

Hi ,

You need to use Liferay Service Wrapper to override Liferay Services. You can refer to the link below: 

https://help.liferay.com/hc/en-us/articles/360018165631-Overriding-Liferay-Services-Service-Wrappers-

Jamie Sammons, modified 2 Years ago. New Member Posts: 3 Join Date: 4/11/23 Recent Posts

Thanks for your answer, Mohammed.

But I think a service wrapper will not help me in my use case.

Imagine I want to filter what FileEntries are shown in the "Document and Media" portlet included with LifeRay. In addition to what Liferay does in the method DlAppServiceUtil.getFoldersAndFileEntriesAndFileShortcuts i want to add code that filters out FileEntries uploaded before the User was created. 

My understanding is that I can create a service wrapper that does that but, since the "Document and Media" Portlet is using DlAppServiceUtil and DlAppService but not DlAppServiceWrapper, my new code would not be called by the portlet.

Regards,

Antonio

thumbnail
Mohammed Yasin, modified 2 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts

DLAppServiceWrapper will be called whenever DLAppServiceUtil or DLAppService is being called across the application.

Ex.DlAppServiceUtil.getFoldersAndFileEntriesAndFileShortcuts this method to override in Service Wrapper and add your filter in this. So, whenever DlAppServiceUtil.getFoldersAndFileEntriesAndFileShortcuts is called, it will execute your custom code. 

Jamie Sammons, modified 2 Years ago. New Member Posts: 3 Join Date: 4/11/23 Recent Posts

Thanks a lot, Mohammed.

Using a wrapper I have been able to achieve what I wanted.

Regards,

Antonio