mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged V3.1 to HEAD
13068: JAWS-456: Site REST API to retrieve collection of site details for specific site list - Implementation for new web script added - Unit test added - Documentation updated http://wiki.alfresco.com/wiki/3.0_REST_API#Site_Service 13122: Fix for Site scaling issue - a user who is a member of a large number of sites and at least one favoriate site would see slow response when viewing any page in Share. Added "Loading search results..." delayed Ajax wait pop-up when searching in Share Site Finder page. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13560 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
<webscript>
|
||||||
|
<shortname>SitesQuery</shortname>
|
||||||
|
<description>Queries the collection of sites.</description>
|
||||||
|
<url>/api/sites/query</url>
|
||||||
|
<format default="json"/>
|
||||||
|
<authentication>user</authentication>
|
||||||
|
<transaction>required</transaction>
|
||||||
|
</webscript>
|
@@ -0,0 +1,8 @@
|
|||||||
|
<#import "site.lib.ftl" as siteLib/>
|
||||||
|
|
||||||
|
[
|
||||||
|
<#list sites as site>
|
||||||
|
<@siteLib.siteJSON site=site/>
|
||||||
|
<#if site_has_next>,</#if>
|
||||||
|
</#list>
|
||||||
|
]
|
@@ -0,0 +1,41 @@
|
|||||||
|
function main()
|
||||||
|
{
|
||||||
|
var sites = null;
|
||||||
|
|
||||||
|
// NOTE:
|
||||||
|
// This implementation is sufficient for the 3.1 requirement, but when site query is expanded
|
||||||
|
// it should be formalised in the underlying JS and JAVA API's. Currently it is very simplistic
|
||||||
|
// as the current use case is very limited.
|
||||||
|
if (json.has("shortName") == true)
|
||||||
|
{
|
||||||
|
var shortNameQuery = json.getJSONObject("shortName");
|
||||||
|
|
||||||
|
// Get the matching mode required (default is "exact")
|
||||||
|
var matchMode = shortNameQuery.get("match")
|
||||||
|
var isMembershipMode = (matchMode == "exact-membership");
|
||||||
|
|
||||||
|
// Get each short name and put the associated site in the list
|
||||||
|
if (shortNameQuery.has("values") == true)
|
||||||
|
{
|
||||||
|
var values = shortNameQuery.getJSONArray("values");
|
||||||
|
var len = values.length();
|
||||||
|
var username = person.properties.userName;
|
||||||
|
sites = new Array(len);
|
||||||
|
for (var index=0; index<len; index++)
|
||||||
|
{
|
||||||
|
var shortName = values.getString(index);
|
||||||
|
var site = siteService.getSite(shortName);
|
||||||
|
if (site != null && (!isMembershipMode || site.isMember(username)))
|
||||||
|
{
|
||||||
|
sites.push(site);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If the query has no values just continue as there will be no matches
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the sites collection in the model
|
||||||
|
model.sites = sites != null ? sites : new Array(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
@@ -27,8 +27,10 @@ package org.alfresco.repo.web.scripts.site;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||||
@@ -72,6 +74,7 @@ public class SiteServiceTest extends BaseWebScriptTest
|
|||||||
private static final String USER_THREE = "SiteTestThree";
|
private static final String USER_THREE = "SiteTestThree";
|
||||||
|
|
||||||
private static final String URL_SITES = "/api/sites";
|
private static final String URL_SITES = "/api/sites";
|
||||||
|
private static final String URL_SITES_QUERY = URL_SITES + "/query";
|
||||||
private static final String URL_MEMBERSHIPS = "/memberships";
|
private static final String URL_MEMBERSHIPS = "/memberships";
|
||||||
|
|
||||||
private List<String> createdSites = new ArrayList<String>(5);
|
private List<String> createdSites = new ArrayList<String>(5);
|
||||||
@@ -193,6 +196,62 @@ public class SiteServiceTest extends BaseWebScriptTest
|
|||||||
assertEquals(5, result.length());
|
assertEquals(5, result.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://issues.alfresco.com/jira/browse/JAWS-456
|
||||||
|
*/
|
||||||
|
public void testQuerySites() throws Exception
|
||||||
|
{
|
||||||
|
// Generate the short names of the sites
|
||||||
|
String[] shortNames = new String[]{GUID.generate(), GUID.generate(), GUID.generate(), GUID.generate(), GUID.generate()};
|
||||||
|
|
||||||
|
// Create the sites
|
||||||
|
createSite("myPreset", shortNames[0], "myTitle", "myDescription", true, 200);
|
||||||
|
createSite("myPreset", shortNames[1], "myTitle", "myDescription", true, 200);
|
||||||
|
createSite("myPreset", shortNames[2], "myTitle", "myDescription", true, 200);
|
||||||
|
createSite("myPreset", shortNames[3], "myTitle", "myDescription", true, 200);
|
||||||
|
createSite("myPreset", shortNames[4], "myTitle", "myDescription", true, 200);
|
||||||
|
|
||||||
|
// build query json
|
||||||
|
JSONObject shortNameQuery = new JSONObject();
|
||||||
|
shortNameQuery.put("match", "exact");
|
||||||
|
JSONArray valuesArray = new JSONArray();
|
||||||
|
valuesArray.put(0, shortNames[0]);
|
||||||
|
valuesArray.put(1, shortNames[2]);
|
||||||
|
valuesArray.put(2, shortNames[4]);
|
||||||
|
valuesArray.put(3, "bobbins");
|
||||||
|
shortNameQuery.put("values", valuesArray);
|
||||||
|
JSONObject query = new JSONObject();
|
||||||
|
query.put("shortName", shortNameQuery);
|
||||||
|
|
||||||
|
// execute site query
|
||||||
|
Response response = sendRequest(new PostRequest(URL_SITES_QUERY, query.toString(), "application/json"), 200);
|
||||||
|
JSONArray result = new JSONArray(response.getContentAsString());
|
||||||
|
|
||||||
|
// check we have the results we expect
|
||||||
|
assertEquals(3, result.length());
|
||||||
|
Set<String> resultSet = new HashSet<String>();
|
||||||
|
for (int i=0; i<result.length(); i++)
|
||||||
|
{
|
||||||
|
resultSet.add((String)result.getJSONObject(i).get("shortName"));
|
||||||
|
}
|
||||||
|
assertTrue(resultSet.contains(shortNames[0]));
|
||||||
|
assertFalse(resultSet.contains(shortNames[1]));
|
||||||
|
assertTrue(resultSet.contains(shortNames[2]));
|
||||||
|
assertFalse(resultSet.contains(shortNames[3]));
|
||||||
|
assertTrue(resultSet.contains(shortNames[4]));
|
||||||
|
assertFalse(resultSet.contains("bobbins"));
|
||||||
|
|
||||||
|
// sample one of the returned sites and check it's what we expect
|
||||||
|
JSONObject site = result.getJSONObject(0);
|
||||||
|
assertNotNull(site);
|
||||||
|
assertEquals("myPreset", site.get("sitePreset"));
|
||||||
|
assertEquals("myTitle", site.get("title"));
|
||||||
|
assertEquals("myDescription", site.get("description"));
|
||||||
|
assertNotNull(site.get("node"));
|
||||||
|
assertNotNull(site.get("tagScope"));
|
||||||
|
assertTrue(site.getBoolean("isPublic"));
|
||||||
|
}
|
||||||
|
|
||||||
public void testGetSite() throws Exception
|
public void testGetSite() throws Exception
|
||||||
{
|
{
|
||||||
// Get a site that doesn't exist
|
// Get a site that doesn't exist
|
||||||
|
Reference in New Issue
Block a user