Merged DEV to HEAD (5.1)

110000: MNT-13836: Custom behaviours cannot be disabled (using disableBehaviour(QName))
      - Changed class policies enabled/disabled checks. Now each behaviour at a given level must be explicitly disabled & re-enabled (unless all behaviours are disabled in the transaction).
      - Added JUnit tests.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@110119 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alex Mukha
2015-08-14 09:16:26 +00:00
parent f1638a83ff
commit f7b86ad94b
3 changed files with 282 additions and 19 deletions

View File

@@ -20,6 +20,7 @@ package org.alfresco.repo.policy;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -161,28 +162,16 @@ import org.alfresco.util.LockHelper;
{
List<BehaviourDefinition> behaviours = new ArrayList<BehaviourDefinition>();
// Determine if behaviour has been disabled
boolean isEnabled = true;
if (filter != null)
// Find class behaviour by scanning up the class hierarchy
List<BehaviourDefinition<B>> behaviour = null;
while (binding != null)
{
NodeRef nodeRef = binding.getNodeRef();
QName className = binding.getClassQName();
isEnabled = (nodeRef == null) ? filter.isEnabled(className) : filter.isEnabled(nodeRef, className);
}
if (isEnabled)
{
// Find class behaviour by scanning up the class hierarchy
List<BehaviourDefinition<B>> behaviour = null;
while (binding != null)
behaviour = classMap.get(binding);
if (behaviour != null && isEnabled(binding))
{
behaviour = classMap.get(binding);
if (behaviour != null)
{
behaviours.addAll(0, behaviour); // note: list base/generalised before extended/specific
}
binding = (B)binding.generaliseBinding();
behaviours.addAll(0, behaviour); // note: list base/generalised before extended/specific
}
binding = (B)binding.generaliseBinding();
}
// Append all service-level behaviours
@@ -266,4 +255,17 @@ import org.alfresco.util.LockHelper;
}
}
private boolean isEnabled(B binding)
{
// Determine if behaviour has been disabled
boolean isEnabled = true;
if (filter != null)
{
NodeRef nodeRef = binding.getNodeRef();
QName className = binding.getClassQName();
isEnabled = (nodeRef == null) ? filter.isEnabled(className) : filter.isEnabled(nodeRef, className);
}
return isEnabled;
}
}