Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud)

65422: Merged V4.2-BUG-FIX (4.2.2) to HEAD-BUG-FIX (4.3/Cloud)
      65044: Merged DEV to V4.2-BUG-FIX (4.2.2)
         65027 : MNT-10969 : FormService doesn't allow empty value in multivalued field
            - Multivalue properties may now contain empty values.
            - Unit test added.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@66234 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2014-04-02 21:07:09 +00:00
parent 277a442fe0
commit f1a304506a
2 changed files with 42 additions and 7 deletions

View File

@@ -29,11 +29,11 @@ import static org.alfresco.repo.forms.processor.node.FormFieldConstants.PROP_DAT
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.StringTokenizer;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@@ -360,12 +360,7 @@ public abstract class ContentModelFormProcessor<ItemType, PersistType> extends
{ {
// if value is a String convert to List of // if value is a String convert to List of
// String // String
StringTokenizer tokenizer = new StringTokenizer((String) value, ","); List<String> list = Arrays.asList(((String)value).split(",", -1));
List<String> list = new ArrayList<String>(8);
while (tokenizer.hasMoreTokens())
{
list.add(tokenizer.nextToken());
}
// persist the List // persist the List
value = list; value = list;

View File

@@ -20,6 +20,7 @@ package org.alfresco.repo.forms;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collection; import java.util.Collection;
import java.util.Date; import java.util.Date;
@@ -1745,6 +1746,45 @@ public class FormServiceImplTest extends BaseAlfrescoSpringTest
assertEquals(newName, updatedName); assertEquals(newName, updatedName);
} }
@SuppressWarnings("unchecked")
public void testMNT_10969() throws Exception
{
// create a node (cm:content)
Map<QName, Serializable> nodeProps = new HashMap<QName, Serializable>(1);
String nodeName = "testNode" + GUID.generate();
nodeProps.put(ContentModel.PROP_NAME, nodeName);
NodeRef node = this.nodeService.createNode(
this.folder,
ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nodeName),
ContentModel.TYPE_CONTENT,
nodeProps).getChildRef();
this.nodeService.addAspect(node, ContentModel.ASPECT_WEBDAV_OBJECT, null);
List<String> fields = new ArrayList<String>(8);
fields.add(ContentModel.PROP_DEAD_PROPERTIES.toPrefixString(this.namespaceService));
Form form = this.formService.getForm(new Item(NODE_FORM_ITEM_KIND, node.toString()), fields);
// check a form got returned
assertNotNull("Expecting form to be present", form);
// check fields were returned
List<String> fieldNames = form.getFieldDefinitionNames();
assertEquals(1, fieldNames.size());
// set the multivalue property with empty values
FormData data = new FormData();
String value = ",titi,toto,";
data.addFieldData("prop_webdav_deadproperties", value);
this.formService.saveForm(new Item(NODE_FORM_ITEM_KIND, node.toString()), data);
Map<QName, Serializable> updatedProps = this.nodeService.getProperties(node);
List<String> savedValue = (List<String>)updatedProps.get(ContentModel.PROP_DEAD_PROPERTIES);
assertEquals(Arrays.asList("", "titi", "toto", ""), savedValue);
}
public void testJavascriptAPI() throws Exception public void testJavascriptAPI() throws Exception
{ {
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();