perms = permissionService.getAllSetPermissions(parent);
for (AccessPermission perm : perms)
@@ -402,10 +404,11 @@ public class FilePlanPermissionServiceImpl extends ServiceBaseImpl
}
/**
- *
- * @param nodeRef
+ * Initiliase the permissions for the given node.
+ *
+ * @param nodeRef node reference
*/
- public void setUpPermissions(final NodeRef nodeRef)
+ private void initPermissions(final NodeRef nodeRef)
{
if (nodeService.exists(nodeRef) == true)
{
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/vital/VitalRecordService.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/vital/VitalRecordService.java
index 3d1f4f5376..c5b88afb14 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/vital/VitalRecordService.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/vital/VitalRecordService.java
@@ -33,8 +33,15 @@ public interface VitalRecordService
static final Period PERIOD_NONE = new Period("none|0");
/**
- * Gets the vital record definition details for the node.
- *
+ * Setup the vital record definition for the given node.
+ *
+ * @param nodeRef node reference
+ */
+ void setupVitalRecordDefinition(NodeRef nodeRef);
+
+ /**
+ * Gets the vital record definition details for the node.
+ *
* @param nodeRef node reference
* @return VitalRecordDefinition vital record definition details
*/
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/vital/VitalRecordServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/vital/VitalRecordServiceImpl.java
index b8d640cc6b..30fe7c0a77 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/vital/VitalRecordServiceImpl.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/vital/VitalRecordServiceImpl.java
@@ -129,11 +129,6 @@ public class VitalRecordServiceImpl implements VitalRecordService,
TYPE_RECORD_FOLDER,
ContentModel.ASSOC_CONTAINS,
onCreateChildAssociation);
- policyComponent.bindAssociationBehaviour(
- NodeServicePolicies.OnCreateChildAssociationPolicy.QNAME,
- TYPE_RECORD_CATEGORY,
- ContentModel.ASSOC_CONTAINS,
- onCreateChildAssociation);
}
/**
@@ -185,7 +180,7 @@ public class VitalRecordServiceImpl implements VitalRecordService,
if (filePlanService.isRecordCategory(nodeRef) == true ||
recordFolderService.isRecordFolder(nodeRef) == true)
{
- inheritVitalRecordDefinition(nodeRef);
+ setupVitalRecordDefinition(nodeRef);
}
return null;
@@ -202,11 +197,10 @@ public class VitalRecordServiceImpl implements VitalRecordService,
}
/**
- * Helper method to set the inherited vital record definition details.
- *
- * @param nodeRef node reference
+ * @see org.alfresco.module.org_alfresco_module_rm.vital.VitalRecordService#setupVitalRecordDefinition(org.alfresco.service.cmr.repository.NodeRef)
*/
- private void inheritVitalRecordDefinition(NodeRef nodeRef)
+ @Override
+ public void setupVitalRecordDefinition(NodeRef nodeRef)
{
// get the current review period value
Period currentReviewPeriod = (Period)nodeService.getProperty(nodeRef, PROP_REVIEW_PERIOD);
diff --git a/rm-server/source/java/org/alfresco/repo/policy/annotation/AnnotatedBehaviourPostProcessor.java b/rm-server/source/java/org/alfresco/repo/policy/annotation/AnnotatedBehaviourPostProcessor.java
new file mode 100644
index 0000000000..40760fcd18
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/repo/policy/annotation/AnnotatedBehaviourPostProcessor.java
@@ -0,0 +1,210 @@
+/*
+ * 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.repo.policy.annotation;
+
+import java.lang.reflect.Method;
+
+import org.alfresco.repo.policy.JavaBehaviour;
+import org.alfresco.repo.policy.PolicyComponent;
+import org.alfresco.service.namespace.NamespaceService;
+import org.alfresco.service.namespace.QName;
+import org.alfresco.util.ParameterCheck;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.config.BeanPostProcessor;
+
+/**
+ * Annotated behaviour bean post processor.
+ *
+ * Registers the annotated methods on behaviour beans with the policy component.
+ *
+ * @author Roy Wetherall
+ */
+public class AnnotatedBehaviourPostProcessor implements BeanPostProcessor
+{
+ /** logger */
+ private static Log logger = LogFactory.getLog(AnnotatedBehaviourPostProcessor.class);
+
+ /** policy component */
+ private PolicyComponent policyComponent;
+
+ /** namespace service */
+ private NamespaceService namespaceService;
+
+ /**
+ * @param policyComponent policy component
+ */
+ public void setPolicyComponent(PolicyComponent policyComponent)
+ {
+ this.policyComponent = policyComponent;
+ }
+
+ /**
+ * @param namespaceService namespace service
+ */
+ public void setNamespaceService(NamespaceService namespaceService)
+ {
+ this.namespaceService = namespaceService;
+ }
+
+ /**
+ * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, java.lang.String)
+ */
+ @Override
+ public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException
+ {
+ // register annotated behavior methods
+ registerBehaviours(bean, beanName);
+
+ return bean;
+ }
+
+ /**
+ * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object, java.lang.String)
+ */
+ @Override
+ public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException
+ {
+ // do nothing
+ return bean;
+ }
+
+ /**
+ *
+ * @param bean
+ * @param beanName
+ */
+ private void registerBehaviours(Object bean, String beanName)
+ {
+ if (bean.getClass().isAnnotationPresent(BehaviourBean.class) == true)
+ {
+ BehaviourBean behaviourBean = bean.getClass().getAnnotation(BehaviourBean.class);
+
+ if (logger.isDebugEnabled() == true)
+ {
+ logger.debug("Annotated behaviour post processing for " + beanName);
+ }
+
+ Method[] methods = bean.getClass().getMethods();
+ for (Method method : methods)
+ {
+ if (method.isAnnotationPresent(Behaviour.class) == true)
+ {
+ registerBehaviour(behaviourBean, bean, beanName, method);
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ * @param bean
+ * @param beanName
+ * @param method
+ * @param classBehaviour
+ */
+ private void registerBehaviour(BehaviourBean behaviourBean, Object bean, String beanName, Method method)
+ {
+ Behaviour behaviour = method.getAnnotation(Behaviour.class);
+ QName policy = resolvePolicy(behaviour.policy(), method);
+ QName type = resolveType(behaviourBean, behaviour.type());
+
+ // assert that the policy and type have been set!!
+ ParameterCheck.mandatory("policy", policy);
+ ParameterCheck.mandatory("type", type);
+
+ if (logger.isDebugEnabled() == true)
+ {
+ logger.debug(" ... registering " + behaviour.kind() + " behaviour for " + beanName + "." + method.getName() +
+ " for policy " + policy.toString() +
+ " and type " + type.toString());
+ }
+
+ JavaBehaviour javaBehaviour = new JavaBehaviour(bean, method.getName(), behaviour.notificationFrequency());
+
+ if (BehaviourKind.CLASS.equals(behaviour.kind()) == true)
+ {
+ policyComponent.bindClassBehaviour(policy,
+ type,
+ javaBehaviour);
+ }
+ else if (BehaviourKind.ASSOCIATION.equals(behaviour.kind()) == true)
+ {
+ policyComponent.bindAssociationBehaviour(policy,
+ type,
+ toQName(behaviour.assocType()),
+ javaBehaviour);
+ }
+ }
+
+ /**
+ *
+ * @param policyName
+ * @param method
+ * @return
+ */
+ private QName resolvePolicy(String policyName, Method method)
+ {
+ QName policy = null;
+ if (policyName.isEmpty() == true)
+ {
+ policy = QName.createQName(NamespaceService.ALFRESCO_URI, method.getName());
+ }
+ else
+ {
+ policy = toQName(policyName);
+ }
+
+ return policy;
+ }
+
+ /**
+ *
+ * @param behaviourBean
+ * @param typeName
+ * @return
+ */
+ private QName resolveType(BehaviourBean behaviourBean, String typeName)
+ {
+ QName type = null;
+ if (typeName.isEmpty() == true)
+ {
+ // get default
+ type = toQName(behaviourBean.defaultType());
+ }
+ else
+ {
+ // convert set
+ type = toQName(typeName);
+ }
+ return type;
+ }
+
+ /**
+ *
+ * @param name
+ * @return
+ */
+ private QName toQName(String name)
+ {
+ return QName.createQName(name, namespaceService);
+ }
+
+}
diff --git a/rm-server/source/java/org/alfresco/repo/policy/annotation/Behaviour.java b/rm-server/source/java/org/alfresco/repo/policy/annotation/Behaviour.java
new file mode 100644
index 0000000000..619677be13
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/repo/policy/annotation/Behaviour.java
@@ -0,0 +1,51 @@
+/*
+ * 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.repo.policy.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
+
+/**
+ * Behaviour method annotation.
+ *
+ * @author Roy Wetherall
+ */
+@Target(value = ElementType.METHOD)
+@Retention(value = RetentionPolicy.RUNTIME)
+public @interface Behaviour
+{
+ /** kind of behaviour */
+ BehaviourKind kind();
+
+ /** qualified name of policy */
+ String policy() default "";
+
+ /** qualified name of type/aspect */
+ String type() default "";
+
+ /** qualified name of association */
+ String assocType() default "cm:contains";
+
+ /** notification frequency */
+ NotificationFrequency notificationFrequency() default NotificationFrequency.EVERY_EVENT;
+}
diff --git a/rm-server/source/java/org/alfresco/repo/policy/annotation/BehaviourBean.java b/rm-server/source/java/org/alfresco/repo/policy/annotation/BehaviourBean.java
new file mode 100644
index 0000000000..9cae4088b3
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/repo/policy/annotation/BehaviourBean.java
@@ -0,0 +1,36 @@
+/*
+ * 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.repo.policy.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @author Roy Wetherall
+ */
+@Target(value = ElementType.TYPE)
+@Retention(value = RetentionPolicy.RUNTIME)
+public @interface BehaviourBean
+{
+ /** qualified name of type/aspect */
+ String defaultType() default "";
+
+}
diff --git a/rm-server/source/java/org/alfresco/repo/policy/annotation/BehaviourKind.java b/rm-server/source/java/org/alfresco/repo/policy/annotation/BehaviourKind.java
new file mode 100644
index 0000000000..c76b664269
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/repo/policy/annotation/BehaviourKind.java
@@ -0,0 +1,31 @@
+/*
+ * 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.repo.policy.annotation;
+
+/**
+ * Enumeration describing the different kinds of behaviour.
+ *
+ * @author Roy Wetherall
+ * @since 2.2
+ */
+public enum BehaviourKind
+{
+ CLASS,
+ ASSOCIATION
+}