首页 > 解决方案 > 以编程方式将文件添加到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?

标签: liferayliferay-7

解决方案


您可以避免entryURL在调用之前添加以下行空白addFileEntry()

serviceContext.setAttribute("entryURL", "anyNotEmptyURL");

notifySubscribers()但是方法运行到最后是不够的。您需要添加另一行代码:

serviceContext.setCommand(Constants.ADD);

除非有适当的命令值,否则通知将被中止。


推荐阅读