mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Updated REST API URLs following discussion last week with Roy
- To get a form definition we now POST to /api/formdefinitions - To persist a form we now POST to /api/item_kind/item_id/formprocessor git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14005 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,7 +1,19 @@
|
|||||||
<webscript>
|
<webscript>
|
||||||
<shortname>Form Definition</shortname>
|
<shortname>Form Definitions</shortname>
|
||||||
<description>Returns a form definition for the requested item</description>
|
<description><![CDATA[
|
||||||
<url>/api/form/definition/{item_kind}/{item_id}</url>
|
Returns a form definition for the requested item.<br/>
|
||||||
|
The body of the post should be in the form<br/>
|
||||||
|
{<br/>
|
||||||
|
"itemKind" : item kind,<br/>
|
||||||
|
"itemId" : item id,<br/>
|
||||||
|
"fields" : [fields],<br/>
|
||||||
|
"force" : [force]<br/>
|
||||||
|
}<br/>
|
||||||
|
<br/>
|
||||||
|
Returns the form model.
|
||||||
|
]]>
|
||||||
|
</description>
|
||||||
|
<url>/api/formdefinitions</url>
|
||||||
<format default="json"/>
|
<format default="json"/>
|
||||||
<authentication>user</authentication>
|
<authentication>user</authentication>
|
||||||
<transaction>required</transaction>
|
<transaction>required</transaction>
|
||||||
|
@@ -1,17 +1,28 @@
|
|||||||
function main()
|
function main()
|
||||||
{
|
{
|
||||||
// Extract template args
|
// check that required data is present in request body
|
||||||
var itemKind = url.templateArgs['item_kind'];
|
if (json.has("itemKind") === false)
|
||||||
var itemId = url.templateArgs['item_id'];
|
{
|
||||||
|
status.setCode(status.STATUS_BAD_REQUEST, "itemKind parameter is not present");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json.has("itemId") === false)
|
||||||
|
{
|
||||||
|
status.setCode(status.STATUS_BAD_REQUEST, "itemId parameter is not present");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// extract required data from request body
|
||||||
|
var itemKind = json.get("itemKind");
|
||||||
|
var itemId = json.get("itemId");
|
||||||
|
|
||||||
if (logger.isLoggingEnabled())
|
if (logger.isLoggingEnabled())
|
||||||
{
|
{
|
||||||
logger.log("itemKind = " + itemKind);
|
logger.log("itemKind = " + itemKind);
|
||||||
logger.log("itemId = " + itemId);
|
logger.log("itemId = " + itemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Return error if item kind and/or id is missing?
|
|
||||||
|
|
||||||
// extract optional data from request body (if present)
|
// extract optional data from request body (if present)
|
||||||
var count = 0;
|
var count = 0;
|
||||||
var fields = null;
|
var fields = null;
|
||||||
@@ -84,9 +95,9 @@ function main()
|
|||||||
formModel.data = {};
|
formModel.data = {};
|
||||||
|
|
||||||
// TODO: retrieve the item URL from the response?
|
// TODO: retrieve the item URL from the response?
|
||||||
formModel.data.item = '/api/form/definition/' + itemKind + '/' + itemId;
|
formModel.data.item = '/api/formdefinitions';
|
||||||
// TODO: look for overridden submission url
|
// TODO: look for overridden submission url
|
||||||
formModel.data.submissionUrl = '/api/form/' + itemKind + '/' + itemId;
|
formModel.data.submissionUrl = '/api/' + itemKind + '/' + itemId + '/formprocessor';
|
||||||
formModel.data.type = formScriptObj.type;
|
formModel.data.type = formScriptObj.type;
|
||||||
|
|
||||||
formModel.data.definition = {};
|
formModel.data.definition = {};
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<webscript>
|
<webscript>
|
||||||
<shortname>Form</shortname>
|
<shortname>Form Persistence</shortname>
|
||||||
<description>Handles the submission of a form</description>
|
<description>Handles the submission of a form</description>
|
||||||
<url>/api/form/{item_kind}/{item_id}</url>
|
<url>/api/{item_kind}/{item_id}/formprocessor</url>
|
||||||
<authentication>user</authentication>
|
<authentication>user</authentication>
|
||||||
<transaction>required</transaction>
|
<transaction>required</transaction>
|
||||||
<lifecycle>internal</lifecycle>
|
<lifecycle>internal</lifecycle>
|
||||||
|
@@ -52,9 +52,8 @@ public abstract class AbstractTestFormRestApi extends BaseWebScriptTest
|
|||||||
protected static final String APPLICATION_JSON = "application/json";
|
protected static final String APPLICATION_JSON = "application/json";
|
||||||
protected static final String TEST_FORM_DESCRIPTION = "Test form description";
|
protected static final String TEST_FORM_DESCRIPTION = "Test form description";
|
||||||
protected static final String TEST_FORM_TITLE = "Test form title";
|
protected static final String TEST_FORM_TITLE = "Test form title";
|
||||||
protected String referencingNodeDefUrl;
|
protected static final String FORM_DEF_URL = "/api/formdefinitions";
|
||||||
protected String referencingNodeUpdateUrl;
|
protected String referencingNodeUpdateUrl;
|
||||||
protected String containingNodeDefUrl;
|
|
||||||
protected String containingNodeUpdateUrl;
|
protected String containingNodeUpdateUrl;
|
||||||
protected String containingNodeUrl;
|
protected String containingNodeUrl;
|
||||||
protected NodeRef referencingDocNodeRef;
|
protected NodeRef referencingDocNodeRef;
|
||||||
@@ -154,24 +153,13 @@ public abstract class AbstractTestFormRestApi extends BaseWebScriptTest
|
|||||||
|
|
||||||
// Create and store the urls to the referencingNode
|
// Create and store the urls to the referencingNode
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("/api/form/definition/node/workspace/").append(referencingDocNodeRef.getStoreRef().getIdentifier())
|
builder.append("/api/node/workspace/").append(referencingDocNodeRef.getStoreRef().getIdentifier())
|
||||||
.append("/").append(referencingDocNodeRef.getId());
|
.append("/").append(referencingDocNodeRef.getId()).append("/formprocessor");
|
||||||
this.referencingNodeDefUrl = builder.toString();
|
|
||||||
|
|
||||||
builder = new StringBuilder();
|
|
||||||
builder.append("/api/form/node/workspace/").append(referencingDocNodeRef.getStoreRef().getIdentifier())
|
|
||||||
.append("/").append(referencingDocNodeRef.getId());
|
|
||||||
this.referencingNodeUpdateUrl = builder.toString();
|
this.referencingNodeUpdateUrl = builder.toString();
|
||||||
|
|
||||||
// Create and store the urls to the containing node
|
|
||||||
builder = new StringBuilder();
|
builder = new StringBuilder();
|
||||||
builder.append("/api/form/definition/node/workspace/").append(containerNodeRef.getStoreRef().getIdentifier())
|
builder.append("/api/node/workspace/").append(containerNodeRef.getStoreRef().getIdentifier())
|
||||||
.append("/").append(containerNodeRef.getId());
|
.append("/").append(containerNodeRef.getId()).append("/formprocessor");
|
||||||
this.containingNodeDefUrl = builder.toString();
|
|
||||||
|
|
||||||
builder = new StringBuilder();
|
|
||||||
builder.append("/api/form/node/workspace/").append(containerNodeRef.getStoreRef().getIdentifier())
|
|
||||||
.append("/").append(containerNodeRef.getId());
|
|
||||||
this.containingNodeUpdateUrl = builder.toString();
|
this.containingNodeUpdateUrl = builder.toString();
|
||||||
|
|
||||||
// Store the original properties of this node
|
// Store the original properties of this node
|
||||||
|
@@ -29,6 +29,7 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.alfresco.repo.content.MimetypeMap;
|
import org.alfresco.repo.content.MimetypeMap;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.web.scripts.TestWebScriptServer.PostRequest;
|
import org.alfresco.web.scripts.TestWebScriptServer.PostRequest;
|
||||||
import org.alfresco.web.scripts.TestWebScriptServer.Response;
|
import org.alfresco.web.scripts.TestWebScriptServer.Response;
|
||||||
import org.alfresco.web.scripts.json.JSONUtils;
|
import org.alfresco.web.scripts.json.JSONUtils;
|
||||||
@@ -38,30 +39,49 @@ import org.json.JSONTokener;
|
|||||||
|
|
||||||
public class FormRestApiGet_Test extends AbstractTestFormRestApi
|
public class FormRestApiGet_Test extends AbstractTestFormRestApi
|
||||||
{
|
{
|
||||||
public void testResponseContentType() throws Exception
|
protected JSONObject createItemJSON(NodeRef nodeRef) throws Exception
|
||||||
{
|
{
|
||||||
JSONObject jsonPostData = new JSONObject();
|
JSONObject jsonPostData = new JSONObject();
|
||||||
|
|
||||||
|
jsonPostData.put("itemKind", "node");
|
||||||
|
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append(nodeRef.getStoreRef().getProtocol()).append("/").append(
|
||||||
|
nodeRef.getStoreRef().getIdentifier()).append("/").append(nodeRef.getId());
|
||||||
|
jsonPostData.put("itemId", builder.toString());
|
||||||
|
|
||||||
|
return jsonPostData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testResponseContentType() throws Exception
|
||||||
|
{
|
||||||
|
JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef);
|
||||||
String jsonPostString = jsonPostData.toString();
|
String jsonPostString = jsonPostData.toString();
|
||||||
Response rsp = sendRequest(new PostRequest(referencingNodeDefUrl,
|
Response rsp = sendRequest(new PostRequest(FORM_DEF_URL,
|
||||||
jsonPostString, APPLICATION_JSON), 200);
|
jsonPostString, APPLICATION_JSON), 200);
|
||||||
assertEquals("application/json;charset=UTF-8", rsp.getContentType());
|
assertEquals("application/json;charset=UTF-8", rsp.getContentType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetFormForNonExistentNode() throws Exception
|
public void testGetFormForNonExistentNode() throws Exception
|
||||||
{
|
{
|
||||||
// Replace all digits with an 'x' char - this should make for a non-existent node.
|
// Create a NodeRef with all digits changed to an 'x' char -
|
||||||
JSONObject jsonPostData = new JSONObject();
|
// this should make for a non-existent node.
|
||||||
|
String missingId = this.referencingDocNodeRef.getId().replaceAll("\\d", "x");
|
||||||
|
NodeRef missingNodeRef = new NodeRef(this.referencingDocNodeRef.getStoreRef(),
|
||||||
|
missingId);
|
||||||
|
|
||||||
|
JSONObject jsonPostData = createItemJSON(missingNodeRef);
|
||||||
String jsonPostString = jsonPostData.toString();
|
String jsonPostString = jsonPostData.toString();
|
||||||
Response rsp = sendRequest(new PostRequest(referencingNodeDefUrl.replaceAll("\\d", "x"),
|
Response rsp = sendRequest(new PostRequest(FORM_DEF_URL,
|
||||||
jsonPostString, APPLICATION_JSON), 404);
|
jsonPostString, APPLICATION_JSON), 404);
|
||||||
assertEquals("application/json;charset=UTF-8", rsp.getContentType());
|
assertEquals("application/json;charset=UTF-8", rsp.getContentType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testJsonContentParsesCorrectly() throws Exception
|
public void testJsonContentParsesCorrectly() throws Exception
|
||||||
{
|
{
|
||||||
JSONObject jsonPostData = new JSONObject();
|
JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef);
|
||||||
String jsonPostString = jsonPostData.toString();
|
String jsonPostString = jsonPostData.toString();
|
||||||
Response rsp = sendRequest(new PostRequest(referencingNodeDefUrl,
|
Response rsp = sendRequest(new PostRequest(FORM_DEF_URL,
|
||||||
jsonPostString, APPLICATION_JSON), 200);
|
jsonPostString, APPLICATION_JSON), 200);
|
||||||
String jsonResponseString = rsp.getContentAsString();
|
String jsonResponseString = rsp.getContentAsString();
|
||||||
|
|
||||||
@@ -71,9 +91,9 @@ public class FormRestApiGet_Test extends AbstractTestFormRestApi
|
|||||||
|
|
||||||
public void testJsonUpperStructure() throws Exception
|
public void testJsonUpperStructure() throws Exception
|
||||||
{
|
{
|
||||||
JSONObject jsonPostData = new JSONObject();
|
JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef);
|
||||||
String jsonPostString = jsonPostData.toString();
|
String jsonPostString = jsonPostData.toString();
|
||||||
Response rsp = sendRequest(new PostRequest(referencingNodeDefUrl,
|
Response rsp = sendRequest(new PostRequest(FORM_DEF_URL,
|
||||||
jsonPostString, APPLICATION_JSON), 200);
|
jsonPostString, APPLICATION_JSON), 200);
|
||||||
String jsonResponseString = rsp.getContentAsString();
|
String jsonResponseString = rsp.getContentAsString();
|
||||||
|
|
||||||
@@ -101,9 +121,9 @@ public class FormRestApiGet_Test extends AbstractTestFormRestApi
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testJsonFormData() throws Exception
|
public void testJsonFormData() throws Exception
|
||||||
{
|
{
|
||||||
JSONObject jsonPostData = new JSONObject();
|
JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef);
|
||||||
String jsonPostString = jsonPostData.toString();
|
String jsonPostString = jsonPostData.toString();
|
||||||
Response rsp = sendRequest(new PostRequest(referencingNodeDefUrl,
|
Response rsp = sendRequest(new PostRequest(FORM_DEF_URL,
|
||||||
jsonPostString, APPLICATION_JSON), 200);
|
jsonPostString, APPLICATION_JSON), 200);
|
||||||
String jsonResponseString = rsp.getContentAsString();
|
String jsonResponseString = rsp.getContentAsString();
|
||||||
// At this point the formData names have underscores
|
// At this point the formData names have underscores
|
||||||
@@ -135,9 +155,9 @@ public class FormRestApiGet_Test extends AbstractTestFormRestApi
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testJsonDefinitionFields() throws Exception
|
public void testJsonDefinitionFields() throws Exception
|
||||||
{
|
{
|
||||||
JSONObject jsonPostData = new JSONObject();
|
JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef);
|
||||||
String jsonPostString = jsonPostData.toString();
|
String jsonPostString = jsonPostData.toString();
|
||||||
Response rsp = sendRequest(new PostRequest(referencingNodeDefUrl,
|
Response rsp = sendRequest(new PostRequest(FORM_DEF_URL,
|
||||||
jsonPostString, APPLICATION_JSON), 200);
|
jsonPostString, APPLICATION_JSON), 200);
|
||||||
String jsonResponseString = rsp.getContentAsString();
|
String jsonResponseString = rsp.getContentAsString();
|
||||||
|
|
||||||
@@ -172,7 +192,7 @@ public class FormRestApiGet_Test extends AbstractTestFormRestApi
|
|||||||
|
|
||||||
public void testJsonSelectedFields() throws Exception
|
public void testJsonSelectedFields() throws Exception
|
||||||
{
|
{
|
||||||
JSONObject jsonPostData = new JSONObject();
|
JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef);
|
||||||
JSONArray jsonFields = new JSONArray();
|
JSONArray jsonFields = new JSONArray();
|
||||||
jsonFields.put("cm:name");
|
jsonFields.put("cm:name");
|
||||||
jsonFields.put("cm:title");
|
jsonFields.put("cm:title");
|
||||||
@@ -181,7 +201,7 @@ public class FormRestApiGet_Test extends AbstractTestFormRestApi
|
|||||||
|
|
||||||
// Submit the JSON request.
|
// Submit the JSON request.
|
||||||
String jsonPostString = jsonPostData.toString();
|
String jsonPostString = jsonPostData.toString();
|
||||||
Response rsp = sendRequest(new PostRequest(referencingNodeDefUrl, jsonPostString,
|
Response rsp = sendRequest(new PostRequest(FORM_DEF_URL, jsonPostString,
|
||||||
APPLICATION_JSON), 200);
|
APPLICATION_JSON), 200);
|
||||||
|
|
||||||
String jsonResponseString = rsp.getContentAsString();
|
String jsonResponseString = rsp.getContentAsString();
|
||||||
@@ -202,7 +222,7 @@ public class FormRestApiGet_Test extends AbstractTestFormRestApi
|
|||||||
|
|
||||||
public void testJsonForcedFields() throws Exception
|
public void testJsonForcedFields() throws Exception
|
||||||
{
|
{
|
||||||
JSONObject jsonPostData = new JSONObject();
|
JSONObject jsonPostData = createItemJSON(this.referencingDocNodeRef);
|
||||||
|
|
||||||
JSONArray jsonFields = new JSONArray();
|
JSONArray jsonFields = new JSONArray();
|
||||||
jsonFields.put("cm:name");
|
jsonFields.put("cm:name");
|
||||||
@@ -218,7 +238,7 @@ public class FormRestApiGet_Test extends AbstractTestFormRestApi
|
|||||||
|
|
||||||
// Submit the JSON request.
|
// Submit the JSON request.
|
||||||
String jsonPostString = jsonPostData.toString();
|
String jsonPostString = jsonPostData.toString();
|
||||||
Response rsp = sendRequest(new PostRequest(referencingNodeDefUrl, jsonPostString,
|
Response rsp = sendRequest(new PostRequest(FORM_DEF_URL, jsonPostString,
|
||||||
APPLICATION_JSON), 200);
|
APPLICATION_JSON), 200);
|
||||||
|
|
||||||
String jsonResponseString = rsp.getContentAsString();
|
String jsonResponseString = rsp.getContentAsString();
|
||||||
|
Reference in New Issue
Block a user