码迷,mamicode.com
首页 > 其他好文 > 详细

Liferay7 BPM门户开发之35: AssetTag的集成查询

时间:2016-11-14 14:37:22      阅读:267      评论:0      收藏:0      [点我收藏+]

标签:entry   getname   开发   tle   count   page   div   exce   soc   

Tag是liferay中的Asset特性,可以用来对信息进行分类,在iferay中的Asset类型为:

  • 1、 Web Content(自定义内容)
  • 2、 Documents and Media(文档库和媒体文件)
  • 3、 Blogs (博客文章)
  • 4、 Message Boards
  • 5、 Wiki Page
  • 6、 Bookmarks

可以根据tagName来对信息进行归类统计,演示代码:

//查询Tag的数量(符合tagName=‘news’)
ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
String tagName = "news";
try {
AssetTag assetTag = AssetTagLocalServiceUtil.getTag(themeDisplay.getScopeGroupId(), tagName);
int assetCount = assetTag.getAssetCount();
System.out.println("Tage name: "+tagName);
System.out.println("Number of associated assets: "+assetCount);
 
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}

//=======================
//查询all assets (by tagName)

ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest
.getAttribute(WebKeys.THEME_DISPLAY);
String tagName = "news";
try {
AssetTag assetTag = AssetTagLocalServiceUtil.getTag(themeDisplay.getScopeGroupId(), tagName);
 
AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
long[] tagIds = { assetTag.getTagId() };
assetEntryQuery.setAnyTagIds(tagIds);
List<AssetEntry> assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
for (AssetEntry assetEntry : assetEntryList) {
//Here all the logic will go
......
}
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}


//=======================
//查询JournalArticle所有符合tagName=‘news’的文章
//备注:JournalArticle是liferay内置的一种Web CMS Content,利用它可以做新闻类的展示


ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest
.getAttribute(WebKeys.THEME_DISPLAY);
String tagName = "news";
try {
AssetTag assetTag = AssetTagLocalServiceUtil.getTag(themeDisplay.getScopeGroupId(), tagName);
 
AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
long[] tagIds = { assetTag.getTagId() };
assetEntryQuery.setAnyTagIds(tagIds);
assetEntryQuery.setClassName(JournalArticle.class.getName());
List<AssetEntry> assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
//开始遍历JournalArticle
for (AssetEntry assetEntry : assetEntryList) { 
JournalArticleResource journalArticleResource = JournalArticleResourceLocalServiceUtil.getJournalArticleResource(assetEntry.getClassPK());
JournalArticle journalArticle = JournalArticleLocalServiceUtil.getArticle(journalArticleResource.getGroupId(),journalArticleResource.getArticleId());
System.out.println("Journal Article Title: "+journalArticle.getTitle(themeDisplay.getLocale()));
}
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}


//=======================
//查询所有符合tagName=‘news’的书签等信息

ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
String tagName = "news";
try {
AssetTag assetTag = AssetTagLocalServiceUtil.getTag(themeDisplay.getScopeGroupId(), tagName);
AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
long[] tagIds = { assetTag.getTagId() };
assetEntryQuery.setAnyTagIds(tagIds);
/**
*  Bookmarks
*/
assetEntryQuery.setClassName(BookmarksEntry.class.getName());
List<AssetEntry> assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
for (AssetEntry assetEntry : assetEntryList) {
 
BookmarksEntry bookmarksEntry = BookmarksEntryLocalServiceUtil.getBookmarksEntry(assetEntry.getClassPK());
....to do something
 
}
/**
*  Blogs
*/
assetEntryQuery.setClassName(BlogsEntry.class.getName());
assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
for (AssetEntry assetEntry : assetEntryList) {
BlogsEntry BlogsEntry = BlogsEntryLocalServiceUtil.getBlogsEntry(assetEntry.getClassPK());
....to do something
 
}
 
/**
*  Documents and media
*/
assetEntryQuery.setClassName(DLFileEntry.class.getName());
assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
for (AssetEntry assetEntry : assetEntryList) {
DLFileEntry dLFileEntry = DLFileEntryLocalServiceUtil.getDLFileEntry(assetEntry.getClassPK());
....to do something
 
}
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}

 

Liferay7 BPM门户开发之35: AssetTag的集成查询

标签:entry   getname   开发   tle   count   page   div   exce   soc   

原文地址:http://www.cnblogs.com/starcrm/p/6061427.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!