mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-2130 Add support for other collections than Lists.
Unfortunately most methods in the CollectionUtils helper class convert collections to lists, and so is not suitable for our usage. +review RM @taksoy git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/DEV/ENFORCE@107282 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -18,10 +18,6 @@
|
||||
*/
|
||||
package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.alfresco.util.collections.CollectionUtils;
|
||||
import org.alfresco.util.collections.Filter;
|
||||
|
||||
/**
|
||||
* Abstract Post Method Invocation Processor
|
||||
@@ -39,29 +35,9 @@ public abstract class AbstractPostMethodInvocationProcessor extends BasePostMeth
|
||||
*/
|
||||
protected abstract <T> T processSingleElement(T object);
|
||||
|
||||
/**
|
||||
* Processes a collection
|
||||
*
|
||||
* @param collection The collection to process
|
||||
* @return Processed collection
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
protected Collection processCollection(Collection collection)
|
||||
{
|
||||
return CollectionUtils.filter(collection, new Filter()
|
||||
{
|
||||
@Override
|
||||
public Boolean apply(Object element)
|
||||
{
|
||||
return processSingleElement(element) != null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object)
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public <T> T process(T object)
|
||||
{
|
||||
@@ -69,18 +45,7 @@ public abstract class AbstractPostMethodInvocationProcessor extends BasePostMeth
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
if (isCollection(result))
|
||||
{
|
||||
Collection collection = ((Collection) result);
|
||||
if (!collection.isEmpty())
|
||||
{
|
||||
result = (T) processCollection(collection);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = processSingleElement(result);
|
||||
}
|
||||
result = processSingleElement(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@@ -20,8 +20,6 @@ package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.pr
|
||||
|
||||
import static org.alfresco.model.ContentModel.TYPE_CONTENT;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService;
|
||||
@@ -185,17 +183,6 @@ public abstract class BasePostMethodInvocationProcessor
|
||||
getPostMethodInvocationProcessor().register(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given object is a collection
|
||||
*
|
||||
* @param object Object to check
|
||||
* @return <code>true</code> if the code is a collection, <code>false</code> otherwise
|
||||
*/
|
||||
protected <T> 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.
|
||||
|
@@ -20,7 +20,6 @@ package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.pr
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -39,8 +38,7 @@ public class CollectionPostMethodInvocationProcessor extends BasePostMethodInvoc
|
||||
@Override
|
||||
protected Class<?> getClassName()
|
||||
{
|
||||
// FIXME!!!
|
||||
return List.class;
|
||||
return Collection.class;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,12 +56,23 @@ public class CollectionPostMethodInvocationProcessor extends BasePostMethodInvoc
|
||||
if (!collection.isEmpty())
|
||||
{
|
||||
Iterator iterator = collection.iterator();
|
||||
if (iterator.hasNext())
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
BasePostMethodInvocationProcessor processor = getPostMethodInvocationProcessor().getProcessor(iterator.next());
|
||||
Object next = iterator.next();
|
||||
// TODO: Can we guarantee that all the elements of a collection can be processed by the same processor?
|
||||
BasePostMethodInvocationProcessor processor = getPostMethodInvocationProcessor().getProcessor(next);
|
||||
if (processor != null)
|
||||
{
|
||||
result = processor.process(object);
|
||||
Object processed = processor.process(next);
|
||||
if (processed == null)
|
||||
{
|
||||
iterator.remove();
|
||||
}
|
||||
else if (!processed.equals(next))
|
||||
{
|
||||
// TODO Support this, as it will be hit by e.g. collections of collections.
|
||||
throw new IllegalStateException("Modifying members of a collection is not yet supported.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user