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@106774 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2015-06-22 22:41:26 +00:00
parent 21a62b3e1f
commit 87d77fd755
3 changed files with 245 additions and 0 deletions

View File

@@ -119,6 +119,14 @@
class="org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.ListPostMethodInvocationProcessor">
</bean>
<!-- FIXME: Implementation needs to be changed -->
<!--
<bean id="resultSetPostMethodInvocationProcessor"
parent="collectionPostMethodInvocationProcessor"
class="org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.ResultSetPostMethodInvocationProcessor">
</bean>
-->
<bean id="arrayPostMethodInvocationProcessor"
parent="abstractPostMethodInvocationProcessor"
class="org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.ArrayPostMethodInvocationProcessor">

View File

@@ -0,0 +1,100 @@
/*
* 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.BitSet;
import java.util.Iterator;
import java.util.List;
import org.alfresco.repo.search.SimpleResultSetMetaData;
import org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.search.PermissionEvaluationMode;
import org.alfresco.service.cmr.search.ResultSet;
/**
* ResultSet Post Method Invocation Processor
*
* @author Tuna Aksoy
* @since 3.0
*/
public class ResultSetPostMethodInvocationProcessor extends BasePostMethodInvocationProcessor
{
/**
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#getClassName()
*/
@Override
protected Class<ResultSet> getClassName()
{
return ResultSet.class;
}
// FIXME: Change implementation
/**
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.CollectionPostMethodInvocationProcessor#process(java.lang.Object)
*/
@SuppressWarnings({ "unchecked" })
@Override
public <T> T process(T object)
{
T result = object;
ResultSet resultSet = getClassName().cast(result);
BitSet inclusionMask = new BitSet(resultSet.length());
FilteringResultSet filteringResultSet = new FilteringResultSet(resultSet, inclusionMask);
filteringResultSet.setResultSetMetaData(
new SimpleResultSetMetaData(
resultSet.getResultSetMetaData().getLimitedBy(),
PermissionEvaluationMode.EAGER,
resultSet.getResultSetMetaData().getSearchParameters()));
List<NodeRef> nodeRefs = resultSet.getNodeRefs();
if (!nodeRefs.isEmpty())
{
Iterator<NodeRef> iterator = nodeRefs.iterator();
BasePostMethodInvocationProcessor processor = getPostMethodInvocationProcessor().getProcessor(iterator.next());
for (int i = 0; i < nodeRefs.size(); i++)
{
if (processor.process(nodeRefs.get(i)) == null)
{
inclusionMask.set(i, false);
}
}
}
List<ChildAssociationRef> childAssocRefs = getClassName().cast(filteringResultSet).getChildAssocRefs();
if (!childAssocRefs.isEmpty())
{
Iterator<ChildAssociationRef> iterator = childAssocRefs.iterator();
BasePostMethodInvocationProcessor processor = getPostMethodInvocationProcessor().getProcessor(iterator.next());
for (int i = 0; i < childAssocRefs.size(); i++)
{
if (processor.process(nodeRefs.get(i)) == null)
{
inclusionMask.set(i, false);
}
}
}
return (T) filteringResultSet;
}
}

View File

@@ -0,0 +1,137 @@
/*
* 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.test.integration.classification;
import static java.lang.Integer.MAX_VALUE;
import static org.alfresco.repo.site.SiteModel.SITE_MANAGER;
import static org.alfresco.service.cmr.repository.StoreRef.STORE_REF_WORKSPACE_SPACESSTORE;
import static org.alfresco.service.cmr.search.SearchService.LANGUAGE_FTS_ALFRESCO;
import static org.alfresco.service.namespace.NamespaceService.CONTENT_MODEL_1_0_URI;
import static org.alfresco.util.GUID.generate;
import java.util.List;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.SearchParameters;
/**
* Integration test for ResultTest post method invocation processor
*
* @author Tuna Aksoy
* @since 3.0
*/
public class ResultSetPostMethodInvocationProcessorTest extends BaseRMTestCase
{
private static final String LEVEL1 = "level1";
private static final String REASON = "Test Reason 1";
/**
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#isCollaborationSiteTest()
*/
@Override
protected boolean isCollaborationSiteTest()
{
return true;
}
public void testResultSetPostMethodInvocationProcessor()
{
doBehaviourDrivenTest(new BehaviourDrivenTest()
{
private String myUser;
private NodeRef doc1;
private NodeRef doc2;
private String searchQuery = generate();
private ResultSet result;
/**
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase.BehaviourDrivenTest#given()
*/
@Override
public void given() throws Exception
{
myUser = generate();
createPerson(myUser);
siteService.setMembership(collabSiteId, myUser, SITE_MANAGER);
doc1 = fileFolderService.create(documentLibrary, searchQuery + generate(), TYPE_CONTENT).getNodeRef();
doc2 = fileFolderService.create(documentLibrary, searchQuery + generate(), TYPE_CONTENT).getNodeRef();
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase.BehaviourDrivenTest#when()
*/
@Override
public void when() throws Exception
{
doTestInTransaction(new Test<Void>()
{
@Override
public Void run()
{
//contentClassificationService.classifyContent(LEVEL1, generate(), newHashSet(REASON), doc1);
return null;
}
});
doTestInTransaction(new Test<Void>()
{
@Override
public Void run()
{
SearchParameters searchParameters = new SearchParameters();
searchParameters.setQuery("@cm\\:name:" + searchQuery + "*");
searchParameters.setLanguage(LANGUAGE_FTS_ALFRESCO);
searchParameters.addStore(STORE_REF_WORKSPACE_SPACESSTORE);
searchParameters.setMaxItems(MAX_VALUE);
searchParameters.setNamespace(CONTENT_MODEL_1_0_URI);
result = searchService.query(searchParameters);
return null;
}
}, myUser);
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase.BehaviourDrivenTest#then()
*/
@Override
public void then() throws Exception
{
doTestInTransaction(new Test<Void>()
{
@Override
public Void run()
{
List<NodeRef> nodeRefs = result.getNodeRefs();
assertEquals(2, nodeRefs.size());
assertTrue(nodeRefs.contains(doc1));
assertTrue(nodeRefs.contains(doc2));
return null;
}
}, myUser);
}
});
}
}