Merged BRANCHES/DEV/V3.4-BUG-FIX to HEAD

Fix build failures related to Audit 
   28511: Fix build - VersionMigratorTest testMigrateVersionWithAssocs - defaultOnCreateVersion() being called for each aspect as default policy was bound as a service.
   28505: Test failure - AbstractVersionServiceImpl was not running defaultOnCreateVersion() as AccessAuditor provided a policy to listen to events.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28517 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2011-06-22 13:34:02 +00:00
parent d9a3f5d504
commit 9bc6e57f22
3 changed files with 64 additions and 29 deletions

View File

@@ -141,7 +141,7 @@ public class AccessAuditorTest
// Mock up an auditComponent to see the results of our tests
AuditComponent auditComponent = mock(AuditComponent.class);
when(auditComponent.areAuditValuesRequired()).thenReturn(true);
when(auditComponent.areAuditValuesRequired(anyString())).thenReturn(true);
when(auditComponent.recordAuditValues(anyString(), anyMap())).thenAnswer(new Answer<Map<String, Serializable>>()
{
public Map<String, Serializable> answer(InvocationOnMock invocation) throws Throwable

View File

@@ -48,6 +48,8 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.version.VersionServicePolicies.OnCreateVersionPolicy;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.InvalidQNameException;
import org.alfresco.service.namespace.NamespaceException;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
@@ -573,7 +575,7 @@ import org.alfresco.service.namespace.QName;
// Audit QNames with the prefix set. The key can be used in original Set and
// Map operations as only the namesapace and local name are used in equals and
// hashcode methods.
QName key = entry.getKey().getPrefixedQName(namespaceService);
QName key = getPrefixedQName(entry.getKey());
String name = replaceInvalidPathChars(key.toPrefixString());
Serializable beforeValue = entry.getValue();
@@ -612,7 +614,9 @@ import org.alfresco.service.namespace.QName;
newKeys.removeAll(fromProperties.keySet());
for (QName key: newKeys)
{
key = key.getPrefixedQName(namespaceService); // Audit QNames with the prefix set.
// Audit QNames with the prefix set.
key = getPrefixedQName(key);
Serializable afterValue = toProperties.get(key);
String name = replaceInvalidPathChars(key.toPrefixString());
auditMap.put(buildPath(PROPERTIES, ADD, name), afterValue);
@@ -648,7 +652,9 @@ import org.alfresco.service.namespace.QName;
HashSet<QName> prefixedAspects = new HashSet<QName>(aspects.size());
for (QName aspect: aspects)
{
aspect = aspect.getPrefixedQName(namespaceService); // Audit QNames with the prefix set.
// Audit QNames with the prefix set.
aspect = getPrefixedQName(aspect);
prefixedAspects.add(aspect);
String name = replaceInvalidPathChars(aspect.toPrefixString());
auditMap.put(buildPath(ASPECTS, addOrDelete, name), null);
@@ -664,7 +670,25 @@ import org.alfresco.service.namespace.QName;
{
for (Map.Entry<String, Serializable> entry: properties.entrySet())
{
auditMap.put(buildPath(VERSION_PROPERTIES, entry.getKey()), entry.getValue());
// The key may be the string version ({URI}localName) of a QName.
// If so get the prefixed version.
String key = entry.getKey();
if (key.indexOf(QName.NAMESPACE_PREFIX) == 0)
{
try
{
QName qNameKey = QName.createQName(key);
qNameKey = getPrefixedQName(qNameKey);
key = qNameKey.toPrefixString();
}
catch (InvalidQNameException e)
{
// Its just a String.
}
}
String name = replaceInvalidPathChars(key);
auditMap.put(buildPath(VERSION_PROPERTIES, name), entry.getValue());
}
if (!subAction)
{
@@ -725,6 +749,22 @@ import org.alfresco.service.namespace.QName;
return sb.toString();
}
/**
* @return a new QName that has the prefix set or the original if it is unknown.
*/
private QName getPrefixedQName(QName qName)
{
try
{
qName = qName.getPrefixedQName(namespaceService);
}
catch (NamespaceException e)
{
// ignore - go with what we have
}
return qName;
}
/**
* @return a String where all invalid audit path characters are replaced by a '-'.
*/

View File

@@ -178,9 +178,6 @@ public abstract class AbstractVersionServiceImpl
NodeRef nodeRef,
Map<String, Serializable> versionProperties,
PolicyScope nodeDetails)
{
Collection<OnCreateVersionPolicy> policies = this.onCreateVersionDelegate.getList(classRef);
if (policies.size() == 0)
{
// Call the default implementation
defaultOnCreateVersion(
@@ -188,10 +185,9 @@ public abstract class AbstractVersionServiceImpl
nodeRef,
versionProperties,
nodeDetails);
}
else
{
// Call the policy definitions
Collection<OnCreateVersionPolicy> policies = this.onCreateVersionDelegate.getList(classRef);
for (VersionServicePolicies.OnCreateVersionPolicy policy : policies)
{
policy.onCreateVersion(
@@ -201,11 +197,10 @@ public abstract class AbstractVersionServiceImpl
nodeDetails);
}
}
}
/**
* Default implementation of the on create version policy. Called if no behaviour is registered for the
* policy for the specified type.
* Default implementation of the on create version policy.
* Override if you wish to supply your own policy.
*
* @param nodeRef
* @param versionProperties