mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -37,7 +37,7 @@ public class Form
|
|||||||
{
|
{
|
||||||
protected String item;
|
protected String item;
|
||||||
protected String type;
|
protected String type;
|
||||||
protected Collection<FieldDefinition> fieldDefinitions;
|
protected List<FieldDefinition> fieldDefinitions;
|
||||||
protected Collection<FieldGroup> fieldGroups;
|
protected Collection<FieldGroup> fieldGroups;
|
||||||
protected FormData data;
|
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;
|
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
|
* 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;
|
this.fieldDefinitions = fieldDefinitions;
|
||||||
}
|
}
|
||||||
@@ -179,6 +179,7 @@ public class Form
|
|||||||
/*
|
/*
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
StringBuilder buffer = new StringBuilder(super.toString());
|
StringBuilder buffer = new StringBuilder(super.toString());
|
||||||
|
@@ -74,7 +74,6 @@ public class FormServiceImpl implements FormService
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO Check with Gav that this is ok.
|
|
||||||
Form result = null;
|
Form result = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@@ -52,6 +52,7 @@ public class NodeFormProcessor extends AbstractFormProcessorByHandlers
|
|||||||
/*
|
/*
|
||||||
* @see org.alfresco.repo.forms.processor.AbstractFormProcessor#getTypedItem(java.lang.String)
|
* @see org.alfresco.repo.forms.processor.AbstractFormProcessor#getTypedItem(java.lang.String)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected Object getTypedItem(String item)
|
protected Object getTypedItem(String item)
|
||||||
{
|
{
|
||||||
// create NodeRef representation
|
// create NodeRef representation
|
||||||
|
@@ -64,6 +64,7 @@ public class ScriptFieldDefinition extends ScriptableObject
|
|||||||
*
|
*
|
||||||
* @see org.mozilla.javascript.Scriptable#get(String, Scriptable)
|
* @see org.mozilla.javascript.Scriptable#get(String, Scriptable)
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Object get(String name, Scriptable start)
|
public Object get(String name, Scriptable start)
|
||||||
{
|
{
|
||||||
@@ -81,7 +82,6 @@ public class ScriptFieldDefinition extends ScriptableObject
|
|||||||
return NOT_FOUND;
|
return NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Value conversion.
|
|
||||||
if (result instanceof List)
|
if (result instanceof List)
|
||||||
{
|
{
|
||||||
return ((List)result).toArray();
|
return ((List)result).toArray();
|
||||||
@@ -92,6 +92,7 @@ public class ScriptFieldDefinition extends ScriptableObject
|
|||||||
/**
|
/**
|
||||||
* @see org.mozilla.javascript.Scriptable#getClassName()
|
* @see org.mozilla.javascript.Scriptable#getClassName()
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String getClassName()
|
public String getClassName()
|
||||||
{
|
{
|
||||||
return this.getClass().getSimpleName();
|
return this.getClass().getSimpleName();
|
||||||
@@ -100,6 +101,7 @@ public class ScriptFieldDefinition extends ScriptableObject
|
|||||||
/**
|
/**
|
||||||
* @see org.mozilla.javascript.Scriptable#has(String, Scriptable)
|
* @see org.mozilla.javascript.Scriptable#has(String, Scriptable)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public boolean has(String name, Scriptable start)
|
public boolean has(String name, Scriptable start)
|
||||||
{
|
{
|
||||||
if (super.has(name, start))
|
if (super.has(name, start))
|
||||||
|
@@ -28,6 +28,7 @@ import java.io.Serializable;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.alfresco.repo.forms.FieldDefinition;
|
import org.alfresco.repo.forms.FieldDefinition;
|
||||||
@@ -76,7 +77,7 @@ public class ScriptForm implements Serializable
|
|||||||
|
|
||||||
public FieldDefinition[] getFieldDefinitions()
|
public FieldDefinition[] getFieldDefinitions()
|
||||||
{
|
{
|
||||||
Collection<FieldDefinition> fieldDefs = form.getFieldDefinitions();
|
List<FieldDefinition> fieldDefs = form.getFieldDefinitions();
|
||||||
if (fieldDefs == null)
|
if (fieldDefs == null)
|
||||||
{
|
{
|
||||||
fieldDefs = Collections.emptyList();
|
fieldDefs = Collections.emptyList();
|
||||||
@@ -84,14 +85,19 @@ public class ScriptForm implements Serializable
|
|||||||
return fieldDefs.toArray(new FieldDefinition[fieldDefs.size()]);
|
return fieldDefs.toArray(new FieldDefinition[fieldDefs.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScriptableHashMap<String, ScriptFieldDefinition> getFieldDefinitionData()
|
public ScriptableHashMap<Integer, ScriptFieldDefinition> getFieldDefinitionData()
|
||||||
{
|
{
|
||||||
ScriptableHashMap<String, ScriptFieldDefinition> result =
|
ScriptableHashMap<Integer, ScriptFieldDefinition> result =
|
||||||
new ScriptableHashMap<String, ScriptFieldDefinition>();
|
new ScriptableHashMap<Integer, ScriptFieldDefinition>();
|
||||||
Collection<FieldDefinition> fieldDefs = form.getFieldDefinitions();
|
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)
|
for (FieldDefinition fd : fieldDefs)
|
||||||
{
|
{
|
||||||
result.put(fd.getName(), new ScriptFieldDefinition(fd));
|
result.put(i++, new ScriptFieldDefinition(fd));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@@ -24,17 +24,20 @@ function testGetFormForContentNode()
|
|||||||
|
|
||||||
test.assertEquals(22, fieldDefs.length);
|
test.assertEquals(22, fieldDefs.length);
|
||||||
|
|
||||||
|
// This dataHash is now an integer-keyed hash of the field definition data objects.
|
||||||
var fieldDefnDataHash = form.fieldDefinitionData;
|
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 nameField = getFieldDefnFromMap('cm:name', fieldDefnDataHash);
|
||||||
var titleField = fieldDefnDataHash['cm:title'];
|
var titleField = getFieldDefnFromMap('cm:title', fieldDefnDataHash);
|
||||||
var descField = fieldDefnDataHash['cm:description'];
|
var descField = getFieldDefnFromMap('cm:description', fieldDefnDataHash);
|
||||||
var originatorField = fieldDefnDataHash['cm:originator'];
|
var originatorField = getFieldDefnFromMap('cm:originator', fieldDefnDataHash);
|
||||||
var addresseeField = fieldDefnDataHash['cm:addressee'];
|
var addresseeField = getFieldDefnFromMap('cm:addressee', fieldDefnDataHash);
|
||||||
var addresseesField = fieldDefnDataHash['cm:addressees'];
|
var addresseesField = getFieldDefnFromMap('cm:addressees', fieldDefnDataHash);
|
||||||
var subjectField = fieldDefnDataHash['cm:subjectline'];
|
var subjectField = getFieldDefnFromMap('cm:subjectline', fieldDefnDataHash);
|
||||||
var sentDateField = fieldDefnDataHash['cm:sentdate'];
|
var sentDateField = getFieldDefnFromMap('cm:sentdate', fieldDefnDataHash);
|
||||||
var referencesField = fieldDefnDataHash['cm:references'];
|
var referencesField = getFieldDefnFromMap('cm:references', fieldDefnDataHash);
|
||||||
|
|
||||||
test.assertNotNull(nameField, "Expecting to find the cm:name field");
|
test.assertNotNull(nameField, "Expecting to find the cm:name field");
|
||||||
test.assertNotNull(titleField, "Expecting to find the cm:title field");
|
test.assertNotNull(titleField, "Expecting to find the cm:title field");
|
||||||
@@ -120,6 +123,21 @@ function testGetFormForContentNode()
|
|||||||
test.assertEquals(testAssociatedDoc, targets[0]);
|
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
|
// Execute tests
|
||||||
testGetFormForNonExistentContentNode();
|
testGetFormForNonExistentContentNode();
|
||||||
testGetFormForContentNode();
|
testGetFormForContentNode();
|
Reference in New Issue
Block a user