首页 > 代码库 > Liferay7 BPM门户开发之35: AssetTag的集成查询

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);//开始遍历JournalArticlefor (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的集成查询