1

I am trying to filter the web content according to the site/community name of current logged in user and below code is written in portal_normal.vm. I am using my own custom theme.I have 3 sites in my portal application ,namely,Global ,Liferay,myCustomSite.

I have default liferay user "test" as part of Liferay site, and my own user as part of "myCustomSite".


    #set ($group_local_service = $serviceLocator.findService("com.liferay.portal.service.GroupLocalService"))
    #set ($user_groups = $group_local_service.getUserGroups($user.getUserId()))
    #foreach ($user_group in $user_groups)
    #if ($user_group.isRegularSite())
        #set ($journal_article_local_service = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))
        #set ($journal_articles = $journal_article_local_service.getArticles($user_group.getGroupId()))
        #foreach ($article in $journal_articles)
            #if($article.getStatus() ==0)
                #set ($VOID = $velocityPortletPreferences.setValue('groupId',$user_group.getGroupId().toString()))
                #set ($VOID = $velocityPortletPreferences.setValue('articleId', $article.getArticleId().toString()))
                #set ($VOID = $velocityPortletPreferences.setValue('portletSetupShowBorders', 'false'))
                #set ($portlet_id = '56')
                #set ($my_portlet_id = "${portlet_id}_INSTANCE_${article.getArticleId()}")
                $theme.runtime($my_portlet_id, "", $velocityPortletPreferences.toString())
                $velocityPortletPreferences.reset()
            #end
        #end
        #end
    #end

When I run above code , I am able to fetch all the articles in my custom site but facing issues while dynamically adding them. I get an error like

11:06:39,420 INFO  [JournalContentImpl:306] Get article display {10184, 14853, }
11:06:39,421 WARN  [JournalContentImpl:317] Unable to get display for 10184 14853 en_US

"10184" is the default liferay group/site id and "14853" is my article id under my custom site.I am not sure why its using liferay site id even when I pass site id of current user.

When i checked "ThemeDisplay.getScopGroupId" ,I am always getting liferay site id back. I am using liferay 6.2 GA2. Any pointers would really help.Thanks.

Mani
  • 283
  • 3
  • 21

1 Answers1

0

Let me explain what you're doing in this code. First: What Liferay technically calls group, typically manifests in a site (simplified, but enough for the purpose of this answer)

What your code is doing is:

Get *all* sites that the current User is member of
For each of those sites:
   Get *all* articles from CMS for this site
   For each of these articles:
       if the article is workflow-approved (status==0)
           include a Web Content Display Portlet, properly configured

As you can see these are two nested loops, enumerating a potentially large number of sites and articles - and I assume this is not what you want to do.

As you just state that your code doesn't do what you expect (but not what you actually expect), I hope that this explanation is enough to point you to the root cause of your problem.

I'm assuming that you probably want to show a single article somewhere, as it's embedded in the theme, thus on every page. As a theme renders on every single page request, you should make sure that you don't enumerate all sites and articles for each single request.

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
  • Yes,You have rightly explained pseudocode for my java code.Here I am geting all sites as I will only be assigning only 1 site to any user. Here site represents the client name that person is working for .So there will always be 1 site assigned to any user.I am able to correctly fetch the articled ids according to user site.Its just when adding it dynamically it fails.I am thinking that scopgroupid is something which is set internally and whatver I have set using `$velocityPortletPreferences.setValue('groupId',$user_group.getGroupId().toString()))` is not used for locating the articles in db. – Mani Jun 26 '14 at 09:29