Search code examples
pythonliferayjythonportlet

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 a certain structure.

I am able to get the list of categories but cannot find a way using the liferay api to get a list of articles by category?

I have searched allover but it seems to me the method should be on this page:

http://docs.liferay.com/portal/6.1/javadocs/com/liferay/portlet/journal/service/JournalArticleLocalServiceUtil.html


Solution

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

    <%
    String languageId = LanguageUtil.getLanguageId( renderRequest );
    List<JournalArticle> journalArticleList = new ArrayList<JournalArticle>();
    
    AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
    assetEntryQuery.setAnyCategoryIds(new long[] { 12704 }); //category Id
    assetEntryQuery.setOrderByCol1("modifiedDate");
    assetEntryQuery.setEnd(5);
    List<AssetEntry> assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
    for (AssetEntry ae : assetEntryList) {
        JournalArticleResource journalArticleResource = JournalArticleResourceLocalServiceUtil.getJournalArticleResource(ae.getClassPK());
        JournalArticle journalArticle = JournalArticleLocalServiceUtil.getLatestArticle(journalArticleResource.getResourcePrimKey());
    
    
        JournalContentUtil.clearCache();
        String content = JournalContentUtil.getContent(journalArticleResource.getGroupId(), journalArticle.getArticleId(), "view", languageId, themeDisplay);
    
        out.println("<br>"+journalArticle.getTitle(languageId)+"<br>");
        out.println(content);
    
    }
    %>