Skip to content Skip to sidebar Skip to footer

Getting Journal Articles By Category: Liferay Portlet Written In Python

I am trying to write a simple Liferay portlet in Python. The portlet will show a list of categories and when clicked will show a list of Web Content articles (journal articles) of

Solution 1:

It is a Java implementation but really easy to convert into python.

<%
StringlanguageId= LanguageUtil.getLanguageId( renderRequest );
List<JournalArticle> journalArticleList = newArrayList<JournalArticle>();

AssetEntryQueryassetEntryQuery=newAssetEntryQuery();
assetEntryQuery.setAnyCategoryIds(newlong[] { 12704 }); //category Id
assetEntryQuery.setOrderByCol1("modifiedDate");
assetEntryQuery.setEnd(5);
List<AssetEntry> assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
for (AssetEntry ae : assetEntryList) {
    JournalArticleResourcejournalArticleResource= JournalArticleResourceLocalServiceUtil.getJournalArticleResource(ae.getClassPK());
    JournalArticlejournalArticle= JournalArticleLocalServiceUtil.getLatestArticle(journalArticleResource.getResourcePrimKey());


    JournalContentUtil.clearCache();
    Stringcontent= JournalContentUtil.getContent(journalArticleResource.getGroupId(), journalArticle.getArticleId(), "view", languageId, themeDisplay);

    out.println("<br>"+journalArticle.getTitle(languageId)+"<br>");
    out.println(content);

}
%>

Solution 2:

Thanks, AssetEntryQuery was the solution:

from com.liferay.portlet.asset.service.persistence import AssetEntryQuery
from com.liferay.portlet.asset.service import AssetEntryServiceUtil

aq = AssetEntryQuery()
aq.setAllCategoryIds([442492])
articles = AssetEntryServiceUtil.getEntries(aq)

for a in articles:
  out.write(str(a.title))
  out.write(str(a))

Post a Comment for "Getting Journal Articles By Category: Liferay Portlet Written In Python"