From 205b7b7697b6232926eafd6522ac3f15072aed87 Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Wed, 11 Mar 2009 10:10:43 +0000 Subject: [PATCH] Merged V3.1 to HEAD 13034: Performance improvements to SiteService listSites(username) method. Removal of some non-sensical javascript. ***NOTE: Unable to apply critical 3.1E SiteService performance improvements due to HEAD changes *** 13036: Site Favorites restored to working order. If the user does not have any site favorite prefs then API call to retrieve the user sites list is avoided and exceptions are no longer produced and ignored. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13554 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/repo/site/SiteServiceImpl.java | 75 ++++++++++--------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/source/java/org/alfresco/repo/site/SiteServiceImpl.java b/source/java/org/alfresco/repo/site/SiteServiceImpl.java index 3e65560f3f..50071eaf72 100644 --- a/source/java/org/alfresco/repo/site/SiteServiceImpl.java +++ b/source/java/org/alfresco/repo/site/SiteServiceImpl.java @@ -27,6 +27,7 @@ package org.alfresco.repo.site; import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -74,6 +75,8 @@ import org.json.JSONObject; */ public class SiteServiceImpl implements SiteService, SiteModel { + private static final String GROUP_SITE_PREFIX = PermissionService.GROUP_PREFIX + "site_"; + /** Logger */ private static Log logger = LogFactory.getLog(SiteServiceImpl.class); @@ -364,6 +367,26 @@ public class SiteServiceImpl implements SiteService, SiteModel return siteInfo; } + /** + * Gets a map containing the site's custom properties + * + * @return Map map containing the custom properties of the site + */ + private Map getSiteCustomProperties(Map properties) + { + Map customProperties = new HashMap(4); + + for (Map.Entry entry : properties.entrySet()) + { + if (entry.getKey().getNamespaceURI().equals(SITE_CUSTOM_PROPERTY_URL) == true) + { + customProperties.put(entry.getKey(), entry.getValue()); + } + } + + return customProperties; + } + /** * Gets a map containing the site's custom properties * @@ -371,7 +394,7 @@ public class SiteServiceImpl implements SiteService, SiteModel */ private Map getSiteCustomProperties(NodeRef siteNodeRef) { - Map customProperties = new HashMap(5); + Map customProperties = new HashMap(4); Map properties = nodeService.getProperties(siteNodeRef); for (Map.Entry entry : properties.entrySet()) @@ -429,7 +452,7 @@ public class SiteServiceImpl implements SiteService, SiteModel */ public String getSiteRoleGroup(String shortName, String permission, boolean withGroupPrefix) { - return getSiteGroup(shortName, withGroupPrefix) + "_" + permission; + return getSiteGroup(shortName, withGroupPrefix) + '_' + permission; } /** @@ -535,19 +558,17 @@ public class SiteServiceImpl implements SiteService, SiteModel private SiteInfo createSiteInfo(NodeRef siteNodeRef) { // Get the properties - Map properties = this.nodeService - .getProperties(siteNodeRef); + Map properties = this.nodeService.getProperties(siteNodeRef); String shortName = (String) properties.get(ContentModel.PROP_NAME); String sitePreset = (String) properties.get(PROP_SITE_PRESET); String title = (String) properties.get(ContentModel.PROP_TITLE); - String description = (String) properties - .get(ContentModel.PROP_DESCRIPTION); + String description = (String) properties.get(ContentModel.PROP_DESCRIPTION); // Get the visibility of the site SiteVisibility visibility = getSiteVisibility(siteNodeRef); // Create and return the site information - Map customProperties = getSiteCustomProperties(siteNodeRef); + Map customProperties = getSiteCustomProperties(properties); SiteInfo siteInfo = new SiteInfoImpl(sitePreset, shortName, title, description, visibility, customProperties, siteNodeRef); return siteInfo; } @@ -904,45 +925,29 @@ public class SiteServiceImpl implements SiteService, SiteModel return result; } + /** + * Helper method to get the permission groups for a given authority on a site. + * Returns empty List if the user does not have a explicit membership to the site. + * + * @param siteShortName site short name + * @param authorityName authority name + * @return List Permission groups, empty list if no explicit membership set + */ private List getPermissionGroups(String siteShortName, String authorityName) { List result = new ArrayList(5); - Set roles = permissionService.getSettablePermissions(SiteModel.TYPE_SITE); + Set roles = this.permissionService.getSettablePermissions(SiteModel.TYPE_SITE); for (String role : roles) { String roleGroup = getSiteRoleGroup(siteShortName, role, true); - Set authorities = this.authorityService.getContainedAuthorities(null, roleGroup, false); + Set authorities = this.authorityService.getContainedAuthorities(null, roleGroup, false); if (authorities.contains(authorityName) == true) { result.add(roleGroup); } - } + } return result; - } - - /** - * Helper method to get the permission group for a given authority on a site. - * Returns null if the user does not have a explicit membership to the site. - * - * @param siteShortName site short name - * @param authorityName authority name - * @return String permission group, null if no explicit membership set - */ -// private String getPermissionGroup(String siteShortName, String authorityName) -// { -// String result = null; -// Set groups = this.authorityService.getContainingAuthorities(AuthorityType.GROUP, authorityName, true); -// for (String group : groups) -// { -// if (group.startsWith(PermissionService.GROUP_PREFIX + "site_" -// + siteShortName) == true) -// { -// result = group; -// break; -// } -// } -// return result; -// } + } /** * @see org.alfresco.service.cmr.site.SiteService#getSiteRoles()