Fix a couple of minor issues with sites search REST API (no results were being returned)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29213 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2011-07-20 09:41:51 +00:00
parent 0af05e8256
commit dba83496a9
3 changed files with 59 additions and 6 deletions

View File

@@ -810,7 +810,7 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
*/ */
public List<SiteInfo> listSites(String nameFilter, String sitePresetFilter) public List<SiteInfo> listSites(String nameFilter, String sitePresetFilter)
{ {
return listSites(nameFilter, sitePresetFilter, 0); return listSites(nameFilter, sitePresetFilter, -1);
} }
/** /**
@@ -828,7 +828,7 @@ public class SiteServiceImpl extends AbstractLifecycleBean implements SiteServic
List<Pair<QName, Boolean>> sortProps = null; List<Pair<QName, Boolean>> sortProps = null;
PagingRequest pagingRequest = new PagingRequest(size == 0 ? Integer.MAX_VALUE : size); PagingRequest pagingRequest = new PagingRequest(size <= 0 ? Integer.MAX_VALUE : size);
List<FilterProp> filterProps = new ArrayList<FilterProp>(); List<FilterProp> filterProps = new ArrayList<FilterProp>();
if (filterHasValue) if (filterHasValue)

View File

@@ -161,15 +161,15 @@ public class ScriptSiteService extends BaseScopableProcessorExtension
* If no filters are specified then all the available sites are returned. * If no filters are specified then all the available sites are returned.
* *
* @param filter inclusion filter for returned sites. Only sites whose cm:name OR cm:title * @param filter inclusion filter for returned sites. Only sites whose cm:name OR cm:title
* OR cm:description CONTAIN the filter string will be returned. * OR cm:description start with the filter string will be returned.
* @param sitePresetFilter site preset filter * @param sitePresetFilter site preset filter
* @return Site[] a list of the site filtered as appropriate * @return Site[] a list of the site filtered as appropriate
* *
* @see SiteService#findSites(String, String, int) for a description of the limitations of this method. * @see SiteService#listSites(String, String, int) for a description of the limitations of this method.
*/ */
public Site[] listSites(String filter, String sitePresetFilter) public Site[] listSites(String filter, String sitePresetFilter)
{ {
return listSites(filter, sitePresetFilter, 0); return listSites(filter, sitePresetFilter, -1);
} }
/** /**
@@ -179,6 +179,26 @@ public class ScriptSiteService extends BaseScopableProcessorExtension
* If no filters are specified then all the available sites are returned. * If no filters are specified then all the available sites are returned.
* *
* @param filter inclusion filter for returned sites. Only sites whose cm:name OR cm:title * @param filter inclusion filter for returned sites. Only sites whose cm:name OR cm:title
* OR cm:description start with the filter string will be returned.
* @param sitePresetFilter site preset filter
* @param size max results size crop if >0
* @return Site[] a list of the site filtered as appropriate
*
* @see SiteService#listSites(String, String, int) for a description of the limitations of this method.
*/
public Site[] listSites(String filter, String sitePresetFilter, int size)
{
List<SiteInfo> siteInfos = this.siteService.listSites(filter, sitePresetFilter, size);
return makeSitesArray(siteInfos);
}
/**
* Find (search) the sites available in the repository. The returned list can optionally be filtered by name and site
* preset.
* <p/>
* If no filters are specified then all the available sites are returned.
*
* @param filter inclusion filter for returned sites. Only sites whose cm:name OR cm:title
* OR cm:description CONTAIN the filter string will be returned. * OR cm:description CONTAIN the filter string will be returned.
* @param sitePresetFilter site preset filter * @param sitePresetFilter site preset filter
* @param size max results size crop if >0 * @param size max results size crop if >0
@@ -186,15 +206,29 @@ public class ScriptSiteService extends BaseScopableProcessorExtension
* @return Site[] a list of the site filtered as appropriate * @return Site[] a list of the site filtered as appropriate
* *
* @see SiteService#findSites(String, String, int) for a description of the limitations of this method. * @see SiteService#findSites(String, String, int) for a description of the limitations of this method.
* @since 4.0
*/ */
public Site[] listSites(String filter, String sitePresetFilter, int size) public Site[] findSites(String filter, String sitePresetFilter, int size)
{ {
List<SiteInfo> siteInfos = this.siteService.findSites(filter, sitePresetFilter, size); List<SiteInfo> siteInfos = this.siteService.findSites(filter, sitePresetFilter, size);
return makeSitesArray(siteInfos);
}
/**
* Converts the given List of SiteInfo objects to a JavaScript friendly array
* of Site objects.
*
* @param siteInfos
* @return Array of Site objects
*/
protected Site[] makeSitesArray(List<SiteInfo> siteInfos)
{
List<Site> sites = new ArrayList<Site>(siteInfos.size()); List<Site> sites = new ArrayList<Site>(siteInfos.size());
for (SiteInfo siteInfo : siteInfos) for (SiteInfo siteInfo : siteInfos)
{ {
sites.add(new Site(siteInfo, this.serviceRegistry, this.siteService, getScope())); sites.add(new Site(siteInfo, this.serviceRegistry, this.siteService, getScope()));
} }
return sites.toArray(new Site[sites.size()]); return sites.toArray(new Site[sites.size()]);
} }

View File

@@ -57,6 +57,24 @@ function testListSites()
// TODO .. check the filters // TODO .. check the filters
} }
function testFindSites()
{
// Find all the sites
var sites = siteService.findSites(null, null, -1);
test.assertEquals(preexistingSiteCount + 2, sites.length);
// find all sites with "short" in the name
sites = siteService.findSites("short", null, -1);
test.assertEquals(2, sites.length);
sites = siteService.findSites("short", null, 0);
test.assertEquals(2, sites.length);
// find just one site with "short" in the name
sites = siteService.findSites("short", null, 1);
test.assertEquals(1, sites.length);
}
function testMembership() function testMembership()
{ {
var site = siteService.getSite("siteShortName"); var site = siteService.getSite("siteShortName");
@@ -207,6 +225,7 @@ function testSiteCustomProperties()
// Execute test's // Execute test's
testCRUD(); testCRUD();
testListSites(); testListSites();
testFindSites();
testMembership(); testMembership();
testContainer(); testContainer();
testPermissions(); testPermissions();