liferay - 以编程方式将文件添加到liferay中的文档和媒体文件夹时如何向订阅者发送电子邮件通知
问题描述
我有多个具有管理员角色的用户订阅了一个存储某种图像和文档的公共文件夹。当一个用户在文件夹中添加一些图像时,会向具有查看权限的订阅用户发送一封通知电子邮件。当我通过门户上传图像时,我的问题从这里开始,电子邮件通知已成功发送。但是,当我尝试使用以下代码保存图像时,不会发送电子邮件通知。
**
_dlAppLocalService.addFileEntry(userId, companyGroup.getGroupId(), folder.getFolderId(), fileName,
ContentTypes.TEXT_CSV_UTF8, fileContent.getBytes(), serviceContext);
**
为了进一步解释:- 这个特定的代码是在调度内部触发的,所以我正在创建 ServiceContext,如下所示:-
long companyId = _portal.getDefaultCompanyId();
Company company = _companyLocalService.getCompany(companyId);
Group companyGroup = _groupLocalService.getCompanyGroup(companyId);
User defaultUser = company.getDefaultUser();
long userId = defaultUser.getUserId();
ServiceContext serviceContext = new ServiceContext();
serviceContext.setCompanyId(companyId);
serviceContext.setUserId(userId);
然后在上述方法中传递服务上下文。我发现com.liferay.portlet.documentlibrary.util.DLImpl.startWorkflowInstance(long, DLFileVersion, String, ServiceContext)中的 request 和 themeDisplay 为 null,这会导致 blankEntryURL 和com.liferay.portlet.documentlibrary.service.impl。 DLAppHelperLocalServiceImpl.notifySubscribers(long, FileVersion, String, ServiceContext ) 方法执行失败。
任何人都可以帮忙吗?如何在没有 themeDisplay 和 request 对象的情况下获取文件 entryURL?
解决方案
您可以避免entryURL
在调用之前添加以下行空白addFileEntry()
:
serviceContext.setAttribute("entryURL", "anyNotEmptyURL");
notifySubscribers()
但是方法运行到最后是不够的。您需要添加另一行代码:
serviceContext.setCommand(Constants.ADD);
除非有适当的命令值,否则通知将被中止。
推荐阅读
- react-native - 如何在tcomb中输入按钮反应原生
- php - 使用正则表达式计算具有某些内容的 php 脚本
- reactjs - 没有为 antd 菜单选项加载 CSS
- ruby-on-rails - Ruby 将参数传递给构造函数,使其行为类似于动态方法
- reporting-services - 如何设置不同的 SSRS 图表图例文本颜色
- javascript - 使用 FileReader 的 onload 函数的返回值
- sql - 如何在一列下获得一个月中的天数,并在不同列中显示不同的月份
- java - 在 Windows 上运行 JavaFX 应用程序时出错
- python - 如何在 Pytransitions 中向现有状态对象添加标签?
- account-kit - Facebook 帐户工具包已弃用