Changed ScriptForm.getFieldDefinitionData return type to integer-keyed Map

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13718 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Neil McErlean
2009-03-23 11:32:26 +00:00
parent ff3a10faaf
commit 61442fd07b
6 changed files with 51 additions and 24 deletions

View File

@@ -37,7 +37,7 @@ public class Form
{
protected String item;
protected String type;
protected Collection<FieldDefinition> fieldDefinitions;
protected List<FieldDefinition> fieldDefinitions;
protected Collection<FieldGroup> fieldGroups;
protected FormData data;
@@ -84,11 +84,11 @@ public class Form
}
/**
* Returns the collection of field definitions for the form
* Returns the list of field definitions for the form
*
* @return Collection of FieldDefintion objects or null if there are no fields
* @return List of FieldDefinition objects or null if there are no fields
*/
public Collection<FieldDefinition> getFieldDefinitions()
public List<FieldDefinition> getFieldDefinitions()
{
return this.fieldDefinitions;
}
@@ -104,12 +104,12 @@ public class Form
}
/**
* Sets the collection of FieldDefintion objects representing the fields the
* Sets the list of FieldDefinition objects representing the fields the
* form is able to display
*
* @param fieldDefinitions Collection of FieldDefinition objects
* @param fieldDefinitions List of FieldDefinition objects
*/
public void setFieldDefinitions(Collection<FieldDefinition> fieldDefinitions)
public void setFieldDefinitions(List<FieldDefinition> fieldDefinitions)
{
this.fieldDefinitions = fieldDefinitions;
}
@@ -179,6 +179,7 @@ public class Form
/*
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
StringBuilder buffer = new StringBuilder(super.toString());

View File

@@ -74,7 +74,6 @@ public class FormServiceImpl implements FormService
}
else
{
// TODO Check with Gav that this is ok.
Form result = null;
try
{

View File

@@ -52,6 +52,7 @@ public class NodeFormProcessor extends AbstractFormProcessorByHandlers
/*
* @see org.alfresco.repo.forms.processor.AbstractFormProcessor#getTypedItem(java.lang.String)
*/
@Override
protected Object getTypedItem(String item)
{
// create NodeRef representation

View File

@@ -64,6 +64,7 @@ public class ScriptFieldDefinition extends ScriptableObject
*
* @see org.mozilla.javascript.Scriptable#get(String, Scriptable)
*/
@SuppressWarnings("unchecked")
@Override
public Object get(String name, Scriptable start)
{
@@ -81,7 +82,6 @@ public class ScriptFieldDefinition extends ScriptableObject
return NOT_FOUND;
}
//TODO Value conversion.
if (result instanceof List)
{
return ((List)result).toArray();
@@ -92,6 +92,7 @@ public class ScriptFieldDefinition extends ScriptableObject
/**
* @see org.mozilla.javascript.Scriptable#getClassName()
*/
@Override
public String getClassName()
{
return this.getClass().getSimpleName();
@@ -100,6 +101,7 @@ public class ScriptFieldDefinition extends ScriptableObject
/**
* @see org.mozilla.javascript.Scriptable#has(String, Scriptable)
*/
@Override
public boolean has(String name, Scriptable start)
{
if (super.has(name, start))

View File

@@ -28,6 +28,7 @@ import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.forms.FieldDefinition;
@@ -76,7 +77,7 @@ public class ScriptForm implements Serializable
public FieldDefinition[] getFieldDefinitions()
{
Collection<FieldDefinition> fieldDefs = form.getFieldDefinitions();
List<FieldDefinition> fieldDefs = form.getFieldDefinitions();
if (fieldDefs == null)
{
fieldDefs = Collections.emptyList();
@@ -84,14 +85,19 @@ public class ScriptForm implements Serializable
return fieldDefs.toArray(new FieldDefinition[fieldDefs.size()]);
}
public ScriptableHashMap<String, ScriptFieldDefinition> getFieldDefinitionData()
public ScriptableHashMap<Integer, ScriptFieldDefinition> getFieldDefinitionData()
{
ScriptableHashMap<String, ScriptFieldDefinition> result =
new ScriptableHashMap<String, ScriptFieldDefinition>();
Collection<FieldDefinition> fieldDefs = form.getFieldDefinitions();
ScriptableHashMap<Integer, ScriptFieldDefinition> result =
new ScriptableHashMap<Integer, ScriptFieldDefinition>();
List<FieldDefinition> fieldDefs = form.getFieldDefinitions();
// An Integer-based Map is being used here as we need to allow field definitions
// for both properties and associations. It is possible for a property and an
// association to coexist with the same name.
int i = 0;
for (FieldDefinition fd : fieldDefs)
{
result.put(fd.getName(), new ScriptFieldDefinition(fd));
result.put(i++, new ScriptFieldDefinition(fd));
}
return result;
}

View File

@@ -24,17 +24,20 @@ function testGetFormForContentNode()
test.assertEquals(22, fieldDefs.length);
// This dataHash is now an integer-keyed hash of the field definition data objects.
var fieldDefnDataHash = form.fieldDefinitionData;
test.assertNotNull(fieldDefnDataHash, "field definition data should not be null.");
test.assertEquals(22, fieldDefnDataHash.length);
var nameField = fieldDefnDataHash['cm:name'];
var titleField = fieldDefnDataHash['cm:title'];
var descField = fieldDefnDataHash['cm:description'];
var originatorField = fieldDefnDataHash['cm:originator'];
var addresseeField = fieldDefnDataHash['cm:addressee'];
var addresseesField = fieldDefnDataHash['cm:addressees'];
var subjectField = fieldDefnDataHash['cm:subjectline'];
var sentDateField = fieldDefnDataHash['cm:sentdate'];
var referencesField = fieldDefnDataHash['cm:references'];
var nameField = getFieldDefnFromMap('cm:name', fieldDefnDataHash);
var titleField = getFieldDefnFromMap('cm:title', fieldDefnDataHash);
var descField = getFieldDefnFromMap('cm:description', fieldDefnDataHash);
var originatorField = getFieldDefnFromMap('cm:originator', fieldDefnDataHash);
var addresseeField = getFieldDefnFromMap('cm:addressee', fieldDefnDataHash);
var addresseesField = getFieldDefnFromMap('cm:addressees', fieldDefnDataHash);
var subjectField = getFieldDefnFromMap('cm:subjectline', fieldDefnDataHash);
var sentDateField = getFieldDefnFromMap('cm:sentdate', fieldDefnDataHash);
var referencesField = getFieldDefnFromMap('cm:references', fieldDefnDataHash);
test.assertNotNull(nameField, "Expecting to find the cm:name field");
test.assertNotNull(titleField, "Expecting to find the cm:title field");
@@ -120,6 +123,21 @@ function testGetFormForContentNode()
test.assertEquals(testAssociatedDoc, targets[0]);
}
function getFieldDefnFromMap(name, fieldDefnDataHash)
{
var result = '';
for (var i = 0; i < fieldDefnDataHash.length; i++)
{
var candidateFieldDefn = fieldDefnDataHash[i];
if (candidateFieldDefn.name == name)
{
result = candidateFieldDefn;
break;
}
}
return result;
}
// Execute tests
testGetFormForNonExistentContentNode();
testGetFormForContentNode();