RM-2130 (Check classification after method execution, filtering results where appropriate)

- Code refactored

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@107441 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2015-06-30 19:15:27 +00:00
parent fa3f1230a4
commit ea4d00f100
19 changed files with 145 additions and 580 deletions

View File

@@ -49,7 +49,7 @@ public class ArrayPostMethodInvocationProcessor extends BasePostMethodInvocation
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public <T> T process(T object)
protected <T> T process(T object)
{
T result = object;

View File

@@ -44,7 +44,7 @@ public class AssociationRefPostMethodInvocationProcessor extends BasePostMethodI
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object)
*/
@Override
public <T> T process(T object)
protected <T> T process(T object)
{
T result = object;

View File

@@ -97,51 +97,11 @@ public abstract class BasePostMethodInvocationProcessor
return this.postMethodInvocationProcessor;
}
/**
* @param nodeService the nodeService to set
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @param dictionaryService the dictionaryService to set
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* @param contentClassificationService the contentClassificationService to set
*/
public void setContentClassificationService(ContentClassificationService contentClassificationService)
{
this.contentClassificationService = contentClassificationService;
}
/**
* @param securityClearanceService the securityClearanceService to set
*/
public void setSecurityClearanceService(SecurityClearanceService securityClearanceService)
{
this.securityClearanceService = securityClearanceService;
}
/**
* @param postMethodInvocationProcessor the postMethodInvocationProcessor to set
*/
public void setPostMethodInvocationProcessor(PostMethodInvocationProcessor postMethodInvocationProcessor)
{
this.postMethodInvocationProcessor = postMethodInvocationProcessor;
}
/**
* Registers the post method invocation processors
*/
@PostConstruct
public void register()
private void register()
{
getPostMethodInvocationProcessor().register(this);
}

View File

@@ -44,7 +44,7 @@ public class ChildAssociationRefPostMethodInvocationProcessor extends BasePostMe
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object)
*/
@Override
public <T> T process(T object)
protected <T> T process(T object)
{
T result = object;

View File

@@ -35,8 +35,9 @@ public class CollectionPostMethodInvocationProcessor extends BasePostMethodInvoc
/**
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#getClassName()
*/
@SuppressWarnings("rawtypes")
@Override
protected Class<?> getClassName()
protected Class<Collection> getClassName()
{
return Collection.class;
}
@@ -46,79 +47,38 @@ public class CollectionPostMethodInvocationProcessor extends BasePostMethodInvoc
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public <T> T process(T object)
protected <T> T process(T object)
{
Collection collection = ((Collection) object);
T result = object;
if (collection != null)
if (result != null)
{
BasePostMethodInvocationProcessor processor = pickProcessor(collection);
if (processor != null)
{
object = (T) processCollection(collection, processor);
}
}
BasePostMethodInvocationProcessor processor = null;
Collection collection = getClassName().cast(object);
Iterator<T> iterator = collection.iterator();
return object;
}
/**
* Process a collection using the supplied processor.
*
* @param collection The collection to be processed.
* @param processor A collection suitable for access by someone with the current security clearance.
*/
protected <T> Collection<T> processCollection(Collection<T> collection, BasePostMethodInvocationProcessor processor)
{
Iterator<T> iterator = collection.iterator();
while (iterator.hasNext())
{
Object next = iterator.next();
Object processed = processor.process(next);
try
while (iterator.hasNext())
{
if (processed == null)
Object element = iterator.next();
if (processor == null)
{
processor = getPostMethodInvocationProcessor().getProcessor(element);
if (processor == null)
{
break;
}
}
Object processedElement = processor.process(element);
if (processedElement == null)
{
iterator.remove();
}
else if (!processed.equals(next))
{
// Modifying members of this type of collection is not supported, so filter the whole collection.
return null;
}
}
catch (UnsupportedOperationException e)
{
// If the collection cannot be modified and it contains classified data then the whole thing must be filtered.
return null;
}
}
return collection;
}
/**
* Pick a suitable processor for the members of the collection. We assume that all the elements of a collection can
* be processed by the same processor.
*
* @param collection The collection to be processed.
* @return The chosen processor, or {@code null} if no suitable processor could be found.
*/
@SuppressWarnings("rawtypes")
private BasePostMethodInvocationProcessor pickProcessor(Collection collection)
{
Iterator iterator = collection.iterator();
while (iterator.hasNext())
{
Object next = iterator.next();
if (next != null)
{
BasePostMethodInvocationProcessor processor = getPostMethodInvocationProcessor().getProcessor(next);
if (processor != null)
{
return processor;
}
}
result = (T) collection;
}
return null;
return result;
}
}

View File

@@ -1,47 +0,0 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* List Post Method Invocation Processor. This replaces the existing list with a filtered {@link ArrayList}. By doing
* this we gain the ability to replace members of a list, which is not possible using the
* {@link CollectionPostMethodInvocationProcessor}. The downside is that whatever type of list was provided gets
* replaced with an {@code ArrayList}.
*
* @author Tom Page
* @since 3.0
*/
public class ListPostMethodInvocationProcessor extends ModifiableCollectionPostMethodInvocationProcessor
{
@Override
protected Class<?> getClassName()
{
return List.class;
}
@Override
protected <T> Collection<T> createEmptyCollection(Collection<T> collection)
{
return new ArrayList<>();
}
}

View File

@@ -1,61 +0,0 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor;
import java.util.ArrayList;
import java.util.Collection;
/**
* List Post Method Invocation Processor. This replaces the existing list with a filtered {@link ArrayList}. By doing
* this we gain the ability to replace members of a list, which is not possible using the
* {@link CollectionPostMethodInvocationProcessor}. The downside is that whatever type of list was provided gets
* replaced with an {@code ArrayList}.
*
* @author Tom Page
* @since 3.0
*/
public abstract class ModifiableCollectionPostMethodInvocationProcessor extends CollectionPostMethodInvocationProcessor
{
@Override
abstract protected Class<?> getClassName();
/**
* Create an empty modifiable collection.
*
* @param collection The source collection to try to mimic.
* @return The new empty collection.
*/
abstract protected <T> Collection<T> createEmptyCollection(Collection<T> collection);
/** {@inheritDoc} */
@Override
protected <T> Collection<T> processCollection(Collection<T> collection, BasePostMethodInvocationProcessor processor)
{
Collection<T> returnList = createEmptyCollection(collection);
for (T member : collection)
{
T processed = processor.process(member);
if (processed != null)
{
returnList.add(processed);
}
}
return returnList;
}
}

View File

@@ -43,7 +43,7 @@ public class NodeRefPostMethodInvocationProcessor extends BasePostMethodInvocati
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object)
*/
@Override
public <T> T process(T object)
protected <T> T process(T object)
{
T result = object;

View File

@@ -48,7 +48,7 @@ public class PagingResultsPostMethodInvocationProcessor extends BasePostMethodIn
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public <T> T process(T object)
protected <T> T process(T object)
{
T result = object;

View File

@@ -44,7 +44,7 @@ public class PermissionCheckValuePostMethodInvocationProcessor extends BasePostM
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object)
*/
@Override
public <T> T process(T object)
protected <T> T process(T object)
{
T result = object;

View File

@@ -50,7 +50,7 @@ public class QueryEngineResultsPostMethodInvocationProcessor extends BasePostMet
*/
@SuppressWarnings("unchecked")
@Override
public <T> T process(T object)
protected <T> T process(T object)
{
T result = object;

View File

@@ -55,7 +55,7 @@ public class ResultSetPostMethodInvocationProcessor extends BasePostMethodInvoca
*/
@SuppressWarnings({ "unchecked" })
@Override
public <T> T process(T object)
protected <T> T process(T object)
{
T result = object;

View File

@@ -1,47 +0,0 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
/**
* Set Post Method Invocation Processor. This replaces the existing set with a filtered {@link HashSet}. By doing
* this we gain the ability to replace members of a set, which is not possible using the
* {@link CollectionPostMethodInvocationProcessor}. The downside is that whatever type of set was provided gets
* replaced with an {@code HashSet}.
*
* @author Tom Page
* @since 3.0
*/
public class SetPostMethodInvocationProcessor extends ModifiableCollectionPostMethodInvocationProcessor
{
@Override
protected Class<?> getClassName()
{
return Set.class;
}
@Override
protected <T> Collection<T> createEmptyCollection(Collection<T> collection)
{
return new HashSet<>();
}
}

View File

@@ -1,45 +0,0 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor;
import java.util.Collection;
import java.util.SortedSet;
import java.util.TreeSet;
/**
* Sorted Set Post Method Invocation Processor. This replaces the existing set with a filtered {@link TreeSet}.
*
* @author Tom Page
* @since 3.0
*/
public class SortedSetPostMethodInvocationProcessor extends ModifiableCollectionPostMethodInvocationProcessor
{
@Override
protected Class<?> getClassName()
{
return SortedSet.class;
}
@Override
protected <T> Collection<T> createEmptyCollection(Collection<T> collection)
{
SortedSet<T> sortedSet = (SortedSet<T>) collection;
return new TreeSet<>(sortedSet.comparator());
}
}

View File

@@ -41,10 +41,10 @@ public class StoreRefPostMethodInvocationProcessor extends BasePostMethodInvocat
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.AbstractPostMethodInvocationProcessor#processSingleElement(java.lang.Object)
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object)
*/
@Override
public <T> T process(T object)
protected <T> T process(T object)
{
T result = object;