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

+review RM-94

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/DEV/ENFORCE@106658 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2015-06-21 21:58:42 +00:00
parent 862fde1e61
commit 24cc5ca519
11 changed files with 87 additions and 217 deletions

View File

@@ -20,6 +20,9 @@ package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.pr
import java.util.Collection;
import org.alfresco.util.collections.CollectionUtils;
import org.alfresco.util.collections.Filter;
/**
* Abstract Post Method Invocation Processor
*
@@ -37,13 +40,23 @@ public abstract class AbstractPostMethodInvocationProcessor extends BasePostMeth
protected abstract <T> T processSingleElement(T object);
/**
* Abstract method to process a collection
* Processes a collection
*
* @param collection The collection to process
* @return Processed collection
*/
@SuppressWarnings("rawtypes")
protected abstract Collection processCollection(Collection 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)
@@ -61,13 +74,11 @@ public abstract class AbstractPostMethodInvocationProcessor extends BasePostMeth
Collection collection = ((Collection) result);
if (!collection.isEmpty())
{
checkObjectClass(collection.iterator().next());
result = (T) processCollection(collection);
}
}
else
{
checkObjectClass(result);
result = processSingleElement(result);
}
}

View File

@@ -18,12 +18,8 @@
*/
package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor;
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
@@ -48,7 +44,7 @@ public class AssociationRefPostMethodInvocationProcessor extends AbstractPostMet
@Override
protected <T> T processSingleElement(T object)
{
AssociationRef associationRef = (AssociationRef) object;
AssociationRef associationRef = getClassName().cast(object);
NodeRef sourceRef = associationRef.getSourceRef();
NodeRef filteredSource = filter(sourceRef);
@@ -58,21 +54,4 @@ public class AssociationRefPostMethodInvocationProcessor extends AbstractPostMet
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<AssociationRef>()
{
@Override
public Boolean apply(AssociationRef associationRef)
{
return processSingleElement(associationRef) != null;
}
});
}
}

View File

@@ -23,7 +23,6 @@ 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.processor.ClassificationPostMethodInvocationException.NotSupportedClassTypeException;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
@@ -135,19 +134,6 @@ public abstract class BasePostMethodInvocationProcessor
getPostMethodInvocationProcessor().register(this);
}
/**
* Checks if the given object's class is suitable for the processor
*
* @param object The object to process
*/
protected void checkObjectClass(Object object)
{
if (!(object.getClass().equals(getClassName())))
{
throw new NotSupportedClassTypeException("The object is not an instance of '" + getClassName() + "' but '" + object.getClass() + "'.");
}
}
/**
* Checks if the given object is a collection
*

View File

@@ -18,12 +18,8 @@
*/
package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor;
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
@@ -48,7 +44,7 @@ public class ChildAssociationRefPostMethodInvocationProcessor extends AbstractPo
@Override
protected <T> T processSingleElement(T object)
{
ChildAssociationRef childAssociationRef = ((ChildAssociationRef) object);
ChildAssociationRef childAssociationRef = getClassName().cast(object);
NodeRef childRef = childAssociationRef.getChildRef();
NodeRef filteredChildRef = filter(childRef);
@@ -58,21 +54,4 @@ public class ChildAssociationRefPostMethodInvocationProcessor extends AbstractPo
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<ChildAssociationRef>()
{
@Override
public Boolean apply(ChildAssociationRef childAssociationRef)
{
return processSingleElement(childAssociationRef) != null;
}
});
}
}

View File

@@ -1,80 +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 org.alfresco.error.AlfrescoRuntimeException;
/**
* Generic class for any runtime exception thrown within the {@link BasePostMethodInvocationProcessor} and subclasses.
*
* @author Tuna Aksoy
* @since 3.0
*/
public class ClassificationPostMethodInvocationException extends AlfrescoRuntimeException
{
/** Serial version UID */
private static final long serialVersionUID = 2614182915625548638L;
/**
* Base classification post method invocation exception
*
* @param msgId The text which will be shown in the exception
*/
public ClassificationPostMethodInvocationException(String msgId)
{
super(msgId);
}
/**
* Base classification post method invocation exception
*
* @param msgId The text which will be shown in the exception
* @param cause The cause of the exception
*/
public ClassificationPostMethodInvocationException(String msgId, Throwable cause)
{
super(msgId, cause);
}
/**
* Represents a fatal error due to a wrong class type
*/
public static class NotSupportedClassTypeException extends ClassificationPostMethodInvocationException
{
/** Serial version UID */
private static final long serialVersionUID = 7614080640030648878L;
/**
* @param msgId The text which will be shown in the exception
*/
public NotSupportedClassTypeException(String msgId)
{
super(msgId);
}
/**
* @param msgId The text which will be shown in the exception
* @param cause The cause of the exception
*/
public NotSupportedClassTypeException(String msgId, Throwable cause)
{
super(msgId, cause);
}
}
}

View File

@@ -18,11 +18,7 @@
*/
package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor;
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
@@ -47,24 +43,7 @@ public class NodeRefPostMethodInvocationProcessor extends AbstractPostMethodInvo
@Override
protected <T> T processSingleElement(T object)
{
NodeRef nodeRef = (NodeRef) object;
NodeRef nodeRef = getClassName().cast(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<NodeRef>()
{
@Override
public Boolean apply(NodeRef nodeRef)
{
return processSingleElement(nodeRef) != null;
}
});
}
}

View File

@@ -0,0 +1,51 @@
/*
* 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 org.alfresco.repo.security.permissions.PermissionCheckValue;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Permission Check Value Post Method Invocation Processor
*
* @author Tuna Aksoy
* @since 3.0
*/
public class PermissionCheckValuePostMethodInvocationProcessor extends AbstractPostMethodInvocationProcessor
{
/**
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#getClassName()
*/
@Override
protected Class<PermissionCheckValue> getClassName()
{
return PermissionCheckValue.class;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.AbstractPostMethodInvocationProcessor#processSingleElement(java.lang.Object)
*/
@Override
protected <T> T processSingleElement(T object)
{
PermissionCheckValue permissionCheckValue = getClassName().cast(object);
NodeRef nodeRef = permissionCheckValue.getNodeRef();
return filter(nodeRef) == null ? null : object;
}
}

View File

@@ -18,12 +18,8 @@
*/
package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor;
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
@@ -48,24 +44,8 @@ public class StoreRefPostMethodInvocationProcessor extends AbstractPostMethodInv
@Override
protected <T> T processSingleElement(T object)
{
NodeRef nodeRef = getNodeService().getRootNode((StoreRef) object);
StoreRef storeRef = getClassName().cast(object);
NodeRef nodeRef = getNodeService().getRootNode(storeRef);
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<NodeRef>()
{
@Override
public Boolean apply(NodeRef nodeRef)
{
return processSingleElement(nodeRef) != null;
}
});
}
}