Yannick Pignot (European Commission) multilingual services

- EditionService for versioning of groups of translations
 - Quite a bit of trimming of whitespace that I have no intention of undoing.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5927 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2007-06-13 01:13:25 +00:00
parent f4c758dfe5
commit 9e836f04f8
23 changed files with 1835 additions and 1067 deletions

View File

@@ -15,11 +15,11 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.model.ml.tools;
@@ -33,6 +33,7 @@ import org.alfresco.repo.transaction.TransactionUtil;
import org.alfresco.repo.transaction.TransactionUtil.TransactionWork;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.ml.ContentFilterLanguagesService;
import org.alfresco.service.cmr.ml.EditionService;
import org.alfresco.service.cmr.ml.MultilingualContentService;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.repository.ContentWriter;
@@ -48,12 +49,12 @@ import org.springframework.context.ApplicationContext;
/**
* Base multilingual test cases
*
*
* @author yanipig
*/
public abstract class AbstractMultilingualTestCases extends TestCase
public abstract class AbstractMultilingualTestCases extends TestCase
{
protected static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
protected ServiceRegistry serviceRegistry;
@@ -66,6 +67,8 @@ public abstract class AbstractMultilingualTestCases extends TestCase
protected NodeRef folderNodeRef;
protected ContentFilterLanguagesService contentFilterLanguagesService;
protected NodeArchiveService nodeArchiveService;
protected EditionService editionService;
@Override
protected void setUp() throws Exception
{
@@ -78,10 +81,11 @@ public abstract class AbstractMultilingualTestCases extends TestCase
versionService = serviceRegistry.getVersionService();
multilingualContentService = (MultilingualContentService) ctx.getBean("MultilingualContentService");
contentFilterLanguagesService = (ContentFilterLanguagesService) ctx.getBean("ContentFilterLanguagesService");
editionService = (EditionService) ctx.getBean("EditionService");
// Run as admin
authenticationComponent.setCurrentUser("admin");
// Create a folder to work in
TransactionWork<NodeRef> createFolderWork = new TransactionWork<NodeRef>()
{
@@ -101,7 +105,7 @@ public abstract class AbstractMultilingualTestCases extends TestCase
};
folderNodeRef = TransactionUtil.executeInUserTransaction(transactionService, createFolderWork);
}
@Override
protected void tearDown() throws Exception
{
@@ -115,13 +119,13 @@ public abstract class AbstractMultilingualTestCases extends TestCase
e.printStackTrace();
}
}
protected NodeRef createContent()
{
String name = "" + System.currentTimeMillis();
return createContent(name);
}
protected NodeRef createContent(String name)
{
NodeRef contentNodeRef = fileFolderService.create(
@@ -134,7 +138,7 @@ public abstract class AbstractMultilingualTestCases extends TestCase
// done
return contentNodeRef;
}
public void testSetup() throws Exception
{
// Ensure that content can be created

View File

@@ -35,7 +35,7 @@ import java.util.Locale;
* @see org.alfresco.service.cmr.ml.ContentFilterLanguagesService
* @see org.alfresco.repo.model.ml.ContentFilterLanguagesMap
*
* @author yanipig
* @author Yannick Pignot
*/
public class ContentFilterLanguagesMapTest extends AbstractMultilingualTestCases
{

View File

@@ -0,0 +1,233 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.model.ml.tools;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.version.VersionModel;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionHistory;
import org.alfresco.service.cmr.version.VersionType;
/**
* Edition Service test cases
*
* @since 2.1
* @author Yannick Pignot
*/
public class EditionServiceImplTest extends AbstractMultilingualTestCases
{
private static String FRENCH_CONTENT = "FRENCH_CONTENT";
private static String CHINESE_CONTENT = "CHINESE_CONTENT";
private static String JAPANESE_CONTENT = "JAPANESE_CONTENT";
public void testAutoEdition() throws Exception
{
// create a mlContainer with some content
checkFirstVersion(this.createMLContainerWithContent());
}
public void testEditionLabels()
{
// create a mlContainer with some content
NodeRef mlContainerNodeRef = createMLContainerWithContent();
Map<String, Serializable> versionProperties = null;
List<Version> editions = null;
NodeRef pivot = multilingualContentService.getPivotTranslation(mlContainerNodeRef);
checkFirstVersion(mlContainerNodeRef);
/*
* at the creation (1.0)
*/
Version rootEdition = editionService.getEditions(mlContainerNodeRef).getAllVersions().iterator().next();
// Ensure that the version label is 1.0
assertTrue("The edition label would be 1.0 and not " + rootEdition.getVersionLabel(), rootEdition.getVersionLabel().equals("1.0"));
/*
* default (1.1)
*/
pivot = editionService.createEdition(pivot, versionProperties);
editions = orderVersions(editionService.getEditions(mlContainerNodeRef).getAllVersions());
Version firstEdition = editions.get(0);
// Ensure that the version label is 1.1
assertTrue("The edition label would be 1.1 and not " + firstEdition.getVersionLabel(), firstEdition.getVersionLabel().equals("1.1"));
/*
* major (2.0)
*/
versionProperties = new HashMap<String, Serializable>();
versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
pivot = editionService.createEdition(pivot, versionProperties);
editions = orderVersions(editionService.getEditions(mlContainerNodeRef).getAllVersions());
Version secondEdition = editions.get(0);
// Ensure that the version label is 2.0
assertTrue("The edition label would be 2.0 and not " + secondEdition.getVersionLabel(), secondEdition.getVersionLabel().equals("2.0"));
/*
* minor (2.1)
*/
versionProperties = new HashMap<String, Serializable>();
versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);
pivot = editionService.createEdition(pivot, versionProperties);
editions = orderVersions(editionService.getEditions(mlContainerNodeRef).getAllVersions());
Version thirdEdition = editions.get(0);
// Ensure that the version label is 2.1
assertTrue("The edition label would be 2.1 and not " + thirdEdition.getVersionLabel(), thirdEdition.getVersionLabel().equals("2.1"));
}
public void testCreateEdition() throws Exception
{
// create a mlContainer with some content
NodeRef mlContainerNodeRef = createMLContainerWithContent();
// get the french translation
NodeRef frenchContentNodeRef = multilingualContentService.getTranslationForLocale(mlContainerNodeRef, Locale.FRENCH);
checkFirstVersion(mlContainerNodeRef);
// create a new edition form the french translation
NodeRef newStartingPoint = editionService.createEdition(frenchContentNodeRef, null);
// get the edition history
VersionHistory editionHistory = editionService.getEditions(mlContainerNodeRef);
// Ensure that the edition history contains two versions
assertTrue("The edition history must contain two versions", editionHistory.getAllVersions().size() == 2);
// Ensure that the locale of the container is changer
assertTrue("The locale of the conatiner should be changed", nodeService.getProperty(mlContainerNodeRef, ContentModel.PROP_LOCALE).equals(Locale.FRENCH));
// get the two editions
Version rootEdition = editionHistory.getVersion("1.0");
Version actualEdition = editionHistory.getVersion("1.1");
// get the translations of the root versions
List<VersionHistory> rootVersionTranslations = editionService.getVersionedTranslations(rootEdition);
// Ensure that the editions are not null
assertNotNull("The root edition can't be null", rootEdition);
assertNotNull("The actual edition can't be null", actualEdition);
assertNotNull("The translations list of the root edition can't be null", rootVersionTranslations);
// Ensure that the new starting document noderef is different that the initial one
assertFalse("The created starting document must be different that the starting document of the edition", frenchContentNodeRef.equals(newStartingPoint));
// Ensure that the new starting document is the pivot of the current translation
assertTrue("The new pivot must be equal to the created starting document", newStartingPoint.equals(multilingualContentService.getPivotTranslation(mlContainerNodeRef)));
int numberOfTranslations;
// Ensure that the current translations size is 1
numberOfTranslations = multilingualContentService.getTranslations(mlContainerNodeRef).size();
assertEquals("The number of translations must be 1 and not " + numberOfTranslations, 1, numberOfTranslations);
// Ensure that the number of translations of the current edition is 0
numberOfTranslations = editionService.getVersionedTranslations(actualEdition).size();
assertEquals("The number of translations must be 0 and not " + numberOfTranslations, 0, numberOfTranslations);
// Ensure that the number of translations of the root verions is 3
numberOfTranslations = rootVersionTranslations.size();
assertEquals("The number of translations must be 3 and not " + numberOfTranslations, 3, numberOfTranslations);
}
public void testReadVersionedContent() throws Exception
{
}
public void testReadVersionedProperties() throws Exception
{
}
private void checkFirstVersion(NodeRef mlContainerNodeRef)
{
// get the edition list of edition
VersionHistory editionHistory = editionService.getEditions(mlContainerNodeRef);
// Ensure that the first edition of the mlContainer is created
assertNotNull("The edition history can't be null", editionHistory);
// Ensure that it contains only one version
assertTrue("The edition history must contain only one edition", editionHistory.getAllVersions().size() == 1);
// get the edition
Version currentEdition = editionHistory.getAllVersions().iterator().next();
// Ensure that this version is the edition of the mlContainer
assertTrue("The versioned mlContainer noderef of the editon must be the noderef of the created mlContainer", currentEdition.getVersionedNodeRef().equals(mlContainerNodeRef));
// get the list of translations
List<VersionHistory> translations = editionService.getVersionedTranslations(currentEdition);
// Ensure that the get versioned translations is empty
assertNotNull("The translations list of the current edition can't be null", translations);
// Ensure that the list is empty
assertTrue("The translations list of the current edition would be empty", translations.size() == 0);
}
private NodeRef createMLContainerWithContent()
{
NodeRef chineseContentNodeRef = createContent(CHINESE_CONTENT + "_1.0");
NodeRef frenchContentNodeRef = createContent(FRENCH_CONTENT + "_1.0");
NodeRef japaneseContentNodeRef = createContent(JAPANESE_CONTENT + "_1.0");
multilingualContentService.makeTranslation(chineseContentNodeRef, Locale.CHINESE);
multilingualContentService.addTranslation(frenchContentNodeRef, chineseContentNodeRef, Locale.FRENCH);
multilingualContentService.addTranslation(japaneseContentNodeRef, chineseContentNodeRef, Locale.JAPANESE);
return multilingualContentService.getTranslationContainer(chineseContentNodeRef);
}
private Comparator versionComparator = new Comparator()
{
public int compare(Object o1, Object o2)
{
String label01 = ((Version) o1).getVersionLabel();
String label02 = ((Version) o2).getVersionLabel();
// sort the list ascending
return label02.compareTo(label01);
}
};
@SuppressWarnings("unchecked")
private List<Version> orderVersions(Collection<Version> allVersions)
{
List<Version> versionsAsList = new ArrayList<Version>(allVersions.size());
versionsAsList.addAll(allVersions);
Collections.sort(versionsAsList, versionComparator);
return versionsAsList;
}
}

View File

@@ -40,7 +40,7 @@ import org.alfresco.service.namespace.QName;
*
* @see org.alfresco.service.cmr.ml.EmptyTranslationAspect
*
* @author yanipig
* @author Yannick Pignot
*/
public class EmptyTranslationAspectTest extends AbstractMultilingualTestCases {

View File

@@ -37,7 +37,7 @@ import org.alfresco.service.namespace.QName;
*
* @see org.alfresco.service.cmr.ml.MLContainerType
*
* @author yanipig
* @author Yannick Pignot
*/
public class MLContainerTypeTest extends AbstractMultilingualTestCases
{

View File

@@ -24,11 +24,8 @@
*/
package org.alfresco.repo.model.ml.tools;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import net.sf.acegisecurity.Authentication;
@@ -39,8 +36,6 @@ 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.security.PermissionService;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionHistory;
/**
* @see org.alfresco.repo.ml.MultilingualContentServiceImpl
@@ -231,58 +226,6 @@ public class MultilingualContentServiceImplTest extends AbstractMultilingualTest
assertEquals("Empty translation name not generated correctly.", "Document2.txt", differentName);
}
@SuppressWarnings("unused")
public void testCreateEdition() throws Exception
{
// Make some content
NodeRef chineseContentNodeRef = createContent();
NodeRef frenchContentNodeRef = createContent();
NodeRef japaneseContentNodeRef = createContent();
// Add to container
multilingualContentService.makeTranslation(chineseContentNodeRef, Locale.CHINESE);
multilingualContentService.addTranslation(frenchContentNodeRef, chineseContentNodeRef, Locale.FRENCH);
multilingualContentService.addTranslation(japaneseContentNodeRef, chineseContentNodeRef, Locale.JAPANESE);
NodeRef mlContainerNodeRef = multilingualContentService.getTranslationContainer(chineseContentNodeRef);
// Check the container child count
assertEquals("Incorrect number of child nodes", 3, nodeService.getChildAssocs(mlContainerNodeRef).size());
// Version each of the documents
List<NodeRef> nodeRefs = new ArrayList<NodeRef>(3);
nodeRefs.add(chineseContentNodeRef);
nodeRefs.add(frenchContentNodeRef);
nodeRefs.add(japaneseContentNodeRef);
versionService.createVersion(nodeRefs, null);
// Get the current versions of each of the documents
Version chineseVersionPreEdition = versionService.getCurrentVersion(chineseContentNodeRef);
Version frenchVersionPreEdition = versionService.getCurrentVersion(frenchContentNodeRef);
Version japaneseVersionPreEdition = versionService.getCurrentVersion(japaneseContentNodeRef);
// Create the edition, keeping the Chinese translation as the basis
multilingualContentService.createEdition(chineseContentNodeRef);
// Check the container child count
assertEquals("Incorrect number of child nodes", 1, nodeService.getChildAssocs(mlContainerNodeRef).size());
// Get the document versions now
Version chineseVersionPostEdition = versionService.getCurrentVersion(chineseContentNodeRef);
assertFalse("Expected document to be gone", nodeService.exists(frenchContentNodeRef));
assertFalse("Expected document to be gone", nodeService.exists(japaneseContentNodeRef));
// Now be sure that we can get the required information using the version service
VersionHistory mlContainerVersionHistory = versionService.getVersionHistory(mlContainerNodeRef);
Collection<Version> mlContainerVersions = mlContainerVersionHistory.getAllVersions();
// Loop through and get all the children of each version
for (Version mlContainerVersion : mlContainerVersions)
{
NodeRef versionedMLContainerNodeRef = mlContainerVersion.getFrozenStateNodeRef();
// Get all the children
Map<Locale, NodeRef> translationsByLocale = multilingualContentService.getTranslations(
versionedMLContainerNodeRef);
// Count the children
int count = translationsByLocale.size();
}
}
public void testGetTranslationContainerPermissions() throws Exception
{
// Grant the guest user rights to our working folder
@@ -335,7 +278,6 @@ public class MultilingualContentServiceImplTest extends AbstractMultilingualTest
multilingualContentService.makeTranslation(chineseContentNodeRef, Locale.CHINESE);
multilingualContentService.addTranslation(frenchContentNodeRef, chineseContentNodeRef, Locale.FRENCH);
multilingualContentService.addEmptyTranslation(chineseContentNodeRef, null, Locale.JAPANESE);
multilingualContentService.createEdition(chineseContentNodeRef);
}
finally
{

View File

@@ -37,7 +37,7 @@ import org.alfresco.service.namespace.QName;
*
* @see org.alfresco.service.cmr.ml.MultilingualDocumentAspect
*
* @author yanipig
* @author Yannick Pignot
*/
public class MultilingualDocumentAspectTest extends AbstractMultilingualTestCases
{