mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Further method implementations of ML service
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4738 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -129,9 +129,11 @@ public class MultilingualContentServiceImpl implements MultilingualContentServic
|
|||||||
* <b>cm:mlDocument</b> already applied.
|
* <b>cm:mlDocument</b> already applied.
|
||||||
*
|
*
|
||||||
* @param mlDocumentNodeRef an existing <b>cm:mlDocument</b>
|
* @param mlDocumentNodeRef an existing <b>cm:mlDocument</b>
|
||||||
|
* @param allowCreate <tt>true</tt> if a <b>cm:mlContainer</b> must be created if on doesn't exist,
|
||||||
|
* otherwise <tt>false</tt> if a parent <b>cm:mlContainer</b> is expected to exist.
|
||||||
* @return Returns the <b>cm:mlContainer</b> parent
|
* @return Returns the <b>cm:mlContainer</b> parent
|
||||||
*/
|
*/
|
||||||
private NodeRef getOrCreateMLContainer(NodeRef mlDocumentNodeRef)
|
private NodeRef getOrCreateMLContainer(NodeRef mlDocumentNodeRef, boolean allowCreate)
|
||||||
{
|
{
|
||||||
if (!nodeService.hasAspect(mlDocumentNodeRef, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT))
|
if (!nodeService.hasAspect(mlDocumentNodeRef, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT))
|
||||||
{
|
{
|
||||||
@@ -146,17 +148,23 @@ public class MultilingualContentServiceImpl implements MultilingualContentServic
|
|||||||
ContentModel.ASSOC_MULTILINGUAL_CHILD,
|
ContentModel.ASSOC_MULTILINGUAL_CHILD,
|
||||||
RegexQNamePattern.MATCH_ALL);
|
RegexQNamePattern.MATCH_ALL);
|
||||||
if (parentAssocRefs.size() == 0)
|
if (parentAssocRefs.size() == 0)
|
||||||
|
{
|
||||||
|
if (allowCreate)
|
||||||
{
|
{
|
||||||
// Create a ML container
|
// Create a ML container
|
||||||
mlContainerNodeRef = makeMLContainer();
|
mlContainerNodeRef = makeMLContainer();
|
||||||
createAssociation = true;
|
createAssociation = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("No multilingual container exists for document node: " + mlDocumentNodeRef);
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (parentAssocRefs.size() == 1)
|
else if (parentAssocRefs.size() == 1)
|
||||||
{
|
{
|
||||||
// Just get it
|
// Just get it
|
||||||
ChildAssociationRef toKeepAssocRef = parentAssocRefs.get(0);
|
ChildAssociationRef toKeepAssocRef = parentAssocRefs.get(0);
|
||||||
mlContainerNodeRef = toKeepAssocRef.getParentRef();
|
mlContainerNodeRef = toKeepAssocRef.getParentRef();
|
||||||
createAssociation = true;
|
|
||||||
}
|
}
|
||||||
else if (parentAssocRefs.size() > 1)
|
else if (parentAssocRefs.size() > 1)
|
||||||
{
|
{
|
||||||
@@ -189,7 +197,7 @@ public class MultilingualContentServiceImpl implements MultilingualContentServic
|
|||||||
return mlContainerNodeRef;
|
return mlContainerNodeRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NodeRef makeTranslation(NodeRef contentNodeRef, Locale locale)
|
private NodeRef makeTranslationImpl(NodeRef mlContainerNodeRef, NodeRef contentNodeRef, Locale locale)
|
||||||
{
|
{
|
||||||
// Add the aspect using the given locale, of necessary
|
// Add the aspect using the given locale, of necessary
|
||||||
if (!nodeService.hasAspect(contentNodeRef, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT))
|
if (!nodeService.hasAspect(contentNodeRef, ContentModel.ASPECT_MULTILINGUAL_DOCUMENT))
|
||||||
@@ -203,20 +211,72 @@ public class MultilingualContentServiceImpl implements MultilingualContentServic
|
|||||||
// The aspect is present, so just ensure that the locale is correct
|
// The aspect is present, so just ensure that the locale is correct
|
||||||
nodeService.setProperty(contentNodeRef, ContentModel.PROP_LOCALE, locale);
|
nodeService.setProperty(contentNodeRef, ContentModel.PROP_LOCALE, locale);
|
||||||
}
|
}
|
||||||
// Get or create the container
|
// Do we make use of an existing container?
|
||||||
NodeRef mlContainerNodeRef = getOrCreateMLContainer(contentNodeRef);
|
if (mlContainerNodeRef == null)
|
||||||
|
{
|
||||||
|
// Make one
|
||||||
|
mlContainerNodeRef = getOrCreateMLContainer(contentNodeRef, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Use the existing container
|
||||||
|
nodeService.addChild(
|
||||||
|
mlContainerNodeRef,
|
||||||
|
contentNodeRef,
|
||||||
|
ContentModel.ASSOC_MULTILINGUAL_CHILD,
|
||||||
|
QNAME_ML_TRANSLATION);
|
||||||
|
}
|
||||||
// done
|
// done
|
||||||
return mlContainerNodeRef;
|
return mlContainerNodeRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NodeRef makeTranslation(NodeRef contentNodeRef, Locale locale)
|
||||||
|
{
|
||||||
|
NodeRef mlContainerNodeRef = makeTranslationImpl(null, contentNodeRef, locale);
|
||||||
|
// done
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("Made a translation: \n" +
|
||||||
|
" content: " + contentNodeRef + "\n" +
|
||||||
|
" locale: " + locale + "\n" +
|
||||||
|
" container: " + mlContainerNodeRef);
|
||||||
|
}
|
||||||
|
return mlContainerNodeRef;
|
||||||
|
}
|
||||||
|
|
||||||
public NodeRef addTranslation(NodeRef newTranslationNodeRef, NodeRef translationOfNodeRef, Locale locale)
|
public NodeRef addTranslation(NodeRef newTranslationNodeRef, NodeRef translationOfNodeRef, Locale locale)
|
||||||
{
|
{
|
||||||
throw new UnsupportedOperationException();
|
NodeRef mlContainerNodeRef = null;
|
||||||
|
// Were we given the translation or the container
|
||||||
|
QName typeQName = nodeService.getType(translationOfNodeRef);
|
||||||
|
if (typeQName.equals(ContentModel.TYPE_MULTILINGUAL_CONTAINER))
|
||||||
|
{
|
||||||
|
// We have the container
|
||||||
|
mlContainerNodeRef = translationOfNodeRef;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Get the container
|
||||||
|
mlContainerNodeRef = getOrCreateMLContainer(translationOfNodeRef, false);
|
||||||
|
}
|
||||||
|
// Use the existing container to make the new content into a translation
|
||||||
|
makeTranslationImpl(mlContainerNodeRef, newTranslationNodeRef, locale);
|
||||||
|
// done
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("Added a translation: \n" +
|
||||||
|
" Translation of: " + translationOfNodeRef + " of type " + typeQName + "\n" +
|
||||||
|
" New translation: " + newTranslationNodeRef + "\n" +
|
||||||
|
" Locale: " + locale);
|
||||||
|
}
|
||||||
|
return mlContainerNodeRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NodeRef getTranslationContainer(NodeRef translationNodeRef)
|
public NodeRef getTranslationContainer(NodeRef translationNodeRef)
|
||||||
{
|
{
|
||||||
throw new UnsupportedOperationException();
|
NodeRef mlContainerNodeRef = getOrCreateMLContainer(translationNodeRef, false);
|
||||||
|
// done
|
||||||
|
return mlContainerNodeRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NodeRef createEdition(NodeRef mlContainerNodeRef, NodeRef translationNodeRef)
|
public NodeRef createEdition(NodeRef mlContainerNodeRef, NodeRef translationNodeRef)
|
||||||
|
@@ -127,5 +127,46 @@ public class MultilingualContentServiceImplTest extends TestCase
|
|||||||
NodeRef mlContainerNodeRef = multilingualContentService.makeTranslation(contentNodeRef, Locale.CHINESE);
|
NodeRef mlContainerNodeRef = multilingualContentService.makeTranslation(contentNodeRef, Locale.CHINESE);
|
||||||
// Check it
|
// Check it
|
||||||
assertNotNull("Container not created", mlContainerNodeRef);
|
assertNotNull("Container not created", mlContainerNodeRef);
|
||||||
|
// Check the container child count
|
||||||
|
int childCount = nodeService.getChildAssocs(mlContainerNodeRef).size();
|
||||||
|
assertEquals("Incorrect number of child nodes", 1, childCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAddTranslationUsingContainer() throws Exception
|
||||||
|
{
|
||||||
|
// Make a container with a single translation
|
||||||
|
NodeRef chineseContentNodeRef = createContent();
|
||||||
|
NodeRef mlContainerNodeRef = multilingualContentService.makeTranslation(chineseContentNodeRef, Locale.CHINESE);
|
||||||
|
// Create some more content
|
||||||
|
NodeRef frenchContentNodeRef = createContent();
|
||||||
|
// Make this a translation of the Chinese
|
||||||
|
NodeRef newMLContainerNodeRef = multilingualContentService.addTranslation(
|
||||||
|
frenchContentNodeRef,
|
||||||
|
mlContainerNodeRef,
|
||||||
|
Locale.FRENCH);
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAddTranslationUsingContent() throws Exception
|
||||||
|
{
|
||||||
|
// Make a container with a single translation
|
||||||
|
NodeRef chineseContentNodeRef = createContent();
|
||||||
|
NodeRef mlContainerNodeRef = multilingualContentService.makeTranslation(chineseContentNodeRef, Locale.CHINESE);
|
||||||
|
// Create some more content
|
||||||
|
NodeRef frenchContentNodeRef = createContent();
|
||||||
|
// Make this a translation of the Chinese
|
||||||
|
NodeRef newMLContainerNodeRef = multilingualContentService.addTranslation(
|
||||||
|
frenchContentNodeRef,
|
||||||
|
chineseContentNodeRef,
|
||||||
|
Locale.FRENCH);
|
||||||
|
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user