mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Further ML implementation: createEdition
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4744 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -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<ChildAssociationRef> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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<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(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<ChildAssociationRef> mlContainerRootVersionChildren = nodeService.getChildAssocs(mlContainerRootVersionNodeRef);
|
||||
// Check them
|
||||
// assertEquals("Incorrect number of child nodes for root version", 3, mlContainerRootVersionChildren.size());
|
||||
}
|
||||
}
|
||||
|
@@ -75,9 +75,8 @@ public interface MultilingualContentService
|
||||
*
|
||||
* @param mlContainerNodeRef An existing <b>cm:mlContainer</b>
|
||||
* @param translationNodeRef The specific <b>cm:mlDocument</b> to use as the starting point
|
||||
* of the new edition.
|
||||
* @return Returns the <b>cm:mlContainer</b>
|
||||
* 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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user