mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
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:
@@ -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?}&pos={position?}</url>
|
||||
<format default="json"/>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
main();
|
||||
|
@@ -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());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user