在 Liferay 6.2 中订阅 Add/update/delete 个文件夹
Subscribe to Add/update/delete of folder in Liferay 6.2
您好,我想在 Liferay 的文档和媒体 portlet.
中实现文件夹的订阅功能
liferay 提供的当前功能是这样的,如果您订阅任何 folder/parent 文件夹,那么您将收到有关 add/update 个文件的电子邮件,但不会收到文件夹的电子邮件。
因此,如果您将子文件夹添加到订阅的文件夹,您将不会收到任何电子邮件。
感谢您对此提供任何帮助。
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 returns false.
并且由于 Liferay 不支持 Add/update/delete 个文件夹的电子邮件订阅,我们不得不实施我们自己的解决方案。
下面是实现此功能的步骤。
1) 为 addFolder、updateFolder 和 [= 创建一个钩子并覆盖 DLAppService 32=]moveFolderToTrash 方法。
在这里我将展示如何添加文件夹订阅,其余相同。
@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 是一个使用静态方法创建的实用程序 class。
现在在 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(),原因如上文所述,即由于权限检查问题.
在这样做之前,使用动态查询从订阅 table 获取文件夹订阅。
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 的文档和媒体 portlet.
中实现文件夹的订阅功能liferay 提供的当前功能是这样的,如果您订阅任何 folder/parent 文件夹,那么您将收到有关 add/update 个文件的电子邮件,但不会收到文件夹的电子邮件。
因此,如果您将子文件夹添加到订阅的文件夹,您将不会收到任何电子邮件。
感谢您对此提供任何帮助。
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 returns false.
并且由于 Liferay 不支持 Add/update/delete 个文件夹的电子邮件订阅,我们不得不实施我们自己的解决方案。
下面是实现此功能的步骤。
1) 为 addFolder、updateFolder 和 [= 创建一个钩子并覆盖 DLAppService 32=]moveFolderToTrash 方法。 在这里我将展示如何添加文件夹订阅,其余相同。
@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 是一个使用静态方法创建的实用程序 class。
现在在 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(),原因如上文所述,即由于权限检查问题. 在这样做之前,使用动态查询从订阅 table 获取文件夹订阅。
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();