Liferay7 BPM门户开发之35: AssetTag的集成查询
Posted 昕友软件开发
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Liferay7 BPM门户开发之35: AssetTag的集成查询相关的知识,希望对你有一定的参考价值。
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的集成查询的主要内容,如果未能解决你的问题,请参考以下文章
Liferay7 BPM门户开发之17: Portlet 生命周期
Liferay7 BPM门户开发之3: Activiti开发环境搭建
Liferay7 BPM门户开发之14: Liferay开发体系简介
Liferay7 BPM门户开发之34: liferay7对外服务类生成(RestService Get Url)