mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Fixed name issues on children of copied nodes
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3680 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -193,17 +193,17 @@ public class CopyServiceImpl implements CopyService
|
|||||||
*/
|
*/
|
||||||
public NodeRef copy(
|
public NodeRef copy(
|
||||||
NodeRef sourceNodeRef,
|
NodeRef sourceNodeRef,
|
||||||
NodeRef destinationParent,
|
NodeRef destinationParentRef,
|
||||||
QName destinationAssocTypeQName,
|
QName destinationAssocTypeQName,
|
||||||
QName destinationQName,
|
QName destinationQName,
|
||||||
boolean copyChildren)
|
boolean copyChildren)
|
||||||
{
|
{
|
||||||
// Check that all the passed values are not null
|
// Check that all the passed values are not null
|
||||||
ParameterCheck.mandatory("Source Node", sourceNodeRef);
|
ParameterCheck.mandatory("Source Node", sourceNodeRef);
|
||||||
ParameterCheck.mandatory("Destination Parent", destinationParent);
|
ParameterCheck.mandatory("Destination Parent", destinationParentRef);
|
||||||
ParameterCheck.mandatory("Destination Association Name", destinationQName);
|
ParameterCheck.mandatory("Destination Association Name", destinationQName);
|
||||||
|
|
||||||
if (sourceNodeRef.getStoreRef().equals(destinationParent.getStoreRef()) == false)
|
if (sourceNodeRef.getStoreRef().equals(destinationParentRef.getStoreRef()) == false)
|
||||||
{
|
{
|
||||||
// TODO We need to create a new node in the other store with the same id as the source
|
// TODO We need to create a new node in the other store with the same id as the source
|
||||||
|
|
||||||
@@ -211,9 +211,19 @@ public class CopyServiceImpl implements CopyService
|
|||||||
throw new UnsupportedOperationException("Copying nodes across stores is not currently supported.");
|
throw new UnsupportedOperationException("Copying nodes across stores is not currently supported.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the original parent reference
|
||||||
|
NodeRef sourceParentRef = nodeService.getPrimaryParent(sourceNodeRef).getParentRef();
|
||||||
// Recursively copy node
|
// Recursively copy node
|
||||||
Map<NodeRef, NodeRef> copiedChildren = new HashMap<NodeRef, NodeRef>();
|
Map<NodeRef, NodeRef> copiedChildren = new HashMap<NodeRef, NodeRef>();
|
||||||
NodeRef copy = recursiveCopy(sourceNodeRef, destinationParent, destinationAssocTypeQName, destinationQName, copyChildren, copiedChildren);
|
NodeRef copy = recursiveCopy(
|
||||||
|
sourceNodeRef,
|
||||||
|
sourceParentRef,
|
||||||
|
destinationParentRef,
|
||||||
|
destinationAssocTypeQName,
|
||||||
|
destinationQName,
|
||||||
|
copyChildren,
|
||||||
|
true, // top-level copy drops the name, if the parent is different
|
||||||
|
copiedChildren);
|
||||||
|
|
||||||
// Foreach of the newly created copies call the copy complete policy
|
// Foreach of the newly created copies call the copy complete policy
|
||||||
for (Map.Entry<NodeRef, NodeRef> entry : copiedChildren.entrySet())
|
for (Map.Entry<NodeRef, NodeRef> entry : copiedChildren.entrySet())
|
||||||
@@ -360,20 +370,16 @@ public class CopyServiceImpl implements CopyService
|
|||||||
/**
|
/**
|
||||||
* Recursive copy algorithm
|
* Recursive copy algorithm
|
||||||
*
|
*
|
||||||
* @param sourceNodeRef
|
* @param dropName drop the name property when associations don't allow duplicately named children
|
||||||
* @param destinationParent
|
|
||||||
* @param destinationAssocTypeQName
|
|
||||||
* @param destinationQName
|
|
||||||
* @param copyChildren
|
|
||||||
* @param copiedChildren
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
private NodeRef recursiveCopy(
|
private NodeRef recursiveCopy(
|
||||||
NodeRef sourceNodeRef,
|
NodeRef sourceNodeRef,
|
||||||
NodeRef destinationParent,
|
NodeRef sourceParentRef,
|
||||||
|
NodeRef destinationParentRef,
|
||||||
QName destinationAssocTypeQName,
|
QName destinationAssocTypeQName,
|
||||||
QName destinationQName,
|
QName destinationQName,
|
||||||
boolean copyChildren,
|
boolean copyChildren,
|
||||||
|
boolean dropName,
|
||||||
Map<NodeRef, NodeRef> copiedChildren)
|
Map<NodeRef, NodeRef> copiedChildren)
|
||||||
{
|
{
|
||||||
// Extract Type Definition
|
// Extract Type Definition
|
||||||
@@ -385,7 +391,7 @@ public class CopyServiceImpl implements CopyService
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Establish the scope of the copy
|
// Establish the scope of the copy
|
||||||
PolicyScope copyDetails = getCopyDetails(sourceNodeRef, destinationParent.getStoreRef(), true);
|
PolicyScope copyDetails = getCopyDetails(sourceNodeRef, destinationParentRef.getStoreRef(), true);
|
||||||
|
|
||||||
// Create collection of properties for type and mandatory aspects
|
// Create collection of properties for type and mandatory aspects
|
||||||
Map<QName, Serializable> typeProps = copyDetails.getProperties();
|
Map<QName, Serializable> typeProps = copyDetails.getProperties();
|
||||||
@@ -403,8 +409,8 @@ public class CopyServiceImpl implements CopyService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the parent node is the same, then remove the name property - it will have to
|
// Drop the name property, if required. This prevents duplicate names and leaves it up to the client
|
||||||
// be changed by the client code
|
// to assign a new name.
|
||||||
AssociationDefinition assocDef = dictionaryService.getAssociation(destinationAssocTypeQName);
|
AssociationDefinition assocDef = dictionaryService.getAssociation(destinationAssocTypeQName);
|
||||||
if (!assocDef.isChild())
|
if (!assocDef.isChild())
|
||||||
{
|
{
|
||||||
@@ -413,7 +419,7 @@ public class CopyServiceImpl implements CopyService
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
ChildAssociationDefinition childAssocDef = (ChildAssociationDefinition) assocDef;
|
ChildAssociationDefinition childAssocDef = (ChildAssociationDefinition) assocDef;
|
||||||
if (!childAssocDef.getDuplicateChildNamesAllowed())
|
if (dropName && !childAssocDef.getDuplicateChildNamesAllowed())
|
||||||
{
|
{
|
||||||
// duplicate children are not allowed.
|
// duplicate children are not allowed.
|
||||||
properties.remove(ContentModel.PROP_NAME);
|
properties.remove(ContentModel.PROP_NAME);
|
||||||
@@ -422,14 +428,14 @@ public class CopyServiceImpl implements CopyService
|
|||||||
|
|
||||||
// Create the new node
|
// Create the new node
|
||||||
ChildAssociationRef destinationChildAssocRef = this.nodeService.createNode(
|
ChildAssociationRef destinationChildAssocRef = this.nodeService.createNode(
|
||||||
destinationParent,
|
destinationParentRef,
|
||||||
destinationAssocTypeQName,
|
destinationAssocTypeQName,
|
||||||
destinationQName,
|
destinationQName,
|
||||||
sourceTypeRef,
|
sourceTypeRef,
|
||||||
properties);
|
properties);
|
||||||
NodeRef destinationNodeRef = destinationChildAssocRef.getChildRef();
|
NodeRef destinationNodeRef = destinationChildAssocRef.getChildRef();
|
||||||
copiedChildren.put(sourceNodeRef, destinationNodeRef);
|
copiedChildren.put(sourceNodeRef, destinationNodeRef);
|
||||||
|
|
||||||
// Prevent any rules being fired on the new destination node
|
// Prevent any rules being fired on the new destination node
|
||||||
this.ruleService.disableRules(destinationNodeRef);
|
this.ruleService.disableRules(destinationNodeRef);
|
||||||
try
|
try
|
||||||
@@ -736,9 +742,9 @@ public class CopyServiceImpl implements CopyService
|
|||||||
*/
|
*/
|
||||||
private void copyChildAssociations(
|
private void copyChildAssociations(
|
||||||
QName classRef,
|
QName classRef,
|
||||||
NodeRef destinationNodeRef,
|
NodeRef destinationNodeRef,
|
||||||
PolicyScope copyDetails,
|
PolicyScope copyDetails,
|
||||||
boolean copyChildren,
|
boolean copyChildren,
|
||||||
Map<NodeRef, NodeRef> copiedChildren)
|
Map<NodeRef, NodeRef> copiedChildren)
|
||||||
{
|
{
|
||||||
List<ChildAssociationRef> childAssocs = copyDetails.getChildAssociations(classRef);
|
List<ChildAssociationRef> childAssocs = copyDetails.getChildAssociations(classRef);
|
||||||
@@ -756,11 +762,13 @@ public class CopyServiceImpl implements CopyService
|
|||||||
{
|
{
|
||||||
// Copy the child
|
// Copy the child
|
||||||
recursiveCopy(
|
recursiveCopy(
|
||||||
childAssoc.getChildRef(),
|
childAssoc.getChildRef(),
|
||||||
|
childAssoc.getParentRef(),
|
||||||
destinationNodeRef,
|
destinationNodeRef,
|
||||||
childAssoc.getTypeQName(),
|
childAssoc.getTypeQName(),
|
||||||
childAssoc.getQName(),
|
childAssoc.getQName(),
|
||||||
copyChildren,
|
copyChildren,
|
||||||
|
false, // the target and source parents can't be the same
|
||||||
copiedChildren);
|
copiedChildren);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -784,11 +792,13 @@ public class CopyServiceImpl implements CopyService
|
|||||||
{
|
{
|
||||||
// Always recursivly copy configuration folders
|
// Always recursivly copy configuration folders
|
||||||
recursiveCopy(
|
recursiveCopy(
|
||||||
childRef,
|
childRef,
|
||||||
|
childAssoc.getParentRef(),
|
||||||
destinationNodeRef,
|
destinationNodeRef,
|
||||||
childAssoc.getTypeQName(),
|
childAssoc.getTypeQName(),
|
||||||
childAssoc.getQName(),
|
childAssoc.getQName(),
|
||||||
true,
|
true,
|
||||||
|
false, // the target and source parents can't be the same
|
||||||
copiedChildren);
|
copiedChildren);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -59,6 +59,11 @@ public interface CopyService
|
|||||||
* not copied.
|
* not copied.
|
||||||
* <p>
|
* <p>
|
||||||
* Source association are not copied.
|
* Source association are not copied.
|
||||||
|
* <p>
|
||||||
|
* <b>NOTE:</b> The top-level node has it's <b>cm:name</b> property removed for
|
||||||
|
* associations that do not allow duplicately named children in order
|
||||||
|
* to prevent any chance of a duplicate name clash. Reassign the
|
||||||
|
* <b>cm:name</b> property and catch the {@link DuplicateChildNodeNameException}.
|
||||||
*
|
*
|
||||||
* @param sourceNodeRef the node reference used as the source of the copy
|
* @param sourceNodeRef the node reference used as the source of the copy
|
||||||
* @param destinationParent the intended parent of the new node
|
* @param destinationParent the intended parent of the new node
|
||||||
|
Reference in New Issue
Block a user