mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Sites collection added to person rest API, check point of tagging rest API
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10025 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
<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>
|
||||
<format default="json"/>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
</webscript>
|
@@ -0,0 +1,23 @@
|
||||
function main()
|
||||
{
|
||||
// Get the user name of the person to get
|
||||
var userName = url.templateArgs.userid;
|
||||
|
||||
// Get the person who has that user name
|
||||
var person = people.getPerson(userName);
|
||||
|
||||
if (person === null)
|
||||
{
|
||||
// Return 404 - Not Found
|
||||
status.setCode(status.STATUS_NOT_FOUND, "Person " + userName + " does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the list of sites
|
||||
var sites = siteService.listUserSites(userName);
|
||||
|
||||
// Pass the queried sites to the template
|
||||
model.sites = sites;
|
||||
}
|
||||
|
||||
main();
|
@@ -0,0 +1,8 @@
|
||||
<#import "../site/site.lib.ftl" as siteLib/>
|
||||
|
||||
[
|
||||
<#list sites as site>
|
||||
<@siteLib.siteJSON site=site/>
|
||||
<#if site_has_next>,</#if>
|
||||
</#list>
|
||||
]
|
@@ -0,0 +1,9 @@
|
||||
<webscript>
|
||||
<shortname>NodeTags</shortname>
|
||||
<description>Get all the tags for a node</description>
|
||||
<url>/api/node/{store_type}/{store_id}/{id}/tags</url>
|
||||
<url>/api/path/{store_type}/{store_id}/{id}/tags</url>
|
||||
<format default="json"/>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
</webscript>
|
@@ -0,0 +1,19 @@
|
||||
function main()
|
||||
{
|
||||
// Get the node from the URL
|
||||
var pathSegments = url.match.split("/");
|
||||
var reference = [ url.templateArgs.store_type, url.templateArgs.store_id ].concat(url.templateArgs.id.split("/"));
|
||||
var node = search.findNode(pathSegments[2], reference);
|
||||
|
||||
// 404 if the node is not found
|
||||
if (node == null)
|
||||
{
|
||||
status.setCode(status.STATUS_NOT_FOUND, "The node could not be found");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the tags of the node
|
||||
model.tags = node.tags;
|
||||
}
|
||||
|
||||
main();
|
@@ -0,0 +1,5 @@
|
||||
[
|
||||
<#list tags as tag>
|
||||
${tag}<#if tag_has_next>,</#if>
|
||||
</#list>
|
||||
]
|
@@ -0,0 +1,9 @@
|
||||
<webscript>
|
||||
<shortname>NodeTags</shortname>
|
||||
<description>Add the posted tags to the node</description>
|
||||
<url>/api/node/{store_type}/{store_id}/{id}/tags</url>
|
||||
<url>/api/path/{store_type}/{store_id}/{id}/tags</url>
|
||||
<format default="json"/>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
</webscript>
|
@@ -0,0 +1,25 @@
|
||||
function main()
|
||||
{
|
||||
// Get the node from the URL
|
||||
var pathSegments = url.match.split("/");
|
||||
var reference = [ url.templateArgs.store_type, url.templateArgs.store_id ].concat(url.templateArgs.id.split("/"));
|
||||
var node = search.findNode(pathSegments[2], reference);
|
||||
|
||||
// 404 if the node is not found
|
||||
if (node == null)
|
||||
{
|
||||
status.setCode(status.STATUS_NOT_FOUND, "The node could not be found");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the array of posted tags
|
||||
for(var index = 0; index < json.length; index++)
|
||||
{
|
||||
node.addTag(json.getString(index);
|
||||
}
|
||||
|
||||
// Get the tags of the node
|
||||
model.tags = node.tags;
|
||||
}
|
||||
|
||||
main();
|
@@ -0,0 +1,5 @@
|
||||
[
|
||||
<#list tags as tag>
|
||||
${tag}<#if tag_has_next>,</#if>
|
||||
</#list>
|
||||
]
|
@@ -0,0 +1,8 @@
|
||||
<webscript>
|
||||
<shortname>Tags</shortname>
|
||||
<description>Get the currently available tags</description>
|
||||
<url>/api/tags/{store_type}/{store_id}?tf={tag_filter?}</url>
|
||||
<format default="json"/>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
</webscript>
|
@@ -0,0 +1,15 @@
|
||||
// Get the store reference
|
||||
var store = url.templateArgs.store_type + "://" + url.templateArgs.store_id;
|
||||
|
||||
var filter = args["tf"];
|
||||
if (filter === null)
|
||||
{
|
||||
// Get all the tags
|
||||
model.tags = taggingService.getTags(store);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get a list of filtered tags
|
||||
model.tags = taggingService.getTags(store, filter);
|
||||
}
|
||||
|
@@ -0,0 +1,5 @@
|
||||
[
|
||||
<#list tags as tag>
|
||||
${tag}<#if tag_has_next>,</#if>
|
||||
</#list>
|
||||
]
|
@@ -0,0 +1,8 @@
|
||||
<webscript>
|
||||
<shortname>TagNodes</shortname>
|
||||
<description>Get the nodes for a given tag</description>
|
||||
<url>/api/tags/{store_type}/{store_id}/{tag}/nodes</url>
|
||||
<format default="json"/>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
</webscript>
|
@@ -0,0 +1,21 @@
|
||||
|
||||
function main()
|
||||
{
|
||||
// Get the store reference
|
||||
var store = url.templateArgs.store_type + "://" + url.templateArgs.store_id;
|
||||
|
||||
// Get the tag
|
||||
var tag = url.templateArgs.tag;
|
||||
if (tag == null)
|
||||
{
|
||||
// Error since no tag specified on the URL
|
||||
status.setCode(404, "No tag specified");
|
||||
return;
|
||||
}
|
||||
|
||||
// do the search
|
||||
model.nodes = search.tagSearch(store, tag);
|
||||
}
|
||||
|
||||
main();
|
||||
|
@@ -0,0 +1,8 @@
|
||||
[
|
||||
<#list nodes as node>
|
||||
{
|
||||
"nodeRef" : "${node.storeType}://${node.storeId}/${node.id}",
|
||||
"url" : "${url.serviceContext}/api/node/${node.storeType}/${node.storeId}/${node.id}"
|
||||
}<#if node_has_next>,</#if>
|
||||
</#list>
|
||||
]
|
@@ -332,4 +332,51 @@ public class SiteServiceTest extends BaseWebScriptTest
|
||||
getRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS + "/" + USER_TWO, 404);
|
||||
|
||||
}
|
||||
|
||||
public void testGetPersonSites() throws Exception
|
||||
{
|
||||
// Create a site
|
||||
String shortName = GUID.generate();
|
||||
createSite("myPreset", shortName, "myTitle", "myDescription", true, 200);
|
||||
String shortName2 = GUID.generate();
|
||||
createSite("myPreset", shortName2, "myTitle", "myDescription", true, 200);
|
||||
|
||||
MockHttpServletResponse response = getRequest("/api/people/" + USER_TWO + "/sites", 200);
|
||||
JSONArray result = new JSONArray(response.getContentAsString());
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(0, result.length());
|
||||
|
||||
// Add some memeberships
|
||||
JSONObject membership = new JSONObject();
|
||||
membership.put("role", SiteModel.SITE_CONSUMER);
|
||||
JSONObject person = new JSONObject();
|
||||
person.put("userName", USER_TWO);
|
||||
membership.put("person", person);
|
||||
postRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, 200, membership.toString(), "application/json");
|
||||
membership = new JSONObject();
|
||||
membership.put("role", SiteModel.SITE_CONSUMER);
|
||||
person = new JSONObject();
|
||||
person.put("userName", USER_TWO);
|
||||
membership.put("person", person);
|
||||
postRequest(URL_SITES + "/" + shortName2 + URL_MEMBERSHIPS, 200, membership.toString(), "application/json");
|
||||
|
||||
response = getRequest("/api/people/" + USER_TWO + "/sites", 200);
|
||||
result = new JSONArray(response.getContentAsString());
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(2, result.length());
|
||||
|
||||
response = getRequest("/api/people/" + USER_ONE + "/sites", 200);
|
||||
result = new JSONArray(response.getContentAsString());
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(2, result.length());
|
||||
|
||||
response = getRequest("/api/people/" + USER_THREE + "/sites", 200);
|
||||
result = new JSONArray(response.getContentAsString());
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(0, result.length());
|
||||
}
|
||||
}
|
||||
|
@@ -25,12 +25,20 @@
|
||||
package org.alfresco.repo.web.scripts.tagging;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.tagging.TaggingService;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.PropertyMap;
|
||||
import org.json.JSONArray;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
/**
|
||||
* Unit test to test tagging Web Script API
|
||||
@@ -43,9 +51,20 @@ public class TaggingServiceTest extends BaseWebScriptTest
|
||||
private AuthenticationComponent authenticationComponent;
|
||||
private PersonService personService;
|
||||
private TaggingService taggingService;
|
||||
private FileFolderService fileFolderService;
|
||||
private Repository repositoryHelper;
|
||||
private NodeService nodeService;
|
||||
|
||||
private static final String TEST_USER = "TaggingServiceTestUser";
|
||||
|
||||
|
||||
private static final String TAG_1 = "tagOneREST";
|
||||
private static final String TAG_2 = "tagTwoREST";
|
||||
private static final String TAG_3 = "tagThreeREST";
|
||||
private static final String TAG_4 = "tagFourREST";
|
||||
private static final String TAG_5 = "tagFiveREST";
|
||||
|
||||
private NodeRef nodeOne;
|
||||
private NodeRef nodeTwo;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
@@ -55,7 +74,28 @@ public class TaggingServiceTest extends BaseWebScriptTest
|
||||
this.authenticationService = (AuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService");
|
||||
this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent");
|
||||
this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService");
|
||||
this.taggingService = (TaggingService)getServer().getApplicationContext().getBean("TaggingService");
|
||||
this.taggingService = (TaggingService)getServer().getApplicationContext().getBean("TaggingService");
|
||||
this.fileFolderService = (FileFolderService)getServer().getApplicationContext().getBean("FileFolderService");
|
||||
this.repositoryHelper = (Repository)getServer().getApplicationContext().getBean("repositoryHelper");
|
||||
this.nodeService = (NodeService)getServer().getApplicationContext().getBean("NodeService");
|
||||
|
||||
// Add a load of tags ready to use
|
||||
this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_1);
|
||||
this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_2);
|
||||
this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_3);
|
||||
this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_4);
|
||||
this.taggingService.createTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_5);
|
||||
|
||||
// Create test node's
|
||||
NodeRef testRoot = this.repositoryHelper.getCompanyHome();
|
||||
String guid = GUID.generate();
|
||||
this.nodeOne = this.fileFolderService.create(testRoot, "test_doc1" + guid + ".txt", ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
this.nodeTwo = this.fileFolderService.create(testRoot, "test_dco2" + guid + ".txt", ContentModel.TYPE_CONTENT).getNodeRef();
|
||||
|
||||
// Add tags to test nodes
|
||||
this.taggingService.addTag(nodeOne, TAG_1);
|
||||
this.taggingService.addTag(nodeOne, TAG_2);
|
||||
this.taggingService.addTag(nodeTwo, TAG_2);
|
||||
|
||||
// Create users
|
||||
createUser(TEST_USER);
|
||||
@@ -85,10 +125,62 @@ public class TaggingServiceTest extends BaseWebScriptTest
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
super.tearDown();
|
||||
this.authenticationComponent.setCurrentUser("admin");
|
||||
|
||||
this.taggingService.deleteTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_1);
|
||||
this.taggingService.deleteTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_2);
|
||||
this.taggingService.deleteTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_3);
|
||||
this.taggingService.deleteTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_4);
|
||||
this.taggingService.deleteTag(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), TAG_5);
|
||||
|
||||
this.nodeService.deleteNode(this.nodeOne);
|
||||
this.nodeService.deleteNode(this.nodeTwo);
|
||||
}
|
||||
|
||||
public void testGetTags()
|
||||
throws Exception
|
||||
{
|
||||
MockHttpServletResponse response = getRequest("/api/tags/" + StoreRef.PROTOCOL_WORKSPACE + "/SpacesStore", 200);
|
||||
JSONArray jsonArray = new JSONArray(response.getContentAsString());
|
||||
|
||||
assertNotNull(jsonArray);
|
||||
assertEquals(5, jsonArray.length());
|
||||
|
||||
response = getRequest("/api/tags/" + StoreRef.PROTOCOL_WORKSPACE + "/SpacesStore?tf=one", 200);
|
||||
jsonArray = new JSONArray(response.getContentAsString());
|
||||
|
||||
assertNotNull(jsonArray);
|
||||
assertEquals(1, jsonArray.length());
|
||||
|
||||
response = getRequest("/api/tags/" + StoreRef.PROTOCOL_WORKSPACE + "/SpacesStore?tf=none", 200);
|
||||
jsonArray = new JSONArray(response.getContentAsString());
|
||||
|
||||
assertNotNull(jsonArray);
|
||||
assertEquals(0, jsonArray.length());
|
||||
}
|
||||
|
||||
public void testGetNodes()
|
||||
throws Exception
|
||||
{
|
||||
MockHttpServletResponse response = getRequest("/api/tags/" + StoreRef.PROTOCOL_WORKSPACE + "/SpacesStore/" + TAG_1 + "/nodes", 200);
|
||||
JSONArray jsonArray = new JSONArray(response.getContentAsString());
|
||||
|
||||
assertNotNull(jsonArray);
|
||||
assertEquals(1, jsonArray.length());
|
||||
|
||||
System.out.println(response.getContentAsString());
|
||||
|
||||
response = getRequest("/api/tags/" + StoreRef.PROTOCOL_WORKSPACE + "/SpacesStore/" + TAG_2 + "/nodes", 200);
|
||||
jsonArray = new JSONArray(response.getContentAsString());
|
||||
|
||||
assertNotNull(jsonArray);
|
||||
assertEquals(2, jsonArray.length());
|
||||
|
||||
response = getRequest("/api/tags/" + StoreRef.PROTOCOL_WORKSPACE + "/SpacesStore/jumk/nodes", 200);
|
||||
jsonArray = new JSONArray(response.getContentAsString());
|
||||
|
||||
assertNotNull(jsonArray);
|
||||
assertEquals(0, jsonArray.length());
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user