掲示板

Use JournalArticlePermission w/o portal-impl dependency

thumbnail
8年前 に nicolas saubi によって更新されました。

Use JournalArticlePermission w/o portal-impl dependency

Junior Member 投稿: 43 参加年月日: 09/10/28 最新の投稿
hi there !

I've a problem accessing JournalArticlePermission in a JSP. We were including portal-impl.jar in our portlet dependencies, but doing that we faces a log4j classCastException:
"java.lang.ClassCastException: org.apache.log4j.ConsoleAppender cannot be cast to org.apache.log4j.Appender"

Here they say never import portal-impl.jar in a portlet : http://tinyurl.com/nevd4oy. Removing the portal-impl from dependencies actually remove the classCastException... but jsp can't compile :/

Question : how to use objects from portal-impl w/o importing the dependence ?
I tried to set the portal-impl dependency as <scope>provided</scope> in my pom.xml (working with maven) but it crashes on runtime (not actually finding the class) :
"Only a type can be imported. com.liferay.portlet.journal.service.permission.JournalArticlePermission resolves to a package"

Thanks in advance.
thumbnail
8年前 に Andew Jardine によって更新されました。

RE: Use JournalArticlePermission w/o portal-impl dependency

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
Hi Nicolas,

The JournalArticlePermission is in the Portal's (ROOT application) Class Loader which is not visibile to you plugin (which has it's own class loader). You would need the class, normally, to be either part of your plugin, or in the global library space (eg. TOMCAT_HOME/lib/ext). You can try getting a handle on the class using the PortalClassLoaderUtil. Once you have the object you can use reflection to invoke the method -- however this is probably not a best practice emoticon

The whole reason you are not supposed to include the portal-impl as a dependency is just as the jar name implies -- it is the Portals Implementation. The implementation can be altered via plugins and configuration. You might even find individuals who compile their own forked version in which case the class you are looking for might not be present, or have been renamed.

Maybe if you describe what you need that class for, what you are trying to do basically someone in the forums can offer you an alternate approach.
thumbnail
8年前 に David H Nebinger によって更新されました。

RE: Use JournalArticlePermission w/o portal-impl dependency

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
You cannot use portal classes directly in your code.

If it's a JSP hook, it will have visibility to the portal classes when deployed.

Otherwise you are left to reflection to try to get an instance of the class at runtime and invoke it indirectly, but this is generally bad practice.
thumbnail
8年前 に Andew Jardine によって更新されました。

RE: Use JournalArticlePermission w/o portal-impl dependency

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
LOL -- I think we hit save at the same time emoticon
thumbnail
8年前 に nicolas saubi によって更新されました。

RE: Use JournalArticlePermission w/o portal-impl dependency

Junior Member 投稿: 43 参加年月日: 09/10/28 最新の投稿
Hi and thanks for your replies !

Here are my concerns :
custom configuration for a portlet (jsp) :
Line 15 we're calling JournalArticlePermission to check if we can display some articles.

	PortletPreferences preferences = renderRequest.getPreferences();
	String domainName = ConfigurationActionImpl.DOMAIN_NAME;
	String communauteName = ConfigurationActionImpl.COMMUNAUTE_NAME;
	
	String[] journalArticleUrlTitle = preferences.getValues(ConfigurationActionImpl.LIST_ARTICLES, null);
	String[] journalArticlePositions = preferences.getValues(ConfigurationActionImpl.LIST_ARTICLES_POSITIONS, null);
	String[] articleIds = preferences.getValues(ConfigurationActionImpl.LIST_ARTICLES_IDS, null);
	
	List<articlebandeau> listArticleBandeau = new ArrayList<articlebandeau>();
	if(journalArticlePositions != null){
		for (int i = 0; i &lt; journalArticlePositions.length; i++) {
			if (journalArticlePositions[i] != null&amp;&amp; journalArticlePositions[i].length() != 0) {
				long articleResourcePrimKey = LiferayObjectKeyFinder.findArticleResourcePrimKey(domainName, communauteName, journalArticleUrlTitle[i]);
				if(JournalArticlePermission.contains(themeDisplay.getPermissionChecker(), articleResourcePrimKey,ActionKeys.VIEW)) {
					listArticleBandeau.add(new ArticleBandeau( journalArticleUrlTitle[i], journalArticlePositions[i], articleIds[i]));			
				}
			}
		}
		Collections.sort(listArticleBandeau,new ArticleBandeauComparator());
	}
</articlebandeau></articlebandeau>



Any way to do that without importing the JournalArticlePermission class ?


Thanks in advance.
thumbnail
8年前 に Andew Jardine によって更新されました。

RE: Use JournalArticlePermission w/o portal-impl dependency (回答)

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
Hey Nicolas,

I would suggest trying something like this --


PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();
permissionChecker.hasPermission(<groupid>, <portlet-name>, <resource pk>, <action-id"); < code></action-id");></resource></portlet-name></groupid>
<br><br>HOWEVER, have a look at the JournalArticlePermission class. The logic in there goes much deeper as it makes sure you have the latest version, does a check for staging if it is enabled etc. <br><br>What kind of plugin is it that you are creating? A custom portlet? Can you tell us a little more about what the portlet is aimed to do?
thumbnail
8年前 に nicolas saubi によって更新されました。

RE: Use JournalArticlePermission w/o portal-impl dependency

Junior Member 投稿: 43 参加年月日: 09/10/28 最新の投稿
Sure,

this portlet is a rolling banner with permissions.
It grabs all the articles which use a "banner" structure (custom structure), looks at the permission to see if the article is viewable, and put all the visibles articles in a list.

This list is displayed afterward.
thumbnail
8年前 に Andew Jardine によって更新されました。

RE: Use JournalArticlePermission w/o portal-impl dependency

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
Hey Nicolas,

Do you mean "viewable" based on a users role? If this is the case, then maybe you need to use one of the methods from the ResourcePermissionsLocalServiceUtil class? perhaps this one? --



public static com.liferay.portal.model.ResourcePermission getResourcePermission(
		long companyId, java.lang.String name, int scope,
		java.lang.String primKey, long roleId)
		throws com.liferay.portal.kernel.exception.PortalException,
			com.liferay.portal.kernel.exception.SystemException 


Can you give that a shot and let us know if it works?
thumbnail
8年前 に Jan Geißler によって更新されました。

RE: Use JournalArticlePermission w/o portal-impl dependency

Liferay Master 投稿: 735 参加年月日: 11/07/05 最新の投稿
Are you relying on the basic view permissions? If so, than maybe a call to JournalArticleServiceUtil would be enough? The view permission is checked if you retrieve the Data from the Service (not LocalService).
thumbnail
8年前 に Andew Jardine によって更新されました。

RE: Use JournalArticlePermission w/o portal-impl dependency

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
Hi Jan, I did not know that! I;m going to have to try this out. Thanks!
thumbnail
8年前 に nicolas saubi によって更新されました。

RE: Use JournalArticlePermission w/o portal-impl dependency

Junior Member 投稿: 43 参加年月日: 09/10/28 最新の投稿
Hi,

Working !

I replaced

if(JournalArticlePermission.contains(themeDisplay.getPermissionChecker(), articleResourcePrimKey,ActionKeys.VIEW)) {


By

if(permissionChecker.hasPermission(themeDisplay.getScopeGroupId(), JournalArticle.class.getName(), articleResourcePrimKey, ActionKeys.VIEW)){



Thanks all for your help emoticon