Added client and server side support for transient properties

- As long as a template for a control is configured fields without a definition can now be displayed
 - Added 3 well known transient properties; mimetype, encoding and size (these are similar to the propertyResolvers we had in the JSF client)
 - Added explicit persistence handling for the new transient properties, the name property and adds aspect if title/description and/or author property is present
 - Added saveForm test

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13693 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2009-03-19 21:24:59 +00:00
parent 91f91fa383
commit 15b7ea1e88
3 changed files with 25 additions and 13 deletions

View File

@@ -49,12 +49,7 @@ function main()
{
// Replace the first 2 underscores with colons.
var alteredName = formdata.fields[i].name.replaceFirst("_", ":").replaceFirst("_", ":");
var dataValue = formdata.fields[i].value;
if (dataValue.length() === 0)
{
dataValue = null;
}
repoFormData.addData(alteredName, dataValue);
repoFormData.addData(alteredName, formdata.fields[i].value);
}
formService.saveForm(nodeRef, repoFormData);

View File

@@ -48,13 +48,7 @@ function main()
// Replace the first 2 underscores with colons.
var nextKey = jsonKeys.next();
var alteredKey = nextKey.replaceFirst("_", ":").replaceFirst("_", ":");
var dataValue = json.get(nextKey);
if (dataValue.length() === 0)
{
dataValue = null;
}
repoFormData.addData(alteredKey, dataValue);
repoFormData.addData(alteredKey, json.get(nextKey));
}
formService.saveForm(nodeRef, repoFormData);

View File

@@ -28,6 +28,8 @@ import java.io.IOException;
import java.io.Serializable;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.web.scripts.TestWebScriptServer.GetRequest;
import org.alfresco.web.scripts.TestWebScriptServer.PostRequest;
import org.alfresco.web.scripts.TestWebScriptServer.Response;
@@ -37,6 +39,7 @@ import org.json.JSONObject;
public class FormRestApiJsonPost_Test extends AbstractTestFormRestApi
{
private static final String PROP_CM_DESCRIPTION = "prop_cm_description";
private static final String PROP_MIMETYPE = "prop_mimetype";
private static final String APPLICATION_JSON = "application/json";
public void testSimpleJsonPostRequest() throws IOException, JSONException
@@ -46,10 +49,19 @@ public class FormRestApiJsonPost_Test extends AbstractTestFormRestApi
nodeService.getProperty(testNodeRef, ContentModel.PROP_DESCRIPTION);
assertEquals(TEST_FORM_DESCRIPTION, originalDescription);
// get the original mimetype
String originalMimetype = null;
ContentData content = (ContentData)this.nodeService.getProperty(testNodeRef, ContentModel.PROP_CONTENT);
if (content != null)
{
originalMimetype = content.getMimetype();
}
// Construct some JSON to represent a new value.
JSONObject jsonPostData = new JSONObject();
final String proposedNewDescription = "Modified Description";
jsonPostData.put(PROP_CM_DESCRIPTION, proposedNewDescription);
jsonPostData.put(PROP_MIMETYPE, MimetypeMap.MIMETYPE_HTML);
// Submit the JSON request.
Response ignoredRsp = sendRequest(new PostRequest(testNodeUrl, jsonPostData.toString(),
@@ -59,6 +71,15 @@ public class FormRestApiJsonPost_Test extends AbstractTestFormRestApi
Serializable modifiedDescription =
nodeService.getProperty(testNodeRef, ContentModel.PROP_DESCRIPTION);
assertEquals(proposedNewDescription, modifiedDescription);
// get the original mimetype
String modifiedMimetype = null;
content = (ContentData)this.nodeService.getProperty(testNodeRef, ContentModel.PROP_CONTENT);
if (content != null)
{
modifiedMimetype = content.getMimetype();
}
assertEquals(MimetypeMap.MIMETYPE_HTML, modifiedMimetype);
// The Rest API should also give us the modified property.
Response response = sendRequest(new GetRequest(testNodeUrl), 200);
@@ -70,5 +91,7 @@ public class FormRestApiJsonPost_Test extends AbstractTestFormRestApi
assertNotNull(formData);
String retrievedValue = (String)formData.get(PROP_CM_DESCRIPTION);
assertEquals(modifiedDescription, retrievedValue);
String retrievedMimetype = (String)formData.get(PROP_MIMETYPE);
assertEquals(MimetypeMap.MIMETYPE_HTML, modifiedMimetype);
}
}