Sunday, 5 November 2017

Article By Tag Name

As Now we are moving with liferay 6 we would have lot many requirements 
to find the articles by tag name.So in liferay-6 i found little bit 
change to find the articles according to tags in comparison with liferay 5.2.X. 
So here below i have put the code snippet to find articles by tag for liferay 6.
Hope it will be usefull !!!


public List findArticleByTag(ThemeDisplay themeDisplay , String tagName) throws PortalException, SystemException{
  AssetTag assetTagObj = AssetTagLocalServiceUtil.getTag(themeDisplay.getScopeGroupId(), tagName);  
  long tagid = assetTagObj.getTagId(); 
  AssetEntryQuery assetEntryQuery = new AssetEntryQuery(); 
  long[] anyTagIds = {tagid};  
  assetEntryQuery.setAnyTagIds(anyTagIds);  
  List assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);  
  List journalArticleList =new ArrayList();  
  for(AssetEntry ae : assetEntryList)
  {  
     JournalArticleResource journalArticleResourceObj = JournalArticleResourceLocalServiceUtil.getJournalArticleResource(ae.getClassPK()); 
     JournalArticle journalArticleObj = JournalArticleLocalServiceUtil.getArticle(themeDisplay.getScopeGroupId(),journalArticleResourceObj.getArticleId());  
     journalArticleList.add(journalArticleObj); 
  } 
  return journalArticleList;  
 }

No comments:

Post a Comment