RM-1098: Refactor RM model behavior into a more maintainable structure

* moved all behaviours out of records management service
  * finally able to deprecate RecordsManagementService (relic of 1.0)
  * did a little repackaging to make things clear



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@58289 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2013-11-26 03:59:43 +00:00
parent a19adffebc
commit 1f0aab4256
15 changed files with 462 additions and 350 deletions

View File

@@ -10,15 +10,19 @@ log4j.logger.org.alfresco.module.org_alfresco_module_rm.security.RMMethodSecurit
log4j.logger.org.alfresco.module.org_alfresco_module_rm.patch=info
#
# RM Permission Debug Information
# RM permission debug
#
#log4j.logger.org.alfresco.module.org_alfresco_module_rm.capability.RMEntryVoter=debug
#log4j.logger.org.alfresco.module.org_alfresco_module_rm.capability.RMAfterInvocationProvider=debug
#log4j.logger.org.alfresco.module.org_alfresco_module_rm.capability.declarative=debug
#log4j.logger.org.alfresco.module.org_alfresco_module_rm.record.RecordServiceImpl=debug
#log4j.logger.org.springframework.extensions.webscripts.ScriptDebugger=on
#
# RM Audit service debug
#
#log4j.logger.org.alfresco.module.org_alfresco_module_rm.audit.RecordsManagementAuditService=debug
log4j.logger.org.alfresco.repo.policy.annotation.AnnotatedBehaviourPostProcessor=debug
log4j.logger.org.alfresco.module.org_alfresco_module_rm.behaviour.BaseBehaviourBean=debug
#
# Behaviour debug
#
#log4j.logger.org.alfresco.repo.policy.annotation.AnnotatedBehaviourPostProcessor=debug
#log4j.logger.org.alfresco.module.org_alfresco_module_rm.behaviour.BaseBehaviourBean=debug

View File

@@ -59,4 +59,78 @@
</property>
</bean>
<!-- Records Management Service -->
<!-- @deprecated As of release 2.2 -->
<bean id="recordsManagementService" class="org.alfresco.module.org_alfresco_module_rm.RecordsManagementServiceImpl">
<property name="recordsManagementServiceRegistry" ref="RecordsManagementServiceRegistry"/>
<property name="nodeService" ref="nodeService"/>
</bean>
<bean id="RecordsManagementService" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>org.alfresco.module.org_alfresco_module_rm.RecordsManagementService</value>
</property>
<property name="target">
<ref bean="recordsManagementService"/>
</property>
<property name="interceptorNames">
<list>
<idref local="RecordsManagementService_transaction"/>
<idref bean="exceptionTranslator"/>
<idref local="RecordsManagementService_security"/>
</list>
</property>
</bean>
<bean id="RecordsManagementService_transaction" parent="baseTransaction"/>
<bean id="RecordsManagementService_security" class="org.alfresco.repo.security.permissions.impl.acegi.MethodSecurityInterceptor">
<property name="authenticationManager">
<ref bean="authenticationManager"/>
</property>
<property name="accessDecisionManager">
<ref bean="accessDecisionManager"/>
</property>
<property name="afterInvocationManager">
<ref bean="afterInvocationManager"/>
</property>
<property name="objectDefinitionSource">
<value>
<![CDATA[
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isFilePlanComponent=RM_ALLOW
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.getFilePlanComponentKind=RM_ALLOW
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.getFilePlanComponentKindFromType=RM_ALLOW
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isRecordsManagementContainer=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isFilePlan=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isRecordCategory=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isRecordFolder=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isRecord=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isHold=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isTransfer=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isMetadataStub=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isFrozen=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.hasFrozenChildren=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isCutoff=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.getNodeRefPath=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.getFilePlan=RM.Read.0,AFTER_RM.FilterNode
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.getFilePlans=RM_ALLOW
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.createFilePlan=RM.WRITE.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.getAllContained=RM.Read.0,AFTER_RM.FilterNode
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.getContainedRecordCategories=RM.Read.0,AFTER_RM.FilterNode
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.getContainedRecordFolders=RM.Read.0,AFTER_RM.FilterNode
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.createRecordCategory=RM.Write.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isRecordFolderDeclared=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isRecordFolderClosed=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.createRecordFolder=RM.Write.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.getRecords=RM.Read.0,AFTER_RM.FilterNode
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.getRecordFolders=RM.Read.0,AFTER_RM.FilterNode
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.getRecordMetaDataAspects=RM_ALLOW
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isRecordDeclared=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.*=RM_DENY
]]>
</value>
</property>
</bean>
</beans>

View File

@@ -95,26 +95,41 @@
<property name="behaviourFilter" ref="policyBehaviourFilter" />
</bean>
<bean id="rma.recordsManagementContainer" class="org.alfresco.module.org_alfresco_module_rm.model.rma.RecordsManagementContainerType" parent="rm.baseBehaviour">
<!-- rma model types -->
<bean id="rma.recordsManagementContainer" class="org.alfresco.module.org_alfresco_module_rm.model.rma.type.RecordsManagementContainerType" parent="rm.baseBehaviour">
<property name="identifierService" ref="recordsManagementIdentifierService"/>
</bean>
<bean id="rma.filePlan" class="org.alfresco.module.org_alfresco_module_rm.model.rma.FilePlanType" parent="rm.baseBehaviour">
<bean id="rma.filePlan" class="org.alfresco.module.org_alfresco_module_rm.model.rma.type.FilePlanType" parent="rm.baseBehaviour">
<property name="identifierService" ref="recordsManagementIdentifierService"/>
<property name="filePlanService" ref="FilePlanService" />
<property name="recordFolderService" ref="RecordFolderService" />
<property name="filePlanRoleService" ref="FilePlanRoleService" />
</bean>
<bean id="rma.recordCategory" class="org.alfresco.module.org_alfresco_module_rm.model.rma.RecordCategoryType" parent="rm.baseBehaviour">
<bean id="rma.recordCategory" class="org.alfresco.module.org_alfresco_module_rm.model.rma.type.RecordCategoryType" parent="rm.baseBehaviour">
<property name="vitalRecordService" ref="VitalRecordService" />
<property name="filePlanPermissionService" ref="FilePlanPermissionService" />
</bean>
<bean id="rma.record" class="org.alfresco.module.org_alfresco_module_rm.model.rma.RecordAspect" parent="rm.baseBehaviour">
<bean id="rma.dispositionActionDefinition" class="org.alfresco.module.org_alfresco_module_rm.model.rma.type.DispositionActionDefinitionType" parent="rm.baseBehaviour">
</bean>
<!-- rma model aspects -->
<bean id="rma.filePlanComponent" class="org.alfresco.module.org_alfresco_module_rm.model.rma.aspect.FilePlanComponentAspect" parent="rm.baseBehaviour">
<property name="scriptService" ref="ScriptService" />
<property name="namespaceService" ref="NamespaceService" />
</bean>
<bean id="rma.record" class="org.alfresco.module.org_alfresco_module_rm.model.rma.aspect.RecordAspect" parent="rm.baseBehaviour">
<property name="scriptService" ref="ScriptService" />
<property name="extendedSecurityService" ref="ExtendedSecurityService" />
</bean>
<bean id="rma.recordComponentIdentifier" class="org.alfresco.module.org_alfresco_module_rm.model.rma.aspect.RecordComponentIdentifierAspect" parent="rm.baseBehaviour">
</bean>
<!-- END -->

View File

@@ -44,80 +44,7 @@
<property name="filePlanAuthenticationService" ref="FilePlanAuthenticationService"/>
</bean>
<!-- Records Management Service -->
<bean id="recordsManagementService" class="org.alfresco.module.org_alfresco_module_rm.RecordsManagementServiceImpl"
depends-on="org_alfresco_module_rm_dictionaryBootstrap" init-method="init">
<property name="recordsManagementServiceRegistry" ref="RecordsManagementServiceRegistry"/>
<property name="nodeService" ref="nodeService"/>
<property name="policyComponent" ref="policyComponent"/>
</bean>
<bean id="RecordsManagementService" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>org.alfresco.module.org_alfresco_module_rm.RecordsManagementService</value>
</property>
<property name="target">
<ref bean="recordsManagementService"/>
</property>
<property name="interceptorNames">
<list>
<idref local="RecordsManagementService_transaction"/>
<idref bean="exceptionTranslator"/>
<idref local="RecordsManagementService_security"/>
</list>
</property>
</bean>
<bean id="RecordsManagementService_transaction" parent="baseTransaction"/>
<bean id="RecordsManagementService_security" class="org.alfresco.repo.security.permissions.impl.acegi.MethodSecurityInterceptor">
<property name="authenticationManager">
<ref bean="authenticationManager"/>
</property>
<property name="accessDecisionManager">
<ref bean="accessDecisionManager"/>
</property>
<property name="afterInvocationManager">
<ref bean="afterInvocationManager"/>
</property>
<property name="objectDefinitionSource">
<value>
<![CDATA[
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isFilePlanComponent=RM_ALLOW
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.getFilePlanComponentKind=RM_ALLOW
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.getFilePlanComponentKindFromType=RM_ALLOW
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isRecordsManagementContainer=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isFilePlan=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isRecordCategory=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isRecordFolder=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isRecord=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isHold=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isTransfer=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isMetadataStub=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isFrozen=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.hasFrozenChildren=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isCutoff=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.getNodeRefPath=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.getFilePlan=RM.Read.0,AFTER_RM.FilterNode
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.getFilePlans=RM_ALLOW
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.createFilePlan=RM.WRITE.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.getAllContained=RM.Read.0,AFTER_RM.FilterNode
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.getContainedRecordCategories=RM.Read.0,AFTER_RM.FilterNode
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.getContainedRecordFolders=RM.Read.0,AFTER_RM.FilterNode
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.createRecordCategory=RM.Write.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isRecordFolderDeclared=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isRecordFolderClosed=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.createRecordFolder=RM.Write.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.getRecords=RM.Read.0,AFTER_RM.FilterNode
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.getRecordFolders=RM.Read.0,AFTER_RM.FilterNode
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.getRecordMetaDataAspects=RM_ALLOW
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.isRecordDeclared=RM.Read.0
org.alfresco.module.org_alfresco_module_rm.RecordsManagementService.*=RM_DENY
]]>
</value>
</property>
</bean>
<!-- Vital Record Service -->

View File

@@ -39,6 +39,7 @@ import org.alfresco.service.namespace.QName;
* Allows simple creation, manipulation and querying of records management components.
*
* @author Roy Wetherall
* @deprecated as of 2.2
*/
public interface RecordsManagementService
{

View File

@@ -20,14 +20,10 @@ package org.alfresco.module.org_alfresco_module_rm;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanComponentKind;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
@@ -37,34 +33,20 @@ import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService;
import org.alfresco.module.org_alfresco_module_rm.transfer.TransferService;
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.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.ScriptService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.PropertyMap;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* Records management service implementation.
*
* @author Roy Wetherall
* @deprecated as of 2.2
*/
public class RecordsManagementServiceImpl extends ServiceBaseImpl
implements RecordsManagementService,
RecordsManagementModel //,
//RecordsManagementPolicies.OnCreateReference,
//RecordsManagementPolicies.OnRemoveReference
RecordsManagementModel
{
/** I18N */
private final static String MSG_UPDATE_DISP_ACT_DEF = "rm.service.update-disposition-action-def";
private final static String MSG_SET_ID = "rm.service.set-id";
/** Store that the RM roots are contained within */
@SuppressWarnings("unused")
@Deprecated
@@ -73,15 +55,6 @@ public class RecordsManagementServiceImpl extends ServiceBaseImpl
/** Service registry */
private RecordsManagementServiceRegistry serviceRegistry;
/** Policy component */
private PolicyComponent policyComponent;
///** Well-known location of the scripts folder. */
private NodeRef scriptsFolderNodeRef = new NodeRef("workspace", "SpacesStore", "rm_behavior_scripts");
/** Java behaviour */
private JavaBehaviour onChangeToDispositionActionDefinition;
/**
* Set the service registry service
*
@@ -94,16 +67,6 @@ public class RecordsManagementServiceImpl extends ServiceBaseImpl
this.dictionaryService = serviceRegistry.getDictionaryService();
}
/**
* Set policy component
*
* @param policyComponent policy component
*/
public void setPolicyComponent(PolicyComponent policyComponent)
{
this.policyComponent = policyComponent;
}
/**
* Sets the default RM store reference
* @param defaultStoreRef store reference
@@ -154,22 +117,6 @@ public class RecordsManagementServiceImpl extends ServiceBaseImpl
return serviceRegistry.getDispositionService();
}
/**
* @return Script Service
*/
private ScriptService getScriptService()
{
return serviceRegistry.getScriptService();
}
/**
* @return Namespace service
*/
private NamespaceService getNamespaceService()
{
return serviceRegistry.getNamespaceService();
}
/**
* @return Transfer service
*/
@@ -178,209 +125,6 @@ public class RecordsManagementServiceImpl extends ServiceBaseImpl
return serviceRegistry.getTransferService();
}
/**
* Init method. Registered behaviours.
*/
public void init()
{
// Register script execution behaviour on RM property update.
policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onUpdateProperties"),
ASPECT_FILE_PLAN_COMPONENT,
new JavaBehaviour(this, "onChangeToAnyRmProperty", NotificationFrequency.TRANSACTION_COMMIT));
// Disposition behaviours
onChangeToDispositionActionDefinition = new JavaBehaviour(this, "onChangeToDispositionActionDefinition", NotificationFrequency.TRANSACTION_COMMIT);
this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onUpdateProperties"),
TYPE_DISPOSITION_ACTION_DEFINITION,
onChangeToDispositionActionDefinition);
// Identifier behaviours
policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onUpdateProperties"),
ASPECT_RECORD_COMPONENT_ID,
new JavaBehaviour(this, "onIdentifierUpdate", NotificationFrequency.TRANSACTION_COMMIT));
}
/**
* Called after a DispositionActionDefinition property has been updated.
*/
public void onChangeToDispositionActionDefinition(NodeRef node, Map<QName, Serializable> oldProps, Map<QName, Serializable> newProps)
{
if (nodeService.exists(node) == true)
{
onChangeToDispositionActionDefinition.disable();
try
{
// Determine the properties that have changed
Set<QName> changedProps = this.determineChangedProps(oldProps, newProps);
if (nodeService.hasAspect(node, ASPECT_UNPUBLISHED_UPDATE) == false)
{
// Apply the unpublished aspect
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
props.put(PROP_UPDATE_TO, UPDATE_TO_DISPOSITION_ACTION_DEFINITION);
props.put(PROP_UPDATED_PROPERTIES, (Serializable)changedProps);
nodeService.addAspect(node, ASPECT_UNPUBLISHED_UPDATE, props);
}
else
{
Map<QName, Serializable> props = nodeService.getProperties(node);
// Check that there isn't a update currently being published
if ((Boolean)props.get(PROP_PUBLISH_IN_PROGRESS).equals(Boolean.TRUE) == true)
{
// Can not update the disposition schedule since there is an outstanding update being published
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_UPDATE_DISP_ACT_DEF));
}
// Update the update information
props.put(PROP_UPDATE_TO, UPDATE_TO_DISPOSITION_ACTION_DEFINITION);
props.put(PROP_UPDATED_PROPERTIES, (Serializable)changedProps);
nodeService.setProperties(node, props);
}
}
finally
{
onChangeToDispositionActionDefinition.enable();
}
}
}
/**
* This method compares the oldProps map against the newProps map and returns
* a set of QNames of the properties that have changed. Changed here means one of
* <ul>
* <li>the property has been removed</li>
* <li>the property has had its value changed</li>
* <li>the property has been added</li>
* </ul>
*/
private Set<QName> determineChangedProps(Map<QName, Serializable> oldProps, Map<QName, Serializable> newProps)
{
Set<QName> result = new HashSet<QName>();
for (QName qn : oldProps.keySet())
{
if (newProps.get(qn) == null ||
newProps.get(qn).equals(oldProps.get(qn)) == false)
{
result.add(qn);
}
}
for (QName qn : newProps.keySet())
{
if (oldProps.get(qn) == null)
{
result.add(qn);
}
}
return result;
}
/**
* Called after any Records Management property has been updated.
*/
public void onChangeToAnyRmProperty(final NodeRef node, final Map<QName, Serializable> oldProps, final Map<QName, Serializable> newProps)
{
AuthenticationUtil.runAs(new RunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
if (nodeService.exists(node) == true)
{
RecordsManagementServiceImpl.this.lookupAndExecuteScripts(node, oldProps, newProps);
}
return null;
}
}, AuthenticationUtil.getAdminUserName());
}
/**
* This method examines the old and new property sets and for those properties which
* have changed, looks for script resources corresponding to those properties.
* Those scripts are then called via the ScriptService.
*
* @param nodeWithChangedProperties the node whose properties have changed.
* @param oldProps the old properties and their values.
* @param newProps the new properties and their values.
*
* @see #lookupScripts(Map<QName, Serializable>, Map<QName, Serializable>)
*/
private void lookupAndExecuteScripts(NodeRef nodeWithChangedProperties,
Map<QName, Serializable> oldProps, Map<QName, Serializable> newProps)
{
List<NodeRef> scriptRefs = lookupScripts(oldProps, newProps);
Map<String, Object> objectModel = new HashMap<String, Object>(1);
objectModel.put("node", nodeWithChangedProperties);
objectModel.put("oldProperties", oldProps);
objectModel.put("newProperties", newProps);
ScriptService scriptService = getScriptService();
for (NodeRef scriptRef : scriptRefs)
{
scriptService.executeScript(scriptRef, null, objectModel);
}
}
/**
* This method determines which properties have changed and for each such property
* looks for a script resource in a well-known location.
*
* @param oldProps the old properties and their values.
* @param newProps the new properties and their values.
* @return A list of nodeRefs corresponding to the Script resources.
*
* @see #determineChangedProps(Map<QName, Serializable>, Map<QName, Serializable>)
*/
private List<NodeRef> lookupScripts(Map<QName, Serializable> oldProps, Map<QName, Serializable> newProps)
{
List<NodeRef> result = new ArrayList<NodeRef>();
Map<QName, Serializable> changedProps = PropertyMap.getChangedProperties(oldProps, newProps);
for (QName propQName : changedProps.keySet())
{
QName prefixedQName = propQName.getPrefixedQName(getNamespaceService());
String [] splitQName = QName.splitPrefixedQName(prefixedQName.toPrefixString());
final String shortPrefix = splitQName[0];
final String localName = splitQName[1];
// This is the filename pattern which is assumed.
// e.g. a script file cm_name.js would be called for changed to cm:name
String expectedScriptName = shortPrefix + "_" + localName + ".js";
NodeRef nextElement = nodeService.getChildByName(scriptsFolderNodeRef, ContentModel.ASSOC_CONTAINS, expectedScriptName);
if (nextElement != null) result.add(nextElement);
}
return result;
}
/**
* Property update behaviour implementation
*
* @param node
* @param oldProps
* @param newProps
*/
public void onIdentifierUpdate(NodeRef node, Map<QName, Serializable> oldProps, Map<QName, Serializable> newProps)
{
if (nodeService.exists(node) == true)
{
String newIdValue = (String)newProps.get(PROP_IDENTIFIER);
if (newIdValue != null)
{
String oldIdValue = (String)oldProps.get(PROP_IDENTIFIER);
if (oldIdValue != null && oldIdValue.equals(newIdValue) == false)
{
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_SET_ID, node.toString()));
}
}
}
}
/**
* @deprecated As of 2.1, see {@link FilePlanService#isFilePlanComponent(NodeRef)}
*/

View File

@@ -1,9 +1,8 @@
/**
*
*/
package org.alfresco.module.org_alfresco_module_rm.model.rma;
package org.alfresco.module.org_alfresco_module_rm.model;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.repo.policy.BehaviourFilter;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeRef;

View File

@@ -0,0 +1,169 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.alfresco.module.org_alfresco_module_rm.model.rma.aspect;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.policy.annotation.Behaviour;
import org.alfresco.repo.policy.annotation.BehaviourBean;
import org.alfresco.repo.policy.annotation.BehaviourKind;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.ScriptService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.PropertyMap;
/**
* rma:filePlanComponent behaviour bean
*
* @author Roy Wetherall
* @since 2.2
*/
@BehaviourBean
(
defaultType = "rma:filePlanComponent"
)
public class FilePlanComponentAspect extends BaseBehaviourBean
implements NodeServicePolicies.OnUpdatePropertiesPolicy
{
/** Well-known location of the scripts folder. */
private NodeRef scriptsFolderNodeRef = new NodeRef("workspace", "SpacesStore", "rm_behavior_scripts");
/** script service */
private ScriptService scriptService;
/** namespace service */
private NamespaceService namespaceService;
/**
* @param scriptService set script service
*/
public void setScriptService(ScriptService scriptService)
{
this.scriptService = scriptService;
}
/**
* @param namespaceService namespace service
*/
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
/**
* @see org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy#onUpdateProperties(org.alfresco.service.cmr.repository.NodeRef, java.util.Map, java.util.Map)
*/
@Override
@Behaviour
(
kind = BehaviourKind.CLASS,
notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT
)
public void onUpdateProperties(final NodeRef nodeRef, final Map<QName, Serializable> before, final Map<QName, Serializable> after)
{
AuthenticationUtil.runAs(new RunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
if (nodeService.exists(nodeRef) == true)
{
lookupAndExecuteScripts(nodeRef, before, after);
}
return null;
}
}, AuthenticationUtil.getAdminUserName());
}
/**
* This method examines the old and new property sets and for those properties which
* have changed, looks for script resources corresponding to those properties.
* Those scripts are then called via the ScriptService.
*
* @param nodeWithChangedProperties the node whose properties have changed.
* @param oldProps the old properties and their values.
* @param newProps the new properties and their values.
*
* @see #lookupScripts(Map<QName, Serializable>, Map<QName, Serializable>)
*/
private void lookupAndExecuteScripts(NodeRef nodeWithChangedProperties,
Map<QName, Serializable> oldProps,
Map<QName, Serializable> newProps)
{
List<NodeRef> scriptRefs = lookupScripts(oldProps, newProps);
Map<String, Object> objectModel = new HashMap<String, Object>(1);
objectModel.put("node", nodeWithChangedProperties);
objectModel.put("oldProperties", oldProps);
objectModel.put("newProperties", newProps);
;
for (NodeRef scriptRef : scriptRefs)
{
scriptService.executeScript(scriptRef, null, objectModel);
}
}
/**
* This method determines which properties have changed and for each such property
* looks for a script resource in a well-known location.
*
* @param oldProps the old properties and their values.
* @param newProps the new properties and their values.
* @return A list of nodeRefs corresponding to the Script resources.
*
* @see #determineChangedProps(Map<QName, Serializable>, Map<QName, Serializable>)
*/
private List<NodeRef> lookupScripts(Map<QName, Serializable> oldProps, Map<QName, Serializable> newProps)
{
List<NodeRef> result = new ArrayList<NodeRef>();
Map<QName, Serializable> changedProps = PropertyMap.getChangedProperties(oldProps, newProps);
for (QName propQName : changedProps.keySet())
{
QName prefixedQName = propQName.getPrefixedQName(namespaceService);
String [] splitQName = QName.splitPrefixedQName(prefixedQName.toPrefixString());
final String shortPrefix = splitQName[0];
final String localName = splitQName[1];
// This is the filename pattern which is assumed.
// e.g. a script file cm_name.js would be called for changed to cm:name
String expectedScriptName = shortPrefix + "_" + localName + ".js";
NodeRef nextElement = nodeService.getChildByName(scriptsFolderNodeRef, ContentModel.ASSOC_CONTAINS, expectedScriptName);
if (nextElement != null) result.add(nextElement);
}
return result;
}
}

View File

@@ -16,7 +16,7 @@
* 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.model.rma;
package org.alfresco.module.org_alfresco_module_rm.model.rma.aspect;
import java.util.HashMap;
import java.util.Map;
@@ -24,6 +24,7 @@ import java.util.Set;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementCustomModel;
import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService;
import org.alfresco.repo.node.NodeServicePolicies;

View File

@@ -0,0 +1,75 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.alfresco.module.org_alfresco_module_rm.model.rma.aspect;
import java.io.Serializable;
import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.policy.annotation.Behaviour;
import org.alfresco.repo.policy.annotation.BehaviourBean;
import org.alfresco.repo.policy.annotation.BehaviourKind;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* rma:recordComponentIdentifier behaviour bean
*
* @author Roy Wetherall
* @since 2.2
*/
@BehaviourBean
(
defaultType = "rma:recordComponentIdentifier"
)
public class RecordComponentIdentifierAspect extends BaseBehaviourBean
implements NodeServicePolicies.OnUpdatePropertiesPolicy
{
/** I18N */
private final static String MSG_SET_ID = "rm.service.set-id";
/**
* @see org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy#onUpdateProperties(org.alfresco.service.cmr.repository.NodeRef, java.util.Map, java.util.Map)
*/
@Override
@Behaviour
(
kind = BehaviourKind.CLASS,
notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT
)
public void onUpdateProperties(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after)
{
if (nodeService.exists(nodeRef) == true)
{
String newIdValue = (String)after.get(PROP_IDENTIFIER);
if (newIdValue != null)
{
String oldIdValue = (String)before.get(PROP_IDENTIFIER);
if (oldIdValue != null && oldIdValue.equals(newIdValue) == false)
{
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_SET_ID, nodeRef.toString()));
}
}
}
}
}

View File

@@ -0,0 +1,99 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.policy.annotation.Behaviour;
import org.alfresco.repo.policy.annotation.BehaviourBean;
import org.alfresco.repo.policy.annotation.BehaviourKind;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.PropertyMap;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* rma:dispositionActionDefinition behaviour bean
*
* @author Roy Wetherall
* @since 2.2
*/
@BehaviourBean
(
defaultType = "rma:dispositionActionDefinition"
)
public class DispositionActionDefinitionType extends BaseBehaviourBean
implements NodeServicePolicies.OnUpdatePropertiesPolicy
{
/** I18N */
private final static String MSG_UPDATE_DISP_ACT_DEF = "rm.service.update-disposition-action-def";
/**
* @see org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy#onUpdateProperties(org.alfresco.service.cmr.repository.NodeRef, java.util.Map, java.util.Map)
*/
@Override
@Behaviour
(
kind = BehaviourKind.CLASS,
notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT
)
public void onUpdateProperties(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after)
{
if (nodeService.exists(nodeRef) == true)
{
// Determine the properties that have changed
Set<QName> changedProps = new HashSet<QName>(PropertyMap.getChangedProperties(before, after).keySet());
changedProps.addAll(PropertyMap.getAddedProperties(before, after).keySet());
if (nodeService.hasAspect(nodeRef, ASPECT_UNPUBLISHED_UPDATE) == false)
{
// Apply the unpublished aspect
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
props.put(PROP_UPDATE_TO, UPDATE_TO_DISPOSITION_ACTION_DEFINITION);
props.put(PROP_UPDATED_PROPERTIES, (Serializable)changedProps);
nodeService.addAspect(nodeRef, ASPECT_UNPUBLISHED_UPDATE, props);
}
else
{
Map<QName, Serializable> props = nodeService.getProperties(nodeRef);
// Check that there isn't a update currently being published
if ((Boolean)props.get(PROP_PUBLISH_IN_PROGRESS).equals(Boolean.TRUE) == true)
{
// Can not update the disposition schedule since there is an outstanding update being published
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_UPDATE_DISP_ACT_DEF));
}
// Update the update information
props.put(PROP_UPDATE_TO, UPDATE_TO_DISPOSITION_ACTION_DEFINITION);
props.put(PROP_UPDATED_PROPERTIES, (Serializable)changedProps);
nodeService.setProperties(nodeRef, props);
}
}
}
}

View File

@@ -16,12 +16,13 @@
* 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.model.rma;
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
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.BaseBehaviourBean;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService;
import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService;

View File

@@ -16,10 +16,11 @@
* 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.model.rma;
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
import org.alfresco.module.org_alfresco_module_rm.security.FilePlanPermissionService;
import org.alfresco.module.org_alfresco_module_rm.vital.VitalRecordService;
import org.alfresco.repo.copy.CopyBehaviourCallback;

View File

@@ -16,10 +16,11 @@
* 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.model.rma;
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.identifier.IdentifierService;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;

View File

@@ -114,6 +114,7 @@ public class AnnotatedBehaviourPostProcessor implements BeanPostProcessor
}
/**
* Register behaviour with the policy.
*
* @param bean
* @param beanName