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());
}
}
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
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:
Post a Comment