From 757496970caeb4c940c09d080e35c05f45a39367 Mon Sep 17 00:00:00 2001 From: Craig Tan Date: Wed, 31 Jul 2013 04:46:14 +0000 Subject: [PATCH] RM-737 RM rule compensating JS scripts ... * Added a new patch RMv21BehaviorScriptsPatch that creates the new "Records Management Behavior Scripts" folder and moves existing behavior scripts from the old "Records Management Scripts" folder to the new folder. * Removed rma_isClosed.js from being created in bootstrap from 2.1 onwards. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@53438 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../bootstrap/RMDataDictionaryBootstrap.xml | 33 ++-- .../rm-patch-context.xml | 13 ++ .../RecordsManagementServiceImpl.java | 4 +- .../patch/RMv21BehaviorScriptsPatch.java | 178 ++++++++++++++++++ 4 files changed, 208 insertions(+), 20 deletions(-) create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/RMv21BehaviorScriptsPatch.java 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 e0bab16f9c..292c4e6485 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 @@ -69,33 +69,19 @@ - + workspace SpacesStore - rm_scripts - Records Management Scripts - Records Management Scripts + rm_behavior_scripts + Records Management Behavior Scripts + Records Management Behavior 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 - - - @@ -113,6 +99,17 @@ + + + workspace + SpacesStore + rm_scripts + Records Management Scripts + Records Management Scripts + Scripts specific to RM that can also be executed by RM rules. + + + workspace diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-patch-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-patch-context.xml index f248d27a92..794995df4a 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-patch-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-patch-context.xml @@ -164,4 +164,17 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementServiceImpl.java index 11fdaa1180..b53f78eb80 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementServiceImpl.java @@ -35,9 +35,9 @@ import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementCustomM import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService; import org.alfresco.module.org_alfresco_module_rm.util.ServiceBaseImpl; +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.service.cmr.repository.ChildAssociationRef; @@ -85,7 +85,7 @@ public class RecordsManagementServiceImpl extends ServiceBaseImpl private PolicyComponent policyComponent; /** Well-known location of the scripts folder. */ - private NodeRef scriptsFolderNodeRef = new NodeRef("workspace", "SpacesStore", "rm_scripts"); + private NodeRef scriptsFolderNodeRef = new NodeRef("workspace", "SpacesStore", "rm_behavior_scripts"); /** Java behaviour */ private JavaBehaviour onChangeToDispositionActionDefinition; diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/RMv21BehaviorScriptsPatch.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/RMv21BehaviorScriptsPatch.java new file mode 100644 index 0000000000..b05ad11336 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/RMv21BehaviorScriptsPatch.java @@ -0,0 +1,178 @@ +/* + * Copyright (C) 2005-2013 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.module.org_alfresco_module_rm.patch; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.model.ContentModel; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; +import org.alfresco.repo.transaction.RetryingTransactionHelper; +import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; +import org.alfresco.service.cmr.model.FileFolderService; +import org.alfresco.service.cmr.model.FileInfo; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.BeanNameAware; + +/** + * This patch creates a new "Records Management Behavior Scripts" folder and moves existing behavior scripts from the old "Records Management Scripts" folder to the new folder. + * This is to compensate for any non-behavior RM scripts so that they can live in the old "Records Management Scripts" folder for its intended purpose and be picked up by the + * execute script rule action. + * + * @author Craig Tan + * @since 2.1 + */ +public class RMv21BehaviorScriptsPatch extends ModulePatchComponent implements BeanNameAware +{ + /** logger */ + private static Log logger = LogFactory.getLog(RMv21BehaviorScriptsPatch.class); + + /** rm config folder root lookup */ + protected static final NodeRef RM_CONFIG = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "rm_config_folder"); + + /** old behavior scripts folder root lookup */ + protected static final NodeRef OLD_BEHAVIOR_SCRIPTS_FOLDER = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "rm_scripts"); + + /** new behavior scripts folder root lookup */ + protected static NodeRef newBehaviorScriptsFolder = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "rm_behavior_scripts"); + + /** Node Service */ + private NodeService nodeService; + + /** File Folder Service */ + private FileFolderService fileFolderService; + + private RetryingTransactionHelper retryingTransactionHelper; + + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } + + public void setFileFolderService(FileFolderService fileFolderService) + { + this.fileFolderService = fileFolderService; + } + + public void setRetryingTransactionHelper(RetryingTransactionHelper retryingTransactionHelper) + { + this.retryingTransactionHelper = retryingTransactionHelper; + } + + @Override + protected void executePatch() throws Throwable + { + if (logger.isDebugEnabled() == true) + { + logger.debug("RM module: RMv21BehaviorScriptsPatch executing ..."); + } + + // check that the rm config root has been correctly bootstrapped + if (nodeService.exists(RM_CONFIG) == false) + { + throw new AlfrescoRuntimeException("Unable to complete the patch because RM config root folder does not exist in the data dictionary."); + } + + // check that the behavior scripts folder exists + if (nodeService.exists(newBehaviorScriptsFolder) == false) + { + if (logger.isDebugEnabled() == true) + { + logger.debug(" ... creating RM Behavior Scripts folder"); + } + + String newBehaviorScriptsFolderName = "Records Management Behavior Scripts"; + String newBehaviorScriptsNodeUUID = "rm_behavior_scripts"; + String newBehaviorScriptsAssocQName = "records_management_behavior_scripts"; + + Map newBehaviorScriptsFolderProps = new HashMap(); + newBehaviorScriptsFolderProps.put(ContentModel.PROP_NODE_UUID, newBehaviorScriptsNodeUUID); + newBehaviorScriptsFolderProps.put(ContentModel.PROP_NAME, newBehaviorScriptsFolderName); + newBehaviorScriptsFolderProps.put(ContentModel.PROP_TITLE, newBehaviorScriptsFolderName); + newBehaviorScriptsFolderProps.put(ContentModel.PROP_DESCRIPTION, "Scripts intended for execution in response to RM events."); + + newBehaviorScriptsFolder = nodeService.createNode(RM_CONFIG, ContentModel.ASSOC_CONTAINS, + QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, newBehaviorScriptsAssocQName), + ContentModel.TYPE_FOLDER, newBehaviorScriptsFolderProps).getChildRef(); + } + + // move to the new behavior scripts folder if the old behavior scripts folder exists and contains files + if (nodeService.exists(OLD_BEHAVIOR_SCRIPTS_FOLDER) == true) + { + + // run the following code as System + AuthenticationUtil.runAs(new RunAsWork() + { + public Object doWork() + { + RetryingTransactionCallback callback = new RetryingTransactionCallback() + { + public Void execute() throws Throwable + { + // Update the description of the old Scripts folder. + nodeService.setProperty(OLD_BEHAVIOR_SCRIPTS_FOLDER, ContentModel.PROP_DESCRIPTION, "Scripts specific to RM that can also be executed by RM rules."); + + // Move files from RM Scripts folder to RM Behavior Scripts folder. + List oldBehaviorScripts = fileFolderService.listFiles(OLD_BEHAVIOR_SCRIPTS_FOLDER); + + if (oldBehaviorScripts != null && oldBehaviorScripts.isEmpty() != true) + { + if (logger.isDebugEnabled() == true) + { + logger.debug(" ... moving files from RM Scripts folder to RM Behavior Scripts folder"); + } + + for (FileInfo script : oldBehaviorScripts) + { + fileFolderService.moveFrom(script.getNodeRef(), OLD_BEHAVIOR_SCRIPTS_FOLDER, RMv21BehaviorScriptsPatch.newBehaviorScriptsFolder, script.getName()); + + if (logger.isDebugEnabled() == true) + { + logger.debug(" ...... moved " + script.getName()); + } + } + } + return null; + } + }; + + retryingTransactionHelper.doInTransaction(callback); + return null; + } + }, AuthenticationUtil.getSystemUserName()); + + } + + if (logger.isDebugEnabled() == true) + { + logger.debug(" ... complete"); + } + } + +}