Index: DelegatedAccessSiteHierarchyJob.java =================================================================== --- DelegatedAccessSiteHierarchyJob.java (revision 78250) +++ DelegatedAccessSiteHierarchyJob.java (working copy) @@ -2,6 +2,7 @@ import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.Map.Entry; @@ -15,6 +16,7 @@ import org.quartz.JobExecutionException; import org.sakaiproject.delegatedaccess.logic.SakaiProxy; import org.sakaiproject.delegatedaccess.util.DelegatedAccessConstants; +import org.sakaiproject.entity.api.ResourceProperties; import org.sakaiproject.hierarchy.HierarchyService; import org.sakaiproject.hierarchy.model.HierarchyNode; import org.sakaiproject.site.api.Site; @@ -89,29 +91,46 @@ hierarchy = defaultHierarchy; } - for(Site site : sakaiProxy.getAllSites()){ - //search through all sites and add it to the hierarchy if the site has information (otherwise skip) - try{ - String siteParentId = rootNode.id; - //find lowest hierarchy node: - for(String hiearchyProperty : hierarchy){ - String siteProperty = site.getProperties().getProperty(hiearchyProperty); - if(siteProperty != null && !"".equals(siteProperty)){ - siteParentId = checkAndAddNode(siteParentId, siteProperty, siteProperty, null); - }else{ - //nothing, so break - break; + int page = 1; + int pageFirstRecord = 1; + int pageLastRecord = DelegatedAccessConstants.MAX_SITES_PER_PAGE; + boolean hasMoreSites = true; + int processedSites = 0; + while (hasMoreSites) { + List sites = sakaiProxy.getAllSitesByPages(pageFirstRecord, pageLastRecord); + for(Site site : sites){ + //search through all sites and add it to the hierarchy if the site has information (otherwise skip) + try{ + String siteParentId = rootNode.id; + ResourceProperties props = site.getProperties(); + + //find lowest hierarchy node: + for(String hiearchyProperty : hierarchy){ + String siteProperty = props.getProperty(hiearchyProperty); + if(siteProperty != null && !"".equals(siteProperty)){ + siteParentId = checkAndAddNode(siteParentId, siteProperty, siteProperty, null); + }else{ + //nothing, so break + break; + } } - } - if(!rootNode.id.equals(siteParentId)){ - //save the site under the parent hierarchy if any data was found - //Site - checkAndAddNode(siteParentId, site.getTitle(), site.getReference(), site.getProperties().getProperty(sakaiProxy.getTermField())); + if(!rootNode.id.equals(siteParentId)){ + //save the site under the parent hierarchy if any data was found + //Site + checkAndAddNode(siteParentId, site.getTitle(), site.getReference(), props.getProperty(sakaiProxy.getTermField())); + } + processedSites++; + }catch (Exception e) { + log.error(e); + errors.put(site.getId(), e.getMessage()); } - }catch (Exception e) { - log.error(e); - errors.put(site.getId(), e.getMessage()); + pageFirstRecord = (DelegatedAccessConstants.MAX_SITES_PER_PAGE * page) + 1; + page ++; + pageLastRecord = DelegatedAccessConstants.MAX_SITES_PER_PAGE * page; + if (sites.isEmpty()) { + hasMoreSites = false; + } } } @@ -129,7 +148,7 @@ //remove any sites that don't exist in the hierarchy (aka properties changed or site has been deleted): removeMissingNodes(rootNode); - log.info("DelegatedAccessSiteHierarchyJob finished in " + (System.currentTimeMillis() - startTime) + " ms"); + log.info("DelegatedAccessSiteHierarchyJob finished in " + (System.currentTimeMillis() - startTime) + " ms and processed " + processedSites + " sites."); }catch (Exception e) { log.error(e); sakaiProxy.sendEmail("Error occurred in DelegatedAccessSiteHierarchyJob", e.getMessage());