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:
@@ -25,6 +25,7 @@
|
||||
package org.alfresco.repo.forms.script;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.forms.FormData;
|
||||
@@ -86,9 +87,50 @@ public class ScriptFormData implements Serializable
|
||||
public Object 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)
|
||||
{
|
||||
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
|
||||
{
|
||||
return rawResult;
|
||||
|
@@ -16,12 +16,10 @@ function testGetFormForContentNode()
|
||||
test.assertEquals(testDoc, form.item);
|
||||
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.");
|
||||
|
||||
var fieldDefs = form.fieldDefinitions;
|
||||
test.assertNotNull(fieldDefs, "field definitions should not be null.");
|
||||
|
||||
test.assertEquals(22, fieldDefs.length);
|
||||
|
||||
// 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(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
|
||||
test.assertEquals("Name", nameField.label);
|
||||
test.assertEquals("Title", titleField.label);
|
||||
@@ -87,9 +81,6 @@ function testGetFormForContentNode()
|
||||
// Expecting cm:addressees to be multi-valued.
|
||||
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
|
||||
test.assertEquals("cm:content", referencesField.endpointType);
|
||||
|
||||
@@ -125,8 +116,9 @@ function testGetFormForContentNode()
|
||||
test.assertFalse(isNaN(Date.parse(sentDate)));
|
||||
|
||||
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)
|
||||
|
Reference in New Issue
Block a user