diff --git a/config/alfresco/model-specific-services-context.xml b/config/alfresco/model-specific-services-context.xml
index 310bdeac98..0625ba257b 100644
--- a/config/alfresco/model-specific-services-context.xml
+++ b/config/alfresco/model-specific-services-context.xml
@@ -44,6 +44,7 @@
+
diff --git a/source/java/org/alfresco/repo/model/ml/MultilingualContentServiceImpl.java b/source/java/org/alfresco/repo/model/ml/MultilingualContentServiceImpl.java
index 4664eac3a3..e324c37762 100644
--- a/source/java/org/alfresco/repo/model/ml/MultilingualContentServiceImpl.java
+++ b/source/java/org/alfresco/repo/model/ml/MultilingualContentServiceImpl.java
@@ -29,6 +29,7 @@ import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.SearchParameters;
import org.alfresco.service.cmr.search.SearchService;
+import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
@@ -279,8 +280,50 @@ public class MultilingualContentServiceImpl implements MultilingualContentServic
return mlContainerNodeRef;
}
- public NodeRef createEdition(NodeRef mlContainerNodeRef, NodeRef translationNodeRef)
+ public void createEdition(NodeRef mlContainerNodeRef, NodeRef translationNodeRef)
{
- throw new UnsupportedOperationException();
+ // Ensure that the translation given is one of the children
+ getOrCreateMLContainer(translationNodeRef, false);
+ // Get all the container's children
+ List childAssocRefs = nodeService.getChildAssocs(
+ mlContainerNodeRef,
+ ContentModel.ASSOC_MULTILINGUAL_CHILD,
+ RegexQNamePattern.MATCH_ALL);
+ // Version the container and all its children
+ versionService.createVersion(mlContainerNodeRef, null, true);
+ // Remove all the child documents apart from the given node
+ boolean found = false;
+ for (ChildAssociationRef childAssoc : childAssocRefs)
+ {
+ NodeRef documentNodeRef = childAssoc.getChildRef();
+ // Is this the node to keep?
+ if (documentNodeRef.equals(translationNodeRef))
+ {
+ // It is, so keep it
+ found = true;
+ continue;
+ }
+ // Delete it
+ nodeService.deleteNode(documentNodeRef);
+ }
+ // Check that we left a document
+ if (!found)
+ {
+ throw new AlfrescoRuntimeException(
+ "The translation provided is not a child of the multilingual container: \n" +
+ " Container: " + mlContainerNodeRef + "\n" +
+ " Translation: " + translationNodeRef);
+ }
+ // Done
+ if (logger.isDebugEnabled())
+ {
+ // Get the version information
+ Version mlContainerVersion = versionService.getCurrentVersion(mlContainerNodeRef);
+ String mlContainerVersionLabel = mlContainerVersion.getVersionLabel();
+ logger.debug(
+ "Versioned multilingual container: \n" +
+ " Container: " + mlContainerNodeRef + "\n" +
+ " Current Version: " + mlContainerVersionLabel);
+ }
}
}
diff --git a/source/java/org/alfresco/repo/model/ml/MultilingualContentServiceImplTest.java b/source/java/org/alfresco/repo/model/ml/MultilingualContentServiceImplTest.java
index 5f0be55d43..d8bafd84ed 100644
--- a/source/java/org/alfresco/repo/model/ml/MultilingualContentServiceImplTest.java
+++ b/source/java/org/alfresco/repo/model/ml/MultilingualContentServiceImplTest.java
@@ -16,6 +16,8 @@
*/
package org.alfresco.repo.model.ml;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Locale;
import junit.framework.TestCase;
@@ -27,10 +29,14 @@ import org.alfresco.repo.transaction.TransactionUtil.TransactionWork;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.ml.MultilingualContentService;
import org.alfresco.service.cmr.model.FileFolderService;
+import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentWriter;
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.version.Version;
+import org.alfresco.service.cmr.version.VersionHistory;
+import org.alfresco.service.cmr.version.VersionService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
@@ -51,6 +57,7 @@ public class MultilingualContentServiceImplTest extends TestCase
private TransactionService transactionService;
private NodeService nodeService;
private FileFolderService fileFolderService;
+ private VersionService versionService;
private MultilingualContentService multilingualContentService;
private NodeRef folderNodeRef;
@@ -62,6 +69,7 @@ public class MultilingualContentServiceImplTest extends TestCase
transactionService = serviceRegistry.getTransactionService();
nodeService = serviceRegistry.getNodeService();
fileFolderService = serviceRegistry.getFileFolderService();
+ versionService = serviceRegistry.getVersionService();
multilingualContentService = (MultilingualContentService) ctx.getBean("MultilingualContentService");
// Run as admin
@@ -128,8 +136,7 @@ public class MultilingualContentServiceImplTest extends TestCase
// Check it
assertNotNull("Container not created", mlContainerNodeRef);
// Check the container child count
- int childCount = nodeService.getChildAssocs(mlContainerNodeRef).size();
- assertEquals("Incorrect number of child nodes", 1, childCount);
+ assertEquals("Incorrect number of child nodes", 1, nodeService.getChildAssocs(mlContainerNodeRef).size());
}
public void testAddTranslationUsingContainer() throws Exception
@@ -147,8 +154,7 @@ public class MultilingualContentServiceImplTest extends TestCase
// Make sure that the original container was used
assertEquals("Existing container should have been used", mlContainerNodeRef, newMLContainerNodeRef);
// Check the container child count
- int childCount = nodeService.getChildAssocs(mlContainerNodeRef).size();
- assertEquals("Incorrect number of child nodes", 2, childCount);
+ assertEquals("Incorrect number of child nodes", 2, nodeService.getChildAssocs(mlContainerNodeRef).size());
}
public void testAddTranslationUsingContent() throws Exception
@@ -166,7 +172,51 @@ public class MultilingualContentServiceImplTest extends TestCase
// Make sure that the original container was used
assertEquals("Existing container should have been used", mlContainerNodeRef, newMLContainerNodeRef);
// Check the container child count
- int childCount = nodeService.getChildAssocs(mlContainerNodeRef).size();
- assertEquals("Incorrect number of child nodes", 2, childCount);
+ assertEquals("Incorrect number of child nodes", 2, nodeService.getChildAssocs(mlContainerNodeRef).size());
+ }
+
+ @SuppressWarnings("unused")
+ public void testCreateEdition() throws Exception
+ {
+ // Make some content
+ NodeRef chineseContentNodeRef = createContent();
+ NodeRef frenchContentNodeRef = createContent();
+ NodeRef japaneseContentNodeRef = createContent();
+ // Add to container
+ NodeRef mlContainerNodeRef = multilingualContentService.makeTranslation(chineseContentNodeRef, Locale.CHINESE);
+ multilingualContentService.addTranslation(frenchContentNodeRef, mlContainerNodeRef, Locale.FRENCH);
+ multilingualContentService.addTranslation(japaneseContentNodeRef, mlContainerNodeRef, Locale.JAPANESE);
+ // Check the container child count
+ assertEquals("Incorrect number of child nodes", 3, nodeService.getChildAssocs(mlContainerNodeRef).size());
+
+ // Version each of the documents
+ List nodeRefs = new ArrayList(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(mlContainerNodeRef, 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);
+ Version mlContainerRootVersion = mlContainerVersionHistory.getRootVersion();
+ NodeRef mlContainerRootVersionNodeRef = mlContainerRootVersion.getVersionedNodeRef();
+ // Get the root version's children
+ List mlContainerRootVersionChildren = nodeService.getChildAssocs(mlContainerRootVersionNodeRef);
+ // Check them
+// assertEquals("Incorrect number of child nodes for root version", 3, mlContainerRootVersionChildren.size());
}
}
diff --git a/source/java/org/alfresco/service/cmr/ml/MultilingualContentService.java b/source/java/org/alfresco/service/cmr/ml/MultilingualContentService.java
index 7d4a3d06e0..c067d32843 100644
--- a/source/java/org/alfresco/service/cmr/ml/MultilingualContentService.java
+++ b/source/java/org/alfresco/service/cmr/ml/MultilingualContentService.java
@@ -75,9 +75,8 @@ public interface MultilingualContentService
*
* @param mlContainerNodeRef An existing cm:mlContainer
* @param translationNodeRef The specific cm:mlDocument to use as the starting point
- * of the new edition.
- * @return Returns the cm:mlContainer
+ * of the new edition. All other translations will be removed.
*/
@Auditable(key = Auditable.Key.ARG_0, parameters = {"mlContainerNodeRef", "translationNodeRef"})
- NodeRef createEdition(NodeRef mlContainerNodeRef, NodeRef translationNodeRef);
+ void createEdition(NodeRef mlContainerNodeRef, NodeRef translationNodeRef);
}