留言板

Portal Exception while adding resource for model object

Klaus Bachmaier,修改在7 年前。

Portal Exception while adding resource for model object

Regular Member 帖子: 223 加入日期: 13-9-30 最近的帖子
I've set up a Liferay service with servicebuilder. In my MyObjectLocalServiceUtil class, I have an addMyObject() method. Before I create a new MyObject I try to create a resource object for the new entity like this:

public MyObject addMyObject(String name, String year, long userId, long companyId, long groupId) throws SystemException, ParseException, PortalException  {
		MyObject MyObject = new MyObjectImpl();
		MyObject.setId(CounterLocalServiceUtil.increment());
		
		DateFormat df = new SimpleDateFormat("yyyy");
		MyObject.setPubdate(df.parse(year));
		
                MyObject.setName(name);
		MyObject.setCompanyId(companyId);
		MyObject.setGroupId(groupId);
		MyObject.setUserId(userId);

		
		ResourceLocalServiceUtil.addResources(companyId, groupId, userId, MyObject.class.getName(), MyObject.getId(), false, true, true);
		return addMyObject(MyObject);
	}


The ResourceLocalServiceUtil.addResource() line obviously causes a PortalException, but I don't see anything on my console and have no clue what's going on, or why my code don't reaches the "return addMyObject(MyObject);" in my code. Without the code to add resources my object gets saved as expected. Any suggestion on what may be wrong here?
thumbnail
David H Nebinger,修改在7 年前。

RE: Portal Exception while adding resource for model object

Liferay Legend 帖子: 14918 加入日期: 06-9-2 最近的帖子
You shouldn't be mucking around with MyObjectLocalServiceUtil, that is a generated class that you should not be modifying. These kinds of methods belong in MyObjectLocalServiceImpl and then rebuild services to get it created in the MyObjectLocalServiceUtil class.

Klaus Bachmaier:
The ResourceLocalServiceUtil.addResource() line obviously causes a PortalException, but I don't see anything on my console and have no clue what's going on, or why my code don't reaches the "return addMyObject(MyObject);" in my code. Without the code to add resources my object gets saved as expected. Any suggestion on what may be wrong here?


Well sure. You're declaring that the method itself throws exceptions and the ResourceLocalServiceUtil method is throwing the exception that you are not catching. The exception itself will tell you what the problem is and why it does not get to the addMyObject() method.

As a side note, you seem to be over-using the XxxLocalServiceUtil classes. Your MyObjectLocalServiceImpl class should have a "counterLocalService" and "resourceLocalService" instance members available from a super class so you can get to them directly rather than using the static Util classes.







Come meet me at the LSNA!
Klaus Bachmaier,修改在7 年前。

RE: Portal Exception while adding resource for model object

Regular Member 帖子: 223 加入日期: 13-9-30 最近的帖子
Thanks for your response David,

while posting my message above I changed my code a little bit (of course there is no MyObjectLocalService), and accidentally wrote MyObjectLocalServiceUtil instead of MyObjectLocalServiceImpl. The latter is the class which throws the exception. I'm mainly confused because the use of "ResourceLocalServiceUtil.addResources(...)" in a XYLocalServiceImpl method follows a pattern I've already used several times in my Liferay services, and never experienced a PortalException.
What I get when I explicetely catch the exception is:

com.liferay.portal.NoSuchRoleException: No Role exists with the key {companyId=20182, name=Owner}
16:16:44,630 ERROR [http-bio-8080-exec-54][AdvancedPermissionChecker:935] com.liferay.portal.NoSuchResourceActionException: de.myco.liferay.model.MyObject#DELETE
com.liferay.portal.NoSuchResourceActionException: de.myco.liferay.model.MyObject#DELETE
thumbnail
David H Nebinger,修改在7 年前。

RE: Portal Exception while adding resource for model object

Liferay Legend 帖子: 14918 加入日期: 06-9-2 最近的帖子
Have you checked the Role_ table to see if there is a company id of 20182 and a name of Owner? Do you have multiple instances? I know Owner is one of those special portal roles, I just am not sure if it is replicated per company id or not.




Come meet me at the LSNA!
Klaus Bachmaier,修改在7 年前。

RE: Portal Exception while adding resource for model object

Regular Member 帖子: 223 加入日期: 13-9-30 最近的帖子
Solved!

It's a shame, but I simply had an uppercase/lowercase typo in my /resource-actions/default.xml at the portlet name tag :-(

Sorry!
thumbnail
David H Nebinger,修改在7 年前。

RE: Portal Exception while adding resource for model object

Liferay Legend 帖子: 14918 加入日期: 06-9-2 最近的帖子
Hey, it happens!






Come meet me at the LSNA!