RM-2130 Post method invocation processor for QueryEngineResults.

+review RM @taksoy

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/DEV/ENFORCE@107246 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tom Page
2015-06-26 14:47:03 +00:00
parent 03e696e524
commit 06ed0a6015
3 changed files with 180 additions and 0 deletions

View File

@@ -98,6 +98,30 @@ public class PostMethodInvocationProcessor
return result;
}
/**
* Gets the processor from the available processors.
*
* @param clazz The class of the post invocation object.
* @return The suitable processor for the given class.
*/
protected BasePostMethodInvocationProcessor getProcessorForClass(Class<? extends Object> clazz)
{
mandatory("clazz", clazz);
BasePostMethodInvocationProcessor result = null;
Set<Entry<Class<?>, BasePostMethodInvocationProcessor>> processorsEntrySet = getProcessors().entrySet();
for (Map.Entry<Class<?>, BasePostMethodInvocationProcessor> processorEntry : processorsEntrySet)
{
if (processorEntry.getKey().isAssignableFrom(clazz))
{
result = processorEntry.getValue();
break;
}
}
return result;
}
/**
* Processes the given object
*

View File

@@ -0,0 +1,67 @@
/*
* 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.HashMap;
import java.util.Map;
import java.util.Set;
import org.alfresco.repo.search.impl.querymodel.QueryEngineResults;
import org.alfresco.service.cmr.search.ResultSet;
/**
* A post method invocation processor for {@link QueryEngineResults}.
*
* @author Tom Page
* @since 3.0
*/
public class QueryEngineResultsPostMethodInvocationProcessor extends BasePostMethodInvocationProcessor
{
/** The post method invocation processor for {@link ResultSet ResultSets}. */
private BasePostMethodInvocationProcessor resultSetProcessor;
@Override
protected Class<QueryEngineResults> getClassName()
{
return QueryEngineResults.class;
}
@SuppressWarnings("unchecked")
@Override
public <T> T process(T object)
{
if (resultSetProcessor == null)
{
resultSetProcessor = getPostMethodInvocationProcessor().getProcessorForClass(ResultSet.class);
}
QueryEngineResults queryEngineResults = getClassName().cast(object);
Map<Set<String>, ResultSet> resultsMap = queryEngineResults.getResults();
Map<Set<String>, ResultSet> returnMap = new HashMap<>();
for (Set<String> key : resultsMap.keySet())
{
ResultSet newResultSet = resultSetProcessor.process(resultsMap.get(key));
if (newResultSet != null)
{
returnMap.put(key, newResultSet);
}
}
return (T) new QueryEngineResults(returnMap);
}
}