mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Fixed up property type restrictions for types d:any
- You can now pass single or multiple values into a property of type d:any Type | Multiple | Allow Single | Allow Multiple d:text N Y N d:text Y Y Y d:any N Y Y d:any Y Y Y anon Y Y git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2524 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -24,7 +24,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.domain.PropertyValue;
|
import org.alfresco.repo.domain.PropertyValue;
|
||||||
import org.alfresco.repo.node.NodeServicePolicies.BeforeAddAspectPolicy;
|
import org.alfresco.repo.node.NodeServicePolicies.BeforeAddAspectPolicy;
|
||||||
@@ -561,11 +560,17 @@ public abstract class AbstractNodeServiceImpl implements NodeService
|
|||||||
}
|
}
|
||||||
else if (!isMultiValued && (value instanceof Collection))
|
else if (!isMultiValued && (value instanceof Collection))
|
||||||
{
|
{
|
||||||
throw new DictionaryException("A single-valued property may not be a collection: \n" +
|
// we only allow this case if the property type is ANY
|
||||||
|
if (!propertyTypeQName.equals(DataTypeDefinition.ANY))
|
||||||
|
{
|
||||||
|
throw new DictionaryException(
|
||||||
|
"A single-valued property of this type may not be a collection: \n" +
|
||||||
" Property: " + propertyDef + "\n" +
|
" Property: " + propertyDef + "\n" +
|
||||||
|
" Type: " + propertyTypeQName + "\n" +
|
||||||
" Value: " + value);
|
" Value: " + value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PropertyValue propertyValue = new PropertyValue(propertyTypeQName, value);
|
PropertyValue propertyValue = new PropertyValue(propertyTypeQName, value);
|
||||||
|
@@ -27,8 +27,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.content.MimetypeMap;
|
import org.alfresco.repo.content.MimetypeMap;
|
||||||
@@ -44,6 +42,7 @@ import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
|||||||
import org.alfresco.repo.transaction.TransactionUtil;
|
import org.alfresco.repo.transaction.TransactionUtil;
|
||||||
import org.alfresco.repo.transaction.TransactionUtil.TransactionWork;
|
import org.alfresco.repo.transaction.TransactionUtil.TransactionWork;
|
||||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||||
|
import org.alfresco.service.cmr.dictionary.DictionaryException;
|
||||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||||
import org.alfresco.service.cmr.dictionary.InvalidAspectException;
|
import org.alfresco.service.cmr.dictionary.InvalidAspectException;
|
||||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||||
@@ -84,15 +83,15 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest
|
|||||||
public static final String NAMESPACE = "http://www.alfresco.org/test/BaseNodeServiceTest";
|
public static final String NAMESPACE = "http://www.alfresco.org/test/BaseNodeServiceTest";
|
||||||
public static final String TEST_PREFIX = "test";
|
public static final String TEST_PREFIX = "test";
|
||||||
public static final QName TYPE_QNAME_TEST_CONTENT = QName.createQName(NAMESPACE, "content");
|
public static final QName TYPE_QNAME_TEST_CONTENT = QName.createQName(NAMESPACE, "content");
|
||||||
|
public static final QName TYPE_QNAME_TEST_MANY_PROPERTIES = QName.createQName(NAMESPACE, "many-properties");
|
||||||
|
public static final QName TYPE_QNAME_EXTENDED_CONTENT = QName.createQName(NAMESPACE, "extendedcontent");
|
||||||
public static final QName ASPECT_QNAME_TEST_TITLED = QName.createQName(NAMESPACE, "titled");
|
public static final QName ASPECT_QNAME_TEST_TITLED = QName.createQName(NAMESPACE, "titled");
|
||||||
public static final QName ASPECT_QNAME_TEST_MARKER = QName.createQName(NAMESPACE, "marker");
|
public static final QName ASPECT_QNAME_TEST_MARKER = QName.createQName(NAMESPACE, "marker");
|
||||||
public static final QName ASPECT_QNAME_TEST_MARKER2 = QName.createQName(NAMESPACE, "marker2");
|
public static final QName ASPECT_QNAME_TEST_MARKER2 = QName.createQName(NAMESPACE, "marker2");
|
||||||
public static final QName ASPECT_QNAME_MANDATORY = QName.createQName(NAMESPACE, "mandatoryaspect");
|
public static final QName ASPECT_QNAME_MANDATORY = QName.createQName(NAMESPACE, "mandatoryaspect");
|
||||||
|
public static final QName ASPECT_QNAME_WITH_DEFAULT_VALUE = QName.createQName(NAMESPACE, "withDefaultValue");
|
||||||
public static final QName PROP_QNAME_TEST_TITLE = QName.createQName(NAMESPACE, "title");
|
public static final QName PROP_QNAME_TEST_TITLE = QName.createQName(NAMESPACE, "title");
|
||||||
public static final QName PROP_QNAME_TEST_CONTENT = QName.createQName(NAMESPACE, "content");
|
public static final QName PROP_QNAME_TEST_CONTENT = QName.createQName(NAMESPACE, "content");
|
||||||
public static final QName ASSOC_TYPE_QNAME_TEST_CHILDREN = ContentModel.ASSOC_CHILDREN;
|
|
||||||
public static final QName ASSOC_TYPE_QNAME_TEST_NEXT = QName.createQName(NAMESPACE, "next");
|
|
||||||
public static final QName TYPE_QNAME_TEST_MANY_PROPERTIES = QName.createQName(NAMESPACE, "many-properties");
|
|
||||||
public static final QName PROP_QNAME_BOOLEAN_VALUE = QName.createQName(NAMESPACE, "booleanValue");
|
public static final QName PROP_QNAME_BOOLEAN_VALUE = QName.createQName(NAMESPACE, "booleanValue");
|
||||||
public static final QName PROP_QNAME_INTEGER_VALUE = QName.createQName(NAMESPACE, "integerValue");
|
public static final QName PROP_QNAME_INTEGER_VALUE = QName.createQName(NAMESPACE, "integerValue");
|
||||||
public static final QName PROP_QNAME_LONG_VALUE = QName.createQName(NAMESPACE, "longValue");
|
public static final QName PROP_QNAME_LONG_VALUE = QName.createQName(NAMESPACE, "longValue");
|
||||||
@@ -108,10 +107,16 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest
|
|||||||
public static final QName PROP_QNAME_CATEGORY_VALUE = QName.createQName(NAMESPACE, "categoryValue");
|
public static final QName PROP_QNAME_CATEGORY_VALUE = QName.createQName(NAMESPACE, "categoryValue");
|
||||||
public static final QName PROP_QNAME_NULL_VALUE = QName.createQName(NAMESPACE, "nullValue");
|
public static final QName PROP_QNAME_NULL_VALUE = QName.createQName(NAMESPACE, "nullValue");
|
||||||
public static final QName PROP_QNAME_MULTI_VALUE = QName.createQName(NAMESPACE, "multiValue");
|
public static final QName PROP_QNAME_MULTI_VALUE = QName.createQName(NAMESPACE, "multiValue");
|
||||||
public static final QName TYPE_QNAME_EXTENDED_CONTENT = QName.createQName(NAMESPACE, "extendedcontent");
|
|
||||||
public static final QName PROP_QNAME_PROP1 = QName.createQName(NAMESPACE, "prop1");
|
public static final QName PROP_QNAME_PROP1 = QName.createQName(NAMESPACE, "prop1");
|
||||||
public static final QName ASPECT_QNAME_WITH_DEFAULT_VALUE = QName.createQName(NAMESPACE, "withDefaultValue");
|
|
||||||
public static final QName PROP_QNAME_PROP2 = QName.createQName(NAMESPACE, "prop2");
|
public static final QName PROP_QNAME_PROP2 = QName.createQName(NAMESPACE, "prop2");
|
||||||
|
public static final QName ASSOC_TYPE_QNAME_TEST_CHILDREN = ContentModel.ASSOC_CHILDREN;
|
||||||
|
public static final QName ASSOC_TYPE_QNAME_TEST_NEXT = QName.createQName(NAMESPACE, "next");
|
||||||
|
|
||||||
|
public static final QName TYPE_QNAME_TEST_MULTIPLE_TESTER = QName.createQName(NAMESPACE, "multiple-tester");
|
||||||
|
public static final QName PROP_QNAME_STRING_PROP_SINGLE = QName.createQName(NAMESPACE, "stringprop-single");
|
||||||
|
public static final QName PROP_QNAME_STRING_PROP_MULTIPLE = QName.createQName(NAMESPACE, "stringprop-multiple");
|
||||||
|
public static final QName PROP_QNAME_ANY_PROP_SINGLE = QName.createQName(NAMESPACE, "anyprop-single");
|
||||||
|
public static final QName PROP_QNAME_ANY_PROP_MULTIPLE = QName.createQName(NAMESPACE, "anyprop-multiple");
|
||||||
|
|
||||||
protected PolicyComponent policyComponent;
|
protected PolicyComponent policyComponent;
|
||||||
protected DictionaryService dictionaryService;
|
protected DictionaryService dictionaryService;
|
||||||
@@ -207,7 +212,7 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest
|
|||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @return Returns the implementation of <code>NodeService</code> to be
|
* @return Returns the implementation of <code>NodeService</code> to be
|
||||||
* used for this test
|
* used for this test. It must have transaction demarcation.
|
||||||
*/
|
*/
|
||||||
protected abstract NodeService getNodeService();
|
protected abstract NodeService getNodeService();
|
||||||
|
|
||||||
@@ -925,6 +930,45 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest
|
|||||||
assertTrue("Serialization/deserialization failed", checkPropertyQname instanceof QName);
|
assertTrue("Serialization/deserialization failed", checkPropertyQname instanceof QName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testMultiProp() throws Exception
|
||||||
|
{
|
||||||
|
QName undeclaredPropQName = QName.createQName(NAMESPACE, getName());
|
||||||
|
// create node
|
||||||
|
NodeRef nodeRef = nodeService.createNode(
|
||||||
|
rootNodeRef,
|
||||||
|
ASSOC_TYPE_QNAME_TEST_CHILDREN,
|
||||||
|
QName.createQName("pathA"),
|
||||||
|
TYPE_QNAME_TEST_MULTIPLE_TESTER).getChildRef();
|
||||||
|
// commit as we will be breaking the transaction in the test
|
||||||
|
setComplete();
|
||||||
|
endTransaction();
|
||||||
|
|
||||||
|
// each of these tests will be in a new transaction started by the NodeService
|
||||||
|
|
||||||
|
ArrayList<String> values = new ArrayList<String>(1);
|
||||||
|
values.add("ABC");
|
||||||
|
// test allowable conditions
|
||||||
|
nodeService.setProperty(nodeRef, PROP_QNAME_STRING_PROP_SINGLE, "ABC");
|
||||||
|
// nodeService.setProperty(nodeRef, PROP_QNAME_STRING_PROP_SINGLE, values); -- should fail
|
||||||
|
nodeService.setProperty(nodeRef, PROP_QNAME_STRING_PROP_MULTIPLE, "ABC");
|
||||||
|
nodeService.setProperty(nodeRef, PROP_QNAME_STRING_PROP_MULTIPLE, values);
|
||||||
|
nodeService.setProperty(nodeRef, PROP_QNAME_ANY_PROP_SINGLE, "ABC");
|
||||||
|
nodeService.setProperty(nodeRef, PROP_QNAME_ANY_PROP_SINGLE, values);
|
||||||
|
nodeService.setProperty(nodeRef, PROP_QNAME_ANY_PROP_MULTIPLE, "ABC");
|
||||||
|
nodeService.setProperty(nodeRef, PROP_QNAME_ANY_PROP_MULTIPLE, values);
|
||||||
|
nodeService.setProperty(nodeRef, undeclaredPropQName, "ABC");
|
||||||
|
nodeService.setProperty(nodeRef, undeclaredPropQName, values);
|
||||||
|
// this should fail as we are passing multiple values into a non-any that is multiple=false
|
||||||
|
try
|
||||||
|
{
|
||||||
|
nodeService.setProperty(nodeRef, PROP_QNAME_STRING_PROP_SINGLE, values);
|
||||||
|
}
|
||||||
|
catch (DictionaryException e)
|
||||||
|
{
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check that properties go in and come out in the correct format
|
* Check that properties go in and come out in the correct format
|
||||||
*/
|
*/
|
||||||
|
@@ -71,6 +71,33 @@
|
|||||||
</properties>
|
</properties>
|
||||||
</type>
|
</type>
|
||||||
|
|
||||||
|
<type name="test:multiple-tester">
|
||||||
|
<title>Type with ANY props</title>
|
||||||
|
<parent>sys:base</parent>
|
||||||
|
<properties>
|
||||||
|
<property name="test:stringprop-single">
|
||||||
|
<type>d:text</type>
|
||||||
|
<mandatory>false</mandatory>
|
||||||
|
<multiple>false</multiple>
|
||||||
|
</property>
|
||||||
|
<property name="test:stringprop-multiple">
|
||||||
|
<type>d:text</type>
|
||||||
|
<mandatory>false</mandatory>
|
||||||
|
<multiple>true</multiple>
|
||||||
|
</property>
|
||||||
|
<property name="test:anyprop-single">
|
||||||
|
<type>d:any</type>
|
||||||
|
<mandatory>false</mandatory>
|
||||||
|
<multiple>false</multiple>
|
||||||
|
</property>
|
||||||
|
<property name="test:anyprop-multiple">
|
||||||
|
<type>d:any</type>
|
||||||
|
<mandatory>false</mandatory>
|
||||||
|
<multiple>true</multiple>
|
||||||
|
</property>
|
||||||
|
</properties>
|
||||||
|
</type>
|
||||||
|
|
||||||
<type name="test:multiprop">
|
<type name="test:multiprop">
|
||||||
<title>MultiProp</title>
|
<title>MultiProp</title>
|
||||||
<parent>sys:base</parent>
|
<parent>sys:base</parent>
|
||||||
|
Reference in New Issue
Block a user