Added support for pagesize on site collections for preview

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10035 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2008-07-25 15:14:53 +00:00
parent f123bca2f3
commit abc95e42d1
4 changed files with 86 additions and 15 deletions

View File

@@ -1,7 +1,7 @@
<webscript>
<shortname>Sites</shortname>
<description>Get a colleciton of the sites a person has an explicit member to.</description>
<url>/api/people/{userid}/sites</url>
<url>/api/people/{userid}/sites?size={pagesize?}&amp;pos={position?}</url>
<format default="json"/>
<authentication>user</authentication>
<transaction>required</transaction>

View File

@@ -16,6 +16,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;
}

View File

@@ -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);
// Get the list of sites
var sites = siteService.listSites(nameFilter, sitePreset);
// Pass the queried sites to the template
model.sites = sites;
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;
}
main();

View File

@@ -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());
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());
}
}