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:
@@ -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