diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.sites.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.sites.get.desc.xml index 0cca660be2..534d507517 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.sites.get.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.sites.get.desc.xml @@ -1,7 +1,7 @@ Sites Get a colleciton of the sites a person has an explicit member to. - /api/people/{userid}/sites + /api/people/{userid}/sites?size={pagesize?}&pos={position?} user required diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.sites.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.sites.get.js index 4197c7c9f9..a14b313ea9 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.sites.get.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.sites.get.js @@ -15,6 +15,25 @@ function main() // Get the list of sites var sites = siteService.listUserSites(userName); + + var sizeString = args["size"]; + if (sizeString != null) + { + var size = parseInt(sizeString); + + if (size != NaN && size < sites.length) + { + // TODO this is a tempory implementaion to support preview client + // Only return the first n sites based on the passed page size + var pagedSites = Array(); + for (var index = 0; index < size; index++) + { + pagedSites[index] = sites[index]; + } + + sites = pagedSites; + } + } // Pass the queried sites to the template model.sites = sites; diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/site/sites.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/site/sites.get.js index 5a7f273ce6..83555c961e 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/site/sites.get.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/site/sites.get.js @@ -1,9 +1,33 @@ -// Get the filter parameters -var nameFilter = args["namefilter"]; -var sitePreset = args["sitepresetfilter"]; +function main() +{ + // Get the filter parameters + var nameFilter = args["nf"]; + var sitePreset = args["spf"]; + var sizeString = args["size"]; + + // Get the list of sites + var sites = siteService.listSites(nameFilter, sitePreset); + + if (sizeString != null) + { + var size = parseInt(sizeString); + + if (size != NaN && size < sites.length) + { + // TODO this is a tempory implementaion to support preview client + // Only return the first n sites based on the passed page size + var pagedSites = Array(); + for (var index = 0; index < size; index++) + { + pagedSites[index] = sites[index]; + } + + sites = pagedSites; + } + } + + // Add the sites to the model + model.sites = sites; +} -// Get the list of sites -var sites = siteService.listSites(nameFilter, sitePreset); - -// Pass the queried sites to the template -model.sites = sites; \ No newline at end of file +main(); diff --git a/source/java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java b/source/java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java index d4aca66e4f..c34fb18708 100644 --- a/source/java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java +++ b/source/java/org/alfresco/repo/web/scripts/site/SiteServiceTest.java @@ -144,15 +144,31 @@ public class SiteServiceTest extends BaseWebScriptTest public void testGetSites() throws Exception { - // == Test basic GET with no filters == - MockHttpServletResponse response = getRequest(URL_SITES, 200); - JSONArray result = new JSONArray(response.getContentAsString()); + JSONArray result = new JSONArray(response.getContentAsString()); + assertNotNull(result); + assertEquals(0, result.length()); - // TODO formalise this test once i can be sure that i know what's already in the site store - // ie: .. i need to clean up after myself in this test + createSite("myPreset", GUID.generate(), "myTitle", "myDescription", true, 200); + createSite("myPreset", GUID.generate(), "myTitle", "myDescription", true, 200); + createSite("myPreset", GUID.generate(), "myTitle", "myDescription", true, 200); + createSite("myPreset", GUID.generate(), "myTitle", "myDescription", true, 200); + createSite("myPreset", GUID.generate(), "myTitle", "myDescription", true, 200); - System.out.println(response.getContentAsString()); + response = getRequest(URL_SITES, 200); + result = new JSONArray(response.getContentAsString()); + assertNotNull(result); + assertEquals(5, result.length()); + + response = getRequest(URL_SITES + "?size=3", 200); + result = new JSONArray(response.getContentAsString()); + assertNotNull(result); + assertEquals(3, result.length()); + + response = getRequest(URL_SITES + "?size=13", 200); + result = new JSONArray(response.getContentAsString()); + assertNotNull(result); + assertEquals(5, result.length()); } public void testGetSite() throws Exception @@ -378,5 +394,17 @@ public class SiteServiceTest extends BaseWebScriptTest assertNotNull(result); assertEquals(0, result.length()); + + response = getRequest("/api/people/" + USER_ONE + "/sites?size=1", 200); + result = new JSONArray(response.getContentAsString()); + + assertNotNull(result); + assertEquals(1, result.length()); + + response = getRequest("/api/people/" + USER_ONE + "/sites?size=5", 200); + result = new JSONArray(response.getContentAsString()); + + assertNotNull(result); + assertEquals(2, result.length()); } }