mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Added handling for colons,underscores in field names during post
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13312 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -6,10 +6,13 @@ function main()
|
||||
var ta_id = url.templateArgs['id'];
|
||||
var ta_path = url.templateArgs['path'];
|
||||
|
||||
if (logger.isLoggingEnabled())
|
||||
{
|
||||
logger.log("ta_storeType = " + ta_storeType);
|
||||
logger.log("ta_storeId = " + ta_storeId);
|
||||
logger.log("ta_id = " + ta_id);
|
||||
logger.log("ta_path = " + ta_path);
|
||||
}
|
||||
|
||||
var formUrl = '';
|
||||
// The template argument 'path' only appears in the second URI template.
|
||||
@@ -22,17 +25,24 @@ function main()
|
||||
{
|
||||
formUrl = ta_storeType + '://' + ta_storeId + '/' + ta_id;
|
||||
}
|
||||
|
||||
if (logger.isLoggingEnabled())
|
||||
{
|
||||
logger.log("formUrl = " + formUrl);
|
||||
}
|
||||
|
||||
var formScriptObj = formService.getForm(formUrl);
|
||||
|
||||
if (formScriptObj == null)
|
||||
{
|
||||
if (logger.isWarnLoggingEnabled())
|
||||
{
|
||||
var message = "The form for item \"" + formUrl + "\" could not be found.";
|
||||
logger.log(message);
|
||||
logger.warn(message);
|
||||
status.setCode(404, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var formModel = {};
|
||||
formModel.data = {};
|
||||
|
@@ -10,7 +10,6 @@ function main()
|
||||
// The template argument 'path' only appears in the second URI template.
|
||||
if (ta_path != null)
|
||||
{
|
||||
//TODO Need to test this path.
|
||||
nodeRef = ta_path;
|
||||
}
|
||||
else
|
||||
@@ -18,10 +17,19 @@ function main()
|
||||
nodeRef = ta_storeType + '://' + ta_storeId + '/' + ta_id;
|
||||
}
|
||||
|
||||
if (logger.isLoggingEnabled())
|
||||
{
|
||||
logger.log("POST request received for nodeRef: " + nodeRef);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// TODO: check the given nodeRef is real
|
||||
|
||||
|
||||
|
||||
|
||||
// persist the submitted data using the most appropriate data set
|
||||
if (typeof formdata !== "undefined")
|
||||
{
|
||||
@@ -30,22 +38,28 @@ function main()
|
||||
model.data = formdata;
|
||||
|
||||
// Note: This formdata is org/alfresco/web/scripts/servlet/FormData.java
|
||||
if (logger.isLoggingEnabled())
|
||||
{
|
||||
logger.log("Saving form with formdata, " + formdata.fields.length + " fields.");
|
||||
//TODO At this point, for multipart, the field names are e.g. prop_cm_name
|
||||
}
|
||||
|
||||
// N.B. This repoFormData is a different FormData class to that used above.
|
||||
var repoFormData = new Packages.org.alfresco.repo.forms.FormData();
|
||||
for (var i = 0; i < formdata.fields.length; i++)
|
||||
{
|
||||
repoFormData.addData(formdata.fields[i].name, formdata.fields[i].value);
|
||||
// Replace the first 2 underscores with colons.
|
||||
var alteredName = formdata.fields[i].name.replaceFirst("_", ":").replaceFirst("_", ":");
|
||||
repoFormData.addData(alteredName, formdata.fields[i].value);
|
||||
}
|
||||
|
||||
//TODO How to handle false booleans? They are omitted from POST
|
||||
formService.saveForm(nodeRef, repoFormData);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logger.isLoggingEnabled())
|
||||
{
|
||||
logger.log("Saving form with args = " + args);
|
||||
}
|
||||
formService.saveForm(nodeRef, args);
|
||||
}
|
||||
|
||||
|
@@ -17,19 +17,27 @@ function main()
|
||||
nodeRef = ta_storeType + '://' + ta_storeId + '/' + ta_id;
|
||||
}
|
||||
|
||||
logger.log("POST request received for nodeRef: " + nodeRef);
|
||||
if (logger.isLoggingEnabled())
|
||||
{
|
||||
logger.log("JSON POST request received for nodeRef: " + nodeRef);
|
||||
}
|
||||
|
||||
//TODO Add check whether nodeRef exists.
|
||||
|
||||
|
||||
if (typeof json !== "undefined")
|
||||
{
|
||||
logger.log("Saving form with json = " + json);
|
||||
// At this point the field names are e.g. prop_cm_name
|
||||
// and there are some extra values - hidden fields? These are fields from YUI's datepicker(s)
|
||||
// e.g. "template_x002e_form-ui_x002e_form-test_prop_my_date-entry":"2/19/2009"
|
||||
//TODO Need to remove the extra fields.
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.log("json object was undefined.");
|
||||
if (logger.isWarnLoggingEnabled())
|
||||
{
|
||||
logger.warn("json object was undefined.");
|
||||
}
|
||||
status.setCode(501, message);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -37,13 +45,15 @@ function main()
|
||||
var jsonKeys = json.keys();
|
||||
for ( ; jsonKeys.hasNext(); )
|
||||
{
|
||||
// Replace the first 2 underscores with colons.
|
||||
var nextKey = jsonKeys.next();
|
||||
repoFormData.addData(nextKey, json.get(nextKey));
|
||||
var alteredKey = nextKey.replaceFirst("_", ":").replaceFirst("_", ":");
|
||||
|
||||
repoFormData.addData(alteredKey, json.get(nextKey));
|
||||
}
|
||||
|
||||
formService.saveForm(nodeRef, repoFormData);
|
||||
|
||||
|
||||
model.message = "Successfully updated node " + nodeRef;
|
||||
}
|
||||
|
||||
|
@@ -39,7 +39,7 @@ public class TestFormRestAPI_JsonPost extends AbstractTestFormRestApi
|
||||
private static final String PROP_CM_DESCRIPTION = "prop_cm_description";
|
||||
private static final String APPLICATION_JSON = "application/json";
|
||||
|
||||
public void testSubmitJsonPostRequest() throws IOException, JSONException
|
||||
public void testSimpleJsonPostRequest() throws IOException, JSONException
|
||||
{
|
||||
// Retrieve and store the original property value.
|
||||
Serializable originalDescription =
|
||||
|
Reference in New Issue
Block a user