Site Service: refactor container API (Java & JS) to have separate create method, fix-up UI fallout, expose node details on site details (Java/JS/REST), fixup web scripts with correct permission levels

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9918 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2008-07-17 14:17:16 +00:00
parent 3b9c4db6f4
commit 5f5937479b
34 changed files with 212 additions and 49 deletions

View File

@@ -29,8 +29,12 @@ function findNodeInSite()
var node = site.getContainer(containerId);
if (node === null)
{
status.setCode(status.STATUS_NOT_FOUND, "Unable to fetch container '" + containerId + "' of site '" + siteId + "'. (No write permission?)");
return null;
node = site.createContainer(containerId);
if (node === null)
{
status.setCode(status.STATUS_NOT_FOUND, "Unable to fetch container '" + containerId + "' of site '" + siteId + "'. (No write permission?)");
return null;
}
}
// try to fetch the the path is there is any

View File

@@ -3,6 +3,6 @@
<description>Get the membership details for a user</description>
<url>/api/sites/{shortname}/memberships/{username}</url>
<format default="json"/>
<authentication>guest</authentication>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -3,6 +3,6 @@
<description>Get the membership details for a user</description>
<url>/api/sites/{shortname}/memberships/{username}</url>
<format default="json"/>
<authentication>guest</authentication>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -3,6 +3,6 @@
<description>Get the membership details for a user</description>
<url>/api/sites/{shortname}/memberships/{username}</url>
<format default="json"/>
<authentication>guest</authentication>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -3,6 +3,6 @@
<description>Get a colleciton of a sites memberships.</description>
<url>/api/sites/{shortname}/memberships?nf={namefilter?}&amp;rf={rolefilter?}&amp;size={pagesize?}&amp;pos={position?}</url>
<format default="json"/>
<authentication>guest</authentication>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -3,6 +3,6 @@
<description>Adds a new membership to the site</description>
<url>/api/sites/{shortname}/memberships</url>
<format default="json"/>
<authentication>guest</authentication>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -3,6 +3,6 @@
<description>Delete the details of a site.</description>
<url>/api/sites/{shortname}</url>
<format default="json"/>
<authentication>guest</authentication>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -3,6 +3,6 @@
<description>Get the details of a site.</description>
<url>/api/sites/{shortname}</url>
<format default="json"/>
<authentication>guest</authentication>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -5,6 +5,10 @@
"shortName" : "${site.shortName}",
"title" : "${site.title}",
"description" : "${site.description}",
<#if site.node?exists>
"node" : "${url.serviceContext}/api/node/${site.node.storeType}/${site.node.storeId}/${site.node.id}",
"tagScope" : "${url.serviceContext}/api/tagscopes/${site.node.storeType}/${site.node.storeId}/${site.node.id}",
</#if>
"isPublic" : ${site.isPublic?string("true", "false")}
}
</#macro>

View File

@@ -3,6 +3,6 @@
<description>Update the details of a site.</description>
<url>/api/sites/{shortname}</url>
<format default="json"/>
<authentication>guest</authentication>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -3,6 +3,6 @@
<description>Get a colleciton of the sites in the repository. The collection can be filtered by name and/or site preset.</description>
<url>/api/sites?nf={namefilter?}&amp;spf={sitepresetfilter?}&amp;size={pagesize?}&amp;pos={position?}</url>
<format default="json"/>
<authentication>guest</authentication>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -3,6 +3,6 @@
<description>Creates a new site based on the site preset and details provided.</description>
<url>/api/sites</url>
<format default="json"/>
<authentication>guest</authentication>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -17,19 +17,20 @@ function findTargetNode()
}
else if (containerId == undefined)
{
// PENDING: hack!
// site is not a node reference, which we need though to get the tagscope.
// simply take a container we know it exists and fetch the parent
return site.getContainer("blog").parent;
//return site;
// get site node
return site.node;
}
// fetch container
node = site.getContainer(containerId);
if (node === null)
{
status.setCode(status.STATUS_NOT_FOUND, "Unable to fetch container '" + containerId + "' of site '" + siteId + "'. (No write permission?)");
return null;
node = site.createContainer(containerId);
if (node === null)
{
status.setCode(status.STATUS_NOT_FOUND, "Unable to fetch container '" + containerId + "' of site '" + siteId + "'. (No write permission?)");
return null;
}
}
else if (path == undefined)
{

View File

@@ -4,6 +4,6 @@
<url>/api/node/{store_type}/{store_id}/{id}/content{property}/thumbnails/{thumbnailname}</url>
<url>/api/path/{store_type}/{store_id}/{id}/content{property}/thumbnails/{thumbnailname}</url>
<format default="json"/>
<authentication>guest</authentication>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -4,6 +4,6 @@
<url>/api/node/{store_type}/{store_id}/{id}/content{property}/thumbnails/{thumbnailname}?qc={queuecreate?}&amp;ph={placeholder?}</url>
<url>/api/path/{store_type}/{store_id}/{id}/content{property}/thumbnails/{thumbnailname}?qc={queuecreate?}&amp;ph={placeholder?}</url>
<format default="">argument</format>
<authentication>guest</authentication>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -13,7 +13,7 @@ function main()
}
// Get the thumbnail name from the JSON content
var thumbnailName = url.templateArgs.thumbnailname; //pathSegments[pathSegments.length - 1];
var thumbnailName = url.templateArgs.thumbnailname;
// 404 if no thumbnail name found
if (thumbnailName == null)

View File

@@ -4,6 +4,6 @@
<url>/api/node/{store_type}/{store_id}/{id}/content{property}/thumbnails/{thumbnailname}</url>
<url>/api/path/{store_type}/{store_id}/{id}/content{property}/thumbnails/{thumbnailname}</url>
<format default="json"/>
<authentication>guest</authentication>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -4,6 +4,6 @@
<url>/api/node/{store_type}/{store_id}/{id}/content{property}/thumbnails?as={async?}</url>
<url>/api/path/{store_type}/{store_id}/{id}/content{property}/thumbnails?as={async?}</url>
<format default="json"/>
<authentication>guest</authentication>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -96,6 +96,11 @@ else
{
// Upload mode, since uploadDirectory was used
var container = site.getContainer(containerId);
if (container === null)
{
container = site.createContainer(containerId);
}
if (container === null)
{
status.code = 404;

View File

@@ -23,7 +23,11 @@ function deleteEvent()
var eventsFolder = site.getContainer("calendar");
if (eventsFolder === null)
{
return status.STATUS_NOT_FOUND;
eventsFolder = site.createContainer("calendar");
if (eventsFolder === null)
{
return status.STATUS_NOT_FOUND;
}
}
var event = eventsFolder.childByNamePath(params.eventname);

View File

@@ -56,7 +56,11 @@ function main()
var eventsFolder = site.getContainer("calendar");
if (eventsFolder === null)
{
return jsonError("Could not locate events container");
eventsFolder = site.createContainer("calendar");
if (eventsFolder === null)
{
return jsonError("Could not locate events container");
}
}
var event = eventsFolder.childByNamePath(params.eventname);

View File

@@ -52,9 +52,13 @@ function createEvent(siteId, params)
var calendar = site.getContainer("calendar");
if (calendar === null)
{
return {
"error": "Could not get container"
};
calendar = site.createContainer("calendar");
if (calendar === null)
{
return {
"error": "Could not get container"
};
}
}
if (!calendar.isTagScope)

View File

@@ -43,7 +43,11 @@ function main()
var eventsFolder = site.getContainer("calendar");
if (eventsFolder === null)
{
return status.STATUS_NOT_FOUND;
eventsFolder = site.createContainer("calendar");
if (eventsFolder === null)
{
return status.STATUS_NOT_FOUND;
}
}
var event = eventsFolder.childByNamePath(params.eventname);

View File

@@ -14,7 +14,11 @@ function getEvents(siteId)
var calendar = site.getContainer("calendar");
if (calendar === null)
{
return [];
calendar = site.createContainer("calendar");
if (calendar === null)
{
return [];
}
}
if (!calendar.isTagScope)

View File

@@ -25,7 +25,11 @@ function getDocs(siteId, filter)
var parentNode = site.getContainer("documentLibrary");
if (parentNode === null)
{
return jsonError("Document Library container not found in: " + siteId + ". (No write permission?)");
parentNode = site.createContainer("documentLibrary");
if (parentNode === null)
{
return jsonError("Document Library container not found in: " + siteId + ". (No write permission?)");
}
}
// build up the query to get documents modified in the last 7 days

View File

@@ -285,7 +285,11 @@ function getRootNode(p_params)
rootNode = siteNode.getContainer(p_params.containerId);
if (rootNode === null)
{
return "Component container '" + p_params.containerId + "' not found in '" + p_params.siteId + "'.";
rootNode = siteNode.createContainer(p_params.containerId);
if (rootNode === null)
{
return "Component container '" + p_params.containerId + "' not found in '" + p_params.siteId + "'.";
}
}
}
catch(e)

View File

@@ -33,8 +33,12 @@ function getParsedArgs()
rootNode = siteNode.getContainer(container);
if (rootNode === null)
{
status.setCode(status.STATUS_NOT_FOUND, "Document Library container '" + container + "' not found in '" + site + "'. (No permission?)");
return null;
rootNode = siteNode.createContainer(container);
if (rootNode === null)
{
status.setCode(status.STATUS_NOT_FOUND, "Document Library container '" + container + "' not found in '" + site + "'. (No permission?)");
return null;
}
}
}

View File

@@ -31,8 +31,12 @@ function main()
var wiki = site.getContainer("wiki");
if (wiki === null)
{
return jsonError("Could not locate wiki");
}
wiki = site.createContainer("wiki");
if (wiki === null)
{
return jsonError("Could not locate wiki");
}
}
var page = wiki.childByNamePath(params.pageTitle);
if (!page)

View File

@@ -23,12 +23,16 @@ function deleteEvent()
return;
}
var wiki = site.getContainer("wiki");
if (wiki === null)
{
status.setCode(status.STATUS_NOT_FOUND, "Could not find wiki container.");
return;
}
var wiki = site.getContainer("wiki");
if (wiki === null)
{
wiki = site.createContainer("wiki");
if (wiki === null)
{
status.setCode(status.STATUS_NOT_FOUND, "Could not find wiki container.");
return;
}
}
var page = wiki.childByNamePath(params.pageTitle);
if (page === null)

View File

@@ -50,8 +50,12 @@ function main()
var wiki = site.getContainer("wiki");
if (wiki === null)
{
//return jsonError("Could not locate wiki container");
return null;
wiki = site.createContainer("wiki");
if (wiki === null)
{
//return jsonError("Could not locate wiki container");
return null;
}
}
if (!wiki.isTagScope)

View File

@@ -47,7 +47,11 @@ function update()
var wiki = site.getContainer("wiki");
if (wiki === null)
{
return jsonError("Could not locate wiki container");
wiki = site.createContainer("wiki");
if (wiki === null)
{
return jsonError("Could not locate wiki container");
}
}
var page = wiki.childByNamePath(params.pageTitle);

View File

@@ -22,8 +22,12 @@ function getWikiPages(siteId)
var wiki = site.getContainer("wiki");
if (wiki === null)
{
status.setCode(status.STATUS_BAD_REQUEST, "Wiki container not found");
return;
wiki = site.createContainer("wiki");
if (wiki === null)
{
status.setCode(status.STATUS_BAD_REQUEST, "Wiki container not found");
return;
}
}
if (!wiki.isTagScope)

View File

@@ -120,6 +120,8 @@ public class SiteServiceTest extends BaseWebScriptTest
assertEquals(shortName, result.get("shortName"));
assertEquals("myTitle", result.get("title"));
assertEquals("myDescription", result.get("description"));
assertNotNull(result.get("node"));
assertNotNull(result.get("tagScope"));
assertTrue(result.getBoolean("isPublic"));
// Check for duplicate names

View File

@@ -0,0 +1,95 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.web.scripts.tagging;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
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.PropertyMap;
/**
* Unit test to test tagging Web Script API
*
* @author Roy Wetherall
*/
public class TaggingServiceTest extends BaseWebScriptTest
{
private AuthenticationService authenticationService;
private AuthenticationComponent authenticationComponent;
private PersonService personService;
private TaggingService taggingService;
private static final String TEST_USER = "TaggingServiceTestUser";
@Override
protected void setUp() throws Exception
{
super.setUp();
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");
// Create users
createUser(TEST_USER);
// Do tests as user one
this.authenticationComponent.setCurrentUser(TEST_USER);
}
private void createUser(String userName)
{
if (this.authenticationService.authenticationExists(userName) == false)
{
this.authenticationService.createAuthentication(userName, "PWD".toCharArray());
PropertyMap ppOne = new PropertyMap(4);
ppOne.put(ContentModel.PROP_USERNAME, userName);
ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName");
ppOne.put(ContentModel.PROP_LASTNAME, "lastName");
ppOne.put(ContentModel.PROP_EMAIL, "email@email.com");
ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle");
this.personService.createPerson(ppOne);
}
}
@Override
protected void tearDown() throws Exception
{
super.tearDown();
}
public void getTagsTest()
{
}
}