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();
}
时间: 2024-10-15 14:46:38

Liferay7 BPM门户开发之35: AssetTag的集成查询的相关文章

Liferay7 BPM门户开发之37: Liferay7下的OSGi Hook集成开发

hook开发是Liferay客制扩展的一种方式,比插件灵活,即可以扩展liferay门户,也能对原有特性进行更改,Liferay有许多内置的服务,比如用hook甚至可以覆盖Liferay服务. 可作为系统服务挂钩(Liferay Service Hook),还有其他类型的hook... Liferay6.2 时的hook开发比较有限,而在Liferay7则大为不同,OSGi services的彻底改进至Liferay的底层模型框架,使得Liferay可以支持更多的定制扩展!OSGi plugin

Liferay7 BPM门户开发之17: Portlet 生命周期

Portlet 生命周期 init() =〉 render() =〉 processAction() =〉 processEvent() =〉 serveResource() =〉destroy() init() 在Liferay容器部署portlet时,启动portlet实例化 init有两个写法: public void init() throws PortletException public void init(PortletConfig config) throws PortletEx

Liferay7 BPM门户开发之32: 实现自定义认证登陆(定制Authentication Hook)

优秀的平台必然松耦合.易扩展  -- 王昕 第一步:修改liferay-hook.xml <?xml version="1.0"?> <!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.2.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_2_0.dtd"> <hook> <portal-properties>

Liferay7 BPM门户开发之8: Activiti实用问题集合

1.如何实现审核的上级获取(任务逐级审批) 这个是必备功能,通过Spring的注入+Activiti表达式可以很容易解决. 可参考: http://blog.csdn.net/sunxing007/article/details/8491552 http://linhongyu.blog.51cto.com/6373370/1656596 2.如何设置流程发起人,并动态在其他任务中使用 通过变量,在启动的时候设置. activiti里设置流程发起人的功能很绕. activiti 指定发起人,并作

Liferay7 BPM门户开发之19: 理解Service Builder体系

Service Builder是Liferay为业务开发而设计的模型驱动(model-driven)平台工具,提供一系列的实体类.数据持久化.服务相关的代码自动生成服务.支持Hibernate and Spring集成,缓存处理,动态查询等特性.令人惊讶的是,Liferay所有的持久化代码.Servie接口代码都是由Service Builder自动生成的,可见其自动化程度之高. 注意:Liferay的数据持久化开发不是必需用Service Builder,你可以直接用JDBC.JPA等任何技术

Liferay7 BPM门户开发之14: Liferay开发体系简介

Liferay SDK 开发体系 主要分6种: Portlet Hook Theme Layout Templates Web Modules Ext Portlet :类似于servlet的web组件,编译后是war包,是页面的组成元素,可以把它理解为一个web APP 详细介绍:https://web.liferay.com/zh/products/what-is-a-portal/web-platform Hook:钩子插件,用来覆盖门户的JSP文件和配置文件,适用于仅需要少量(jsp)代

Liferay7 BPM门户开发之34: liferay7对外服务类生成(RestService Get Url)

在liferay7中开发不依赖Service Builder的对外服务类,非常简洁,只需要2点注解: 在类的前部定义: @ApplicationPath("/PathXXX") 方法前定义: @GET @Path("/ActionXXX") @Produces("text/plain") 例子:得到注册用户 import com.liferay.portal.kernel.model.User; import com.liferay.portal

Liferay7 BPM门户开发之39: Form表单提交的ProcessAction处理

在v6.2开始后,需要设置<requires-namespaced-parameters>false</requires-namespaced-parameters>  来避免在jsp中写<portlet:namespace/>的input前缀 在v7.0发现,注解方式是不灵的! 即  "javax.portlet.requires-namespaced-parameters=false", 无效果, 真是汗... 但我们是有办法在7.0中解决的,直

Liferay7 BPM门户开发之6: Activiti数据库换为mysql

第一步: 在mysql中创建数据库名字叫 'activiti' 执行D:\activiti-5.21.0\database\create下的脚本 第二步: 打开=> apache-tomcat/webapps/activiti-explorer/WEB-INF/classes/ db.properties 修改配置文件 db.properties db=activiti jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localho