Index: api/src/main/java/org/sakaiproject/site/api/SiteService.java =================================================================== --- api/src/main/java/org/sakaiproject/site/api/SiteService.java (revision 309683) +++ api/src/main/java/org/sakaiproject/site/api/SiteService.java (working copy) @@ -920,9 +920,24 @@ List getUserSites(boolean requireDescription); /** + * Access a list of sites that the specified user can visit, sorted by title, optionally requiring descriptions. + * + * This is a convenience and performance wrapper for getSites. + * + * The sites returned follow the same semantics as those from + * {@link #getSites(SelectionType, Object, String, Map, SortType, PagingPosition, boolean, String) getSites}. + * + * @param requireDescription when true, full descriptions will be included; when false, full descriptions may be omitted. + * @param userId the returned sites will be those which can be accessed by the user with this internal ID. Uses the current user if null. + * @return A List of those sites the current user can access. + */ + List getUserSites(boolean requireDescription, String userId); + + /** * Access a list of Site objects that meet specified criteria. * NOTE: The sites returned may not have child objects loaded. If these sites need to be saved * a completely populated site should be retrieved from {@link #getSite(String)} + * * @param type * The SelectionType specifying what sort of selection is intended. * @param ofType @@ -935,8 +950,30 @@ * A SortType indicating the desired sort. For no sort, set to SortType.NONE. * @param page * The PagePosition subset of items to return. + * @param userId + * The returned sites will be those which can be accessed by the user with this internal ID. Uses the current user if null. * @return The List (Site) of Site objets that meet specified criteria. */ + List getSites(SelectionType type, Object ofType, String criteria, Map propertyCriteria, SortType sort, PagingPosition page, boolean requireDescription, String userId); + + /** + * Access a list of Site objects that meet specified criteria. + * NOTE: The sites returned may not have child objects loaded. If these sites need to be saved + * a completely populated site should be retrieved from {@link #getSite(String)} + * @param type + * The SelectionType specifying what sort of selection is intended. + * @param ofType + * Site type criteria: null for any type; a String to match a single type; A String[], List or Set to match any type in the collection. + * @param criteria + * Additional selection criteria: sites returned will match this string somewhere in their id, title, description, or skin. + * @param propertyCriteria + * Additional selection criteria: sites returned will have a property named to match each key in the map, whose values match (somewhere in their value) the value in the map (may be null or empty). + * @param sort + * A SortType indicating the desired sort. For no sort, set to SortType.NONE. + * @param page + * The PagePosition subset of items to return. + * @return The List (Site) of Site objets that meet specified criteria. + */ List getSites(SelectionType type, Object ofType, String criteria, Map propertyCriteria, SortType sort, PagingPosition page); /** @@ -973,6 +1010,30 @@ * Get the Site IDs for all sites matching criteria. * This is useful when you only need the listing of site ids (for other operations) and do not need the actual Site objects. * + * All parameters are the same as {@link #getSites(org.sakaiproject.site.api.SiteService.SelectionType, Object, String, Map, org.sakaiproject.site.api.SiteService.SortType, PagingPosition, String)} + * + * @param type + * The SelectionType specifying what sort of selection is intended. + * @param ofType + * Site type criteria: null for any type; a String to match a single type; A String[], List or Set to match any type in the collection. + * @param criteria + * Additional selection criteria: sites returned will match this string somewhere in their id, title, description, or skin. + * @param propertyCriteria + * Additional selection criteria: sites returned will have a property named to match each key in the map, whose values match (somewhere in their value) the value in the map (may be null or empty). + * @param sort + * A SortType indicating the desired sort. For no sort, set to SortType.NONE. + * @param page + * The PagePosition subset of items to return. + * @param userId + * The returns sites will be those which can be accessed by the user with this internal ID. Uses the current user if null. + * @return a List of the Site IDs for the sites matching the criteria. + */ + List getSiteIds(SelectionType type, Object ofType, String criteria, Map propertyCriteria, SortType sort, PagingPosition page, boolean requireDescription, String userId); + + /** + * Get the Site IDs for all sites matching criteria. + * This is useful when you only need the listing of site ids (for other operations) and do not need the actual Site objects. + * * All parameters are the same as {@link #getSites(org.sakaiproject.site.api.SiteService.SelectionType, Object, String, Map, org.sakaiproject.site.api.SiteService.SortType, PagingPosition)} * * @param type Index: kernel-impl/src/main/java/org/sakaiproject/site/impl/BaseSiteService.java =================================================================== --- kernel-impl/src/main/java/org/sakaiproject/site/impl/BaseSiteService.java (revision 309683) +++ kernel-impl/src/main/java/org/sakaiproject/site/impl/BaseSiteService.java (working copy) @@ -1975,6 +1975,24 @@ } /** + * @inheritDoc + */ + public List getUserSites(boolean requireDescription, String userId) + { + List userSites = getCachedUserSites(userId); + + if (userSites == null) + { + userSites = getSites(org.sakaiproject.site.api.SiteService.SelectionType.ACCESS, null, null, null, org.sakaiproject.site.api.SiteService.SortType.TITLE_ASC, null, requireDescription, userId); + + // Cache the results + setCachedUserSites(userId, userSites); + } + + return userSites; + } + + /** * Cache the list of accessible Sites for a user. * * @param userId the (internal) user ID for whom to cache sites; null will result in a no-op @@ -2065,6 +2083,14 @@ return storage().getSites(type, ofType, criteria, propertyCriteria, sort, page, requireDescription); } + /** + * @inheritDoc + */ + public List getSites(SelectionType type, Object ofType, String criteria, Map propertyCriteria, SortType sort, PagingPosition page, boolean requireDescription, String userId) + { + return storage().getSites(type, ofType, criteria, propertyCriteria, sort, page, requireDescription, userId); + } + /* (non-Javadoc) * @see org.sakaiproject.site.api.SiteService#getSiteIds(org.sakaiproject.site.api.SiteService.SelectionType, java.lang.Object, java.lang.String, java.util.Map, org.sakaiproject.site.api.SiteService.SortType, org.sakaiproject.javax.PagingPosition) */ @@ -2868,6 +2894,37 @@ PagingPosition page, boolean requireDescription); /** + * Access a list of Site objects that meet specified criteria, with control over description retrieval. + * Note that this signature is primarily provided to help with performance when retrieving lists of + * sites not for full display, specifically for the list of a user's sites for navigation. Note that + * any sites that have their descriptions, pages, or tools cached will be returned completely, so some + * or all full descriptions may be present even when requireDescription is passed as false. + * + * If a fully populated Site is desired from a potentially partially populated Site, call + * {@link #getSite(String id) getSite} or {@link Site#loadAll()}. Either method will load and cache + * whatever additional data is not yet cached. + * + * @param type + * The SelectionType specifying what sort of selection is intended. + * @param ofType + * Site type criteria: null for any type; a String to match a single type; A String[], List or Set to match any type in the collection. + * @param criteria + * Additional selection criteria: sits returned will match this string somewhere in their id, title, description, or skin. + * @param propertyCriteria + * Additional selection criteria: sites returned will have a property named to match each key in the map, whose values match (somewhere in their value) the value in the map (may be null or empty). + * @param sort + * A SortType indicating the desired sort. For no sort, set to SortType.NONE. + * @param page + * The PagePosition subset of items to return. + * @param requireDescription + * When true, force a full retrieval of each description; when false, return any uncached descriptions as the empty string + * @param userId + * The returned sites will be those which can be accessed by the user with this internal ID + * @return The List of Site objects that meet specified criteria. + */ + public List getSites(SelectionType type, Object ofType, String criteria, Map propertyCriteria, SortType sort, PagingPosition page, boolean requireDescription, String userId); + + /** * Get the Site IDs for all sites matching criteria. * This is useful when you only need the listing of site ids (for other operations) and do not need the actual Site objects. * Index: kernel-impl/src/main/java/org/sakaiproject/site/impl/DbSiteService.java =================================================================== --- kernel-impl/src/main/java/org/sakaiproject/site/impl/DbSiteService.java (revision 309683) +++ kernel-impl/src/main/java/org/sakaiproject/site/impl/DbSiteService.java (working copy) @@ -701,8 +701,9 @@ return order; } - - private Object[] getSitesFields(SelectionType type, Object ofType, String criteria, Map propertyCriteria) + + // KNL-1259 + private Object[] getSitesFields(SelectionType type, Object ofType, String criteria, Map propertyCriteria, String userId) { int fieldCount = 0; if (ofType != null) @@ -736,7 +737,7 @@ int pos = 0; if ((type == SelectionType.ACCESS) || (type == SelectionType.UPDATE) || (type == SelectionType.DELETED)) { - fields[pos++] = sessionManager().getCurrentSessionUserId(); + fields[pos++] = getCurrentUserIdIfNull(userId); } if (ofType != null) { @@ -787,13 +788,27 @@ } if (type == SelectionType.JOINABLE) { - fields[pos++] = sessionManager().getCurrentSessionUserId(); + fields[pos++] = getCurrentUserIdIfNull(userId); } } return fields; } + + /** + * convenience method - if the userID is null, return the current user's userID --bbailla2 + */ + private String getCurrentUserIdIfNull(String userId) + { + return userId == null ? sessionManager().getCurrentSessionUserId() : userId; + } + private Object[] getSitesFields(SelectionType type, Object ofType, String criteria, Map propertyCriteria) + { + // getSitesFields with null userId returns the current user's site fields + return getSitesFields(type, ofType, criteria, propertyCriteria, null); + } + private String getSitesJoin(SelectionType type, SortType sort ) { // do we need a join? @@ -953,11 +968,14 @@ /** * {@inheritDoc} */ - public List getSiteIds(SelectionType type, Object ofType, String criteria, Map propertyCriteria, SortType sort, PagingPosition page) + public List getSiteIds(SelectionType type, Object ofType, String criteria, Map propertyCriteria, SortType sort, PagingPosition page, String userId) { + // KNL-1259 + userId = getCurrentUserIdIfNull(userId); + String join = getSitesJoin( type, sort ); String order = getSitesOrder( sort ); - Object[] values = getSitesFields( type, ofType, criteria, propertyCriteria ); + Object[] values = getSitesFields( type, ofType, criteria, propertyCriteria, userId ); String where = getSitesWhere(type, ofType, criteria, propertyCriteria, sort); String sql; @@ -979,6 +997,15 @@ } /** + * {@inheritDoc} + */ + public List getSiteIds(SelectionType type, Object ofType, String criteria, Map propertyCriteria, SortType sort, PagingPosition page) + { + // getSiteIds with userId returns the current user's site Ids + return getSiteIds(type, ofType, criteria, propertyCriteria, sort, page, null); + } + + /** * Get an ordered map corresponding to a list of Site IDs, filled with any matching cached sites. * * @param siteIds @@ -1030,9 +1057,11 @@ * @inheritDoc */ @SuppressWarnings("unchecked") - public List getSites(SelectionType type, Object ofType, String criteria, Map propertyCriteria, SortType sort, PagingPosition page, boolean requireDescription) + public List getSites(SelectionType type, Object ofType, String criteria, Map propertyCriteria, SortType sort, PagingPosition page, boolean requireDescription, String userId) { - List siteIds = getSiteIds(type, ofType, criteria, propertyCriteria, sort, page); + // KNL-1259 + userId = getCurrentUserIdIfNull(userId); + List siteIds = getSiteIds(type, ofType, criteria, propertyCriteria, sort, page, userId); LinkedHashMap siteMap = getOrderedSiteMap(siteIds, requireDescription); SqlReader reader = requireDescription ? fullSiteReader : lightSiteReader; @@ -1075,6 +1104,16 @@ return new ArrayList(siteMap.values()); } + + /** + * @inheritDoc + */ + @SuppressWarnings("unchecked") + public List getSites(SelectionType type, Object ofType, String criteria, Map propertyCriteria, SortType sort, PagingPosition page, boolean requireDescription) + { + // getSites with null userId returns the current user's sites + return getSites(type, ofType, criteria, propertyCriteria, sort, page, requireDescription, null); + } /** * {@inheritDoc} Index: kernel-impl/src/test/java/org/sakaiproject/site/impl/SiteServiceTest.java =================================================================== --- kernel-impl/src/test/java/org/sakaiproject/site/impl/SiteServiceTest.java (revision 309683) +++ kernel-impl/src/test/java/org/sakaiproject/site/impl/SiteServiceTest.java (working copy) @@ -169,4 +169,10 @@ PagingPosition page) { return new ArrayList(0); } + + @Override + public List getSiteIds(SelectionType type, Object ofType, String criteria, Map propertyCriteria, SortType sort, PagingPosition page, boolean requireDescription, String userId) + { + return new ArrayList(0); + } }