liferay - 订阅Liferay 6.2中添加/更新/删除文件夹

标签 liferay liferay-6

您好,我想在 Liferay 的文档和媒体 portlet 中实现文件夹订阅功能

liferay 提供的当前功能是,如果您订阅任何文件夹/父文件夹,那么您将收到有关添加/更新文件的电子邮件,但不会收到有关文件夹的电子邮件。

因此,如果您将子文件夹添加到订阅的文件夹中,您将不会收到任何电子邮件。

对此的任何帮助表示赞赏。

最佳答案

SubscriptionPermissionImpl 中的 hasPermission 方法仅检查 MBDiscussion、BlogsEntry、BookmarksEntry、DLFileEntry、JournalArticle、MBCategory、MBThread、WikiPage 的权限

检查SubscriptionPermissionImpl.java的以下方法

protected Boolean hasPermission(
            PermissionChecker permissionChecker, String className, long classPK,
            String actionId)
        throws PortalException, SystemException {...}

因此,在实现自定义解决方案时当我们说 subscriptionSender.flushNotificationsAsync() 时,它不会为文件夹发送电子邮件,因为 hasPermisson 返回 false

由于 Liferay 不支持添加/更新/删除文件夹的电子邮件订阅,因此我们必须实现自己的解决方案。

以下是实现此功能的步骤。

1) 创建一个钩子(Hook)并重写 addFolderupdateFoldermoveFolderToTrash 方法的 DLAppService。 这里我将展示如何添加文件夹订阅,其余相同。

@Override
    public Folder addFolder(long repositoryId, long parentFolderId,
        String name, String description, ServiceContext serviceContext)
        throws PortalException, SystemException {

    Folder folder = null;

    folder =
        super
            .addFolder(
                repositoryId, parentFolderId, name, description,
                serviceContext);

    MySubscriptionUtil.notifySubscribersForFolders(
        folder, serviceContext, MyDLConstants.EVENT_TYPE_ADD);

    return folder;
}

2) 这里MySubcriptionUtil是一个使用静态方法创建的实用程序类。

现在在 notifySubscribersForFolders 方法中,使用文件夹对象,然后通过设置所需数据创建 subscriptionSender 对象。 例如:

SubscriptionSender subscriptionSender = new SubscriptionSender();

subscriptionSender.setCompanyId(folder.getCompanyId());
subscriptionSender.setContextAttributes(
    "[$FOLDER_NAME$]", folder.getName(), "[$PARENT_FOLDER_NAME$]",
    parentFolderName, "[$SITE$]", group.getDescriptiveName());
subscriptionSender.setContextUserPrefix("FOLDER");
subscriptionSender.setFrom(fromAddress, fromName);
subscriptionSender.setHtmlFormat(true);
subscriptionSender.setBody(body);
subscriptionSender.setSubject(subject);
subscriptionSender.setMailId("folder", folder.getFolderId());
subscriptionSender.setPortletId(PortletKeys.DOCUMENT_LIBRARY);
subscriptionSender.setReplyToAddress(fromAddress);
subscriptionSender.setScopeGroupId(folder.getGroupId());
subscriptionSender.setServiceContext(serviceContext);
subscriptionSender.setUserId(folder.getUserId());

3)现在使用 addRuntimeSubscribers() 而不是 addPersistedSubscribers() ,原因如上所述,即由于权限检查问题。 在此之前,请使用动态查询从订阅表中获取文件夹订阅。

    List<Long> folderIds //set this list with all parents folder ids of the folder

    // adding group id for parent folder
    /*
    * This is the default parent of any folder.
    * So if user is subscribed to home folder then 
    * he will have entry in subscription table with classPK as groupId
    */
    folderIds.add(folder.getGroupId());

    long classNameId = PortalUtil.getClassNameId(Folder.class.getName());

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(Subscription.class);
    dynamicQuery.add(RestrictionsFactoryUtil.in("classPK", folderIds));
    dynamicQuery
        .add(RestrictionsFactoryUtil.eq("classNameId", classNameId));

    List<Subscription> subscriptionList =
        SubscriptionLocalServiceUtil.dynamicQuery(dynamicQuery);

    for(Subscription subscription : subscriptionList) {
        try {
            User user =
                UserLocalServiceUtil.getUser(subscription.getUserId());

            if(user.isActive()) {

                if(_log.isDebugEnabled()) {
                    _log.debug("User added to subscription list : "
                        + user.getEmailAddress());
                }

                /*
                * This is the key method call as this adds all the 
                *users to whom we need to send an email.
                */
                subscriptionSender.addRuntimeSubscribers(
                    user.getEmailAddress(), user.getFirstName()
                        + StringPool.SPACE + user.getLastName());
            }
        }
        catch(Exception e) {
            _log.error("Exception occured while fetching user @_notifySubscribersForFolders : "
                + e.getMessage());
        }
    }

    //This is the last call which will trigger the send email event
    subscriptionSender.flushNotificationsAsync();

关于liferay - 订阅Liferay 6.2中添加/更新/删除文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27754398/

相关文章:

Liferay - 使用第三方库不起作用

java - <C :if/Choose/When> condition to be made as one 的多个实例

java - LIferay 中的 Portlet 未保存到数据库会引发 InvocableTargetException

java - 如何解析: IllegalStateException: Config is null,请确保你的init(config)方法调用了super.init(config)

css - Liferay 禁用 AlloyUI 并仅使用 bootstrap.css

tomcat - 在 8080 端口打开 Tomcat 页面时出错

java - 有人试过在 HP-UX 上安装 Liferay Portal CE 吗?

tomcat - 无法从 Liferay Web 表单发送电子邮件

css - 在 Liferay portlet 中定位表单控件(使用 bootstrap 或其他)

themes - 是否可以将 Liferay 的版本号传递到主题的 Velocity 模板中?