mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Plugged in the correct mlTranslationInterceptor for FileFolderService and removed the NodeService interceptor.
Removed some unecessary interceptor work. Fixed content filtering to default to the pivot translation if there is no translation for a required language. Fixed content filtering when switching back to ALL LANGUAGES. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5802 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -30,7 +30,6 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
@@ -123,7 +122,6 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
private CopyService copyService;
|
||||
private SearchService searchService;
|
||||
private ContentService contentService;
|
||||
private MultilingualContentService multilingualContentService;
|
||||
private MimetypeService mimetypeService;
|
||||
|
||||
// TODO: Replace this with a more formal means of identifying "system" folders (i.e. aspect or UUID)
|
||||
@@ -167,11 +165,6 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
this.contentService = contentService;
|
||||
}
|
||||
|
||||
public void setMultilingualContentService(MultilingualContentService multilingualContentService)
|
||||
{
|
||||
this.multilingualContentService = multilingualContentService;
|
||||
}
|
||||
|
||||
public void setMimetypeService(MimetypeService mimetypeService)
|
||||
{
|
||||
this.mimetypeService = mimetypeService;
|
||||
@@ -217,40 +210,15 @@ public class FileFolderServiceImpl implements FileFolderService
|
||||
*/
|
||||
private FileInfo toFileInfo(NodeRef nodeRef, boolean addTranslations) throws InvalidTypeException
|
||||
{
|
||||
// get the file attributes
|
||||
// Get the file attributes
|
||||
Map<QName, Serializable> properties = nodeService.getProperties(nodeRef);
|
||||
// is it a folder
|
||||
// Is it a folder
|
||||
QName typeQName = nodeService.getType(nodeRef);
|
||||
boolean isFolder = isFolder(typeQName);
|
||||
|
||||
Map<Locale, FileInfo> translations = null;
|
||||
if (!isFolder && addTranslations)
|
||||
{
|
||||
// Get any translations
|
||||
translations = new HashMap<Locale, FileInfo>(13);
|
||||
// Check for the ML aspect
|
||||
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT))
|
||||
{
|
||||
// Get all the translations
|
||||
Map<Locale, NodeRef> translationsToConvert = multilingualContentService.getTranslations(nodeRef);
|
||||
for (Map.Entry<Locale, NodeRef> entry : translationsToConvert.entrySet())
|
||||
{
|
||||
Locale locale = entry.getKey();
|
||||
NodeRef nodeRefToConvert = entry.getValue();
|
||||
FileInfo convertedFileInfo = toFileInfo(nodeRefToConvert, false);
|
||||
// Add to map
|
||||
translations.put(locale, convertedFileInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
translations = Collections.<Locale, FileInfo>emptyMap();
|
||||
}
|
||||
|
||||
// construct the file info and add to the results
|
||||
FileInfo fileInfo = new FileInfoImpl(nodeRef, isFolder, properties, translations);
|
||||
// done
|
||||
// Construct the file info and add to the results
|
||||
FileInfo fileInfo = new FileInfoImpl(nodeRef, isFolder, properties);
|
||||
// Done
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
|
@@ -25,9 +25,7 @@
|
||||
package org.alfresco.repo.model.filefolder;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
@@ -46,7 +44,6 @@ public class FileInfoImpl implements FileInfo
|
||||
{
|
||||
private NodeRef nodeRef;
|
||||
private NodeRef linkNodeRef;
|
||||
private Map<Locale, FileInfo> translations;
|
||||
private boolean isFolder;
|
||||
private boolean isLink;
|
||||
private Map<QName, Serializable> properties;
|
||||
@@ -54,33 +51,14 @@ public class FileInfoImpl implements FileInfo
|
||||
/**
|
||||
* Package-level constructor
|
||||
*/
|
||||
/* package */ FileInfoImpl(NodeRef nodeRef, boolean isFolder, Map<QName, Serializable> properties)
|
||||
{
|
||||
this(nodeRef, isFolder, properties, Collections.<Locale, FileInfo>emptyMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* Package-level constructor
|
||||
*
|
||||
* @param translations a map of translations including this instance. It may be null.
|
||||
*/
|
||||
/* package */ FileInfoImpl(
|
||||
NodeRef nodeRef,
|
||||
boolean isFolder,
|
||||
Map<QName, Serializable> properties,
|
||||
Map<Locale, FileInfo> translations)
|
||||
Map<QName, Serializable> properties)
|
||||
{
|
||||
this.nodeRef = nodeRef;
|
||||
this.isFolder = isFolder;
|
||||
this.properties = properties;
|
||||
if (translations == null || isFolder)
|
||||
{
|
||||
this.translations = Collections.<Locale, FileInfo>emptyMap();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.translations = translations;
|
||||
}
|
||||
|
||||
// Check if this is a link node
|
||||
if ( properties.containsKey( ContentModel.PROP_LINK_DESTINATION))
|
||||
@@ -97,7 +75,15 @@ public class FileInfoImpl implements FileInfo
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (obj == null || this.getClass().isInstance(obj))
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (this == obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (obj instanceof FileInfoImpl == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -130,8 +116,6 @@ public class FileInfoImpl implements FileInfo
|
||||
sb.append(linkNodeRef);
|
||||
}
|
||||
|
||||
sb.append(", translations=").append(translations.size());
|
||||
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
@@ -156,11 +140,6 @@ public class FileInfoImpl implements FileInfo
|
||||
return linkNodeRef;
|
||||
}
|
||||
|
||||
public Map<Locale, FileInfo> getTranslations()
|
||||
{
|
||||
return translations;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return (String) properties.get(ContentModel.PROP_NAME);
|
||||
|
@@ -97,6 +97,7 @@ public class MLTranslationInterceptor implements MethodInterceptor
|
||||
|
||||
private NodeService nodeService;
|
||||
private MultilingualContentService multilingualContentService;
|
||||
private FileFolderService fileFolderService;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -115,6 +116,11 @@ public class MLTranslationInterceptor implements MethodInterceptor
|
||||
this.multilingualContentService = multilingualContentService;
|
||||
}
|
||||
|
||||
public void setFileFolderService(FileFolderService fileFolderService)
|
||||
{
|
||||
this.fileFolderService = fileFolderService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the node referenice where an alternative translation should be used.
|
||||
*
|
||||
@@ -133,13 +139,14 @@ public class MLTranslationInterceptor implements MethodInterceptor
|
||||
{
|
||||
return nodeRef;
|
||||
}
|
||||
// Find the translation
|
||||
Map<Locale, NodeRef> translations = multilingualContentService.getTranslations(nodeRef);
|
||||
Locale filterLocale = I18NUtil.getContentLocaleOrNull();
|
||||
Set<Locale> possibleLocales = translations.keySet();
|
||||
Locale localeToUse = I18NUtil.getNearestLocale(filterLocale, possibleLocales);
|
||||
// Select the node
|
||||
NodeRef translatedNodeRef = translations.get(localeToUse);
|
||||
if (filterLocale == null)
|
||||
{
|
||||
// We aren't doing any filtering
|
||||
return nodeRef;
|
||||
}
|
||||
// Find the best translation. This won't return null.
|
||||
NodeRef translatedNodeRef = multilingualContentService.getTranslationForLocale(nodeRef, filterLocale);
|
||||
// Done
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
@@ -152,7 +159,7 @@ public class MLTranslationInterceptor implements MethodInterceptor
|
||||
logger.debug("NodeRef substitution: " + nodeRef + " (no change)");
|
||||
}
|
||||
}
|
||||
return nodeRef;
|
||||
return translatedNodeRef;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,8 +167,6 @@ public class MLTranslationInterceptor implements MethodInterceptor
|
||||
*
|
||||
* @param fileInfo the basic file or folder info
|
||||
* @return Returns a replacement if required
|
||||
*
|
||||
* @see FileInfo#getTranslations()
|
||||
*/
|
||||
private FileInfo getTranslatedFileInfo(FileInfo fileInfo)
|
||||
{
|
||||
@@ -175,28 +180,20 @@ public class MLTranslationInterceptor implements MethodInterceptor
|
||||
{
|
||||
return fileInfo;
|
||||
}
|
||||
// Ignore files without translations
|
||||
Map<Locale, FileInfo> translations = fileInfo.getTranslations();
|
||||
if (translations.size() == 0)
|
||||
NodeRef nodeRef = fileInfo.getNodeRef();
|
||||
// Get the best translation for the node
|
||||
NodeRef translatedNodeRef = getTranslatedNodeRef(nodeRef);
|
||||
// Convert to FileInfo, if required
|
||||
FileInfo translatedFileInfo = null;
|
||||
if (nodeRef.equals(translatedNodeRef))
|
||||
{
|
||||
return fileInfo;
|
||||
// No need to do any more work
|
||||
translatedFileInfo = fileInfo;
|
||||
}
|
||||
// Get the locale to use
|
||||
Set<Locale> possibleLocales = translations.keySet();
|
||||
Locale filterLocale = I18NUtil.getContentLocaleOrNull();
|
||||
Locale localeToUse = I18NUtil.getNearestLocale(filterLocale, possibleLocales);
|
||||
FileInfo translatedFileInfo = translations.get(localeToUse);
|
||||
// Done
|
||||
if (logger.isDebugEnabled())
|
||||
else
|
||||
{
|
||||
if (fileInfo.equals(translatedFileInfo))
|
||||
{
|
||||
logger.debug("FileInfo substitution: " + fileInfo + " --> " + translatedFileInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.debug("FileInfo substitution: " + fileInfo + " (no change)");
|
||||
}
|
||||
// Get the FileInfo
|
||||
translatedFileInfo = fileFolderService.getFileInfo(translatedNodeRef);
|
||||
}
|
||||
return translatedFileInfo;
|
||||
}
|
||||
@@ -207,7 +204,12 @@ public class MLTranslationInterceptor implements MethodInterceptor
|
||||
Object ret = null;
|
||||
String methodName = invocation.getMethod().getName();
|
||||
|
||||
if (METHOD_NAMES_LIST.contains(methodName))
|
||||
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))
|
||||
{
|
||||
List<FileInfo> fileInfos = (List<FileInfo>) invocation.proceed();
|
||||
// Compile a set to ensure we don't get duplicates
|
||||
@@ -223,13 +225,14 @@ public class MLTranslationInterceptor implements MethodInterceptor
|
||||
Set<FileInfo> alreadyPresent = new HashSet<FileInfo>(fileInfos.size() * 2 + 1);
|
||||
for (FileInfo info : fileInfos)
|
||||
{
|
||||
if (alreadyPresent.contains(info))
|
||||
FileInfo translatedFileInfo = translatedFileInfos.get(info);
|
||||
if (alreadyPresent.contains(translatedFileInfo))
|
||||
{
|
||||
// We've done this one
|
||||
continue;
|
||||
}
|
||||
alreadyPresent.add(info);
|
||||
orderedResults.add(translatedFileInfos.get(info));
|
||||
alreadyPresent.add(translatedFileInfo);
|
||||
orderedResults.add(translatedFileInfo);
|
||||
}
|
||||
ret = orderedResults;
|
||||
}
|
||||
|
@@ -22,7 +22,6 @@
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.model.ml;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -51,17 +50,8 @@ import org.alfresco.service.namespace.QName;
|
||||
public class MLContainerType implements
|
||||
NodeServicePolicies.OnUpdatePropertiesPolicy
|
||||
{
|
||||
/**
|
||||
* set a property with this QName when the deletion process is running on the mlContainer. In this case
|
||||
* the policies of the remove aspect of mlDocument don't delete one more time the mlContainer.
|
||||
*/
|
||||
/*package*/ static QName PROP_NAME_DELETION_RUNNING = QName.createQName("__MLContanier_", "Deletion_Running");
|
||||
|
||||
// Dependencies
|
||||
private PolicyComponent policyComponent;
|
||||
|
||||
private NodeService nodeService;
|
||||
|
||||
private MultilingualContentService multilingualContentService;
|
||||
|
||||
/**
|
||||
|
@@ -103,18 +103,26 @@ public class MLContentInterceptor implements MethodInterceptor
|
||||
}
|
||||
// Get the pivot translation
|
||||
NodeRef pivotNodeRef = multilingualContentService.getPivotTranslation(nodeRef);
|
||||
// Get the reader from that
|
||||
ContentReader pivotContentReader = contentService.getReader(pivotNodeRef, propertyQName);
|
||||
// Done
|
||||
if (logger.isDebugEnabled())
|
||||
if (pivotNodeRef == null)
|
||||
{
|
||||
logger.debug(
|
||||
"Converted reader for empty translation: \n" +
|
||||
" Empty Translation: " + nodeRef + "\n" +
|
||||
" Pivot Translation: " + pivotNodeRef + "\n" +
|
||||
" Reader: " + pivotContentReader);
|
||||
// This is technically possible
|
||||
ret = invocation.proceed();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get the reader from that
|
||||
ContentReader pivotContentReader = contentService.getReader(pivotNodeRef, propertyQName);
|
||||
// Done
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug(
|
||||
"Converted reader for empty translation: \n" +
|
||||
" Empty Translation: " + nodeRef + "\n" +
|
||||
" Pivot Translation: " + pivotNodeRef + "\n" +
|
||||
" Reader: " + pivotContentReader);
|
||||
}
|
||||
ret = pivotContentReader;
|
||||
}
|
||||
ret = pivotContentReader;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -561,6 +561,16 @@ public class MultilingualContentServiceImpl implements MultilingualContentServic
|
||||
Set<Locale> locales = nodeRefsByLocale.keySet();
|
||||
Locale nearestLocale = I18NUtil.getNearestLocale(locale, locales);
|
||||
NodeRef nearestNodeRef = nodeRefsByLocale.get(nearestLocale);
|
||||
if (nearestNodeRef == null)
|
||||
{
|
||||
// There is no translation for the locale, so get the pivot translation
|
||||
nearestNodeRef = getPivotTranslation(translationNodeRef);
|
||||
if (nearestNodeRef == null)
|
||||
{
|
||||
// There is no pivot translation, so just use the given node
|
||||
nearestNodeRef = translationNodeRef;
|
||||
}
|
||||
}
|
||||
// Done
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
@@ -629,24 +639,34 @@ public class MultilingualContentServiceImpl implements MultilingualContentServic
|
||||
/** @inheritDoc */
|
||||
public NodeRef getPivotTranslation(NodeRef nodeRef)
|
||||
{
|
||||
Locale containerLocale = null;
|
||||
if(nodeService.hasAspect(nodeRef, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT))
|
||||
{
|
||||
NodeRef container = getTranslationContainer(nodeRef);
|
||||
Locale containerLocale = (Locale) nodeService.getProperty(container, ContentModel.PROP_LOCALE);
|
||||
|
||||
return getTranslationForLocale(nodeRef, containerLocale);
|
||||
containerLocale = (Locale) nodeService.getProperty(container, ContentModel.PROP_LOCALE);
|
||||
}
|
||||
else if(ContentModel.TYPE_MULTILINGUAL_CONTAINER.equals(nodeService.getType(nodeRef)))
|
||||
{
|
||||
Locale containerLocale = (Locale) nodeService.getProperty(nodeRef, ContentModel.PROP_LOCALE);
|
||||
return getTranslationForLocale(nodeRef, containerLocale);
|
||||
containerLocale = (Locale) nodeService.getProperty(nodeRef, ContentModel.PROP_LOCALE);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn("The node is not multilingual " + nodeRef);
|
||||
|
||||
}
|
||||
// Get all the translations
|
||||
Map<Locale, NodeRef> nodeRefsByLocale = getTranslations(nodeRef);
|
||||
// Get the closest matching locale
|
||||
Set<Locale> locales = nodeRefsByLocale.keySet();
|
||||
Locale nearestLocale = I18NUtil.getNearestLocale(containerLocale, locales);
|
||||
if (nearestLocale == null)
|
||||
{
|
||||
// There is pivot translation
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return nodeRefsByLocale.get(nearestLocale);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -137,31 +137,51 @@ public class MultilingualContentServiceImplTest extends AbstractMultilingualTest
|
||||
assertFalse("Missing Translation List false. Locale " + loc2 + " or " + loc3 + " found", missing.contains(loc2.toString()) || missing.contains(loc3.toString()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void testPivotTranslation() throws Exception
|
||||
public void testGetTranslationForLocale() throws Exception
|
||||
{
|
||||
NodeRef chineseContentNodeRef = createContent();
|
||||
NodeRef mlContainerNodeRef = multilingualContentService.makeTranslation(chineseContentNodeRef, Locale.CHINESE);
|
||||
NodeRef frenchContentNodeRef = createContent();
|
||||
multilingualContentService.addTranslation(frenchContentNodeRef, chineseContentNodeRef, Locale.FRENCH);
|
||||
|
||||
// Get the chinese translation
|
||||
assertEquals("Chinese translation should be present",
|
||||
chineseContentNodeRef,
|
||||
multilingualContentService.getTranslationForLocale(mlContainerNodeRef, Locale.CHINESE));
|
||||
// Get the french translation
|
||||
assertEquals("French translation should be present",
|
||||
frenchContentNodeRef,
|
||||
multilingualContentService.getTranslationForLocale(mlContainerNodeRef, Locale.FRENCH));
|
||||
// The Italian should return the pivot
|
||||
assertEquals("French translation should be present",
|
||||
chineseContentNodeRef,
|
||||
multilingualContentService.getTranslationForLocale(mlContainerNodeRef, Locale.ITALIAN));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void testGetPivotTranslation() throws Exception
|
||||
{
|
||||
NodeRef chineseContentNodeRef = createContent();
|
||||
NodeRef mlContainerNodeRef = multilingualContentService.makeTranslation(chineseContentNodeRef, Locale.CHINESE);
|
||||
|
||||
// make sure that the pivot language is set
|
||||
assertNotNull("Pivot language not set", nodeService.getProperty(mlContainerNodeRef, ContentModel.PROP_LOCALE));
|
||||
|
||||
// make sure that the pivot language is correctly set
|
||||
assertTrue("Pivot language not correctly set", nodeService.getProperty(mlContainerNodeRef, ContentModel.PROP_LOCALE).equals(Locale.CHINESE));
|
||||
assertEquals("Pivot language not correctly set", Locale.CHINESE, nodeService.getProperty(mlContainerNodeRef, ContentModel.PROP_LOCALE));
|
||||
|
||||
NodeRef frenchContentNodeRef = createContent();
|
||||
multilingualContentService.addTranslation(frenchContentNodeRef, chineseContentNodeRef, Locale.FRENCH);
|
||||
|
||||
// make sure that the pivot noderef is correct
|
||||
assertTrue("Pivot node ref not correct", multilingualContentService.getPivotTranslation(mlContainerNodeRef).equals(chineseContentNodeRef));
|
||||
assertEquals("Unable to get pivot from container", chineseContentNodeRef, multilingualContentService.getPivotTranslation(mlContainerNodeRef));
|
||||
assertEquals("Unable to get pivot from translation", chineseContentNodeRef, multilingualContentService.getPivotTranslation(frenchContentNodeRef));
|
||||
|
||||
// modify the pivot language
|
||||
nodeService.setProperty(mlContainerNodeRef, ContentModel.PROP_LOCALE, Locale.FRENCH);
|
||||
|
||||
// make sure that the modified pivot noderef is correct
|
||||
assertTrue("Pivot node ref not correct", multilingualContentService.getPivotTranslation(mlContainerNodeRef).equals(frenchContentNodeRef));
|
||||
|
||||
assertEquals("Pivot node ref not correct", frenchContentNodeRef, multilingualContentService.getPivotTranslation(mlContainerNodeRef));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
Reference in New Issue
Block a user