mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Rendering associations in the repo-tier webscript
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13733 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -83,6 +83,7 @@ public class FormServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
private static String VALUE_MIMETYPE = MimetypeMap.MIMETYPE_TEXT_PLAIN;
|
private static String VALUE_MIMETYPE = MimetypeMap.MIMETYPE_TEXT_PLAIN;
|
||||||
private static String VALUE_ENCODING = "UTF-8";
|
private static String VALUE_ENCODING = "UTF-8";
|
||||||
private static String VALUE_CONTENT = "This is the content for the test document";
|
private static String VALUE_CONTENT = "This is the content for the test document";
|
||||||
|
private static String VALUE_ASSOC_CONTENT = "This is the content for the associated document";
|
||||||
private static Date VALUE_SENT_DATE = new Date();
|
private static Date VALUE_SENT_DATE = new Date();
|
||||||
|
|
||||||
private static String LABEL_NAME = "Name";
|
private static String LABEL_NAME = "Name";
|
||||||
@@ -157,12 +158,17 @@ public class FormServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
ContentModel.TYPE_CONTENT,
|
ContentModel.TYPE_CONTENT,
|
||||||
docProps).getChildRef();
|
docProps).getChildRef();
|
||||||
|
|
||||||
// add some content to the node
|
// add some content to the nodes
|
||||||
ContentWriter writer = this.contentService.getWriter(this.document, ContentModel.PROP_CONTENT, true);
|
ContentWriter writer = this.contentService.getWriter(this.document, ContentModel.PROP_CONTENT, true);
|
||||||
writer.setMimetype(VALUE_MIMETYPE);
|
writer.setMimetype(VALUE_MIMETYPE);
|
||||||
writer.setEncoding(VALUE_ENCODING);
|
writer.setEncoding(VALUE_ENCODING);
|
||||||
writer.putContent(VALUE_CONTENT);
|
writer.putContent(VALUE_CONTENT);
|
||||||
|
|
||||||
|
ContentWriter writer2 = this.contentService.getWriter(this.associatedDoc, ContentModel.PROP_CONTENT, true);
|
||||||
|
writer2.setMimetype(VALUE_MIMETYPE);
|
||||||
|
writer2.setEncoding(VALUE_ENCODING);
|
||||||
|
writer2.putContent(VALUE_ASSOC_CONTENT);
|
||||||
|
|
||||||
// add standard titled aspect
|
// add standard titled aspect
|
||||||
Map<QName, Serializable> aspectProps = new HashMap<QName, Serializable>(2);
|
Map<QName, Serializable> aspectProps = new HashMap<QName, Serializable>(2);
|
||||||
aspectProps.put(ContentModel.PROP_TITLE, VALUE_TITLE);
|
aspectProps.put(ContentModel.PROP_TITLE, VALUE_TITLE);
|
||||||
@@ -462,31 +468,8 @@ public class FormServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void off_testSaveUpdatedForm() throws Exception
|
|
||||||
{
|
|
||||||
fail("Form persistence not yet impl'd.");
|
|
||||||
|
|
||||||
Form originalForm = this.formService.getForm(this.document.toString());
|
|
||||||
FormData formData = originalForm.getFormData();
|
|
||||||
|
|
||||||
FieldData fd = originalForm.getFormData().getData().get("foo");
|
|
||||||
assertNull(fd);
|
|
||||||
|
|
||||||
formData.addData("foo", "bar");
|
|
||||||
|
|
||||||
formService.saveForm(document.toString(), formData);
|
|
||||||
|
|
||||||
Form updatedForm = this.formService.getForm(this.document.toString());
|
|
||||||
assertFalse("Expected form instance to have changed.", originalForm == updatedForm);
|
|
||||||
|
|
||||||
fd = updatedForm.getFormData().getData().get("foo");
|
|
||||||
assertNotNull(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testJavascriptAPI() throws Exception
|
public void testJavascriptAPI() throws Exception
|
||||||
{
|
{
|
||||||
//TODO Form saving is not yet implemented.
|
|
||||||
|
|
||||||
Map<String, Object> model = new HashMap<String, Object>();
|
Map<String, Object> model = new HashMap<String, Object>();
|
||||||
model.put("testDoc", this.document.toString());
|
model.put("testDoc", this.document.toString());
|
||||||
model.put("testAssociatedDoc", this.associatedDoc.toString());
|
model.put("testAssociatedDoc", this.associatedDoc.toString());
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
package org.alfresco.repo.forms.script;
|
package org.alfresco.repo.forms.script;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.alfresco.repo.forms.FormData;
|
import org.alfresco.repo.forms.FormData;
|
||||||
@@ -86,9 +87,50 @@ public class ScriptFormData implements Serializable
|
|||||||
public Object getValue()
|
public Object getValue()
|
||||||
{
|
{
|
||||||
Object rawResult = wrappedFieldData.getValue();
|
Object rawResult = wrappedFieldData.getValue();
|
||||||
|
|
||||||
|
// An implementation decision was taken in handling sequence values here.
|
||||||
|
//
|
||||||
|
// Background:
|
||||||
|
// (1) if this method returns instances of java.util.List as is, the data
|
||||||
|
// webscript that renders the REST JSON in the repo tier will render a
|
||||||
|
// List.toString() for these field values, which works - but see below.
|
||||||
|
//
|
||||||
|
// However the JavaScript API will then not offer sequences as sequences.
|
||||||
|
// Instead they will be Strings (e.g. field.value == "[foo, bar]")
|
||||||
|
// and JavaScript client code will have to parse these strings.
|
||||||
|
//
|
||||||
|
// (2) if this method instead returns listObject.toArray(), then the
|
||||||
|
// JavaScript API will see true sequence objects and can easily consume
|
||||||
|
// them like so field.value[1] == "bar"
|
||||||
|
//
|
||||||
|
// However with arrays returned from this method, the webscript that renders
|
||||||
|
// the REST JSON in the repo tier cannot handle the array type. (I should say
|
||||||
|
// that I am unable at this point to make it handle it.)
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// So should we return List instances or Object[] instances?
|
||||||
|
// In order to allow the JSON to be easily rendered, and also to make it
|
||||||
|
// easier for client JavaScript code to use sequence values, we are
|
||||||
|
// returning our own toString implementation for List instances.
|
||||||
|
//
|
||||||
|
// So instead of "[foo, bar]" we'll have "foo,bar"
|
||||||
|
// This should be very easy for the JavaScript to parse: value.split(",")
|
||||||
|
// and it works for the webscript too.
|
||||||
|
|
||||||
if (rawResult instanceof List)
|
if (rawResult instanceof List)
|
||||||
{
|
{
|
||||||
return ((List) rawResult).toArray();
|
List listValue = (List)rawResult;
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
for (Iterator iter = listValue.iterator(); iter.hasNext(); )
|
||||||
|
{
|
||||||
|
result.append(iter.next());
|
||||||
|
if (iter.hasNext())
|
||||||
|
{
|
||||||
|
result.append(",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.toString();
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
return rawResult;
|
return rawResult;
|
||||||
|
@@ -16,12 +16,10 @@ function testGetFormForContentNode()
|
|||||||
test.assertEquals(testDoc, form.item);
|
test.assertEquals(testDoc, form.item);
|
||||||
test.assertEquals('cm:content', form.type);
|
test.assertEquals('cm:content', form.type);
|
||||||
|
|
||||||
//TODO Do we want this to be null or an empty array?
|
|
||||||
test.assertNull(form.fieldGroups, "form.fieldGroups should be null.");
|
test.assertNull(form.fieldGroups, "form.fieldGroups should be null.");
|
||||||
|
|
||||||
var fieldDefs = form.fieldDefinitions;
|
var fieldDefs = form.fieldDefinitions;
|
||||||
test.assertNotNull(fieldDefs, "field definitions should not be null.");
|
test.assertNotNull(fieldDefs, "field definitions should not be null.");
|
||||||
|
|
||||||
test.assertEquals(22, fieldDefs.length);
|
test.assertEquals(22, fieldDefs.length);
|
||||||
|
|
||||||
// This dataHash is now an integer-keyed hash of the field definition data objects.
|
// This dataHash is now an integer-keyed hash of the field definition data objects.
|
||||||
@@ -49,10 +47,6 @@ function testGetFormForContentNode()
|
|||||||
test.assertNotNull(sentDateField, "Expecting to find the cm:sentdate field");
|
test.assertNotNull(sentDateField, "Expecting to find the cm:sentdate field");
|
||||||
test.assertNotNull(referencesField, "Expecting to find the cm:references field");
|
test.assertNotNull(referencesField, "Expecting to find the cm:references field");
|
||||||
|
|
||||||
//TODO All these checked values will only work for the hard-coded node we're using.
|
|
||||||
// The hard-coded node should be replaced with a temporary one created within
|
|
||||||
// this test case.
|
|
||||||
|
|
||||||
// check the labels of all the fields
|
// check the labels of all the fields
|
||||||
test.assertEquals("Name", nameField.label);
|
test.assertEquals("Name", nameField.label);
|
||||||
test.assertEquals("Title", titleField.label);
|
test.assertEquals("Title", titleField.label);
|
||||||
@@ -87,9 +81,6 @@ function testGetFormForContentNode()
|
|||||||
// Expecting cm:addressees to be multi-valued.
|
// Expecting cm:addressees to be multi-valued.
|
||||||
test.assertTrue(addresseesField.repeating);
|
test.assertTrue(addresseesField.repeating);
|
||||||
|
|
||||||
// TODO The below test is failing for some reason.
|
|
||||||
// test.assertNull(addresseesField.constraints, "addresseesField.constraints should be null.");
|
|
||||||
|
|
||||||
// check the details of the association field
|
// check the details of the association field
|
||||||
test.assertEquals("cm:content", referencesField.endpointType);
|
test.assertEquals("cm:content", referencesField.endpointType);
|
||||||
|
|
||||||
@@ -125,8 +116,9 @@ function testGetFormForContentNode()
|
|||||||
test.assertFalse(isNaN(Date.parse(sentDate)));
|
test.assertFalse(isNaN(Date.parse(sentDate)));
|
||||||
|
|
||||||
var targets = fieldData["assoc:cm:references"].value;
|
var targets = fieldData["assoc:cm:references"].value;
|
||||||
test.assertEquals(1, targets.length);
|
|
||||||
test.assertEquals(testAssociatedDoc, targets[0]);
|
test.assertNotNull(targets, "targets should not be null.");
|
||||||
|
test.assertEquals(testAssociatedDoc, targets);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFieldDefnFromMap(name, fieldDefnDataHash)
|
function getFieldDefnFromMap(name, fieldDefnDataHash)
|
||||||
|
Reference in New Issue
Block a user