留言板

Extending the TeamLocalServiceImpl Class through a hook

Andy Harb,修改在12 年前。

Extending the TeamLocalServiceImpl Class through a hook

Junior Member 帖子: 66 加入日期: 09-10-22 最近的帖子
Hi I have read a few post about extending the Liferay classes and attempted but can't seem to get it to work.

My end goal is to add a function into the TeamLocalServiceImpl shown below:


	public List<user> getUsers(long teamId) throws SystemException
	{
		if(teamId &lt;= 0)
			return null;
		
		return teamPersistence.getUsers(teamId, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
	}
</user>


Since there is currently no way to get a list of users from a team i wanted to add this into the service layer so I could call it from my portlet.

I created a hook and setup the liferay-hook.xml as follows:


<!--?xml version="1.0"?-->


<hook>
  <service>
        <service-type>com.liferay.portal.service.impl.TeamLocalServiceImpl</service-type>
        <service-impl>com.liferay.portal.service.impl.NENTeamLocalServiceImpl</service-impl>
  </service>

</hook>


In my hooks WEB-INF/src/com/liferay/portal/service/impl folder i created a class called NENTeamLocalServiceImpl which extends com.liferay.portal.service.impl.TeamLocalServiceImpl

This is causing an error saying that it can't find the TeamLocalServiceImpl class

So a couple things:

1) am i trying to extend the right class?
2) If the hook does work then would i reference the new function through TeamLocalServiceUtil or by directly calling the new class?

Thanks
thumbnail
Hitoshi Ozawa,修改在12 年前。

RE: Extending the TeamLocalServiceImpl Class through a hook

Liferay Legend 帖子: 7942 加入日期: 10-3-24 最近的帖子
I haven't read your message completely, but it seems you should be trying to create an ext plugin instead of a hook.
Andy Harb,修改在12 年前。

RE: Extending the TeamLocalServiceImpl Class through a hook

Junior Member 帖子: 66 加入日期: 09-10-22 最近的帖子
Thanks Hitoshi,

A bit more info i am on LR 6.0.12EE.

We have an ext plugin and i first attempted this there: I basically overwrote the TeamLocalServiceImpl.java class fully reran the service build compiled and deployed but anytime i tried referencing that function it said it didn't' exist.

Thanks
Andy
thumbnail
Hitoshi Ozawa,修改在12 年前。

RE: Extending the TeamLocalServiceImpl Class through a hook

Liferay Legend 帖子: 7942 加入日期: 10-3-24 最近的帖子
Just read your initial message. Wondering why you want to change Liferay's core functionality to add a new function. It's better to create a new interface in your portlet because I don't think you really want to "change" Liferay's general functionality but just want to "add" a functionality for your portlet.
Andy Harb,修改在12 年前。

RE: Extending the TeamLocalServiceImpl Class through a hook

Junior Member 帖子: 66 加入日期: 09-10-22 最近的帖子
I agree that would be the optimal solution. However, the function that i need to call on exist in the com.liferay.portal.service.persistence.TeamUtil class which can't be called directly [getUsers(long pk) ]. Unfortunately there is no Util class that calls on this function.

Is there another way i can go about accessing this function without adding the call at the service layer?

Thanks
Andy
thumbnail
Hitoshi Ozawa,修改在12 年前。

RE: Extending the TeamLocalServiceImpl Class through a hook

Liferay Legend 帖子: 7942 加入日期: 10-3-24 最近的帖子
Have you looked through this thread? Some one who have more time may be able to help you better. I'm currently working on a tight schedule on several projects myself. :-)

http://www.liferay.com/community/forums/-/message_boards/message/11508231
Andy Harb,修改在12 年前。

RE: Extending the TeamLocalServiceImpl Class through a hook

Junior Member 帖子: 66 加入日期: 09-10-22 最近的帖子
Thanks Hitoshi,

I tried but still had the same issue. It seems like i can overwrite existing functions without an issue but when trying to add a new function on the service layer it has issues fining the method.

So now im attempting to overwrite the functionality in the ext-plugin.

/my-ext/docroot/WEB-INF/ext-impl/src/com/liferay/portal/service/impl/TeamLocalServiceImpl.java

I copied this file from source and moved it in the same directory structure. I edited the updateTeam to output a got here statement to see if the class is being overwritten correctly. I also added the getUsers function as mentioned in previous post

	public List<user> getUsers(long teamId) throws SystemException
	{
		if(teamId &lt;= 0)
			return null;
		
		return teamPersistence.getUsers(teamId, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
	}
</user>


Compile/Deploy my-ext plugin

Restart server

Now if i edit a team i get my output statement as expected. So i know my Impl is being used. However if i try to access the new method i added it throws an error:

An error occurred at line: 45 in the jsp file: /html/contactlist/display/view.jsp
The method getUsers(long) is undefined for the type TeamLocalServiceUtil
42: 			long teamId = selectedTeams.get(teamIndex).getTeamId();
43: 		
44: 	//		List<user> teamUsers = TeamLocalServiceUtil.getService().getUsers(teamId);
45: 				List<user> teamUsers = TeamLocalServiceUtil.getUsers(teamId);
</user></user>


This occurs if i use line 44 or 45. Am i just not referencing the correct class? Also Do i need to declare the method in some other class besides the TeamLocalServiceImpl.java?

Any points would be greatly appreciated and I thank you for your time.