From fb2a90ff29855df5247c2197e2c27e006077061c Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Fri, 1 Feb 2013 14:36:56 +0000 Subject: [PATCH] RM-581 (A user will receive notification of rejected records) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@46138 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../bootstrap/RMDataDictionaryBootstrap.xml | 289 +++++++++--------- .../content/record-rejected-email.ftl | 120 ++++++++ .../messages/notification-service.properties | 3 +- .../rm-service-context.xml | 2 +- .../RecordsManagementNotificationHelper.java | 184 +++++++---- .../patch/NotificationTemplatePatch.java | 60 ++-- .../record/RecordServiceImpl.java | 39 +-- 7 files changed, 441 insertions(+), 256 deletions(-) create mode 100644 rm-server/config/alfresco/module/org_alfresco_module_rm/bootstrap/content/record-rejected-email.ftl diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/bootstrap/RMDataDictionaryBootstrap.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/bootstrap/RMDataDictionaryBootstrap.xml index 2b0850d14f..ab0eab9ccb 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/bootstrap/RMDataDictionaryBootstrap.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/bootstrap/RMDataDictionaryBootstrap.xml @@ -1,28 +1,28 @@ - - + - - + + workspace SpacesStore rm_config_folder @@ -30,15 +30,15 @@ Records Management Configuration information for the Records Management application. - + - + - + workspace SpacesStore rm_event_config @@ -49,11 +49,11 @@ - + - + workspace SpacesStore records_management_custom_model @@ -61,118 +61,133 @@ contentUrl=classpath:alfresco/module/org_alfresco_module_rm/bootstrap/content/recordsCustomModel.xml|mimetype=text/plain|encoding=UTF-8 recordsCustomModel.xml recordsCustomModel.xml - {http://www.alfresco.org/model/rmcustom/1.0}rmcustom - Records Management Custom Model - Alfresco - 1.0 - true - - - - - - - workspace - SpacesStore - rm_scripts - Records Management Scripts - Records Management Scripts - Scripts intended for execution in response to RM events. - - - - - - - - - - workspace - SpacesStore - Records management sample script. - contentUrl=classpath:alfresco/module/org_alfresco_module_rm/bootstrap/content/rma_isClosed.js|mimetype=text/javascript|encoding=UTF-8 - rma_isClosed.js - rma_isClosed.js - - - - - - - - - workspace - SpacesStore - Records management sample script. - contentUrl=classpath:alfresco/module/org_alfresco_module_rm/bootstrap/content/onCreate_supersedes.js|mimetype=text/javascript|encoding=UTF-8 - onCreate_supersedes.js - onCreate_supersedes.js - - - - - - - - - - workspace - SpacesStore - records_management_email_templates - Records Management Email Templates - Records Management Email Templates - Email templates for records management. - - - - - - - - - - - - - - true - - Email template for notify records due for review job. - contentUrl=classpath:alfresco/module/org_alfresco_module_rm/bootstrap/content/notify-records-due-for-review-email.ftl|mimetype=text/plain|size=|encoding=UTF-8|locale=en_US_ - notify-records-due-for-review-email.ftl - - notify-records-due-for-review-email.ftl - org_alfresco_module_rm_notificationTemplatePatch - - - - - - - - - - - - workspace - SpacesStore - record_superseded_template - Record superseded email template. - contentUrl=classpath:alfresco/module/org_alfresco_module_rm/bootstrap/content/record-superseded-email.ftl|mimetype=text/plain|encoding=UTF-8 - record-superseded-email.ftl - record-superseded-email.ftl - org_alfresco_module_rm_notificationTemplatePatch - - - - - - + {http://www.alfresco.org/model/rmcustom/1.0}rmcustom + Records Management Custom Model + Alfresco + 1.0 + true + + + + + + workspace + SpacesStore + rm_scripts + Records Management Scripts + Records Management Scripts + Scripts intended for execution in response to RM events. + + + + + + + + + + workspace + SpacesStore + Records management sample script. + contentUrl=classpath:alfresco/module/org_alfresco_module_rm/bootstrap/content/rma_isClosed.js|mimetype=text/javascript|encoding=UTF-8 + rma_isClosed.js + rma_isClosed.js + + + + + + + + + workspace + SpacesStore + Records management sample script. + contentUrl=classpath:alfresco/module/org_alfresco_module_rm/bootstrap/content/onCreate_supersedes.js|mimetype=text/javascript|encoding=UTF-8 + onCreate_supersedes.js + onCreate_supersedes.js + + + + + + + + + workspace + SpacesStore + records_management_email_templates + Records Management Email Templates + Records Management Email Templates + Email templates for records management. + + + + + + + + + + + + + + true + + Email template for notify records due for review job. + contentUrl=classpath:alfresco/module/org_alfresco_module_rm/bootstrap/content/notify-records-due-for-review-email.ftl|mimetype=text/plain|size=|encoding=UTF-8|locale=en_US_ + notify-records-due-for-review-email.ftl + + notify-records-due-for-review-email.ftl + org_alfresco_module_rm_notificationTemplatePatch + + + + + + + + + + + + workspace + SpacesStore + record_superseded_template + Record superseded email template. + contentUrl=classpath:alfresco/module/org_alfresco_module_rm/bootstrap/content/record-superseded-email.ftl|mimetype=text/plain|encoding=UTF-8 + record-superseded-email.ftl + record-superseded-email.ftl + org_alfresco_module_rm_notificationTemplatePatch + + + + + + + + + + + workspace + SpacesStore + record_rejected_template + Record rejected email template. + contentUrl=classpath:alfresco/module/org_alfresco_module_rm/bootstrap/content/record-rejected-email.ftl|mimetype=text/plain|encoding=UTF-8 + record-rejected-email.ftl + record-rejected-email.ftl + org_alfresco_module_rm_notificationTemplatePatch + + + + + - + - + \ No newline at end of file diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/bootstrap/content/record-rejected-email.ftl b/rm-server/config/alfresco/module/org_alfresco_module_rm/bootstrap/content/record-rejected-email.ftl new file mode 100644 index 0000000000..98702e42dc --- /dev/null +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/bootstrap/content/record-rejected-email.ftl @@ -0,0 +1,120 @@ + + + + + + + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + +
+ + +
+ Record has been rejected +
+
+ ${args.rejectDate?datetime?string.full} +
+
+
+

Hello ${args.userName},

+ +

${args.rejectedPerson} has rejected the following record with this reason:

+ +

${args.rejectReason}

+ + + + + + +
+ + + + + +
+ + + + + + + + + + + + +
${args.record.properties["rma:identifier"]!} ${args.record.name}
Click on this link to view the record:
+ + ${shareUrl}/page/site/${args.site}/document-details?nodeRef=${args.record.storeType}://${args.record.storeId}/${args.record.id} +
+
+
+ +

Sincerely,
+ Alfresco ${productName!""}

+
+
+
+
 
+
+ To find out more about Alfresco ${productName!""} visit http://www.alfresco.com +
+
 
+
+ +
+
+
+ + diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/messages/notification-service.properties b/rm-server/config/alfresco/module/org_alfresco_module_rm/messages/notification-service.properties index 60d1ffdc22..c669b641a6 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/messages/notification-service.properties +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/messages/notification-service.properties @@ -1,2 +1,3 @@ notification.dueforreview.subject=Records Due For Review Notification -notification.superseded.subject=Record Superseded Notification \ No newline at end of file +notification.superseded.subject=Record Superseded Notification +notification.rejected.subject=Record Rejected Notification \ No newline at end of file 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 9b4287d051..c74120979d 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 @@ -1101,7 +1101,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 0c35b8973a..597d2cbb59 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 @@ -19,6 +19,7 @@ package org.alfresco.module.org_alfresco_module_rm.notification; import java.io.Serializable; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -26,6 +27,7 @@ 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.model.RecordsManagementModel; import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService; import org.alfresco.module.org_alfresco_module_rm.role.Role; import org.alfresco.repo.notification.EMailNotificationProvider; @@ -46,6 +48,7 @@ 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.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.extensions.surf.util.I18NUtil; @@ -53,17 +56,18 @@ import org.springframework.extensions.surf.util.I18NUtil; /** * Helper bean containing methods useful when sending records * management notifications via the {@link NotificationService} - * + * * @author Roy Wetherall */ -public class RecordsManagementNotificationHelper +public class RecordsManagementNotificationHelper implements RecordsManagementModel { 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"; - + private static final String MSG_SUBJECT_RECORD_REJECTED = "notification.rejected.subject"; + /** Defaults */ private static final String DEFAULT_SITE = "rm"; @@ -77,14 +81,15 @@ public class RecordsManagementNotificationHelper private AuthorityService authorityService; private TenantAdminService tenantAdminService; private NodeService nodeService; - + /** Notification role */ private String notificationRole; - + /** EMail notification templates */ private NodeRef supersededTemplate = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "record_superseded_template"); private NodeRef dueForReviewTemplate; - + private NodeRef rejectedTemplate = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "record_rejected_template"); + /** * @param notificationService notification service */ @@ -92,7 +97,7 @@ public class RecordsManagementNotificationHelper { this.notificationService = notificationService; } - + /** * @param recordsManagementService rm service */ @@ -100,7 +105,7 @@ public class RecordsManagementNotificationHelper { this.recordsManagementService = recordsManagementService; } - + /** * @param filePlanRoleService file plan role service */ @@ -108,7 +113,7 @@ public class RecordsManagementNotificationHelper { this.filePlanRoleService = filePlanRoleService; } - + /** * @param notificationRole rm notification role */ @@ -116,7 +121,7 @@ public class RecordsManagementNotificationHelper { this.notificationRole = notificationRole; } - + /** * @param searchService search service */ @@ -124,7 +129,7 @@ public class RecordsManagementNotificationHelper { this.searchService = searchService; } - + /** * @param namespaceService namespace service */ @@ -132,7 +137,7 @@ public class RecordsManagementNotificationHelper { this.namespaceService = namespaceService; } - + /** * @param siteService site service */ @@ -140,7 +145,7 @@ public class RecordsManagementNotificationHelper { this.siteService = siteService; } - + /** * @param authorityService authority service */ @@ -148,7 +153,7 @@ public class RecordsManagementNotificationHelper { this.authorityService = authorityService; } - + /** * @param nodeService node service */ @@ -156,7 +161,7 @@ public class RecordsManagementNotificationHelper { this.nodeService = nodeService; } - + /** * @param tenantAdminService tenant admin service */ @@ -164,7 +169,7 @@ public class RecordsManagementNotificationHelper { this.tenantAdminService = tenantAdminService; } - + /** * @return superseded email template */ @@ -172,7 +177,15 @@ public class RecordsManagementNotificationHelper { return supersededTemplate; } - + + /** + * @return rejected email template + */ + public NodeRef getRejectedTemplate() + { + return rejectedTemplate; + } + /** * @return due for review email template */ @@ -180,11 +193,11 @@ public class RecordsManagementNotificationHelper { if (dueForReviewTemplate == null) { - List nodeRefs = + List nodeRefs = searchService.selectNodes( - getRootNode(), - "app:company_home/app:dictionary/cm:records_management/cm:records_management_email_templates/cm:notify-records-due-for-review-email.ftl", null, - namespaceService, + getRootNode(), + "app:company_home/app:dictionary/cm:records_management/cm:records_management_email_templates/cm:notify-records-due-for-review-email.ftl", null, + namespaceService, false); if (nodeRefs.size() == 1) { @@ -193,10 +206,10 @@ public class RecordsManagementNotificationHelper } return dueForReviewTemplate; } - + /** * Helper method to get root node in a tenant safe way. - * + * * @return NodeRef root node of spaces store */ private NodeRef getRootNode() @@ -205,15 +218,15 @@ public class RecordsManagementNotificationHelper return TenantUtil.runAsSystemTenant(new TenantRunAsWork() { public NodeRef doWork() throws Exception - { + { return nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); } }, tenantDomain); } - + /** * Sends records due for review email notification. - * + * * @param records records due for review */ public void recordsDueForReviewEmailNotification(final List records) @@ -222,23 +235,23 @@ public class RecordsManagementNotificationHelper if (records.isEmpty() == false) { NodeRef root = getRMRoot(records.get(0)); - String groupName = getGroupName(root); - + String groupName = getGroupName(root); + 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("records", (Serializable)records); args.put("site", getSiteName(root)); notificationContext.setTemplateArgs(args); - - notificationContext.addTo(groupName); - + + notificationContext.addTo(groupName); + notificationService.sendNotification(EMailNotificationProvider.NAME, notificationContext); } else @@ -247,39 +260,39 @@ public class RecordsManagementNotificationHelper { 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."); } } - } - + } + /** * Sends record superseded email notification. - * + * * @param record superseded record */ public void recordSupersededEmailNotification(final NodeRef record) { - ParameterCheck.mandatory("record", record); - + ParameterCheck.mandatory("record", record); + NodeRef root = getRMRoot(record); String groupName = getGroupName(root); - + 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("record", record); args.put("site", getSiteName(root)); notificationContext.setTemplateArgs(args); - - notificationContext.addTo(groupName); - + + notificationContext.addTo(groupName); + notificationService.sendNotification(EMailNotificationProvider.NAME, notificationContext); } else @@ -290,10 +303,59 @@ public class RecordsManagementNotificationHelper } } } - + + /** + * Sends record rejected email notification. + * + * @param record rejected record + * @param reason reason for rejection + * @param userId the user id who rejected the record + */ + public void recordRejectedEmailNotification(NodeRef record, String reason, String userId) + { + ParameterCheck.mandatory("record", record); + ParameterCheck.mandatoryString("reason", reason); + ParameterCheck.mandatoryString("userId", userId); + + String recordCreator = (String) nodeService.getProperty(record, PROP_RECORD_USER_ID); + if (StringUtils.isNotBlank(recordCreator) == true) + { + SiteInfo site = siteService.getSite(record); + if (site == null) + { + throw new AlfrescoRuntimeException("Could not find the site which should contain the node '" + record.toString() + "'."); + } + + NotificationContext notificationContext = new NotificationContext(); + + notificationContext.addTo(recordCreator); + notificationContext.setSubject(I18NUtil.getMessage(MSG_SUBJECT_RECORD_REJECTED)); + notificationContext.setBodyTemplate(getRejectedTemplate()); + + Map args = new HashMap(6); + args.put("site", site.getShortName()); + args.put("record", record); + args.put("userName", recordCreator); + args.put("rejectReason", reason); + args.put("rejectDate", new Date()); + args.put("rejectedPerson", userId); + + notificationContext.setTemplateArgs(args); + + notificationService.sendNotification(EMailNotificationProvider.NAME, notificationContext); + } + else + { + if (logger.isWarnEnabled() == true) + { + logger.warn("Unable to send record rejected email notification, because notification user was empty."); + } + } + } + /** * Gets the rm root given a context node. - * + * * @param context context node reference * @return {@link NodeRef} rm root node reference */ @@ -305,15 +367,15 @@ public class RecordsManagementNotificationHelper public NodeRef doWork() throws Exception { return recordsManagementService.getFilePlan(context); - + } }, AuthenticationUtil.getSystemUserName()); - + } - + /** * Gets the group name for the notification role. - * + * * @param root rm root node * @return String notification role's group name */ @@ -326,11 +388,11 @@ public class RecordsManagementNotificationHelper { // Find the authority for the given role Role role = filePlanRoleService.getRole(root, notificationRole); - return role.getRoleGroupName(); + return role.getRoleGroupName(); } }, AuthenticationUtil.getSystemUserName()); } - + private boolean doesGroupContainUsers(final String groupName) { return AuthenticationUtil.runAs(new RunAsWork() @@ -343,10 +405,10 @@ public class RecordsManagementNotificationHelper } }, AuthenticationUtil.getSystemUserName()); } - + /** * Get the site name, default if none/undetermined. - * + * * @param root rm root * @return String site name */ @@ -358,16 +420,16 @@ public class RecordsManagementNotificationHelper public String doWork() throws Exception { String result = DEFAULT_SITE; - + SiteInfo siteInfo = siteService.getSite(root); if (siteInfo != null) { result = siteInfo.getShortName(); } - + return result; } }, AuthenticationUtil.getSystemUserName()); - + } } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/NotificationTemplatePatch.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/NotificationTemplatePatch.java index e56439965c..ebc71f78ab 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/NotificationTemplatePatch.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/NotificationTemplatePatch.java @@ -44,36 +44,37 @@ import org.springframework.beans.factory.BeanNameAware; /** * @author Roy Wetherall */ -public class NotificationTemplatePatch extends AbstractModuleComponent +public class NotificationTemplatePatch extends AbstractModuleComponent implements BeanNameAware { /** Last patch update property */ private static final QName PROP_LAST_PATCH_UPDATE = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "lastPatchUpdate"); - + private static final String PATH_DUE_FOR_REVIEW = "alfresco/module/org_alfresco_module_rm/bootstrap/content/notify-records-due-for-review-email.ftl"; private static final String PATH_SUPERSEDED = "alfresco/module/org_alfresco_module_rm/bootstrap/content/record-superseded-email.ftl"; - + private static final String PATH_REJECTED = "alfresco/module/org_alfresco_module_rm/bootstrap/content/record-rejected-email.ftl"; + /** Logger */ private static Log logger = LogFactory.getLog(NotificationTemplatePatch.class); - + /** Records management notification helper */ private RecordsManagementNotificationHelper notificationHelper; - + /** Node service */ private NodeService nodeService; - + /** Content service */ private ContentService contentService; - + /** Version service */ private VersionService versionService; - + /** Audit service */ private AuditService auditService; - + /** Bean name */ private String name; - + /** * @param notificationHelper notification helper */ @@ -81,7 +82,7 @@ public class NotificationTemplatePatch extends AbstractModuleComponent { this.notificationHelper = notificationHelper; } - + /** * @param nodeService node service */ @@ -89,7 +90,7 @@ public class NotificationTemplatePatch extends AbstractModuleComponent { this.nodeService = nodeService; } - + /** * @param contentService content service */ @@ -97,7 +98,7 @@ public class NotificationTemplatePatch extends AbstractModuleComponent { this.contentService = contentService; } - + /** * @param versionService version service */ @@ -105,7 +106,7 @@ public class NotificationTemplatePatch extends AbstractModuleComponent { this.versionService = versionService; } - + /** * @param auditService audit service */ @@ -113,7 +114,7 @@ public class NotificationTemplatePatch extends AbstractModuleComponent { this.auditService = auditService; } - + /** * @see org.alfresco.repo.module.AbstractModuleComponent#setBeanName(java.lang.String) */ @@ -122,7 +123,7 @@ public class NotificationTemplatePatch extends AbstractModuleComponent { this.name = name; } - + /** * @see org.alfresco.repo.module.AbstractModuleComponent#executeInternal() */ @@ -133,17 +134,20 @@ public class NotificationTemplatePatch extends AbstractModuleComponent { logger.debug("RM Module NotificationTemplatePatch ..."); } - + NodeRef supersededTemplate = notificationHelper.getSupersededTemplate(); updateTemplate(supersededTemplate, PATH_SUPERSEDED); - + NodeRef dueForReviewTemplate = notificationHelper.getDueForReviewTemplate(); updateTemplate(dueForReviewTemplate, PATH_DUE_FOR_REVIEW); + + NodeRef rejectedTemplate = notificationHelper.getRejectedTemplate(); + updateTemplate(rejectedTemplate, PATH_REJECTED); } - + /** * Attempt to update the template with the updated version - * + * * @param template * @param updatedTemplate */ @@ -159,7 +163,7 @@ public class NotificationTemplatePatch extends AbstractModuleComponent else { System.out.println(nodeService.getProperty(template, ContentModel.PROP_DESCRIPTION)); - + // Check to see if this template has already been updated String lastPatchUpdate = (String)nodeService.getProperty(template, PROP_LAST_PATCH_UPDATE); if (lastPatchUpdate == null || name.equals(lastPatchUpdate) == false) @@ -168,24 +172,24 @@ public class NotificationTemplatePatch extends AbstractModuleComponent { logger.debug("Applying update to template. (template=" + template.toString() + ", templateUpdate=" + templateUpdate + ")"); } - + // Make sure the template is versionable if (nodeService.hasAspect(template, ContentModel.ASPECT_VERSIONABLE) == false) { nodeService.addAspect(template, ContentModel.ASPECT_VERSIONABLE, null); - + // Create version (before template is updated) Map versionProperties = new HashMap(2); - versionProperties.put(Version.PROP_DESCRIPTION, "Initial version"); + versionProperties.put(Version.PROP_DESCRIPTION, "Initial version"); versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR); versionService.createVersion(template, versionProperties); - } - + } + // Update the content of the template InputStream is = getClass().getClassLoader().getResourceAsStream(templateUpdate); ContentWriter writer = contentService.getWriter(template, ContentModel.PROP_CONTENT, true); writer.putContent(is); - + boolean enabled = auditService.isAuditEnabled(); auditService.setAuditEnabled(false); try @@ -206,5 +210,5 @@ public class NotificationTemplatePatch extends AbstractModuleComponent } } } - } + } } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java index aee0a6a005..48d92f2a73 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java @@ -36,20 +36,18 @@ import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; import org.alfresco.module.org_alfresco_module_rm.identifier.IdentifierService; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; +import org.alfresco.module.org_alfresco_module_rm.notification.RecordsManagementNotificationHelper; import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService; import org.alfresco.module.org_alfresco_module_rm.vital.VitalRecordServiceImpl; import org.alfresco.repo.node.NodeServicePolicies; -import org.alfresco.repo.notification.EMailNotificationProvider; +import org.alfresco.repo.policy.Behaviour.NotificationFrequency; import org.alfresco.repo.policy.JavaBehaviour; import org.alfresco.repo.policy.PolicyComponent; -import org.alfresco.repo.policy.Behaviour.NotificationFrequency; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.service.cmr.dictionary.AspectDefinition; import org.alfresco.service.cmr.dictionary.DictionaryService; -import org.alfresco.service.cmr.notification.NotificationContext; -import org.alfresco.service.cmr.notification.NotificationService; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; @@ -57,11 +55,9 @@ import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.namespace.QName; import org.alfresco.util.ParameterCheck; -import org.apache.commons.lang.StringUtils; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; -import org.springframework.mail.MailPreparationException; /** * Record service implementation @@ -101,8 +97,8 @@ public class RecordServiceImpl implements RecordService, /** File plan service */ private FilePlanService filePlanService; - /** Notification service */ - private NotificationService notificationService; + /** Records management notification helper */ + private RecordsManagementNotificationHelper notificationHelper; /** Policy component */ private PolicyComponent policyComponent; @@ -187,11 +183,11 @@ public class RecordServiceImpl implements RecordService, } /** - * @param notificationService notification service + * @param notificationHelper notification helper */ - public void setNotificationService(NotificationService notificationService) + public void setNotificationHelper(RecordsManagementNotificationHelper notificationHelper) { - this.notificationService = notificationService; + this.notificationHelper = notificationHelper; } /** @@ -455,6 +451,9 @@ public class RecordServiceImpl implements RecordService, ParameterCheck.mandatory("NodeRef", nodeRef); ParameterCheck.mandatoryString("Reason", reason); + // Save the id of the currently logged in user + final String userId = AuthenticationUtil.getRunAsUser(); + // do the work of rejecting the record as the system user AuthenticationUtil.runAsSystem(new RunAsWork() { @@ -490,23 +489,7 @@ public class RecordServiceImpl implements RecordService, extendedSecurityService.removeAllExtendedReaders(nodeRef); // Send an email to the record creator - String recordCreator = (String) nodeService.getProperty(nodeRef, PROP_RECORD_USER_ID); - if (StringUtils.isNotBlank(recordCreator)) - { - NotificationContext context = new NotificationContext(); - - context.addTo(recordCreator); - // FIXME: Subject -> i18n - context.setSubject("Record rejected"); - // FIXME: Use email template - context.setBody(reason); - - notificationService.sendNotification(EMailNotificationProvider.NAME, context); - } - else - { - throw new MailPreparationException("The id of the record creator cannot be found!"); - } + notificationHelper.recordRejectedEmailNotification(nodeRef, reason, userId); return null; }