diff --git a/source/java/org/alfresco/repo/rule/ruletrigger/SingleAssocRefPolicyRuleTrigger.java b/source/java/org/alfresco/repo/rule/ruletrigger/SingleAssocRefPolicyRuleTrigger.java index 4273268519..3516e0f52b 100644 --- a/source/java/org/alfresco/repo/rule/ruletrigger/SingleAssocRefPolicyRuleTrigger.java +++ b/source/java/org/alfresco/repo/rule/ruletrigger/SingleAssocRefPolicyRuleTrigger.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2012 Alfresco Software Limited. * * This file is part of Alfresco * @@ -34,45 +34,49 @@ public class SingleAssocRefPolicyRuleTrigger extends RuleTriggerAbstractBase { private static Log logger = LogFactory.getLog(OnPropertyUpdateRuleTrigger.class); - private String policyNamespace = NamespaceService.ALFRESCO_URI; - private String policyName; - - public void setPolicyNamespace(String policyNamespace) - { - this.policyNamespace = policyNamespace; - } - - public void setPolicyName(String policyName) - { - this.policyName = policyName; - } - - /** - * @see org.alfresco.repo.rule.ruletrigger.RuleTrigger#registerRuleTrigger() - */ - public void registerRuleTrigger() - { - PropertyCheck.mandatory(this, "policyNamespace", policyNamespace); + private String policyNamespace = NamespaceService.ALFRESCO_URI; + private String policyName; + + public void setPolicyNamespace(String policyNamespace) + { + this.policyNamespace = policyNamespace; + } + + public void setPolicyName(String policyName) + { + this.policyName = policyName; + } + + /** + * @see org.alfresco.repo.rule.ruletrigger.RuleTrigger#registerRuleTrigger() + */ + public void registerRuleTrigger() + { + PropertyCheck.mandatory(this, "policyNamespace", policyNamespace); PropertyCheck.mandatory(this, "policyName", policyName); - - this.policyComponent.bindAssociationBehaviour( - QName.createQName(this.policyNamespace, this.policyName), - this, - new JavaBehaviour(this, "policyBehaviour")); - } - - public void policyBehaviour(AssociationRef assocRef) + + this.policyComponent.bindAssociationBehaviour( + QName.createQName(this.policyNamespace, this.policyName), + this, + new JavaBehaviour(this, "policyBehaviour")); + } + + public void policyBehaviour(AssociationRef assocRef) { NodeRef nodeRef = assocRef.getSourceRef(); - List parentsAssocRefs = this.nodeService.getParentAssocs(nodeRef); - for (ChildAssociationRef parentAssocRef : parentsAssocRefs) + + if (nodeService.exists(nodeRef)) { - triggerRules(parentAssocRef.getParentRef(), nodeRef); - if (logger.isDebugEnabled() == true) + List parentsAssocRefs = this.nodeService.getParentAssocs(nodeRef); + for (ChildAssociationRef parentAssocRef : parentsAssocRefs) { - logger.debug( - "OnUpdateAssoc rule triggered (parent); " + - "nodeRef=" + parentAssocRef.getParentRef()); + triggerRules(parentAssocRef.getParentRef(), nodeRef); + if (logger.isDebugEnabled() == true) + { + logger.debug( + "OnUpdateAssoc rule triggered (parent); " + + "nodeRef=" + parentAssocRef.getParentRef()); + } } } } diff --git a/source/java/org/alfresco/repo/search/impl/lucene/ADMLuceneIndexerImpl.java b/source/java/org/alfresco/repo/search/impl/lucene/ADMLuceneIndexerImpl.java index 467c357fb2..b1a638b402 100644 --- a/source/java/org/alfresco/repo/search/impl/lucene/ADMLuceneIndexerImpl.java +++ b/source/java/org/alfresco/repo/search/impl/lucene/ADMLuceneIndexerImpl.java @@ -947,7 +947,7 @@ public class ADMLuceneIndexerImpl extends AbstractLuceneIndexerImpl imp } // Only process 'containers' - not leaves - if (getCachedChildren(childAssociationsSinceFlush, nodeRef).isEmpty()) + if (getCachedChildren(childAssociationsSinceFlush, nodeRef, cascade).isEmpty()) { continue; } @@ -987,7 +987,7 @@ public class ADMLuceneIndexerImpl extends AbstractLuceneIndexerImpl imp if (cascade) { List childPaths = new LinkedList(); - for (ChildAssociationRef childRef : getCachedChildren(childAssociationsSinceFlush, nodeRef)) + for (ChildAssociationRef childRef : getCachedChildren(childAssociationsSinceFlush, nodeRef, cascade)) { childPaths.add(new Path().append(path).append(new Path.ChildAssocElement(childRef))); } @@ -998,14 +998,14 @@ public class ADMLuceneIndexerImpl extends AbstractLuceneIndexerImpl imp } private List getCachedChildren( - Map> childAssociationsSinceFlush, NodeRef nodeRef) + Map> childAssociationsSinceFlush, NodeRef nodeRef, boolean bulkLoad) { List children = childAssociationsSinceFlush.get(nodeRef); // Cache the children in case there are many paths to the same node if (children == null) { - children = nodeService.getChildAssocs(nodeRef, RegexQNamePattern.MATCH_ALL, RegexQNamePattern.MATCH_ALL, false); + children = nodeService.getChildAssocs(nodeRef, RegexQNamePattern.MATCH_ALL, RegexQNamePattern.MATCH_ALL, bulkLoad); for (ChildAssociationRef childRef : children) { // We don't want index numbers in generated paths diff --git a/source/java/org/alfresco/repo/security/sync/ChainingUserRegistrySynchronizer.java b/source/java/org/alfresco/repo/security/sync/ChainingUserRegistrySynchronizer.java index 53461085f3..fac22758b7 100644 --- a/source/java/org/alfresco/repo/security/sync/ChainingUserRegistrySynchronizer.java +++ b/source/java/org/alfresco/repo/security/sync/ChainingUserRegistrySynchronizer.java @@ -1671,9 +1671,7 @@ public class ChainingUserRegistrySynchronizer extends AbstractLifecycleBean impl + "'. This user will in future be assumed to originate from user registry '" + zone + "'."); } - ChainingUserRegistrySynchronizer.this.authorityService.removeAuthorityFromZones(personName, - zones); - ChainingUserRegistrySynchronizer.this.authorityService.addAuthorityToZones(personName, zoneSet); + updateAuthorityZones(personName, zones, zoneSet); ChainingUserRegistrySynchronizer.this.personService.setPersonProperties(personName, personProperties, false); } @@ -1875,6 +1873,33 @@ public class ChainingUserRegistrySynchronizer extends AbstractLifecycleBean impl return zones; } + /** + * Modifies an authority's zone set from oldZones to newZones in the most efficient manner (avoiding unnecessary + * reindexing cost). + * + * @param authorityName + * @param oldZones + * @param newZones + */ + private void updateAuthorityZones(String authorityName, Set oldZones, final Set newZones) + { + Set zonesToRemove = new HashSet(oldZones); + zonesToRemove.removeAll(newZones); + // Let's keep the authority in the alfresco auth zone if it was already there. Otherwise we may have to + // regenerate all paths to this authority from site groups, which could be very expensive! + zonesToRemove.remove(AuthorityService.ZONE_AUTH_ALFRESCO); + if (!zonesToRemove.isEmpty()) + { + this.authorityService.removeAuthorityFromZones(authorityName, zonesToRemove); + } + Set zonesToAdd = new HashSet(newZones); + zonesToAdd.removeAll(oldZones); + if (!zonesToAdd.isEmpty()) + { + this.authorityService.addAuthorityToZones(authorityName, zonesToAdd); + } + } + /* * (non-Javadoc) * @seeorg.springframework.extensions.surf.util.AbstractLifecycleBean#onBootstrap(org.springframework.context.