mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ML fixes
- The naming convention for a french empty translation of x.doc is x_fr.doc - Fixed mimetype and initial file sizes - Raised minor issue: AR-1487 - Shortened crazy language names - Made language name ordering follow the declaration order in the config XML file git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5812 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -37,7 +37,6 @@ import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.search.QueryParameterDefImpl;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.ml.MultilingualContentService;
|
||||
import org.alfresco.service.cmr.model.FileExistsException;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
|
@@ -59,7 +59,6 @@ public class ContentFilterLanguagesMap implements ContentFilterLanguagesService
|
||||
private static final String DEFAULT_LANGUAGE_LIST_STANDARD = "ISO 639-1";
|
||||
|
||||
private static final String ATTR_CODE = "code";
|
||||
private static final String ATTR_ORDER = "order";
|
||||
private static final String ATTR_DEFAULT = "default";
|
||||
|
||||
private static final Log logger = LogFactory.getLog(ContentFilterLanguagesMap.class);
|
||||
@@ -210,11 +209,10 @@ public class ContentFilterLanguagesMap implements ContentFilterLanguagesService
|
||||
for (ConfigElement langElem : languages)
|
||||
{
|
||||
String code = convertToOldISOCode(langElem.getAttribute(ATTR_CODE));
|
||||
String order = langElem.getAttribute(ATTR_ORDER);
|
||||
String value = langElem.getValue();
|
||||
String def = langElem.getAttribute(ATTR_DEFAULT);
|
||||
|
||||
orderedLangCodes.add(Integer.parseInt(order) - 1, code);
|
||||
orderedLangCodes.add(code);
|
||||
|
||||
languagesByCode.put(code, value);
|
||||
|
||||
|
@@ -39,6 +39,7 @@ import org.alfresco.repo.version.VersionModel;
|
||||
import org.alfresco.service.cmr.ml.ContentFilterLanguagesService;
|
||||
import org.alfresco.service.cmr.ml.MultilingualContentService;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
@@ -674,56 +675,95 @@ public class MultilingualContentServiceImpl implements MultilingualContentServic
|
||||
*/
|
||||
public NodeRef addEmptyTranslation(NodeRef translationOfNodeRef, String name, Locale locale)
|
||||
{
|
||||
// any node used as reference
|
||||
NodeRef anyTranslation;
|
||||
// the empty document to create
|
||||
NodeRef newTranslationNodeRef = null;
|
||||
|
||||
QName typeQName = nodeService.getType(translationOfNodeRef);
|
||||
if (typeQName.equals(ContentModel.TYPE_MULTILINGUAL_CONTAINER))
|
||||
boolean hasMLAspect = nodeService.hasAspect(translationOfNodeRef, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT);
|
||||
if (hasMLAspect || typeQName.equals(ContentModel.TYPE_MULTILINGUAL_CONTAINER))
|
||||
{
|
||||
// Set the ml container ans get the pivot
|
||||
anyTranslation = getPivotTranslation(translationOfNodeRef);
|
||||
}
|
||||
else if(nodeService.hasAspect(translationOfNodeRef, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT))
|
||||
{
|
||||
anyTranslation = translationOfNodeRef;
|
||||
// Get the pivot translation
|
||||
NodeRef pivotTranslationNodeRef = getPivotTranslation(translationOfNodeRef);
|
||||
if (pivotTranslationNodeRef != null)
|
||||
{
|
||||
// We found a pivot translation, so use it
|
||||
translationOfNodeRef = pivotTranslationNodeRef;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We use the given translation, provided it is an actual translation
|
||||
if (!hasMLAspect)
|
||||
{
|
||||
throw new IllegalArgumentException(
|
||||
"The node provided is not associated with a pivot translation " +
|
||||
"and is not in itself a translation: \n" +
|
||||
" Translation: " + translationOfNodeRef + "\n" +
|
||||
" Locale: " + locale);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException(
|
||||
"Node must have aspect " + ContentModel.ASPECT_MULTILINGUAL_DOCUMENT + " applied or be a " + ContentModel.TYPE_MULTILINGUAL_CONTAINER);
|
||||
"Node must have aspect " + ContentModel.ASPECT_MULTILINGUAL_DOCUMENT +
|
||||
" or be a " + ContentModel.TYPE_MULTILINGUAL_CONTAINER + ": \n" +
|
||||
" Translation: " + translationOfNodeRef + "\n" +
|
||||
" Locale: " + locale);
|
||||
}
|
||||
|
||||
FileInfo translationOfFileInfo = fileFolderService.getFileInfo(translationOfNodeRef);
|
||||
String translationOfName = translationOfFileInfo.getName();
|
||||
// If name is null, supply one
|
||||
if (name == null)
|
||||
{
|
||||
name = translationOfName;
|
||||
}
|
||||
// If there is a name clash, add the locale to the main portion of the filename
|
||||
if (name.equals(translationOfName))
|
||||
{
|
||||
String localeStr = locale.toString();
|
||||
if (localeStr.endsWith("_"))
|
||||
{
|
||||
localeStr = localeStr.substring(0, localeStr.length() - 1);
|
||||
}
|
||||
String rawName;
|
||||
String extension;
|
||||
int index = name.lastIndexOf('.');
|
||||
if (index > 0)
|
||||
{
|
||||
rawName = name.substring(0, index);
|
||||
extension = "." + name.substring(index + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
rawName = name;
|
||||
extension = ""; // No extension
|
||||
}
|
||||
name = rawName + "_" + localeStr + extension;
|
||||
}
|
||||
|
||||
// Create the document in the space of the node of reference
|
||||
NodeRef parentNodeRef = nodeService.getPrimaryParent(anyTranslation).getParentRef();
|
||||
NodeRef parentNodeRef = nodeService.getPrimaryParent(translationOfNodeRef).getParentRef();
|
||||
|
||||
newTranslationNodeRef = fileFolderService.create(
|
||||
// Create the empty translation
|
||||
NodeRef newTranslationNodeRef = fileFolderService.create(
|
||||
parentNodeRef,
|
||||
name,
|
||||
ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
|
||||
|
||||
// add the translation to the container
|
||||
addTranslation(newTranslationNodeRef, translationOfNodeRef, locale);
|
||||
|
||||
// Although the content is spoofed from the pivot translation, it isn't done for all services
|
||||
// TODO: Fix http://issues.alfresco.com/browse/AR-1487
|
||||
ContentData translationOfContentData = (ContentData) nodeService.getProperty(translationOfNodeRef, ContentModel.PROP_CONTENT);
|
||||
if (translationOfContentData != null)
|
||||
{
|
||||
nodeService.setProperty(newTranslationNodeRef, ContentModel.PROP_CONTENT, translationOfContentData);
|
||||
}
|
||||
|
||||
// set it empty
|
||||
nodeService.addAspect(newTranslationNodeRef, ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION, null);
|
||||
// Initially, the file should be temporary. This will be changed as soon as some content is added.
|
||||
nodeService.addAspect(newTranslationNodeRef, ContentModel.ASPECT_TEMPORARY, null);
|
||||
|
||||
// get the extension and set the ContentData property with an null URL.
|
||||
// TODO: Mimetype must be correct, i.e. taken from the original
|
||||
String extension = "";
|
||||
int dotIdx;
|
||||
if((dotIdx = name.lastIndexOf(".")) > -1 )
|
||||
{
|
||||
extension = name.substring(dotIdx);
|
||||
}
|
||||
|
||||
nodeService.setProperty(newTranslationNodeRef, ContentModel.PROP_CONTENT,
|
||||
new ContentData(null, extension, 0, "UTF-8", locale));
|
||||
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Added an empty translation: \n" +
|
||||
|
@@ -117,10 +117,16 @@ public abstract class AbstractMultilingualTestCases extends TestCase
|
||||
}
|
||||
|
||||
protected NodeRef createContent()
|
||||
{
|
||||
String name = "" + System.currentTimeMillis();
|
||||
return createContent(name);
|
||||
}
|
||||
|
||||
protected NodeRef createContent(String name)
|
||||
{
|
||||
NodeRef contentNodeRef = fileFolderService.create(
|
||||
folderNodeRef,
|
||||
"" + System.currentTimeMillis(),
|
||||
name,
|
||||
ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
// add some content
|
||||
ContentWriter contentWriter = fileFolderService.getWriter(contentNodeRef);
|
||||
@@ -128,7 +134,7 @@ public abstract class AbstractMultilingualTestCases extends TestCase
|
||||
// done
|
||||
return contentNodeRef;
|
||||
}
|
||||
|
||||
|
||||
public void testSetup() throws Exception
|
||||
{
|
||||
// Ensure that content can be created
|
||||
|
@@ -30,10 +30,11 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import org.alfresco.i18n.I18NUtil;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||
import org.alfresco.service.cmr.version.Version;
|
||||
import org.alfresco.service.cmr.version.VersionHistory;
|
||||
|
||||
@@ -187,17 +188,57 @@ public class MultilingualContentServiceImplTest extends AbstractMultilingualTest
|
||||
@SuppressWarnings("unused")
|
||||
public void testCreateEmptyTranslation() throws Exception
|
||||
{
|
||||
NodeRef chineseContentNodeRef = createContent();
|
||||
NodeRef chineseContentNodeRef = createContent("Document.txt");
|
||||
NodeRef mlContainerNodeRef = multilingualContentService.makeTranslation(chineseContentNodeRef, Locale.CHINESE);
|
||||
|
||||
NodeRef empty = multilingualContentService.addEmptyTranslation(chineseContentNodeRef, "" + System.currentTimeMillis(), Locale.CANADA);
|
||||
// This should use the pivot language
|
||||
NodeRef emptyNodeRef = multilingualContentService.addEmptyTranslation(mlContainerNodeRef, "Document.txt", Locale.CANADA);
|
||||
|
||||
// Ensure that the empty translation is not null
|
||||
assertNotNull("The creation of the empty document failed ", empty);
|
||||
assertNotNull("The creation of the empty document failed ", emptyNodeRef);
|
||||
// Ensure that the empty translation has the mlDocument aspect
|
||||
assertTrue("The empty document must have the mlDocument aspect", nodeService.hasAspect(empty, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT));
|
||||
assertTrue("The empty document must have the mlDocument aspect",
|
||||
nodeService.hasAspect(emptyNodeRef, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT));
|
||||
// Ensure that the empty translation has the mlEmptyTranslation aspect
|
||||
assertTrue("The empty document must have the mlEmptyTranslation aspect", nodeService.hasAspect(empty, ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION));
|
||||
assertTrue("The empty document must have the mlEmptyTranslation aspect",
|
||||
nodeService.hasAspect(emptyNodeRef, ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION));
|
||||
// Check that the auto renaming worked
|
||||
String emptyName = DefaultTypeConverter.INSTANCE.convert(String.class,
|
||||
nodeService.getProperty(emptyNodeRef, ContentModel.PROP_NAME));
|
||||
assertEquals("Empty auto-rename didn't work for same-named document", "Document_en_CA.txt", emptyName);
|
||||
|
||||
// Check that the content is identical
|
||||
ContentData chineseContentData = fileFolderService.getReader(chineseContentNodeRef).getContentData();
|
||||
ContentData emptyContentData = fileFolderService.getReader(emptyNodeRef).getContentData();
|
||||
}
|
||||
|
||||
public void testCreateEmptyTranslationNames() throws Exception
|
||||
{
|
||||
NodeRef chineseContentNodeRef = createContent("Document.txt");
|
||||
NodeRef mlContainerNodeRef = multilingualContentService.makeTranslation(chineseContentNodeRef, Locale.CHINESE);
|
||||
NodeRef koreanContentNodeRef = createContent("Document_ko.txt");
|
||||
multilingualContentService.addTranslation(koreanContentNodeRef, chineseContentNodeRef, Locale.KOREAN);
|
||||
// Create with a null name, and off a non-pivot just to be sure
|
||||
NodeRef nullNameNodeRef = multilingualContentService.addEmptyTranslation(
|
||||
koreanContentNodeRef,
|
||||
null,
|
||||
Locale.CANADA);
|
||||
String nullName = fileFolderService.getFileInfo(nullNameNodeRef).getName();
|
||||
assertEquals("Empty translation name not generated correctly.", "Document_en_CA.txt", nullName);
|
||||
// Create with the same name
|
||||
NodeRef sameNameNodeRef = multilingualContentService.addEmptyTranslation(
|
||||
mlContainerNodeRef,
|
||||
"Document.txt",
|
||||
Locale.CANADA_FRENCH);
|
||||
String sameName = fileFolderService.getFileInfo(sameNameNodeRef).getName();
|
||||
assertEquals("Empty translation name not generated correctly.", "Document_fr_CA.txt", sameName);
|
||||
// Create with a different name
|
||||
NodeRef differentNameNodeRef = multilingualContentService.addEmptyTranslation(
|
||||
mlContainerNodeRef,
|
||||
"Document2.txt",
|
||||
Locale.JAPANESE);
|
||||
String differentName = fileFolderService.getFileInfo(differentNameNodeRef).getName();
|
||||
assertEquals("Empty translation name not generated correctly.", "Document2.txt", differentName);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
@@ -46,7 +46,6 @@ import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.service.cmr.security.OwnableService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
|
@@ -164,12 +164,20 @@ public interface MultilingualContentService
|
||||
NodeRef getPivotTranslation(NodeRef nodeRef);
|
||||
|
||||
/**
|
||||
* Make a empty translation out of an existing document. The necessary translation structures will be created
|
||||
* as necessary.
|
||||
* Make a empty translation out of an existing pivot translation. The given translation or
|
||||
* container will be used to find the pivot translation. Failing this, the given translation
|
||||
* will be used directly. If no name is provided or if the name is the same as the original's
|
||||
* then the locale will be added to the main portion of the filename, i.e.
|
||||
* <pre>
|
||||
* Document.txt --> Document_fr.txt
|
||||
* </pre>
|
||||
* <p/>
|
||||
* The necessary translation structures will be created as necessary.
|
||||
*
|
||||
* @param translationOfNodeRef An existing <b>cm:mlDocument</b> or <b>cm:mlContainer</b>
|
||||
* @param name The name of the translation to create
|
||||
* @return Returns the new created <b>cm:mlEmptyTranslation</b>
|
||||
* @param name The name of the file to create, or <tt>null</tt> to use
|
||||
* the default naming convention.
|
||||
* @return Returns the new created <b>cm:mlEmptyTranslation</b>
|
||||
*/
|
||||
@Auditable(key = Auditable.Key.ARG_0, parameters = {"translationOfNodeRef", "name", "locale"})
|
||||
NodeRef addEmptyTranslation(NodeRef translationOfNodeRef, String name, Locale locale);
|
||||
|
Reference in New Issue
Block a user