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
This commit is contained in:
Craig Tan
2013-07-31 04:46:14 +00:00
parent f22da8595c
commit 757496970c
4 changed files with 208 additions and 20 deletions

View File

@@ -69,33 +69,19 @@
</view:properties>
</cm:dictionaryModel>
<cm:folder view:childName="cm:records_management_scripts">
<cm:folder view:childName="cm:records_management_behavior_scripts">
<view:properties>
<sys:store-protocol>workspace</sys:store-protocol>
<sys:store-identifier>SpacesStore</sys:store-identifier>
<sys:node-uuid>rm_scripts</sys:node-uuid>
<cm:name>Records Management Scripts</cm:name>
<cm:title>Records Management Scripts</cm:title>
<sys:node-uuid>rm_behavior_scripts</sys:node-uuid>
<cm:name>Records Management Behavior Scripts</cm:name>
<cm:title>Records Management Behavior Scripts</cm:title>
<cm:description>Scripts intended for execution in response to RM events.</cm:description>
</view:properties>
<view:associations>
<cm:contains>
<!-- TODO Will likely remove this script. Here for test purposes.
Or perhaps replace it with a product-ready script -->
<cm:content view:childName="cm:rma_isClosed.js">
<view:aspects>
<cm:titled></cm:titled>
</view:aspects>
<view:properties>
<sys:store-protocol>workspace</sys:store-protocol>
<sys:store-identifier>SpacesStore</sys:store-identifier>
<cm:description>Records management sample script.</cm:description>
<cm:content>contentUrl=classpath:alfresco/module/org_alfresco_module_rm/bootstrap/content/rma_isClosed.js|mimetype=text/javascript|encoding=UTF-8</cm:content>
<cm:title>rma_isClosed.js</cm:title>
<cm:name>rma_isClosed.js</cm:name>
</view:properties>
</cm:content>
<cm:content view:childName="cm:onCreate_supersedes.js">
<view:aspects>
<cm:titled></cm:titled>
@@ -113,6 +99,17 @@
</view:associations>
</cm:folder>
<cm:folder view:childName="cm:records_management_scripts">
<view:properties>
<sys:store-protocol>workspace</sys:store-protocol>
<sys:store-identifier>SpacesStore</sys:store-identifier>
<sys:node-uuid>rm_scripts</sys:node-uuid>
<cm:name>Records Management Scripts</cm:name>
<cm:title>Records Management Scripts</cm:title>
<cm:description>Scripts specific to RM that can also be executed by RM rules.</cm:description>
</view:properties>
</cm:folder>
<cm:folder view:childName="cm:records_management_email_templates">
<view:properties>
<sys:store-protocol>workspace</sys:store-protocol>

View File

@@ -164,4 +164,17 @@
<property name="nodeService" ref="NodeService" />
</bean>
<bean id="org_alfresco_module_rm_RMv21BehaviorScriptsPatch"
parent="module.baseComponent"
class="org.alfresco.module.org_alfresco_module_rm.patch.RMv21BehaviorScriptsPatch">
<property name="moduleId" value="org_alfresco_module_rm"/>
<property name="name" value="org_alfresco_module_rm_RMv21BehaviorScriptsPatch"/>
<property name="description" value="Move existing behavior scripts to their dedicated behavior folder, freeing existing scripts folder up for non-behavior RM scripts."/>
<property name="sinceVersion" value="2.1"/>
<property name="appliesFromVersion" value="2.1"/>
<property name="fileFolderService" ref="FileFolderService"/>
<property name="nodeService" ref="NodeService"/>
<property name="retryingTransactionHelper" ref="retryingTransactionHelper" />
</bean>
</beans>

View File

@@ -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;

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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<QName, Serializable> newBehaviorScriptsFolderProps = new HashMap<QName, Serializable>();
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<Object>()
{
public Object doWork()
{
RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>()
{
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<FileInfo> 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");
}
}
}