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 c3dd709f3b..f53b4a81a6 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 @@ -119,6 +119,14 @@ class="org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.ListPostMethodInvocationProcessor"> + + + diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ResultSetPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ResultSetPostMethodInvocationProcessor.java new file mode 100644 index 0000000000..b4694e9054 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ResultSetPostMethodInvocationProcessor.java @@ -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 . + */ +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 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 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 nodeRefs = resultSet.getNodeRefs(); + if (!nodeRefs.isEmpty()) + { + Iterator 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 childAssocRefs = getClassName().cast(filteringResultSet).getChildAssocRefs(); + if (!childAssocRefs.isEmpty()) + { + Iterator 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; + } +} diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/classification/ResultSetPostMethodInvocationProcessorTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/classification/ResultSetPostMethodInvocationProcessorTest.java new file mode 100644 index 0000000000..8955ae82f9 --- /dev/null +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/classification/ResultSetPostMethodInvocationProcessorTest.java @@ -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 . + */ +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() + { + @Override + public Void run() + { + //contentClassificationService.classifyContent(LEVEL1, generate(), newHashSet(REASON), doc1); + + return null; + } + }); + + doTestInTransaction(new Test() + { + @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() + { + @Override + public Void run() + { + List nodeRefs = result.getNodeRefs(); + + assertEquals(2, nodeRefs.size()); + assertTrue(nodeRefs.contains(doc1)); + assertTrue(nodeRefs.contains(doc2)); + + return null; + } + }, myUser); + } + }); + } +}