Merged 5.0.N (5.0.3) to 5.1.N (5.1.1)

114701 amorarasu: Merged V4.2-BUG-FIX (4.2.6) to 5.0.N (5.0.3)
      114590 amorarasu: Merged V4.2.5 (4.2.5) to V4.2-BUG-FIX (4.2.6)
         114466 abozianu: MNT-14994 : CLONE - Alfresco Mobile: All Sites is throwing error when listing sites


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.1.N/root@114742 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Raluca Munteanu
2015-10-20 08:56:12 +00:00
parent 76c9854c93
commit 206b58e99e
3 changed files with 112 additions and 33 deletions

View File

@@ -170,6 +170,7 @@
<property name="tenantService" ref="tenantService"/> <property name="tenantService" ref="tenantService"/>
<property name="singletonCache" ref="immutableSingletonCache"/> <property name="singletonCache" ref="immutableSingletonCache"/>
<property name="siteNodeRefCache" ref="siteNodeRefCache"/> <property name="siteNodeRefCache" ref="siteNodeRefCache"/>
<property name="nodeDAO" ref="nodeDAO"/>
<property name="eventPublisher" ref="eventPublisher" /> <property name="eventPublisher" ref="eventPublisher" />
</bean> </bean>

View File

@@ -25,6 +25,8 @@ import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@@ -51,6 +53,7 @@ import org.alfresco.query.PagingResults;
import org.alfresco.repo.activities.ActivityType; import org.alfresco.repo.activities.ActivityType;
import org.alfresco.repo.admin.SysAdminParams; import org.alfresco.repo.admin.SysAdminParams;
import org.alfresco.repo.cache.SimpleCache; import org.alfresco.repo.cache.SimpleCache;
import org.alfresco.repo.domain.node.NodeDAO;
import org.alfresco.repo.events.EventPreparator; import org.alfresco.repo.events.EventPreparator;
import org.alfresco.repo.events.EventPublisher; import org.alfresco.repo.events.EventPublisher;
import org.alfresco.repo.node.NodeArchiveServicePolicies; import org.alfresco.repo.node.NodeArchiveServicePolicies;
@@ -189,10 +192,13 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
private SitesPermissionCleaner sitesPermissionsCleaner; private SitesPermissionCleaner sitesPermissionsCleaner;
private PolicyComponent policyComponent; private PolicyComponent policyComponent;
private PublicServiceAccessService publicServiceAccessService; private PublicServiceAccessService publicServiceAccessService;
private NodeDAO nodeDAO;
private EventPublisher eventPublisher; private EventPublisher eventPublisher;
private NamedObjectRegistry<CannedQueryFactory<? extends Object>> cannedQueryRegistry; private NamedObjectRegistry<CannedQueryFactory<? extends Object>> cannedQueryRegistry;
private static int GET_CHILD_ASSOCS_PAGE_SIZE = 512;
/** /**
* Set the path to the location of the sites root folder. For example: * Set the path to the location of the sites root folder. For example:
* <pre> * <pre>
@@ -368,6 +374,11 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
this.publicServiceAccessService = publicServiceAccessService; this.publicServiceAccessService = publicServiceAccessService;
} }
public void setNodeDAO(NodeDAO nodeDAO)
{
this.nodeDAO = nodeDAO;
}
/** /**
* Set the registry of {@link CannedQueryFactory canned queries} * Set the registry of {@link CannedQueryFactory canned queries}
*/ */
@@ -3037,25 +3048,49 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
} }
@Override @Override
public List<SiteMembership> listSiteMemberships (String userName, int size) public List<SiteMembership> listSiteMemberships(String userName, int size)
{ {
final int maxResults = size > 0 ? size : 1000; final List<String> siteNames = new LinkedList<String>();
final Set<String> siteNames = new TreeSet<String>();
Map<String, String> roleSitePairs = new HashMap<String, String>(); Map<String, String> roleSitePairs = new HashMap<String, String>();
// MNT-13198 - use the bridge table
String actualUserName = personService.getUserIdentifier(userName); String actualUserName = personService.getUserIdentifier(userName);
if(actualUserName != null) if(actualUserName == null)
{ {
return Collections.emptyList();
}
/* Get the site names and the map between the site name and the role
MNT-13198 - use the bridge table */
Set<String> containingAuthorities = authorityService.getContainingAuthorities(AuthorityType.GROUP, actualUserName, false); Set<String> containingAuthorities = authorityService.getContainingAuthorities(AuthorityType.GROUP, actualUserName, false);
for(String authority : containingAuthorities) for(String authority : containingAuthorities)
{
if (siteNames.size() < maxResults)
{ {
String siteName = resolveSite(authority); String siteName = resolveSite(authority);
// MNT-10836 fix, after MNT-10109 we should also check site existence if(siteName == null)
// A simple exists check would be better than getting the site properties etc - profiling suggests x2 faster
if ((siteName != null) && hasSite(siteName))
{ {
continue;
}
/* if the size is not 0 check site existence */
if(size > 0)
{
/* if we found enough sites ignore the others */
if(siteNames.size() >= size)
{
break;
}
/* MNT-10836 fix, after MNT-10109 we should also check site existence.
A simple exists check would be better than getting the site properties etc - profiling suggests x2 faster.
If size = -1 the sites that don't exist will be removed when getting the child associations. */
if(!hasSite(siteName))
{
// if the site doesn't exist skip the current authority
continue;
}
}
/* resolve the role */
String role = resolveRole(authority); String role = resolveRole(authority);
if (role != null) if (role != null)
{ {
@@ -3063,26 +3098,28 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
roleSitePairs.put(siteName, role); roleSitePairs.put(siteName, role);
} }
} }
}
else
{
break;
}
}
}
if (siteNames.isEmpty()) if (siteNames.isEmpty())
{ {
return Collections.emptyList(); return Collections.emptyList();
} }
List<ChildAssociationRef> assocs = this.nodeService.getChildrenByName(
getSiteRoot(), /* Get the child associations */
ContentModel.ASSOC_CONTAINS, List<ChildAssociationRef> assocs = getSitesAssocsByName(siteNames);
siteNames);
List<SiteMembership> result = new ArrayList<SiteMembership>(assocs.size()); /* Get the node refs and preload the nodes to get the properties faster */
List<NodeRef> siteNodes = new LinkedList<NodeRef>();
for (ChildAssociationRef assoc : assocs) for (ChildAssociationRef assoc : assocs)
{ {
// Ignore any node that is not a "site" type siteNodes.add(assoc.getChildRef());
NodeRef site = assoc.getChildRef(); }
nodeDAO.cacheNodes(siteNodes);
/* Compute the site membership objects */
List<SiteMembership> result = new LinkedList<SiteMembership>();
for (NodeRef site : siteNodes)
{
/* Ignore any node that is not a "site" type */
QName siteClassName = this.directNodeService.getType(site); QName siteClassName = this.directNodeService.getType(site);
if (this.dictionaryService.isSubClass(siteClassName, SiteModel.TYPE_SITE)) if (this.dictionaryService.isSubClass(siteClassName, SiteModel.TYPE_SITE))
{ {
@@ -3090,12 +3127,53 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
result.add(new SiteMembership(siteInfo, userName, roleSitePairs.get(siteInfo.getShortName()))); result.add(new SiteMembership(siteInfo, userName, roleSitePairs.get(siteInfo.getShortName())));
} }
} }
return result; return result;
} }
/**
* Retrieves the child associations for requested site names
* @param siteNames names of the sites to be retrieved
* @return list of child associations between the site root and sites having the requested site names
*/
private List<ChildAssociationRef> getSitesAssocsByName(final List<String> siteNames)
{
Iterator<String> sitesIterator = siteNames.iterator();
List<String> iterationPage = new LinkedList<String>();
List<ChildAssociationRef> assocs = new LinkedList<ChildAssociationRef>();
List<ChildAssociationRef> childRefPage;
NodeRef siteRoot = getSiteRoot();
/* iterate the results and retrieve child associations for batches of 512 elements */
while(sitesIterator.hasNext())
{
String element = sitesIterator.next();
iterationPage.add(element);
/* when the page is full, get the child associations and clean the page */
if(iterationPage.size() >= GET_CHILD_ASSOCS_PAGE_SIZE)
{
/* get the child associations for the current page having siteRoot as parent
use directNodeService to avoid permission check */
childRefPage = directNodeService.getChildrenByName(siteRoot, ContentModel.ASSOC_CONTAINS, iterationPage);
assocs.addAll(childRefPage);
iterationPage.clear();
}
}
if(iterationPage.size() > 0)
{
/* use directNodeService to avoid permission check */
childRefPage = directNodeService.getChildrenByName(siteRoot, ContentModel.ASSOC_CONTAINS, iterationPage);
assocs.addAll(childRefPage);
}
return assocs;
}
public PagingResults<SiteMembership> listSitesPaged(final String userName, List<Pair<SiteService.SortFields, Boolean>> sortProps, final PagingRequest pagingRequest) public PagingResults<SiteMembership> listSitesPaged(final String userName, List<Pair<SiteService.SortFields, Boolean>> sortProps, final PagingRequest pagingRequest)
{ {
List<SiteMembership> siteMembers = listSiteMemberships (userName, -1); List<SiteMembership> siteMembers = listSiteMemberships (userName, 0);
final int totalSize = siteMembers.size(); final int totalSize = siteMembers.size();
final PageDetails pageDetails = PageDetails.getPageDetails(pagingRequest, totalSize); final PageDetails pageDetails = PageDetails.getPageDetails(pagingRequest, totalSize);
final List<SiteMembership> resultList; final List<SiteMembership> resultList;

View File

@@ -226,7 +226,7 @@ public interface SiteService
* Lists all the memberships in sites that the specified user is in. * Lists all the memberships in sites that the specified user is in.
* *
* @param userName String * @param userName String
* @param size int * @param size list maximum size or zero for all
* @return a list of SiteMembership objects * @return a list of SiteMembership objects
*/ */
@NotAuditable @NotAuditable