diff --git a/config/alfresco/messages/patch-service.properties b/config/alfresco/messages/patch-service.properties index 2778af6d65..fa2d4d9ccf 100644 --- a/config/alfresco/messages/patch-service.properties +++ b/config/alfresco/messages/patch-service.properties @@ -433,3 +433,6 @@ patch.nodeTemplatesFolder.description=Patch to create new Data Dictionary folder patch.sitesSpacePermissions.description=Patch to remove the EVERYONE Contributor permissions on the Sites Space (parent container of all Sites) patch.sitesSpacePermissions.result=Permissions corrected. + +patch.updateWorkflowNotificationTemplates.description=Patch to update the workflow notification templates. +patch.updateWorkflowNotificationTemplates.result=Workflow Notification Templates successfully updated. diff --git a/config/alfresco/patch/patch-services-context.xml b/config/alfresco/patch/patch-services-context.xml index 34dcf2636b..da713f8db5 100644 --- a/config/alfresco/patch/patch-services-context.xml +++ b/config/alfresco/patch/patch-services-context.xml @@ -3062,5 +3062,17 @@ + + + patch.updateWorkflowNotificationTemplates + patch.updateWorkflowNotificationTemplates.description + 0 + 5018 + 5019 + true + true + + + diff --git a/config/alfresco/version.properties b/config/alfresco/version.properties index 4f2c88b12d..12b733bb04 100644 --- a/config/alfresco/version.properties +++ b/config/alfresco/version.properties @@ -19,4 +19,4 @@ version.build=@build-number@ # Schema number -version.schema=5018 +version.schema=5019 diff --git a/source/java/org/alfresco/repo/admin/patch/impl/UpdateWorkflowNotificationTemplatesPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/UpdateWorkflowNotificationTemplatesPatch.java new file mode 100644 index 0000000000..cd38c5023f --- /dev/null +++ b/source/java/org/alfresco/repo/admin/patch/impl/UpdateWorkflowNotificationTemplatesPatch.java @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2005-2011 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.repo.admin.patch.impl; + +import java.io.InputStream; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.admin.patch.AbstractPatch; +import org.alfresco.repo.workflow.WorkflowNotificationUtils; +import org.alfresco.service.cmr.model.FileFolderService; +import org.alfresco.service.cmr.repository.ContentService; +import org.alfresco.service.cmr.repository.ContentWriter; +import org.alfresco.service.cmr.repository.NodeRef; +import org.springframework.extensions.surf.util.I18NUtil; + +/** + * Update workflow notification templates patch + * + * @author Roy Wetherall + */ +public class UpdateWorkflowNotificationTemplatesPatch extends AbstractPatch +{ + private ContentService contentService; + + private FileFolderService fileFolderService; + + private static final String PATH = "alfresco/bootstrap/notification/"; + private static final String BASE_FILE = "wf-email.html.ftl"; + private static final String DE_FILE = "wf-email.html_de.ftl"; + private static final String ES_FILE = "wf-email.html_es.ftl"; + private static final String FR_FILE = "wf-email.html_fr.ftl"; + private static final String IT_FILE = "wf-email.html_it.ftl"; + private static final String JA_FILE = "wf-email.html_ja.ftl"; + + public void setContentService(ContentService contentService) + { + this.contentService = contentService; + } + + public void setFileFolderService(FileFolderService fileFolderService) + { + this.fileFolderService = fileFolderService; + } + + /** + * @see org.alfresco.repo.admin.patch.AbstractPatch#applyInternal() + */ + @Override + protected String applyInternal() throws Exception + { + NodeRef baseTemplate = WorkflowNotificationUtils.WF_ASSIGNED_TEMPLATE; + if (nodeService.exists(baseTemplate) == true) + { + updateContent(baseTemplate, PATH, BASE_FILE); + updateSiblingContent(baseTemplate, PATH, DE_FILE); + updateSiblingContent(baseTemplate, PATH, ES_FILE); + updateSiblingContent(baseTemplate, PATH, FR_FILE); + updateSiblingContent(baseTemplate, PATH, IT_FILE); + updateSiblingContent(baseTemplate, PATH, JA_FILE); + } + + return I18NUtil.getMessage("patch.updateWorkflowNotificationTemplates.result"); + } + + private void updateSiblingContent(NodeRef nodeRef, String path, String fileName) + { + NodeRef parent = nodeService.getPrimaryParent(nodeRef).getParentRef(); + if (parent != null) + { + NodeRef sibling = fileFolderService.searchSimple(parent, fileName); + if (sibling != null) + { + updateContent(sibling, path, fileName); + } + } + } + + private void updateContent(NodeRef nodeRef, String path, String fileName) + { + // Make versionable + nodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, null); + + // Update content + InputStream is = this.getClass().getClassLoader().getResourceAsStream(path + fileName); + if (is != null) + { + ContentWriter contentWriter = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); + contentWriter.putContent(is); + } + } + +} diff --git a/source/java/org/alfresco/repo/workflow/WorkflowNotificationUtils.java b/source/java/org/alfresco/repo/workflow/WorkflowNotificationUtils.java index 8991edc658..f910d4a5e8 100644 --- a/source/java/org/alfresco/repo/workflow/WorkflowNotificationUtils.java +++ b/source/java/org/alfresco/repo/workflow/WorkflowNotificationUtils.java @@ -60,7 +60,7 @@ public abstract class WorkflowNotificationUtils public static final String ARG_WF_DOCUMENTS = "workflowDocuments"; /** Standard workflow assigned template */ - private static final NodeRef WF_ASSIGNED_TEMPLATE = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "wf-email-html-ftl"); + public static final NodeRef WF_ASSIGNED_TEMPLATE = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "wf-email-html-ftl"); /** *