diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/classified-content-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/classified-content-context.xml
index d5316533ae..1a5c7bff55 100644
--- a/rm-server/config/alfresco/module/org_alfresco_module_rm/classified-content-context.xml
+++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/classified-content-context.xml
@@ -42,6 +42,9 @@
+
+
@@ -49,25 +52,32 @@
+
+
+
+
@@ -75,9 +85,6 @@
abstract="true"
parent="basePostMethodInvocationProcessor"
class="org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.CollectionPostMethodInvocationProcessor">
-
-
-
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/ClassificationMethodInterceptor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/ClassificationMethodInterceptor.java
index 235e681983..687b0ba392 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/ClassificationMethodInterceptor.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/ClassificationMethodInterceptor.java
@@ -22,13 +22,12 @@ import static org.alfresco.model.ContentModel.TYPE_CONTENT;
import static org.codehaus.plexus.util.StringUtils.isNotBlank;
import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Map;
import org.alfresco.jlan.server.filesys.AccessDeniedException;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceBootstrap;
import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService;
import org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor;
+import org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.PostMethodInvocationProcessorRegistry;
import org.alfresco.module.org_alfresco_module_rm.util.AlfrescoTransactionSupport;
import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
@@ -56,9 +55,6 @@ public class ClassificationMethodInterceptor implements MethodInterceptor, Appli
/** Logger */
private static Logger LOG = Logger.getLogger(ClassificationMethodInterceptor.class);
- /** Post method invocation processors */
- private Map, BasePostMethodInvocationProcessor> processors = new HashMap, BasePostMethodInvocationProcessor>();
-
private static final String KEY_PROCESSING = GUID.generate();
/** application context */
@@ -112,14 +108,9 @@ public class ClassificationMethodInterceptor implements MethodInterceptor, Appli
return (DictionaryService)applicationContext.getBean("dictionaryService");
}
- /**
- * Registers the post method invocation processors
- *
- * @param object The object to register
- */
- public void register(BasePostMethodInvocationProcessor object)
+ protected PostMethodInvocationProcessorRegistry getPostMethodInvocationProcessorRegistry()
{
- processors.put(object.getClassName(), object);
+ return (PostMethodInvocationProcessorRegistry)applicationContext.getBean("postMethodInvocationProcessorRegistry");
}
/**
@@ -238,7 +229,7 @@ public class ClassificationMethodInterceptor implements MethodInterceptor, Appli
if (isUserValid && postInvocation != null)
{
Class extends Object> clazz = postInvocation.getClass();
- BasePostMethodInvocationProcessor processor = getProcessor(processors, clazz);
+ BasePostMethodInvocationProcessor processor = getPostMethodInvocationProcessorRegistry().getProcessor(clazz);
if (processor != null)
{
@@ -252,27 +243,4 @@ public class ClassificationMethodInterceptor implements MethodInterceptor, Appli
return postInvocation;
}
-
- /**
- * Gets the processor from the available processors
- *
- * @param processors Available processors
- * @param clazz The runtime class of the post invocation object
- * @return The suitable processor for the given class
- */
- private BasePostMethodInvocationProcessor getProcessor(Map, BasePostMethodInvocationProcessor> processors, Class extends Object> clazz)
- {
- BasePostMethodInvocationProcessor result = null;
-
- for (Map.Entry, BasePostMethodInvocationProcessor> processor : processors.entrySet())
- {
- if (processor.getKey().isAssignableFrom(clazz))
- {
- result = processor.getValue();
- break;
- }
- }
-
- return result;
- }
}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/AbstractPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/AbstractPostMethodInvocationProcessor.java
new file mode 100644
index 0000000000..022dbed21e
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/AbstractPostMethodInvocationProcessor.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2005-2015 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.classification.interceptor.processor;
+
+import static org.alfresco.util.ParameterCheck.mandatory;
+
+import java.util.Collection;
+
+/**
+ * Abstract Post Method Invocation Processor
+ *
+ * @author Tuna Aksoy
+ * @since 3.0
+ */
+public abstract class AbstractPostMethodInvocationProcessor extends BasePostMethodInvocationProcessor
+{
+ /**
+ * Abstract method to process a single element
+ *
+ * @param object The element to process
+ * @return Processed element
+ */
+ protected abstract T processSingleElement(T object);
+
+ /**
+ * Abstract method to process a collection
+ *
+ * @param collection The collection to process
+ * @return Processed collection
+ */
+ @SuppressWarnings("rawtypes")
+ protected abstract Collection processCollection(Collection collection);
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object)
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Override
+ public T process(T object)
+ {
+ mandatory("object", object);
+
+ T result = null;
+
+ if (isCollection(object))
+ {
+ Collection collection = ((Collection) object);
+ if (!collection.isEmpty())
+ {
+ checkObjectClass(collection.iterator().next());
+ result = (T) processCollection(collection);
+ }
+ }
+ else
+ {
+ checkObjectClass(object);
+ result = (T) processSingleElement(object);
+ }
+
+ return result;
+ }
+}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/AssociationRefPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/AssociationRefPostMethodInvocationProcessor.java
index 841259c259..e077e6558d 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/AssociationRefPostMethodInvocationProcessor.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/AssociationRefPostMethodInvocationProcessor.java
@@ -18,10 +18,12 @@
*/
package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor;
-import static org.alfresco.util.ParameterCheck.mandatory;
+import java.util.Collection;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
+import org.alfresco.util.collections.CollectionUtils;
+import org.alfresco.util.collections.Filter;
/**
* AssociationRef Post Method Invocation Processor
@@ -29,27 +31,24 @@ import org.alfresco.service.cmr.repository.NodeRef;
* @author Tuna Aksoy
* @since 3.0
*/
-public class AssociationRefPostMethodInvocationProcessor extends BasePostMethodInvocationProcessor
+public class AssociationRefPostMethodInvocationProcessor extends AbstractPostMethodInvocationProcessor
{
/**
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#getClassName()
*/
@Override
- public Class getClassName()
+ protected Class getClassName()
{
return AssociationRef.class;
}
/**
- * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object)
+ * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.AbstractPostMethodInvocationProcessor#processSingleElement(java.lang.Object)
*/
@Override
- public T process(T object)
+ protected T processSingleElement(T object)
{
- mandatory("object", object);
- checkObjectClass(object);
-
- AssociationRef associationRef = ((AssociationRef) object);
+ AssociationRef associationRef = (AssociationRef) object;
NodeRef sourceRef = associationRef.getSourceRef();
NodeRef filteredSource = filter(sourceRef);
@@ -59,4 +58,21 @@ public class AssociationRefPostMethodInvocationProcessor extends BasePostMethodI
return (filteredSource == null || filteredTarget == null) ? null : object;
}
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.AbstractPostMethodInvocationProcessor#processCollection(java.util.Collection)
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Override
+ protected Collection processCollection(Collection collection)
+ {
+ return CollectionUtils.filter(collection, new Filter()
+ {
+ @Override
+ public Boolean apply(AssociationRef associationRef)
+ {
+ return processSingleElement(associationRef) != null;
+ }
+ });
+ }
}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/BasePostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/BasePostMethodInvocationProcessor.java
index 9e64b16d7e..9ada7a259e 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/BasePostMethodInvocationProcessor.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/BasePostMethodInvocationProcessor.java
@@ -20,6 +20,8 @@ package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.pr
import static org.alfresco.model.ContentModel.TYPE_CONTENT;
+import java.util.Collection;
+
import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService;
import org.alfresco.module.org_alfresco_module_rm.classification.interceptor.ClassificationMethodInterceptor;
import org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.ClassificationPostMethodInvocationException.NotSupportedClassTypeException;
@@ -47,6 +49,9 @@ public abstract class BasePostMethodInvocationProcessor
/** Content classification service */
private ContentClassificationService contentClassificationService;
+ /** Post method invocation processor registry */
+ private PostMethodInvocationProcessorRegistry postMethodInvocationProcessorRegistry;
+
/**
* @return the classificationMethodInterceptor
*/
@@ -79,6 +84,14 @@ public abstract class BasePostMethodInvocationProcessor
return this.contentClassificationService;
}
+ /**
+ * @return the postMethodInvocationProcessorRegistry
+ */
+ protected PostMethodInvocationProcessorRegistry getPostMethodInvocationProcessorRegistry()
+ {
+ return this.postMethodInvocationProcessorRegistry;
+ }
+
/**
* @param classificationMethodInterceptor the classificationMethodInterceptor to set
*/
@@ -111,12 +124,20 @@ public abstract class BasePostMethodInvocationProcessor
this.contentClassificationService = contentClassificationService;
}
+ /**
+ * @param postMethodInvocationProcessorRegistry the postMethodInvocationProcessorRegistry to set
+ */
+ public void setPostMethodInvocationProcessorRegistry(PostMethodInvocationProcessorRegistry postMethodInvocationProcessorRegistry)
+ {
+ this.postMethodInvocationProcessorRegistry = postMethodInvocationProcessorRegistry;
+ }
+
/**
* Gets the class name
*
* @return The class name
*/
- public abstract Class> getClassName();
+ protected abstract Class> getClassName();
/**
* Performs checks on the given object and throws exception if not all checks pass
@@ -131,7 +152,7 @@ public abstract class BasePostMethodInvocationProcessor
*/
public void register()
{
- getClassificationMethodInterceptor().register(this);
+ getPostMethodInvocationProcessorRegistry().register(this);
}
/**
@@ -147,6 +168,17 @@ public abstract class BasePostMethodInvocationProcessor
}
}
+ /**
+ * Checks if the given object is a collection
+ *
+ * @param object Object to check
+ * @return true
if the code is a collection, false
otherwise
+ */
+ protected boolean isCollection(T object)
+ {
+ return Collection.class.isAssignableFrom(object.getClass());
+ }
+
/**
* Filters the node if the give node reference exist and it is a
* content but the logged in user is not cleared to see the it.
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ChildAssociationRefPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ChildAssociationRefPostMethodInvocationProcessor.java
index b71130584d..7af8983451 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ChildAssociationRefPostMethodInvocationProcessor.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ChildAssociationRefPostMethodInvocationProcessor.java
@@ -18,10 +18,12 @@
*/
package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor;
-import static org.alfresco.util.ParameterCheck.mandatory;
+import java.util.Collection;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
+import org.alfresco.util.collections.CollectionUtils;
+import org.alfresco.util.collections.Filter;
/**
* ChildAssociationRef Post Method Invocation Processor
@@ -29,26 +31,23 @@ import org.alfresco.service.cmr.repository.NodeRef;
* @author Tuna Aksoy
* @since 3.0
*/
-public class ChildAssociationRefPostMethodInvocationProcessor extends BasePostMethodInvocationProcessor
+public class ChildAssociationRefPostMethodInvocationProcessor extends AbstractPostMethodInvocationProcessor
{
/**
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#getClassName()
*/
@Override
- public Class getClassName()
+ protected Class getClassName()
{
return ChildAssociationRef.class;
}
/**
- * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object)
+ * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.AbstractPostMethodInvocationProcessor#processSingleElement(java.lang.Object)
*/
@Override
- public T process(T object)
+ protected T processSingleElement(T object)
{
- mandatory("object", object);
- checkObjectClass(object);
-
ChildAssociationRef childAssociationRef = ((ChildAssociationRef) object);
NodeRef childRef = childAssociationRef.getChildRef();
@@ -59,4 +58,21 @@ public class ChildAssociationRefPostMethodInvocationProcessor extends BasePostMe
return (filteredChildRef == null || filteredParentRef == null) ? null : object;
}
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.AbstractPostMethodInvocationProcessor#processCollection(java.util.Collection)
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Override
+ protected Collection processCollection(Collection collection)
+ {
+ return CollectionUtils.filter(collection, new Filter()
+ {
+ @Override
+ public Boolean apply(ChildAssociationRef childAssociationRef)
+ {
+ return process(childAssociationRef) != null;
+ }
+ });
+ }
}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/CollectionPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/CollectionPostMethodInvocationProcessor.java
index 68c8d6acc3..527e144b3e 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/CollectionPostMethodInvocationProcessor.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/CollectionPostMethodInvocationProcessor.java
@@ -23,12 +23,6 @@ import static org.alfresco.util.ParameterCheck.mandatory;
import java.util.Collection;
import java.util.Iterator;
-import org.alfresco.service.cmr.repository.AssociationRef;
-import org.alfresco.service.cmr.repository.ChildAssociationRef;
-import org.alfresco.service.cmr.repository.NodeRef;
-import org.alfresco.util.collections.CollectionUtils;
-import org.alfresco.util.collections.Filter;
-
/**
* Collection Post Method Invocation Processor
*
@@ -37,63 +31,6 @@ import org.alfresco.util.collections.Filter;
*/
public abstract class CollectionPostMethodInvocationProcessor extends BasePostMethodInvocationProcessor
{
- /** Node ref post method invocation processor */
- private NodeRefPostMethodInvocationProcessor nodeRefPostMethodInvocationProcessor;
-
- /** Association post method invocation processor */
- private AssociationRefPostMethodInvocationProcessor associationRefPostMethodInvocationProcessor;
-
- /** Child association post method invocation processor */
- private ChildAssociationRefPostMethodInvocationProcessor childAssociationRefPostMethodInvocationProcessor;
-
- /**
- * @return the nodeRefPostMethodInvocationProcessor
- */
- protected NodeRefPostMethodInvocationProcessor getNodeRefPostMethodInvocationProcessor()
- {
- return this.nodeRefPostMethodInvocationProcessor;
- }
-
- /**
- * @return the associationRefPostMethodInvocationProcessor
- */
- protected AssociationRefPostMethodInvocationProcessor getAssociationRefPostMethodInvocationProcessor()
- {
- return this.associationRefPostMethodInvocationProcessor;
- }
-
- /**
- * @return the childAssociationRefPostMethodInvocationProcessor
- */
- protected ChildAssociationRefPostMethodInvocationProcessor getChildAssociationRefPostMethodInvocationProcessor()
- {
- return this.childAssociationRefPostMethodInvocationProcessor;
- }
-
- /**
- * @param nodeRefPostMethodInvocationProcessor the nodeRefPostMethodInvocationProcessor to set
- */
- public void setNodeRefPostMethodInvocationProcessor(NodeRefPostMethodInvocationProcessor nodeRefPostMethodInvocationProcessor)
- {
- this.nodeRefPostMethodInvocationProcessor = nodeRefPostMethodInvocationProcessor;
- }
-
- /**
- * @param associationRefPostMethodInvocationProcessor the associationRefPostMethodInvocationProcessor to set
- */
- public void setAssociationRefPostMethodInvocationProcessor(AssociationRefPostMethodInvocationProcessor associationRefPostMethodInvocationProcessor)
- {
- this.associationRefPostMethodInvocationProcessor = associationRefPostMethodInvocationProcessor;
- }
-
- /**
- * @param childAssociationRefPostMethodInvocationProcessor the childAssociationRefPostMethodInvocationProcessor to set
- */
- public void setChildAssociationRefPostMethodInvocationProcessor(ChildAssociationRefPostMethodInvocationProcessor childAssociationRefPostMethodInvocationProcessor)
- {
- this.childAssociationRefPostMethodInvocationProcessor = childAssociationRefPostMethodInvocationProcessor;
- }
-
/**
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object)
*/
@@ -102,91 +39,24 @@ public abstract class CollectionPostMethodInvocationProcessor extends BasePostMe
public T process(T object)
{
mandatory("object", object);
- checkObjectClass(object);
Object result = object;
-
Collection collection = ((Collection) object);
+
if (!collection.isEmpty())
{
Iterator iterator = collection.iterator();
if (iterator.hasNext())
{
Class extends Object> clazz = iterator.next().getClass();
- if (NodeRef.class.isAssignableFrom(clazz))
+ BasePostMethodInvocationProcessor processor = getPostMethodInvocationProcessorRegistry().getProcessor(clazz);
+ if (processor != null)
{
- result = processNodeRef(collection);
- }
-
- if (AssociationRef.class.isAssignableFrom(clazz))
- {
- result = processAssociationRef(collection);
- }
-
- if (ChildAssociationRef.class.isAssignableFrom(clazz))
- {
- result = processChildAssociationRef(collection);
+ result = processor.process(object);
}
}
}
return (T) result;
}
-
- /**
- * Processes a {@link NodeRef} collection
- *
- * @param collection The collection to process
- * @return The processed collection
- */
- @SuppressWarnings({ "rawtypes", "unchecked" })
- private Collection processNodeRef(Collection collection)
- {
- return CollectionUtils.filter(collection, new Filter()
- {
- @Override
- public Boolean apply(NodeRef nodeRef)
- {
- return getNodeRefPostMethodInvocationProcessor().process(nodeRef) != null;
- }
- });
- }
-
- /**
- * Processes a {@link AssociationRef} collection
- *
- * @param collection The collection to process
- * @return The processed collection
- */
- @SuppressWarnings({ "rawtypes", "unchecked" })
- private Collection processAssociationRef(Collection collection)
- {
- return CollectionUtils.filter(collection, new Filter()
- {
- @Override
- public Boolean apply(AssociationRef associationRef)
- {
- return getAssociationRefPostMethodInvocationProcessor().process(associationRef) != null;
- }
- });
- }
-
- /**
- * Processes a {@link ChildAssociationRef} collection
- *
- * @param collection The collection to process
- * @return The processed collection
- */
- @SuppressWarnings({ "rawtypes", "unchecked" })
- private Collection processChildAssociationRef(Collection collection)
- {
- return CollectionUtils.filter(collection, new Filter()
- {
- @Override
- public Boolean apply(ChildAssociationRef childAssociationRef)
- {
- return getChildAssociationRefPostMethodInvocationProcessor().process(childAssociationRef) != null;
- }
- });
- }
}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ListPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ListPostMethodInvocationProcessor.java
index 4962eada3f..0176f9c3e8 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ListPostMethodInvocationProcessor.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ListPostMethodInvocationProcessor.java
@@ -33,7 +33,7 @@ public class ListPostMethodInvocationProcessor extends CollectionPostMethodInvoc
*/
@SuppressWarnings("rawtypes")
@Override
- public Class getClassName()
+ protected Class getClassName()
{
return List.class;
}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/NodeRefPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/NodeRefPostMethodInvocationProcessor.java
index 679ebe034e..4abde0e223 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/NodeRefPostMethodInvocationProcessor.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/NodeRefPostMethodInvocationProcessor.java
@@ -18,9 +18,11 @@
*/
package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor;
-import static org.alfresco.util.ParameterCheck.mandatory;
+import java.util.Collection;
import org.alfresco.service.cmr.repository.NodeRef;
+import org.alfresco.util.collections.CollectionUtils;
+import org.alfresco.util.collections.Filter;
/**
* NodeRef Post Method Invocation Processor
@@ -28,26 +30,41 @@ import org.alfresco.service.cmr.repository.NodeRef;
* @author Tuna Aksoy
* @since 3.0
*/
-public class NodeRefPostMethodInvocationProcessor extends BasePostMethodInvocationProcessor
+public class NodeRefPostMethodInvocationProcessor extends AbstractPostMethodInvocationProcessor
{
/**
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#getClassName()
*/
@Override
- public Class getClassName()
+ protected Class getClassName()
{
return NodeRef.class;
}
/**
- * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object)
+ * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.AbstractPostMethodInvocationProcessor#processSingleElement(java.lang.Object)
*/
@Override
- public T process(T object)
+ protected T processSingleElement(T object)
{
- mandatory("object", object);
- checkObjectClass(object);
+ NodeRef nodeRef = (NodeRef) object;
+ return filter(nodeRef) == null ? null : object;
+ }
- return filter((NodeRef) object) == null ? null : object;
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.AbstractPostMethodInvocationProcessor#processCollection(java.util.Collection)
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Override
+ protected Collection processCollection(Collection collection)
+ {
+ return CollectionUtils.filter(collection, new Filter()
+ {
+ @Override
+ public Boolean apply(NodeRef nodeRef)
+ {
+ return processSingleElement(nodeRef) != null;
+ }
+ });
}
}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/PostMethodInvocationProcessorRegistry.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/PostMethodInvocationProcessorRegistry.java
new file mode 100644
index 0000000000..ae835565ff
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/PostMethodInvocationProcessorRegistry.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2005-2015 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.classification.interceptor.processor;
+
+import static org.alfresco.util.ParameterCheck.mandatory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Registry for post method invocation processors
+ *
+ * @author Tuna Aksoy
+ * @since 3.0
+ */
+public class PostMethodInvocationProcessorRegistry
+{
+ /** Post method invocation processors */
+ private Map, BasePostMethodInvocationProcessor> processors = new HashMap, BasePostMethodInvocationProcessor>();
+
+ /**
+ * Registers a post method invocation processor
+ *
+ * @param Post method invocation processor object
+ */
+ public void register(BasePostMethodInvocationProcessor object)
+ {
+ mandatory("object", object);
+
+ processors.put(object.getClassName(), object);
+ }
+
+ /**
+ * Gets all the available processors
+ *
+ * @return the processors Available processors
+ */
+ public Map, BasePostMethodInvocationProcessor> getProcessors()
+ {
+ return this.processors;
+ }
+
+ /**
+ * Gets the processor from the available processors
+ *
+ * @param clazz The runtime class of the post invocation object
+ * @return The suitable processor for the given class
+ */
+ public BasePostMethodInvocationProcessor getProcessor(Class extends Object> clazz)
+ {
+ mandatory("clazz", clazz);
+
+ BasePostMethodInvocationProcessor result = null;
+
+ for (Map.Entry, BasePostMethodInvocationProcessor> processor : processors.entrySet())
+ {
+ if (processor.getKey().isAssignableFrom(clazz))
+ {
+ result = processor.getValue();
+ break;
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/SetPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/SetPostMethodInvocationProcessor.java
index 6fb47e4516..c8536b65a7 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/SetPostMethodInvocationProcessor.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/SetPostMethodInvocationProcessor.java
@@ -33,7 +33,7 @@ public class SetPostMethodInvocationProcessor extends CollectionPostMethodInvoca
*/
@SuppressWarnings("rawtypes")
@Override
- public Class getClassName()
+ protected Class getClassName()
{
return Set.class;
}
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/StoreRefPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/StoreRefPostMethodInvocationProcessor.java
index 9a9476ca4c..5f9e39251b 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/StoreRefPostMethodInvocationProcessor.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/StoreRefPostMethodInvocationProcessor.java
@@ -18,10 +18,12 @@
*/
package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor;
-import static org.alfresco.util.ParameterCheck.mandatory;
+import java.util.Collection;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
+import org.alfresco.util.collections.CollectionUtils;
+import org.alfresco.util.collections.Filter;
/**
* StoreRef Post Method Invocation Processor
@@ -29,28 +31,41 @@ import org.alfresco.service.cmr.repository.StoreRef;
* @author Tuna Aksoy
* @since 3.0
*/
-public class StoreRefPostMethodInvocationProcessor extends BasePostMethodInvocationProcessor
+public class StoreRefPostMethodInvocationProcessor extends AbstractPostMethodInvocationProcessor
{
/**
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#getClassName()
*/
@Override
- public Class getClassName()
+ protected Class getClassName()
{
return StoreRef.class;
}
/**
- * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object)
+ * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.AbstractPostMethodInvocationProcessor#processSingleElement(java.lang.Object)
*/
@Override
- public T process(T object)
+ protected T processSingleElement(T object)
{
- mandatory("object", object);
- checkObjectClass(object);
-
NodeRef nodeRef = getNodeService().getRootNode((StoreRef) object);
-
return filter(nodeRef) == null ? null : object;
}
+
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.AbstractPostMethodInvocationProcessor#processCollection(java.util.Collection)
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Override
+ protected Collection processCollection(Collection collection)
+ {
+ return CollectionUtils.filter(collection, new Filter()
+ {
+ @Override
+ public Boolean apply(NodeRef nodeRef)
+ {
+ return processSingleElement(nodeRef) != null;
+ }
+ });
+ }
}