按类别获取期刊文章:用Python编写的Liferay Portlet

时间:2013-12-09 19:25:07

标签: python liferay jython portlet

我正在尝试用Python编写一个简单的Liferay portlet。 portlet将显示一个类别列表,点击后将显示某个结构的Web内容文章(期刊文章)列表。

我能够获取类别列表,但无法找到使用liferay api获取类别文章列表的方法吗?

我已全程搜索,但在我看来该方法应该在此页面上:

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

3 个答案:

答案 0 :(得分:3)

这是一个Java实现,但很容易转换为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);

}
%>

答案 1 :(得分:0)

谢谢,AssetEntryQuery就是解决方案:

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))

答案 2 :(得分:0)

The proposed solution is good yet needs one extra piece. It will return all Assets - web-content-articles are a subset of assets. For example, you will get documents (which have been categorized the same way) as well. To refine your search, add a className, classNameid, or classTypeId to the AssetEntryQuery (in addition to the category id). Alternatively, within the for-loop you could pick out the web-content, ignore the others.