FormService improvements

- A 'dataKeyName' property has been added to the field definition to point to the corresponding data
- FormProcessors can now return a submission url to use on the client
- FormProcessors are now responsible for returning a sensible URL to represent the 'item' being processed
- Updated all affected tests

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14021 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2009-04-20 14:53:04 +00:00
parent ce8de3d556
commit 6a99a86d59
4 changed files with 30 additions and 27 deletions

View File

@@ -94,11 +94,13 @@ function main()
var formModel = {};
formModel.data = {};
// TODO: retrieve the item URL from the response?
formModel.data.item = '/api/formdefinitions';
// TODO: look for overridden submission url
formModel.data.submissionUrl = '/api/' + itemKind + '/' + itemId + '/formprocessor';
formModel.data.type = formScriptObj.type;
formModel.data.item = formScriptObj.itemUrl;
formModel.data.type = formScriptObj.itemType;
formModel.data.submissionUrl = formScriptObj.submissionUrl;
if (formScriptObj.submissionUrl === null)
{
formModel.data.submissionUrl = '/api/' + itemKind + '/' + itemId + '/formprocessor';
}
formModel.data.definition = {};
formModel.data.definition.fields = [];
@@ -106,7 +108,7 @@ function main()
// We're explicitly listing the object fields of FieldDefinition.java and its subclasses here.
// I don't see a way to get these dynamically at runtime.
var supportedBaseFieldNames = ['name', 'label', 'description', 'binding',
'defaultValue', 'group', 'protectedField'];
'defaultValue', 'dataKeyName', 'group', 'protectedField'];
var supportedPropertyFieldNames = ['dataType', 'mandatory',
'repeats', 'constraints'];
var supportedAssociationFieldNames = ['endpointType', 'endpointDirection',
@@ -144,13 +146,13 @@ function main()
if (value instanceof java.util.Date)
{
formModel.data.formData[k.replace(/:/g, "_")] = utils.toISO8601(value);
formModel.data.formData[k] = utils.toISO8601(value);
}
// There is no need to handle java.util.List instances here as they are
// returned from ScriptFormData.java as Strings
else
{
formModel.data.formData[k.replace(/:/g, "_")] = value;
formModel.data.formData[k] = value;
}
}

View File

@@ -15,10 +15,6 @@ function main()
// persist the submitted data using the most appropriate data set
if (typeof formdata !== "undefined")
{
// The model.data is set here to allow the rendering of a simple result page.
// TODO This should be removed when the POST is working.
model.data = formdata;
// Note: This formdata is org/alfresco/web/scripts/servlet/FormData.java
if (logger.isLoggingEnabled())
{
@@ -29,9 +25,7 @@ function main()
var repoFormData = new Packages.org.alfresco.repo.forms.FormData();
for (var i = 0; i < formdata.fields.length; i++)
{
// Replace the first 2 underscores with colons.
var alteredName = formdata.fields[i].name.replaceFirst("_", ":").replaceFirst("_", ":");
repoFormData.addData(alteredName, formdata.fields[i].value);
repoFormData.addData(formdata.fields[i].name, formdata.fields[i].value);
}
formService.saveForm(itemKind, itemId, repoFormData);

View File

@@ -31,10 +31,8 @@ function main()
var jsonKeys = json.keys();
for ( ; jsonKeys.hasNext(); )
{
// Replace the first 2 underscores with colons.
var nextKey = jsonKeys.next();
var alteredKey = nextKey.replaceFirst("_", ":").replaceFirst("_", ":");
repoFormData.addData(alteredKey, json.get(nextKey));
repoFormData.addData(nextKey, json.get(nextKey));
}
try

View File

@@ -126,7 +126,6 @@ public class FormRestApiGet_Test extends AbstractTestFormRestApi
Response rsp = sendRequest(new PostRequest(FORM_DEF_URL,
jsonPostString, APPLICATION_JSON), 200);
String jsonResponseString = rsp.getContentAsString();
// At this point the formData names have underscores
JSONObject jsonParsedObject = new JSONObject(new JSONTokener(jsonResponseString));
assertNotNull(jsonParsedObject);
@@ -137,9 +136,7 @@ public class FormRestApiGet_Test extends AbstractTestFormRestApi
List<String> keys = new ArrayList<String>();
for (Iterator iter = formDataObject.keys(); iter.hasNext(); )
{
// None of the formData keys should have a colon in them. We are
// replacing colons in field names with underscores.
String nextFieldName = (String)iter.next();
String nextFieldName = (String)iter.next();
assertEquals("Did not expect to find a colon char in " + nextFieldName,
-1, nextFieldName.indexOf(':'));
keys.add(nextFieldName);
@@ -213,10 +210,16 @@ public class FormRestApiGet_Test extends AbstractTestFormRestApi
JSONArray fieldsArray = (JSONArray)definitionObject.get("fields");
assertEquals("Expected 2 fields", 2, fieldsArray.length());
// get the name and title definitions
JSONObject nameField = (JSONObject)fieldsArray.get(0);
JSONObject titleField = (JSONObject)fieldsArray.get(1);
String nameFieldDataKey = nameField.getString("dataKeyName");
String titleFieldDataKey = titleField.getString("dataKeyName");
// get the data and check it
JSONObject formDataObject = (JSONObject)rootDataObject.get("formData");
assertNotNull("Expected to find cm:name data", formDataObject.get("prop_cm_name"));
assertNotNull("Expected to find cm:title data", formDataObject.get("prop_cm_title"));
assertNotNull("Expected to find cm:name data", formDataObject.get(nameFieldDataKey));
assertNotNull("Expected to find cm:title data", formDataObject.get(titleFieldDataKey));
assertEquals(TEST_FORM_TITLE, formDataObject.get("prop_cm_title"));
}
@@ -250,10 +253,16 @@ public class FormRestApiGet_Test extends AbstractTestFormRestApi
JSONArray fieldsArray = (JSONArray)definitionObject.get("fields");
assertEquals("Expected 3 fields", 3, fieldsArray.length());
// get the name and title definitions
JSONObject nameField = (JSONObject)fieldsArray.get(0);
JSONObject titleField = (JSONObject)fieldsArray.get(1);
String nameFieldDataKey = nameField.getString("dataKeyName");
String titleFieldDataKey = titleField.getString("dataKeyName");
// get the data and check it
JSONObject formDataObject = (JSONObject)rootDataObject.get("formData");
assertNotNull("Expected to find cm:name data", formDataObject.get("prop_cm_name"));
assertNotNull("Expected to find cm:title data", formDataObject.get("prop_cm_title"));
assertNotNull("Expected to find cm:name data", formDataObject.get(nameFieldDataKey));
assertNotNull("Expected to find cm:title data", formDataObject.get(titleFieldDataKey));
assertEquals(TEST_FORM_TITLE, formDataObject.get("prop_cm_title"));
}
}