RINF 50: Authority Service - minor refactor

- ALF-9128 - refactor internals (to clearly split "find" from "list")

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28417 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2011-06-16 08:19:34 +00:00
parent 266afe56d7
commit 9dd2d98dd8
4 changed files with 69 additions and 55 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2010 Alfresco Software Limited. * Copyright (C) 2005-2011 Alfresco Software Limited.
* *
* This file is part of Alfresco * This file is part of Alfresco
* *
@@ -126,6 +126,15 @@ public interface AuthorityDAO
*/ */
void setAuthorityDisplayName(String authorityName, String authorityDisplayName); void setAuthorityDisplayName(String authorityName, String authorityDisplayName);
/**
* Get root authorities
*
* @param type
* @param zoneName
* @return
*/
public Set<String> getRootAuthorities(AuthorityType type, String zoneName);
/** /**
* Find authorities by display name pattern. * Find authorities by display name pattern.
* *

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2010 Alfresco Software Limited. * Copyright (C) 2005-2011 Alfresco Software Limited.
* *
* This file is part of Alfresco * This file is part of Alfresco
* *
@@ -280,6 +280,17 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
return authorities; return authorities;
} }
public Set<String> getRootAuthorities(AuthorityType type, String zoneName)
{
NodeRef container = (zoneName == null ? getAuthorityContainer() : getZone(zoneName));
if (container == null)
{
// The zone doesn't even exist so there are no root authorities
return Collections.emptySet();
}
return getRootAuthoritiesUnderContainer(container, type);
}
public Set<String> findAuthorities(AuthorityType type, String parentAuthority, boolean immediate, public Set<String> findAuthorities(AuthorityType type, String parentAuthority, boolean immediate,
String displayNamePattern, String zoneName) String displayNamePattern, String zoneName)
@@ -292,13 +303,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
Set<String> rootAuthorities = null; Set<String> rootAuthorities = null;
if (parentAuthority == null && immediate) if (parentAuthority == null && immediate)
{ {
NodeRef container = zoneName == null ? getAuthorityContainer() : getZone(zoneName); rootAuthorities = getRootAuthorities(type, zoneName);
if (container == null)
{
// The zone doesn't even exist so there are no root authorities
return Collections.emptySet();
}
rootAuthorities = getRootAuthoritiesUnderContainer(container, type);
if (pattern == null) if (pattern == null)
{ {
return rootAuthorities; return rootAuthorities;
@@ -443,7 +448,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
} }
Set<String> authorities = new TreeSet<String>(); Set<String> authorities = new TreeSet<String>();
findAuthorities(type, nodeRef, authorities, false, !immediate, false); listAuthorities(type, nodeRef, authorities, false, !immediate, false);
return authorities; return authorities;
} }
} }
@@ -481,7 +486,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
if (authorities == null) if (authorities == null)
{ {
authorities = new TreeSet<String>(); authorities = new TreeSet<String>();
findAuthorities(null, name, authorities, true, true); listAuthorities(null, name, authorities, true, true);
userAuthorityCache.put(name, authorities); userAuthorityCache.put(name, authorities);
} }
// If we wanted the unfiltered set we are done // If we wanted the unfiltered set we are done
@@ -501,7 +506,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
else else
{ {
Set<String> authorities = new TreeSet<String>(); Set<String> authorities = new TreeSet<String>();
findAuthorities(type, name, authorities, true, !immediate); listAuthorities(type, name, authorities, true, !immediate);
return authorities; return authorities;
} }
} }
@@ -566,7 +571,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
} }
} }
private void findAuthorities(AuthorityType type, String name, Set<String> authorities, boolean parents, boolean recursive) private void listAuthorities(AuthorityType type, String name, Set<String> authorities, boolean parents, boolean recursive)
{ {
AuthorityType localType = AuthorityType.getAuthorityType(name); AuthorityType localType = AuthorityType.getAuthorityType(name);
if (localType.equals(AuthorityType.GUEST)) if (localType.equals(AuthorityType.GUEST))
@@ -579,7 +584,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
if (ref != null) if (ref != null)
{ {
findAuthorities(type, ref, authorities, parents, recursive, false); listAuthorities(type, ref, authorities, parents, recursive, false);
} }
else if (!localType.equals(AuthorityType.USER)) else if (!localType.equals(AuthorityType.USER))
{ {
@@ -590,7 +595,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
} }
} }
private void findAuthorities(AuthorityType type, NodeRef nodeRef, Set<String> authorities, boolean parents, boolean recursive, boolean includeNode) private void listAuthorities(AuthorityType type, NodeRef nodeRef, Set<String> authorities, boolean parents, boolean recursive, boolean includeNode)
{ {
if (includeNode) if (includeNode)
{ {
@@ -610,7 +615,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
for (ChildAssociationRef car : cars) for (ChildAssociationRef car : cars)
{ {
findAuthorities(type, car.getParentRef(), authorities, true, recursive, true); listAuthorities(type, car.getParentRef(), authorities, true, recursive, true);
} }
} }
else else
@@ -626,7 +631,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
addAuthorityNameIfMatches(authorities, childName, type, null); addAuthorityNameIfMatches(authorities, childName, type, null);
if (recursive && childType != AuthorityType.USER) if (recursive && childType != AuthorityType.USER)
{ {
findAuthorities(type, car.getChildRef(), authorities, false, true, false); listAuthorities(type, car.getChildRef(), authorities, false, true, false);
} }
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2010 Alfresco Software Limited. * Copyright (C) 2005-2011 Alfresco Software Limited.
* *
* This file is part of Alfresco * This file is part of Alfresco
* *
@@ -377,7 +377,7 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean
public Set<String> getAllRootAuthorities(AuthorityType type) public Set<String> getAllRootAuthorities(AuthorityType type)
{ {
return authorityDAO.findAuthorities(type, null, true, null, null); return getAllRootAuthoritiesInZone(null, type);
} }
public Set<String> getContainedAuthorities(AuthorityType type, String name, boolean immediate) public Set<String> getContainedAuthorities(AuthorityType type, String name, boolean immediate)
@@ -469,7 +469,7 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean
public Set<String> getAllRootAuthoritiesInZone(String zoneName, AuthorityType type) public Set<String> getAllRootAuthoritiesInZone(String zoneName, AuthorityType type)
{ {
return authorityDAO.findAuthorities(type, null, true, null, zoneName); return authorityDAO.getRootAuthorities(type, zoneName);
} }
public Set<String> findAuthorities(AuthorityType type, String parentAuthority, boolean immediate, public Set<String> findAuthorities(AuthorityType type, String parentAuthority, boolean immediate,

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2010 Alfresco Software Limited. * Copyright (C) 2005-2011 Alfresco Software Limited.
* *
* This file is part of Alfresco * This file is part of Alfresco
* *
@@ -374,13 +374,13 @@ public interface AuthorityService
public Set<String> getAllAuthoritiesInZone(String zoneName, AuthorityType type); public Set<String> getAllAuthoritiesInZone(String zoneName, AuthorityType type);
/** /**
* Gets the names of all authorities in a zone, optionally filtered by type. * Gets the names of all root authorities in a zone, optionally filtered by type.
* *
* @param zoneName * @param zoneName
* the zone name * the zone name
* @param type * @param type
* the authority type to filter by or <code>null</code> for all authority types * the authority type to filter by or <code>null</code> for all authority types
* @return the names of all authorities in a zone, optionally filtered by type * @return the names of all root authorities in a zone, optionally filtered by type
*/ */
@Auditable(parameters = {"zoneName", "type"}) @Auditable(parameters = {"zoneName", "type"})
public Set<String> getAllRootAuthoritiesInZone(String zoneName, AuthorityType type); public Set<String> getAllRootAuthoritiesInZone(String zoneName, AuthorityType type);
@@ -408,9 +408,10 @@ public interface AuthorityService
@NotAuditable @NotAuditable
public Set<String> getDefaultZones(); public Set<String> getDefaultZones();
/** /**
* Find authorities by pattern matching (* and ?) against the authority name. * Search for authorities by pattern matching (* and ?) against the authority name.
* Note: This will use a search index to find the results (eg. via Lucene / SOLR).
*
* @param type * @param type
* @param parentAuthority if non-null, will look only for authorities who are a child of the named parent * @param parentAuthority if non-null, will look only for authorities who are a child of the named parent
* @param immediate if <code>true</code> then only search root groups if parentAuthority is null, or immediate children of parentAuthority if it is non-null. * @param immediate if <code>true</code> then only search root groups if parentAuthority is null, or immediate children of parentAuthority if it is non-null.
@@ -419,6 +420,5 @@ public interface AuthorityService
* @return * @return
*/ */
@Auditable(parameters = {"type"}) @Auditable(parameters = {"type"})
public Set<String> findAuthorities(AuthorityType type, String parentAuthority, boolean immediate, public Set<String> findAuthorities(AuthorityType type, String parentAuthority, boolean immediate, String displayNamePattern, String zoneName);
String displayNamePattern, String zoneName);
} }