Sunday, November 13, 2016

Fetching Tag Based Documents or Web Contents from Assets

Sometimes we will have the requirement like we need to fetch the documents which are specifically tagged with some tag name. Then no worries below code will help you to fetch the tag based documents from DLFile and also to fetch the tag based web content from Journal Article.

Java Code :-

String[] tagNames = {"get announcements"};

// Getting the ids of journalarticle and DLFille
 long[] requiredClassIds = {PortalUtil.getClassNameId(JournalArticle.class.getName()), PortalUtil.getClassNameId(DLFileEntry.class.getName())};

AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
          assetEntryQuery.setAllTagIds(AssetTagLocalServiceUtil.getTagIds(groupId, tagNames));
         assetEntryQuery.setClassNameIds(requiredClassIds);

List assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);

for (AssetEntry ae : assetEntryList) {
      if(JournalArticle.class.getName().equalsIgnoreCase(ae.getClassName())){

           JournalArticle wc = JournalArticleLocalServiceUtil.getArticle(groupId, String.valueOf(ae.getClassPK() - 2));

             System.out.println("AnnouncementsPortlet : render : found web content name ::"+wc.getUrlTitle());

   } else if(DLFileEntry.class.getName().equalsIgnoreCase(ae.getClassName())){

    DLFileEntry dl =  DLFileEntryLocalServiceUtil.getDLFileEntry(ae.getClassPK());

    }

}

         

No comments:

Liferay DXP JNDI Data Source Cofiguration

 This Blog will help us to learn about the JNDI Data Source Configuration in Liferay DXP. We have tested this with Liferay 7.3 with Tomcat. ...