From e34312ea05dd430f177465637d900c3798028bad Mon Sep 17 00:00:00 2001 From: Derek Hulley Date: Tue, 22 May 2007 05:00:16 +0000 Subject: [PATCH] Merging from EC-MC: Project compile git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5742 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/bootstrap/multilingualRoot.xml | 4 +- config/alfresco/content-services-context.xml | 30 ++--- .../model-specific-services-context.xml | 10 +- config/alfresco/node-services-context.xml | 11 ++ .../org/alfresco/repo/avm/AVMNodeService.java | 8 ++ .../model/ml/ContentFilterLanguagesMap.java | 3 +- .../repo/node/BaseNodeServiceTest.java | 37 +++++- .../repo/node/MLTranslationInterceptor.java | 3 +- .../repo/node/db/DbNodeServiceImpl.java | 125 +++++++++++------- .../SingleNodeRefPolicyRuleTrigger.java | 100 +++++++------- .../repo/version/NodeServiceImpl.java | 8 ++ .../service/cmr/repository/NodeService.java | 10 ++ 12 files changed, 217 insertions(+), 132 deletions(-) diff --git a/config/alfresco/bootstrap/multilingualRoot.xml b/config/alfresco/bootstrap/multilingualRoot.xml index d1010338f8..8269b67343 100644 --- a/config/alfresco/bootstrap/multilingualRoot.xml +++ b/config/alfresco/bootstrap/multilingualRoot.xml @@ -7,8 +7,8 @@ GROUP_EVERYONE - Coordinator - + Consumer + diff --git a/config/alfresco/content-services-context.xml b/config/alfresco/content-services-context.xml index f438267488..d6c1a8f5b4 100644 --- a/config/alfresco/content-services-context.xml +++ b/config/alfresco/content-services-context.xml @@ -99,24 +99,24 @@ - - - - - - classpath:alfresco/ml/content-filter-lang.xml - - - - - - - - + - + + + + classpath:alfresco/ml/content-filter-lang.xml + + + + + + + + + + diff --git a/config/alfresco/model-specific-services-context.xml b/config/alfresco/model-specific-services-context.xml index d43567e6a3..69a0bc0d44 100644 --- a/config/alfresco/model-specific-services-context.xml +++ b/config/alfresco/model-specific-services-context.xml @@ -43,19 +43,19 @@ - + - + - + - + - + diff --git a/config/alfresco/node-services-context.xml b/config/alfresco/node-services-context.xml index 9734b48bb5..c711715a10 100644 --- a/config/alfresco/node-services-context.xml +++ b/config/alfresco/node-services-context.xml @@ -13,6 +13,16 @@ + + + + + + + + + + mlAwareNodeService @@ -24,6 +34,7 @@ + mlTranslationInterceptor mlPropertyInterceptor diff --git a/source/java/org/alfresco/repo/avm/AVMNodeService.java b/source/java/org/alfresco/repo/avm/AVMNodeService.java index 7af924fb41..312dee08d4 100644 --- a/source/java/org/alfresco/repo/avm/AVMNodeService.java +++ b/source/java/org/alfresco/repo/avm/AVMNodeService.java @@ -927,6 +927,14 @@ public class AVMNodeService extends AbstractNodeServiceImpl implements NodeServi } } + /** + * TODO: Implement + */ + public boolean removeSeconaryChildAssociation(ChildAssociationRef childAssocRef) + { + throw new UnsupportedOperationException(); + } + /** * @param nodeRef * @return Returns all properties keyed by their qualified name diff --git a/source/java/org/alfresco/repo/model/ml/ContentFilterLanguagesMap.java b/source/java/org/alfresco/repo/model/ml/ContentFilterLanguagesMap.java index c80b30470b..6dad0b04b9 100644 --- a/source/java/org/alfresco/repo/model/ml/ContentFilterLanguagesMap.java +++ b/source/java/org/alfresco/repo/model/ml/ContentFilterLanguagesMap.java @@ -74,12 +74,11 @@ public class ContentFilterLanguagesMap implements ContentFilterLanguagesService /** * @param configService the config service to use to read languages */ - public ContentFilterLanguagesMap(ConfigService configService) + public void setConfigService(ConfigService configService) { this.configService = configService; } - /* (non-Javadoc) * @see org.alfresco.service.cmr.ml.ContentFilterLanguagesService#getFilterLanguages() */ diff --git a/source/java/org/alfresco/repo/node/BaseNodeServiceTest.java b/source/java/org/alfresco/repo/node/BaseNodeServiceTest.java index c11f272b47..0287885779 100644 --- a/source/java/org/alfresco/repo/node/BaseNodeServiceTest.java +++ b/source/java/org/alfresco/repo/node/BaseNodeServiceTest.java @@ -875,11 +875,12 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest public void testRemoveSpecificChild() throws Exception { - NodeRef parentRef = nodeService.createNode( + ChildAssociationRef pathPrimaryRef = nodeService.createNode( rootNodeRef, ASSOC_TYPE_QNAME_TEST_CHILDREN, QName.createQName("parent_child"), - ContentModel.TYPE_CONTAINER).getChildRef(); + ContentModel.TYPE_CONTAINER); + NodeRef parentRef = pathPrimaryRef.getParentRef(); ChildAssociationRef pathARef = nodeService.createNode( parentRef, ASSOC_TYPE_QNAME_TEST_CHILDREN, @@ -890,12 +891,34 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest pathARef.getChildRef(), ASSOC_TYPE_QNAME_TEST_CHILDREN, QName.createQName("pathB")); + ChildAssociationRef pathCRef = nodeService.addChild( + parentRef, + pathARef.getChildRef(), + ASSOC_TYPE_QNAME_TEST_CHILDREN, + QName.createQName("pathC")); - // now remove the second association - boolean removed = nodeService.removeChildAssociation(pathBRef); - assertTrue("Association was not removed", removed); - removed = nodeService.removeChildAssociation(pathBRef); - assertFalse("Non-existent association was apparently removed", removed); + // remove the path B association + boolean removedB = nodeService.removeChildAssociation(pathBRef); + assertTrue("Association was not removed", removedB); + removedB = nodeService.removeChildAssociation(pathBRef); + assertFalse("Non-existent association was apparently removed", removedB); + + // remove the path C association + boolean removedC = nodeService.removeChildAssociation(pathCRef); + assertTrue("Association was not removed", removedC); + removedC = nodeService.removeSeconaryChildAssociation(pathCRef); + assertFalse("Non-existent association was apparently removed", removedC); + + // Now verify that primary associations are caught + try + { + nodeService.removeSeconaryChildAssociation(pathPrimaryRef); + fail("Primary association not detected"); + } + catch (IllegalArgumentException e) + { + // Expected + } } public void testRemoveChildByRef() throws Exception diff --git a/source/java/org/alfresco/repo/node/MLTranslationInterceptor.java b/source/java/org/alfresco/repo/node/MLTranslationInterceptor.java index 24974c84db..2c2dd2fdf9 100644 --- a/source/java/org/alfresco/repo/node/MLTranslationInterceptor.java +++ b/source/java/org/alfresco/repo/node/MLTranslationInterceptor.java @@ -150,7 +150,8 @@ public class MLTranslationInterceptor implements MethodInterceptor } } - } else + } + else { ret = invocation.proceed(); } diff --git a/source/java/org/alfresco/repo/node/db/DbNodeServiceImpl.java b/source/java/org/alfresco/repo/node/db/DbNodeServiceImpl.java index 0699781870..e70e9d3842 100644 --- a/source/java/org/alfresco/repo/node/db/DbNodeServiceImpl.java +++ b/source/java/org/alfresco/repo/node/db/DbNodeServiceImpl.java @@ -296,11 +296,11 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl // Copy the incomming property map since we may need to modify it later properties = new HashMap(properties); } - - // Invoke policy behaviour - invokeBeforeUpdateNode(parentRef); - invokeBeforeCreateNode(parentRef, assocTypeQName, assocQName, nodeTypeQName); - invokeBeforeCreateNodeAssociation(parentRef, assocTypeQName, assocQName); + + // Invoke policy behaviour + invokeBeforeUpdateNode(parentRef); + invokeBeforeCreateNode(parentRef, assocTypeQName, assocQName, nodeTypeQName); + invokeBeforeCreateNodeAssociation(parentRef, assocTypeQName, assocQName); // get the store that the parent belongs to StoreRef storeRef = parentRef.getStoreRef(); @@ -352,16 +352,16 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl ChildAssociationRef childAssocRef = childAssoc.getChildAssocRef(); // Invoke policy behaviour - invokeOnCreateNode(childAssocRef); - invokeOnCreateNodeAssociation(childAssocRef); + invokeOnCreateNode(childAssocRef); + invokeOnCreateNodeAssociation(childAssocRef); invokeOnUpdateNode(parentRef); if (propertiesAfter != null) { invokeOnUpdateProperties(childAssocRef.getChildRef(), propertiesBefore, propertiesAfter); } - // done - return childAssocRef; + // done + return childAssocRef; } /** @@ -464,8 +464,8 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl // invoke policy behaviour if (movingStore) { - // TODO for now indicate that the node has been archived to prevent the version history from being removed - // in the future a onMove policy could be added and remove the need for onDelete and onCreate to be fired here + // TODO for now indicate that the node has been archived to prevent the version history from being removed + // in the future a onMove policy could be added and remove the need for onDelete and onCreate to be fired here invokeOnDeleteNode(oldAssocRef, nodeToMoveTypeQName, nodeToMoveAspects, true); invokeOnCreateNode(newAssoc.getChildAssocRef()); } @@ -584,9 +584,9 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl // physically attach the aspect to the node if (node.getAspects().add(aspectTypeQName) == true) - { - // Invoke policy behaviours - invokeOnUpdateNode(nodeRef); + { + // Invoke policy behaviours + invokeOnUpdateNode(nodeRef); invokeOnAddAspect(nodeRef, aspectTypeQName); // update the node status @@ -600,10 +600,10 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl public void removeAspect(NodeRef nodeRef, QName aspectTypeQName) throws InvalidNodeRefException, InvalidAspectException { - // Invoke policy behaviours - invokeBeforeUpdateNode(nodeRef); + // Invoke policy behaviours + invokeBeforeUpdateNode(nodeRef); invokeBeforeRemoveAspect(nodeRef, aspectTypeQName); - + // get the aspect AspectDefinition aspectDef = dictionaryService.getAspect(aspectTypeQName); if (aspectDef == null) @@ -691,12 +691,12 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl public void deleteNode(NodeRef nodeRef) { - boolean isArchivedNode = false; + boolean isArchivedNode = false; boolean requiresDelete = false; - - // Invoke policy behaviours - invokeBeforeDeleteNode(nodeRef); - + + // Invoke policy behaviours + invokeBeforeDeleteNode(nodeRef); + // get the node Node node = getNodeNotNull(nodeRef); // get the primary parent-child relationship before it is gone @@ -738,17 +738,17 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl archiveNode(nodeRef, archiveStoreRef); isArchivedNode = true; } - - // Invoke policy behaviours - invokeOnDeleteNode(childAssocRef, nodeTypeQName, nodeAspectQNames, isArchivedNode); + + // Invoke policy behaviours + invokeOnDeleteNode(childAssocRef, nodeTypeQName, nodeAspectQNames, isArchivedNode); } public ChildAssociationRef addChild(NodeRef parentRef, NodeRef childRef, QName assocTypeQName, QName assocQName) { // Invoke policy behaviours - invokeBeforeUpdateNode(parentRef); + invokeBeforeUpdateNode(parentRef); invokeBeforeCreateChildAssociation(parentRef, childRef, assocTypeQName, assocQName); - + // get the parent node and ensure that it is a container node Node parentNode = getNodeNotNull(parentRef); // get the child node @@ -769,10 +769,10 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl // this functionality is provided for free in getPath getPaths(childNodeRef, false); - // Invoke policy behaviours + // Invoke policy behaviours invokeOnCreateChildAssociation(assocRef); - invokeOnUpdateNode(parentRef); - + invokeOnUpdateNode(parentRef); + return assoc.getChildAssocRef(); } @@ -813,9 +813,9 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl deleteNode(primaryAssocRef.getChildRef()); } - // Invoke policy behaviours - invokeOnUpdateNode(parentRef); - + // Invoke policy behaviours + invokeOnUpdateNode(parentRef); + // done } @@ -836,6 +836,31 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl return deleted; } + public boolean removeSeconaryChildAssociation(ChildAssociationRef childAssocRef) + { + Node parentNode = getNodeNotNull(childAssocRef.getParentRef()); + Node childNode = getNodeNotNull(childAssocRef.getChildRef()); + QName typeQName = childAssocRef.getTypeQName(); + QName qname = childAssocRef.getQName(); + ChildAssoc assoc = nodeDaoService.getChildAssoc(parentNode, childNode, typeQName, qname); + if (assoc == null) + { + // No association exists + return false; + } + if (assoc.getIsPrimary()) + { + throw new IllegalArgumentException( + "removeSeconaryChildAssociation can not be applied to a primary association: \n" + + " Child Assoc: " + assoc); + } + // Delete the secondary association + nodeDaoService.deleteChildAssoc(assoc, false); + invokeOnDeleteChildAssociation(childAssocRef); + // Done + return true; + } + /** * Remove properties that should not be persisted as general properties. Where necessary, the * properties are set on the node. @@ -965,7 +990,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl Node node = getNodeNotNull(nodeRef); // Invoke policy behaviours - invokeBeforeUpdateNode(nodeRef); + invokeBeforeUpdateNode(nodeRef); // Do the set properties Map propertiesBefore = getPropertiesImpl(node); @@ -973,8 +998,8 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl setChildUniqueName(node); // ensure uniqueness - // Invoke policy behaviours - invokeOnUpdateNode(nodeRef); + // Invoke policy behaviours + invokeOnUpdateNode(nodeRef); invokeOnUpdateProperties(nodeRef, propertiesBefore, propertiesAfter); } @@ -1027,8 +1052,8 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl Assert.notNull(qname); // Invoke policy behaviours - invokeBeforeUpdateNode(nodeRef); - + invokeBeforeUpdateNode(nodeRef); + // get the node Node node = getNodeNotNull(nodeRef); @@ -1041,8 +1066,8 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl setChildUniqueName(node); // ensure uniqueness } - // Invoke policy behaviours - invokeOnUpdateNode(nodeRef); + // Invoke policy behaviours + invokeOnUpdateNode(nodeRef); invokeOnUpdateProperties(nodeRef, propertiesBefore, propertiesAfter); } @@ -1245,8 +1270,8 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl throws InvalidNodeRefException, AssociationExistsException { // Invoke policy behaviours - invokeBeforeUpdateNode(sourceRef); - + invokeBeforeUpdateNode(sourceRef); + Node sourceNode = getNodeNotNull(sourceRef); Node targetNode = getNodeNotNull(targetRef); // see if it exists @@ -1259,10 +1284,10 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl assoc = nodeDaoService.newNodeAssoc(sourceNode, targetNode, assocTypeQName); AssociationRef assocRef = assoc.getNodeAssocRef(); - // Invoke policy behaviours - invokeOnUpdateNode(sourceRef); + // Invoke policy behaviours + invokeOnUpdateNode(sourceRef); invokeOnCreateAssociation(assocRef); - + return assocRef; } @@ -1281,13 +1306,13 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl AssociationRef assocRef = assoc.getNodeAssocRef(); // Invoke policy behaviours - invokeBeforeUpdateNode(sourceRef); - + invokeBeforeUpdateNode(sourceRef); + // delete it nodeDaoService.deleteNodeAssoc(assoc); - - // Invoke policy behaviours - invokeOnUpdateNode(sourceRef); + + // Invoke policy behaviours + invokeOnUpdateNode(sourceRef); invokeOnDeleteAssociation(assocRef); } diff --git a/source/java/org/alfresco/repo/rule/ruletrigger/SingleNodeRefPolicyRuleTrigger.java b/source/java/org/alfresco/repo/rule/ruletrigger/SingleNodeRefPolicyRuleTrigger.java index 8bed9b1100..d514483e17 100644 --- a/source/java/org/alfresco/repo/rule/ruletrigger/SingleNodeRefPolicyRuleTrigger.java +++ b/source/java/org/alfresco/repo/rule/ruletrigger/SingleNodeRefPolicyRuleTrigger.java @@ -35,55 +35,55 @@ import org.alfresco.service.namespace.QName; public class SingleNodeRefPolicyRuleTrigger extends RuleTriggerAbstractBase { - private static final String ERR_POLICY_NAME_NOT_SET = "Unable to register rule trigger since policy name has not been set."; - - private String policyNamespace = NamespaceService.ALFRESCO_URI; - - private String policyName; - - private boolean triggerParentRules = true; - - public void setPolicyNamespace(String policyNamespace) - { - this.policyNamespace = policyNamespace; - } - - public void setPolicyName(String policyName) - { - this.policyName = policyName; - } - - public void setTriggerParentRules(boolean triggerParentRules) - { - this.triggerParentRules = triggerParentRules; - } - - public void registerRuleTrigger() - { - if (policyName == null) - { - throw new RuleServiceException(ERR_POLICY_NAME_NOT_SET); - } - - this.policyComponent.bindClassBehaviour( - QName.createQName(this.policyNamespace, this.policyName), - this, - new JavaBehaviour(this, "policyBehaviour")); - } + private static final String ERR_POLICY_NAME_NOT_SET = "Unable to register rule trigger since policy name has not been set."; + + private String policyNamespace = NamespaceService.ALFRESCO_URI; + + private String policyName; + + private boolean triggerParentRules = true; + + public void setPolicyNamespace(String policyNamespace) + { + this.policyNamespace = policyNamespace; + } + + public void setPolicyName(String policyName) + { + this.policyName = policyName; + } + + public void setTriggerParentRules(boolean triggerParentRules) + { + this.triggerParentRules = triggerParentRules; + } + + public void registerRuleTrigger() + { + if (policyName == null) + { + throw new RuleServiceException(ERR_POLICY_NAME_NOT_SET); + } + + this.policyComponent.bindClassBehaviour( + QName.createQName(this.policyNamespace, this.policyName), + this, + new JavaBehaviour(this, "policyBehaviour")); + } - public void policyBehaviour(NodeRef nodeRef) - { - if (triggerParentRules == true) - { - List parentsAssocRefs = this.nodeService.getParentAssocs(nodeRef); - for (ChildAssociationRef parentAssocRef : parentsAssocRefs) - { - triggerRules(parentAssocRef.getParentRef(), nodeRef); - } - } - else - { - triggerRules(nodeRef, nodeRef); - } - } + public void policyBehaviour(NodeRef nodeRef) + { + if (triggerParentRules == true) + { + List parentsAssocRefs = this.nodeService.getParentAssocs(nodeRef); + for (ChildAssociationRef parentAssocRef : parentsAssocRefs) + { + triggerRules(parentAssocRef.getParentRef(), nodeRef); + } + } + else + { + triggerRules(nodeRef, nodeRef); + } + } } diff --git a/source/java/org/alfresco/repo/version/NodeServiceImpl.java b/source/java/org/alfresco/repo/version/NodeServiceImpl.java index ed3a556572..dedee57e73 100644 --- a/source/java/org/alfresco/repo/version/NodeServiceImpl.java +++ b/source/java/org/alfresco/repo/version/NodeServiceImpl.java @@ -245,6 +245,14 @@ public class NodeServiceImpl implements NodeService, VersionModel throw new UnsupportedOperationException(MSG_UNSUPPORTED); } + /** + * @throws UnsupportedOperationException always + */ + public boolean removeSeconaryChildAssociation(ChildAssociationRef childAssocRef) + { + throw new UnsupportedOperationException(MSG_UNSUPPORTED); + } + /** * @throws UnsupportedOperationException always */ diff --git a/source/java/org/alfresco/service/cmr/repository/NodeService.java b/source/java/org/alfresco/service/cmr/repository/NodeService.java index f7a26058a5..fa59c93f48 100644 --- a/source/java/org/alfresco/service/cmr/repository/NodeService.java +++ b/source/java/org/alfresco/service/cmr/repository/NodeService.java @@ -339,6 +339,16 @@ public interface NodeService @Auditable(key = Auditable.Key.ARG_0 ,parameters = {"childAssocRef"}) public boolean removeChildAssociation(ChildAssociationRef childAssocRef); + /** + * Remove a specific secondary child association. + * + * @param childAssocRef the association to remove + * @return Returns true if the association existed, otherwise false. + * @throws IllegalArgumentException if the association is primary + */ + @Auditable(key = Auditable.Key.ARG_0 ,parameters = {"childAssocRef"}) + public boolean removeSeconaryChildAssociation(ChildAssociationRef childAssocRef); + /** * @param nodeRef * @return Returns all properties keyed by their qualified name