Fix for MOB-1029: Read operations for zones should not create zones

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14859 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Andrew Hind
2009-06-23 13:39:55 +00:00
parent e2d250171f
commit 7038f07076
6 changed files with 57 additions and 7 deletions

View File

@@ -710,6 +710,7 @@
org.alfresco.service.cmr.security.AuthorityService.setAuthorityDisplayName=ACL_METHOD.ROLE_ADMINISTRATOR org.alfresco.service.cmr.security.AuthorityService.setAuthorityDisplayName=ACL_METHOD.ROLE_ADMINISTRATOR
org.alfresco.service.cmr.security.AuthorityService.getAuthorityDisplayName=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.getAuthorityDisplayName=ACL_ALLOW
org.alfresco.service.cmr.security.AuthorityService.getOrCreateZone=ACL_METHOD.ROLE_ADMINISTRATOR org.alfresco.service.cmr.security.AuthorityService.getOrCreateZone=ACL_METHOD.ROLE_ADMINISTRATOR
org.alfresco.service.cmr.security.AuthorityService.getZone=ACL_ALLOW
org.alfresco.service.cmr.security.AuthorityService.getAuthorityZones=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.getAuthorityZones=ACL_ALLOW
org.alfresco.service.cmr.security.AuthorityService.getAllAuthoritiesInZone=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.getAllAuthoritiesInZone=ACL_ALLOW
org.alfresco.service.cmr.security.AuthorityService.getAllRootAuthoritiesInZone=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.getAllRootAuthoritiesInZone=ACL_ALLOW

View File

@@ -159,6 +159,15 @@ public interface AuthorityDAO
*/ */
public NodeRef getOrCreateZone(String zoneName); public NodeRef getOrCreateZone(String zoneName);
/**
* Gets an authority zone node with the specified name
*
* @param zoneName
* the zone name
* @return reference to the zone node ot null if the zone does not exists
*/
public NodeRef getZone(String zoneName);
/** /**
* Gets the name of the zone containing the specified authority. * Gets the name of the zone containing the specified authority.
* *

View File

@@ -224,7 +224,7 @@ public class AuthorityDAOImpl implements AuthorityDAO
{ {
for (String zone : zones) for (String zone : zones)
{ {
NodeRef container = getOrCreateZone(zone); NodeRef container = getZone(zone);
if (container != null) if (container != null)
{ {
if (container != null) if (container != null)
@@ -500,15 +500,27 @@ public class AuthorityDAOImpl implements AuthorityDAO
} }
public NodeRef getOrCreateZone(String zoneName) public NodeRef getOrCreateZone(String zoneName)
{
return getOrCreateZone(zoneName, true);
}
private NodeRef getOrCreateZone(String zoneName, boolean create)
{ {
NodeRef zoneContainerRef = getZoneContainer(); NodeRef zoneContainerRef = getZoneContainer();
QName zoneQName = QName.createQName("cm", zoneName, namespacePrefixResolver); QName zoneQName = QName.createQName("cm", zoneName, namespacePrefixResolver);
List<ChildAssociationRef> results = nodeService.getChildAssocs(zoneContainerRef, ContentModel.ASSOC_CHILDREN, zoneQName); List<ChildAssociationRef> results = nodeService.getChildAssocs(zoneContainerRef, ContentModel.ASSOC_CHILDREN, zoneQName);
if (results.isEmpty()) if (results.isEmpty())
{ {
HashMap<QName, Serializable> props = new HashMap<QName, Serializable>(); if (create)
props.put(ContentModel.PROP_NAME, zoneName); {
return nodeService.createNode(zoneContainerRef, ContentModel.ASSOC_CHILDREN, zoneQName, ContentModel.TYPE_ZONE, props).getChildRef(); HashMap<QName, Serializable> props = new HashMap<QName, Serializable>();
props.put(ContentModel.PROP_NAME, zoneName);
return nodeService.createNode(zoneContainerRef, ContentModel.ASSOC_CHILDREN, zoneQName, ContentModel.TYPE_ZONE, props).getChildRef();
}
else
{
return null;
}
} }
else else
{ {
@@ -516,6 +528,11 @@ public class AuthorityDAOImpl implements AuthorityDAO
} }
} }
public NodeRef getZone(String zoneName)
{
return getOrCreateZone(zoneName, false);
}
public Set<String> getAuthorityZones(String name) public Set<String> getAuthorityZones(String name)
{ {
HashSet<String> zones = new HashSet<String>(); HashSet<String> zones = new HashSet<String>();
@@ -550,10 +567,13 @@ public class AuthorityDAOImpl implements AuthorityDAO
public Set<String> getAllAuthoritiesInZone(String zoneName, AuthorityType type) public Set<String> getAllAuthoritiesInZone(String zoneName, AuthorityType type)
{ {
HashSet<String> authorities = new HashSet<String>(); HashSet<String> authorities = new HashSet<String>();
NodeRef zoneRef = getOrCreateZone(zoneName); NodeRef zoneRef = getZone(zoneName);
for (ChildAssociationRef childRef : nodeService.getChildAssocs(zoneRef)) if (zoneRef != null)
{ {
addAuthorityNameIfMatches(authorities, childRef.getQName().getLocalName(), type, null); for (ChildAssociationRef childRef : nodeService.getChildAssocs(zoneRef))
{
addAuthorityNameIfMatches(authorities, childRef.getQName().getLocalName(), type, null);
}
} }
return authorities; return authorities;
} }

View File

@@ -398,6 +398,11 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean
return authorityDAO.getOrCreateZone(zoneName); return authorityDAO.getOrCreateZone(zoneName);
} }
public NodeRef getZone(String zoneName)
{
return authorityDAO.getZone(zoneName);
}
public Set<String> getAllAuthoritiesInZone(String zoneName, AuthorityType type) public Set<String> getAllAuthoritiesInZone(String zoneName, AuthorityType type)
{ {
return authorityDAO.getAllAuthoritiesInZone(zoneName, type); return authorityDAO.getAllAuthoritiesInZone(zoneName, type);

View File

@@ -340,4 +340,9 @@ public class SimpleAuthorityServiceImpl implements AuthorityService
{ {
return Collections.<String>emptySet(); return Collections.<String>emptySet();
} }
public NodeRef getZone(String zoneName)
{
return null;
}
} }

View File

@@ -322,6 +322,16 @@ public interface AuthorityService
@Auditable(parameters = {"zoneName"}) @Auditable(parameters = {"zoneName"})
public NodeRef getOrCreateZone(String zoneName); public NodeRef getOrCreateZone(String zoneName);
/**
* Gets an authority zone node with the specified name
*
* @param zoneName
* the zone name
* @return reference to the zone node or null
*/
@Auditable(parameters = {"zoneName"})
public NodeRef getZone(String zoneName);
/** /**
* Gets the name of the zone containing the specified authority. * Gets the name of the zone containing the specified authority.
* *