16 February, 2011

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};  
  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());  
  return journalArticleList;  

Rate Me:

Create Servlet Project as Module

You would have seen that many times we are writing out own servlet in Liferay portal to achieve some specific use case. In DXP, You can st...