zoukankan      html  css  js  c++  java
  • Liferay7 BPM门户开发之20: 理解Asset Framework

    参考:https://www.cnblogs.com/starcrm/p/6046522.html

    Liferay7 BPM门户开发之20: 理解Asset Framework

     

    Asset框架用于将您开发的门户内容添加Liferay的核心系统功能。
    打个比方,你开发了一个事件TodoList管理的插件,在列表显示的时候,你可以集成Asset框架,让你的自定义内容支持Tag标签、分类、评论、星标等功能。它可以关联任意的门户内容,文本、Int、Image、documents、blog entries, bookmarks,或者任何您自己定义的内容。

    这带来门户的一致关联性,非常有益。

    Asset框架主要有下列功能:

    • 1.关联Tag标签到自定义的内容类型,可以创建或关联已存在的Tag。
    • 2.关联类别到自定义的内容类型。作者只能在预定义的词汇中的类别中进行选择。
    • 3.在控制面板中管理标签。管理员可以合并Tag。
    • 4.在控制面板中管理类别,管理员管理类别层级。
    • 5.将评论关联到内容。
    • 6.通过0到5颗星的评级功能来对内容进行评级。
    • 7.分配链接到内容的社交标签。
    • 8.对asset增加自定义字段。
    • 9.将一个asset与另一个asset设置为相关联(即相关文章 或类似的内容,有点像淘宝里的相似商品)。
    • 10.标记不妥的文章。
    • 11.追踪内容的浏览次数。
    • 12.和工作流整合。
    • 13.通过资源发布器(Asset Publisher)portlet来发布和管理内容。

    为自定义内容注入Asset关联 (新增、修改、删除)

    首先要在工程的service.xml文件增加一行
    <reference package-path="com.liferay.portlet.asset" entity="AssetEntry" />
    然后运行Service Builder。

    比如修改一条AssetEntry,一般调用方法是assetEntryLocalService的updateEntry方法:

    复制代码
    AssetEntry updateEntry(
    long userId, long groupId, Date createDate, Date modifiedDate,
    String className, long classPK, String classUuid, long classTypeId,
    long[] categoryIds, String[] tagNames, boolean visible,
    Date startDate, Date endDate, Date expirationDate, String mimeType,
    String title, String description, String summary, String url,
    String layoutUuid, int height, int width, Integer priority,
    boolean sync)
    throws PortalException, SystemException
    复制代码


    如果不用Service Builder体系也可以用AssetLocalServiceUtil的静态方法。

    参数的介绍:

    • userId: 用户ID
    获取userId可以通过2种方式:
    long userId = PortalUtil.getUserId(request)
    long userId = serviceContext.getUserId();
    • groupId: 内容所处的范围维度,如果不支持界限范围,那么直接传0.
    获取groupId的2种方式:
    long groupId = serviceContext.getScopeGroupId();
    long groupId = PortalUtil.getScopeGroupId(renderRequest)
    • createDate: 创建日期
    • modifiedDate: 修改日期
    • className: 实体类型名称,比如[YourClassName].class.getName().
    • classPK: 实体实例主键
    • classUuid: 用于关联跨域的实体实例,方便与内容的导入导出需求,想像一下,如果用了int自增,就没法同步内容了
    • classTypeId: 一般是0
    • categoryIds: 分类IDs
    • assetTagNames: 标签名称s,注意这是个数组
    获取categoryIds和assetTagNames方式:
    ServiceContext serviceContext = ServiceContextFactory.getInstance(
    actionRequest);
    long[] assetCategoryIds = serviceContext.getAssetCategoryIds();
    String[] assetTagNames = serviceContext.getAssetTagNames();
    • visible: 是否可见
    • startDate: Asset Publisher显示内容的日期,一般是null
    • endDate: Asset Publisher停止显示内容的日期,一般是null
    • expirationDate: 过期时间,过期即不显示该实体内容,一般是null
    • mimetype: 比如 ContentTypes.TEXT_HTML, 用于实体的展示格式
    • title: 标题
    • description:
    • summary: 短介绍
    • url: 实体关联的URL,一般是null
    • layoutUuid: 布局ID,一般是null
    • height: 可以是0
    • 可以是0
    • priority: 优先级,一般是null
    • sync: 设置同步开关,一般false

    一个例子更能简单说明问题:
    比如在insult实例调用updateEntry方法. 在add-XXX方法中调用updateEntry在实体添加后,或者在update-XXX方法中。
    注意2点:

    • Insult是实体类
    • insult是Insult的一个实例
    复制代码
    long classTypeId = 0;
    boolean visible = true;
    Date startDate = null;
    Date endDate = null;
    Date expirationDate = null;
    String mimeType = ContentTypes.TEXT_HTML;
    String title = insult.getInsultString();
    String description = insult.getInsultString();
    String summary = insult.getInsultString();
    String url = null;
    String layoutUuid = null;
    int height = 0;
    int width = 0;
    Integer priority = null;
    boolean sync = false;
    
    assetEntryLocalService.updateEntry(
    userId, groupId, insult.getCreateDate(),
    insult.getModifiedDate(), Insult.class.getName(),
    insult.getInsultId(), insult.getUuid(), classTypeId,
    serviceContext.getAssetCategoryIds(),
    serviceContext.getAssetTagNames(), visible, startDate, endDate,
    expirationDate, mimeType, title, description, summary, url,
    layoutUuid, height, width, priority, sync);
    
    Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(Insult.class);
    indexer.reindex(insult);
    复制代码


    在删除实体时,应同时删除相关的asset和索引。

    assetEntryLocalService.deleteEntry(
    Insult.class.getName(), insult.getInsultId());
    
    Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(Insult.class);
    indexer.delete(insult);

    在JSP页面中显示类型和标签Tag选择器

    比如一个portlet中的 edit_XXXentry.jsp:
    添加:

    复制代码
    <liferay-ui:asset-categories-error />
    <liferay-ui:asset-tags-error />
    ...
    <aui:fieldset-group markupView="lexicon">
    ...
    <aui:fieldset collapsed="<%= true %>" collapsible="<%= true %>" label="categorization">
    <aui:input name="categories" type="assetCategories" />
    <aui:input name="tags" type="assetTags" />
    </aui:fieldset>
    ...
    </aui:fieldset-group>
    复制代码

    用于展示:

    复制代码
    <p><liferay-ui:message key="categories" />:</p>
    
    <div class="entry-categories">
    <liferay-ui:asset-categories-summary
    className="<%= BlogsEntry.class.getName() %>"
    classPK="<%= entry.getEntryId() %>"
    portletURL="<%= renderResponse.createRenderURL() %>"
    />
    </div>
    ...
    <div class="entry-tags">
    <p><liferay-ui:message key="tags" />:</p>
    <liferay-ui:asset-tags-summary
    className="<%= BlogsEntry.class.getName() %>"
    classPK="<%= entry.getEntryId() %>"
    portletURL="<%= renderResponse.createRenderURL() %>"
    />
    </div>
    复制代码

    在JSP页面中显示通用评论

    复制代码
    <%
    long insultId = ParamUtil.getLong(renderRequest, "insultId");
    Insult ins = InsultLocalServiceUtil.getInsult(insultId);
    %>
    
    <liferay-ui:panel-container extended="<%=false%>"
    id="insultCommentsPanelContainer" persistState="<%=true%>">
    
    <liferay-ui:panel collapsible="<%=true%>" extended="<%=true%>"
    id="insultCommentsPanel" persistState="<%=true%>"
    title='<%=LanguageUtil.get(pageContext, "comments")%>'>
    
    <portlet:actionURL name="invokeTaglibDiscussion" var="discussionURL" />
    
    <%
    String currentUrl = PortalUtil.getCurrentURL(request);
    %>
    
    <liferay-ui:discussion className="<%=Insult.class.getName()%>"
    classPK="<%=ins.getInsultId()%>"
    formAction="<%=discussionURL%>" formName="fm2"
    ratingsEnabled="<%=true%>" redirect="<%=currentUrl%>"
    subject="<%=ins.getInsultString()%>"
    userId="<%=ins.getUserId()%>" />
    
    </liferay-ui:panel>
    </liferay-ui:panel-container>
    复制代码

    到这里,应该可以清楚的感觉到使用Asset框架的好处:只有用好它,才能继承Liferay的核心关联资产。

  • 相关阅读:
    配置iis支持.json格式的文件
    This function has none of Deterministic,no sql,or reads sql data in its declaration and binary logging is enabled(you *might* want to use the less safe log_bin_trust_function_creators variable
    IIS Asp.Net 访问 Com组件 报拒绝访问
    记一次 mysql 启动没反应
    linux 下安装 redis
    Jexus 安装asp.net mvc EF 项目引发的错误总
    在CentOS中安装arial字体
    Navigator 对象
    location 对象属性
    history对象
  • 原文地址:https://www.cnblogs.com/show58/p/13809250.html
Copyright © 2011-2022 走看看