Retrieving/getting the JournalArticle from the Tag

Whenever we create the JournalArticle we add tag.

Sometimes it is required to get the "Article" from the tag, so how can we do that.

Here is the code,

String tagName = "cricket";

AssetTag assetTag = AssetTagLocalServiceUtil.getTag(themeDisplay.getScopeGroupId(),tagName);

AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
assetEntryQuery.setAllTagIds(new long []{assetTag.getTagId()});

List<journalarticle> journalArticleList = null;


List<assetentry> assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);

for(AssetEntry assetEntry : assetEntryList) {

try {

JournalArticleResource journalArticleResource = JournalArticleResourceLocalServiceUtil .getJournalArticleResource(assetEntry .getClassPK());

JournalArticle journalArticle = JournalArticleLocalServiceUtil.getArticle(groupId,journalArticleResource.getArticleId());

journalArticleList.add(journalArticle);

} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}

}


Here we are getting the jornalArticle from the tag "cricket".

Comments

Popular posts from this blog

Theme display in javascript

How to know which liferay version we are using

Viewing the SQL Query in liferay : debugging the SQL Query in Hibernate