mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-9086 "RINF 52: Lucene Removal: Fix FileFolderService search methods"
- FileFolderService can return List<FileInfo> or PagingResults<FileInfo> git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29603 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -213,6 +213,24 @@ public class FileFolderServiceImplTest extends TestCase
|
||||
checkFileList(files, 2, 3, expectedNames);
|
||||
}
|
||||
|
||||
public void testShallowFilesAndFoldersListWithLocale() throws Exception
|
||||
{
|
||||
Locale savedLocale = I18NUtil.getContentLocaleOrNull();
|
||||
try
|
||||
{
|
||||
I18NUtil.setContentLocale(Locale.CANADA);
|
||||
List<FileInfo> files = fileFolderService.list(workingRootNodeRef);
|
||||
// check
|
||||
String[] expectedNames = new String[]
|
||||
{ NAME_L0_FILE_A, NAME_L0_FILE_B, NAME_L0_FOLDER_A, NAME_L0_FOLDER_B, NAME_L0_FOLDER_C };
|
||||
checkFileList(files, 2, 3, expectedNames);
|
||||
}
|
||||
finally
|
||||
{
|
||||
I18NUtil.setContentLocale(savedLocale);
|
||||
}
|
||||
}
|
||||
|
||||
public void testListPage() throws Exception
|
||||
{
|
||||
// sanity checks only (see also GetChildrenCannedQueryTest)
|
||||
|
@@ -27,6 +27,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.service.cmr.ml.MultilingualContentService;
|
||||
@@ -196,30 +197,36 @@ public class MLTranslationInterceptor implements MethodInterceptor
|
||||
return translatedFileInfo;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable
|
||||
private List<FileInfo> processList(List<FileInfo> fileInfos)
|
||||
{
|
||||
Object ret = null;
|
||||
String methodName = invocation.getMethod().getName();
|
||||
|
||||
if (I18NUtil.getContentLocaleOrNull() == null)
|
||||
{
|
||||
// This can shortcut anything as there is no filtering going on
|
||||
return invocation.proceed();
|
||||
}
|
||||
else if (METHOD_NAMES_LIST.contains(methodName))
|
||||
{
|
||||
final PagingResults<FileInfo> fileInfos = (PagingResults<FileInfo>) invocation.proceed();
|
||||
// Compile a set to ensure we don't get duplicates
|
||||
Map<FileInfo, FileInfo> translatedFileInfos = new HashMap<FileInfo, FileInfo>(17);
|
||||
for (FileInfo fileInfo : fileInfos.getPage())
|
||||
for (FileInfo fileInfo : fileInfos)
|
||||
{
|
||||
FileInfo translatedFileInfo = getTranslatedFileInfo(fileInfo);
|
||||
// Add this to the set
|
||||
translatedFileInfos.put(fileInfo, translatedFileInfo);
|
||||
}
|
||||
// Convert the set back to a PagingResults
|
||||
final List<FileInfo> orderedResults = new ArrayList<FileInfo>(fileInfos.getPage().size());
|
||||
// Convert the set back to a list
|
||||
List<FileInfo> orderedResults = new ArrayList<FileInfo>(fileInfos.size());
|
||||
Set<FileInfo> alreadyPresent = new HashSet<FileInfo>(fileInfos.size() * 2 + 1);
|
||||
for (FileInfo info : fileInfos)
|
||||
{
|
||||
FileInfo translatedFileInfo = translatedFileInfos.get(info);
|
||||
if (alreadyPresent.contains(translatedFileInfo))
|
||||
{
|
||||
// We've done this one
|
||||
continue;
|
||||
}
|
||||
alreadyPresent.add(translatedFileInfo);
|
||||
orderedResults.add(translatedFileInfo);
|
||||
}
|
||||
return orderedResults;
|
||||
}
|
||||
|
||||
private PagingResults<FileInfo> processPagingResults(final PagingResults<FileInfo> fileInfos)
|
||||
{
|
||||
final List<FileInfo> orderedResults = processList(fileInfos.getPage());
|
||||
PagingResults<FileInfo> orderedPagingResults = new PagingResults<FileInfo>()
|
||||
{
|
||||
@Override
|
||||
@@ -243,19 +250,35 @@ public class MLTranslationInterceptor implements MethodInterceptor
|
||||
return fileInfos.getTotalResultCount();
|
||||
}
|
||||
};
|
||||
Set<FileInfo> alreadyPresent = new HashSet<FileInfo>(fileInfos.getPage().size() * 2 + 1);
|
||||
for (FileInfo info : fileInfos.getPage())
|
||||
{
|
||||
FileInfo translatedFileInfo = translatedFileInfos.get(info);
|
||||
if (alreadyPresent.contains(translatedFileInfo))
|
||||
{
|
||||
// We've done this one
|
||||
continue;
|
||||
return orderedPagingResults;
|
||||
}
|
||||
alreadyPresent.add(translatedFileInfo);
|
||||
orderedResults.add(translatedFileInfo);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable
|
||||
{
|
||||
Object ret = null;
|
||||
String methodName = invocation.getMethod().getName();
|
||||
|
||||
if (I18NUtil.getContentLocaleOrNull() == null)
|
||||
{
|
||||
// This can shortcut anything as there is no filtering going on
|
||||
return invocation.proceed();
|
||||
}
|
||||
else if (METHOD_NAMES_LIST.contains(methodName))
|
||||
{
|
||||
Object result = invocation.proceed();
|
||||
if(result instanceof List)
|
||||
{
|
||||
return processList((List<FileInfo>)result);
|
||||
}
|
||||
else if(result instanceof PagingResults)
|
||||
{
|
||||
return processPagingResults((PagingResults<FileInfo>)result);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ClassCastException("Unexpected return type from method " + methodName + " in " + this);
|
||||
}
|
||||
ret = orderedPagingResults;
|
||||
}
|
||||
else if (METHOD_NAMES_SINGLE.contains(methodName))
|
||||
{
|
||||
|
Reference in New Issue
Block a user