diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-job-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-job-context.xml
index 8244f87e89..eb2184ea87 100644
--- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-job-context.xml
+++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-job-context.xml
@@ -29,6 +29,7 @@
+
@@ -78,7 +79,7 @@
- 0 0/15 * * * ?
+ 0 0/15 * * * ?
diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml
index 4f1d02dde2..27155d7460 100644
--- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml
+++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml
@@ -856,6 +856,7 @@
+
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/notification/RecordsManagementNotificationHelper.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/notification/RecordsManagementNotificationHelper.java
index 73e42eb40e..0f03dcdc75 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/notification/RecordsManagementNotificationHelper.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/notification/RecordsManagementNotificationHelper.java
@@ -22,7 +22,9 @@ import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService;
import org.alfresco.module.org_alfresco_module_rm.security.RecordsManagementSecurityService;
import org.alfresco.module.org_alfresco_module_rm.security.Role;
@@ -35,10 +37,14 @@ import org.alfresco.service.cmr.notification.NotificationService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.SearchService;
+import org.alfresco.service.cmr.security.AuthorityService;
+import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.util.ParameterCheck;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.surf.util.I18NUtil;
/**
@@ -49,6 +55,8 @@ import org.springframework.extensions.surf.util.I18NUtil;
*/
public class RecordsManagementNotificationHelper
{
+ private static Log logger = LogFactory.getLog(RecordsManagementNotificationHelper.class);
+
/** I18n */
private static final String MSG_SUBJECT_RECORDS_DUE_FOR_REVIEW = "notification.dueforreview.subject";
private static final String MSG_SUBJECT_RECORD_SUPERCEDED = "notification.superseded.subject";
@@ -64,6 +72,7 @@ public class RecordsManagementNotificationHelper
private SearchService searchService;
private NamespaceService namespaceService;
private SiteService siteService;
+ private AuthorityService authorityService;
/** Notification role */
private String notificationRole;
@@ -137,6 +146,14 @@ public class RecordsManagementNotificationHelper
this.siteService = siteService;
}
+ /**
+ * @param authorityService authority service
+ */
+ public void setAuthorityService(AuthorityService authorityService)
+ {
+ this.authorityService = authorityService;
+ }
+
/**
* @return superseded email template
*/
@@ -177,22 +194,34 @@ public class RecordsManagementNotificationHelper
if (records.isEmpty() == false)
{
NodeRef root = getRMRoot(records.get(0));
+ String groupName = getGroupName(root);
- NotificationContext notificationContext = new NotificationContext();
- notificationContext.setSubject(I18NUtil.getMessage(MSG_SUBJECT_RECORDS_DUE_FOR_REVIEW));
- notificationContext.setAsyncNotification(false);
- notificationContext.setIgnoreNotificationFailure(true);
-
- notificationContext.setBodyTemplate(getDueForReviewTemplate());
- Map args = new HashMap(1, 1.0f);
- args.put("records", (Serializable)records);
- args.put("site", getSiteName(root));
- notificationContext.setTemplateArgs(args);
-
- String groupName = getGroupName(root);
- notificationContext.addTo(groupName);
-
- notificationService.sendNotification(EMailNotificationProvider.NAME, notificationContext);
+ if (doesGroupContainUsers(groupName) == true)
+ {
+ NotificationContext notificationContext = new NotificationContext();
+ notificationContext.setSubject(I18NUtil.getMessage(MSG_SUBJECT_RECORDS_DUE_FOR_REVIEW));
+ notificationContext.setAsyncNotification(false);
+ notificationContext.setIgnoreNotificationFailure(true);
+
+ notificationContext.setBodyTemplate(getDueForReviewTemplate());
+ Map args = new HashMap(1, 1.0f);
+ args.put("records", (Serializable)records);
+ args.put("site", getSiteName(root));
+ notificationContext.setTemplateArgs(args);
+
+ notificationContext.addTo(groupName);
+
+ notificationService.sendNotification(EMailNotificationProvider.NAME, notificationContext);
+ }
+ else
+ {
+ if (logger.isWarnEnabled() == true)
+ {
+ logger.warn("Unable to send record due for review email notification, because notification group was empty.");
+ }
+
+ throw new AlfrescoRuntimeException("Unable to send record due for review email notification, because notification group was empty.");
+ }
}
}
@@ -206,22 +235,34 @@ public class RecordsManagementNotificationHelper
ParameterCheck.mandatory("record", record);
NodeRef root = getRMRoot(record);
-
- NotificationContext notificationContext = new NotificationContext();
- notificationContext.setSubject(I18NUtil.getMessage(MSG_SUBJECT_RECORD_SUPERCEDED));
- notificationContext.setAsyncNotification(false);
- notificationContext.setIgnoreNotificationFailure(true);
-
- notificationContext.setBodyTemplate(supersededTemplate);
- Map args = new HashMap(1, 1.0f);
- args.put("record", record);
- args.put("site", getSiteName(root));
- notificationContext.setTemplateArgs(args);
-
String groupName = getGroupName(root);
- notificationContext.addTo(groupName);
- notificationService.sendNotification(EMailNotificationProvider.NAME, notificationContext);
+ if (doesGroupContainUsers(groupName) == true)
+ {
+ NotificationContext notificationContext = new NotificationContext();
+ notificationContext.setSubject(I18NUtil.getMessage(MSG_SUBJECT_RECORD_SUPERCEDED));
+ notificationContext.setAsyncNotification(false);
+ notificationContext.setIgnoreNotificationFailure(true);
+
+ notificationContext.setBodyTemplate(supersededTemplate);
+ Map args = new HashMap(1, 1.0f);
+ args.put("record", record);
+ args.put("site", getSiteName(root));
+ notificationContext.setTemplateArgs(args);
+
+ notificationContext.addTo(groupName);
+
+ notificationService.sendNotification(EMailNotificationProvider.NAME, notificationContext);
+ }
+ else
+ {
+ if (logger.isWarnEnabled() == true)
+ {
+ logger.warn("Unable to send record superseded email notification, because notification group was empty.");
+ }
+
+ throw new AlfrescoRuntimeException("Unable to send record superseded email notification, because notification group was empty.");
+ }
}
/**
@@ -259,7 +300,20 @@ public class RecordsManagementNotificationHelper
{
// Find the authority for the given role
Role role = securityService.getRole(root, notificationRole);
- return role.getRoleGroupName();
+ return role.getRoleGroupName();
+ }
+ }, AuthenticationUtil.getSystemUserName());
+ }
+
+ private boolean doesGroupContainUsers(final String groupName)
+ {
+ return AuthenticationUtil.runAs(new RunAsWork()
+ {
+ @Override
+ public Boolean doWork() throws Exception
+ {
+ Set users = authorityService.getContainedAuthorities(AuthorityType.USER, groupName, true);
+ return !users.isEmpty();
}
}, AuthenticationUtil.getSystemUserName());
}