From 80ce950335e0658e35198af691386f1b6ebbc013 Mon Sep 17 00:00:00 2001 From: Derek Hulley Date: Wed, 7 Mar 2007 09:50:10 +0000 Subject: [PATCH] Merged V2.0 to HEAD 5116: AWC-1067, AWC-1126 5121: AR-1233 (from 1.4 via 2.0) 5129: AR-966 5131: Overlay copy and duplicate name git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5323 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../action/executer/MailActionExecuter.java | 5 ++ .../alfresco/repo/copy/CopyServiceImpl.java | 3 ++ .../repo/node/BaseNodeServiceTest.java | 48 ++++++++++++++++++- .../repo/node/BaseNodeServiceTest_model.xml | 28 +++++++++++ .../repo/node/db/DbNodeServiceImpl.java | 32 ++++++++++++- 5 files changed, 114 insertions(+), 2 deletions(-) diff --git a/source/java/org/alfresco/repo/action/executer/MailActionExecuter.java b/source/java/org/alfresco/repo/action/executer/MailActionExecuter.java index 388cff3b08..79cecafb08 100644 --- a/source/java/org/alfresco/repo/action/executer/MailActionExecuter.java +++ b/source/java/org/alfresco/repo/action/executer/MailActionExecuter.java @@ -282,6 +282,11 @@ public class MailActionExecuter extends ActionExecuterAbstractBase message.setTo(recipients.toArray(new String[recipients.size()])); } + else + { + // No recipiants have been specified + logger.error("No recipiant has been specified for the mail action"); + } } // set subject line diff --git a/source/java/org/alfresco/repo/copy/CopyServiceImpl.java b/source/java/org/alfresco/repo/copy/CopyServiceImpl.java index 327977a08c..d3d900870b 100644 --- a/source/java/org/alfresco/repo/copy/CopyServiceImpl.java +++ b/source/java/org/alfresco/repo/copy/CopyServiceImpl.java @@ -898,6 +898,9 @@ public class CopyServiceImpl implements CopyService // Get the copy details PolicyScope copyDetails = getCopyDetails(sourceNodeRef, destinationNodeRef.getStoreRef(), false); + // Remove the name property from the policy scope to prevent duplicate name exceptions + copyDetails.removeProperty(ContentModel.PROP_NAME); + // Copy over the top of the destination node copyProperties(destinationNodeRef, copyDetails); copyAspects(destinationNodeRef, copyDetails); diff --git a/source/java/org/alfresco/repo/node/BaseNodeServiceTest.java b/source/java/org/alfresco/repo/node/BaseNodeServiceTest.java index 4c3bbe9b20..0b271c7f84 100644 --- a/source/java/org/alfresco/repo/node/BaseNodeServiceTest.java +++ b/source/java/org/alfresco/repo/node/BaseNodeServiceTest.java @@ -124,6 +124,10 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest public static final QName ASSOC_TYPE_QNAME_TEST_CONTAINS = ContentModel.ASSOC_CONTAINS; public static final QName ASSOC_TYPE_QNAME_TEST_NEXT = QName.createQName(NAMESPACE, "next"); + public static final QName ASPECT_WITH_ASSOCIATIONS = QName.createQName(NAMESPACE, "withAssociations"); + public static final QName ASSOC_ASPECT_CHILD_ASSOC = QName.createQName(NAMESPACE, "aspect-child-assoc"); + public static final QName ASSOC_ASPECT_NORMAL_ASSOC = QName.createQName(NAMESPACE, "aspect-normal-assoc"); + public static final QName TYPE_QNAME_TEST_MULTIPLE_TESTER = QName.createQName(NAMESPACE, "multiple-tester"); public static final QName PROP_QNAME_STRING_PROP_SINGLE = QName.createQName(NAMESPACE, "stringprop-single"); public static final QName PROP_QNAME_STRING_PROP_MULTIPLE = QName.createQName(NAMESPACE, "stringprop-multiple"); @@ -567,7 +571,7 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest QName.createQName(BaseNodeServiceTest.NAMESPACE, "test-container"), ContentModel.TYPE_CONTAINER); NodeRef nodeRef = assocRef.getChildRef(); - // add the content aspect to the node, but don't supply any properties + // add the titled aspect to the node, but don't supply any properties Map properties = new HashMap(20); nodeService.addAspect(nodeRef, BaseNodeServiceTest.ASPECT_QNAME_TEST_TITLED, properties); @@ -604,6 +608,48 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest propertiesAfter.size()); } + public void testAspectRemoval() throws Exception + { + // Create a node to add the aspect to + NodeRef sourceNodeRef = nodeService.createNode( + rootNodeRef, + ASSOC_TYPE_QNAME_TEST_CHILDREN, + QName.createQName(BaseNodeServiceTest.NAMESPACE, "testAspectRemoval-source"), + ContentModel.TYPE_CONTAINER).getChildRef(); + + // Create a target for the associations + NodeRef targetNodeRef = nodeService.createNode( + rootNodeRef, + ASSOC_TYPE_QNAME_TEST_CHILDREN, + QName.createQName(BaseNodeServiceTest.NAMESPACE, "testAspectRemoval-target"), + ContentModel.TYPE_CONTAINER).getChildRef(); + + // Add the aspect to the source + nodeService.addAspect(sourceNodeRef, ASPECT_WITH_ASSOCIATIONS, null); + // Make the associations + nodeService.addChild( + sourceNodeRef, + targetNodeRef, + ASSOC_ASPECT_CHILD_ASSOC, + QName.createQName(NAMESPACE, "aspect-child")); + nodeService.createAssociation(sourceNodeRef, targetNodeRef, ASSOC_ASPECT_NORMAL_ASSOC); + + // Check that the correct associations are present + assertEquals("Expected exactly one child", + 1, nodeService.getChildAssocs(sourceNodeRef).size()); + assertEquals("Expected exactly one target", + 1, nodeService.getTargetAssocs(sourceNodeRef, RegexQNamePattern.MATCH_ALL).size()); + + // Now remove the aspect + nodeService.removeAspect(sourceNodeRef, ASPECT_WITH_ASSOCIATIONS); + + // Check that the associations were removed + assertEquals("Expected exactly one child", + 0, nodeService.getChildAssocs(sourceNodeRef).size()); + assertEquals("Expected exactly one target", + 0, nodeService.getTargetAssocs(sourceNodeRef, RegexQNamePattern.MATCH_ALL).size()); + } + public void testCreateNodeNoProperties() throws Exception { // flush to ensure that the pure JDBC query will work diff --git a/source/java/org/alfresco/repo/node/BaseNodeServiceTest_model.xml b/source/java/org/alfresco/repo/node/BaseNodeServiceTest_model.xml index 18137d1e01..ab0cafc0b8 100644 --- a/source/java/org/alfresco/repo/node/BaseNodeServiceTest_model.xml +++ b/source/java/org/alfresco/repo/node/BaseNodeServiceTest_model.xml @@ -324,6 +324,34 @@ + + Aspect with Associations + + + + false + false + + + sys:base + true + true + + + + + false + false + + + sys:base + true + true + + + + + diff --git a/source/java/org/alfresco/repo/node/db/DbNodeServiceImpl.java b/source/java/org/alfresco/repo/node/db/DbNodeServiceImpl.java index f519ffcb66..e0f1b8f138 100644 --- a/source/java/org/alfresco/repo/node/db/DbNodeServiceImpl.java +++ b/source/java/org/alfresco/repo/node/db/DbNodeServiceImpl.java @@ -605,7 +605,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl // remove the aspect, if present boolean removed = node.getAspects().remove(aspectTypeQName); - // if the aspect was present, remove the associated properties + // if the aspect was present, remove the associated properties and associations if (removed) { Map nodeProperties = node.getProperties(); @@ -615,6 +615,36 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl nodeProperties.remove(propertyName); } + // Remove child associations + Map childAssocDefs = aspectDef.getChildAssociations(); + Collection childAssocs = nodeDaoService.getChildAssocs(node); + for (ChildAssoc childAssoc : childAssocs) + { + // Ignore if the association type is not defined by the aspect + QName childAssocQName = childAssoc.getTypeQName(); + if (!childAssocDefs.containsKey(childAssocQName)) + { + continue; + } + // The association is of a type that should be removed + nodeDaoService.deleteChildAssoc(childAssoc, true); + } + + // Remove regular associations + Map assocDefs = aspectDef.getAssociations(); + List nodeAssocs = nodeDaoService.getTargetNodeAssocs(node); + for (NodeAssoc nodeAssoc : nodeAssocs) + { + // Ignore if the association type is not defined by the aspect + QName nodeAssocQName = nodeAssoc.getTypeQName(); + if (!assocDefs.containsKey(nodeAssocQName)) + { + continue; + } + // Delete the association + nodeDaoService.deleteNodeAssoc(nodeAssoc); + } + // Invoke policy behaviours invokeOnUpdateNode(nodeRef); invokeOnRemoveAspect(nodeRef, aspectTypeQName);