You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by je...@apache.org on 2010/07/07 09:16:13 UTC

svn commit: r961264 - in /incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src: main/java/org/apache/chemistry/opencmis/inmemory/server/ test/java/org/apache/chemistry/opencmis/inmemory/

Author: jens
Date: Wed Jul  7 07:16:13 2010
New Revision: 961264

URL: http://svn.apache.org/viewvc?rev=961264&view=rev
Log:
Fix bug: Correct behavior for default properties on folder types InMemory Server

Modified:
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java?rev=961264&r1=961263&r2=961264&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java Wed Jul  7 07:16:13 2010
@@ -34,7 +34,6 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.data.FailedToDeleteData;
 import org.apache.chemistry.opencmis.commons.data.ObjectData;
 import org.apache.chemistry.opencmis.commons.data.Properties;
-import org.apache.chemistry.opencmis.commons.data.PropertyBoolean;
 import org.apache.chemistry.opencmis.commons.data.PropertyData;
 import org.apache.chemistry.opencmis.commons.data.RenditionData;
 import org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition;
@@ -372,6 +371,11 @@ public class InMemoryObjectServiceImpl e
             fAtomLinkProvider.fillInformationForAtomLinks(repositoryId, so, objectInfo);
             objectInfos.addObjectInfo(objectInfo);
         }
+        
+//        // fill an example extension
+//        List<Object> myExtensions = new ArrayList<Object>();
+//        myExtensions.add(new JAXBElement<ExtensionSample>(new QName("http://apache.org/chemistry/opencmis/extensions", "MyExtension"), ExtensionSample.class, new ExtensionSample()));
+//        od.setExtensions(myExtensions);
 
         LOG.debug("stop getObject()");
 
@@ -780,6 +784,13 @@ public class InMemoryObjectServiceImpl e
         if (!typeDef.getBaseTypeId().equals(BaseTypeId.CMIS_FOLDER))
             throw new RuntimeException("Cannot create a folder, with a non-folder type: " + typeDef.getId());
 
+        Map<String, PropertyData<?>> propMap = properties.getProperties();
+        Map<String, PropertyData<?>> propMapNew = setDefaultProperties(typeDef, propMap);
+        if (propMapNew != propMap) {
+            properties = new PropertiesImpl(propMapNew.values());
+            propMap = propMapNew;
+        }
+
         TypeValidator.validateProperties(typeDef, properties, true);
 
         // create folder

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java?rev=961264&r1=961263&r2=961264&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java Wed Jul  7 07:16:13 2010
@@ -79,7 +79,8 @@ public class ObjectServiceTest extends A
     private static Log log = LogFactory.getLog(ObjectServiceTest.class);
     public static final String TEST_FOLDER_TYPE_ID = "MyFolderType";
     public static final String TEST_DOCUMENT_TYPE_ID = "MyDocumentType";
-    public static final String TEST_DEFAULT_TYPE_ID = "DocumentTypeWithDefault";
+    public static final String TEST_DOC_TYPE_WITH_DEFAULTS_ID = "DocumentTypeWithDefault";
+    public static final String TEST_FOLDER_TYPE_WITH_DEFAULTS_ID = "FolderTypeWithDefault";
     public static final String TEST_FOLDER_STRING_PROP_ID = "MyFolderStringProp";
     public static final String TEST_DOCUMENT_STRING_PROP_ID = "MyDocumentStringProp";
     private static final String TEST_CUSTOM_DOCUMENT_TYPE_ID = "MyCustomDocumentType";
@@ -88,6 +89,9 @@ public class ObjectServiceTest extends A
     private static final String TEST_DOCUMENT_MY_MULTI_STRING_PROP_ID = "MyCustomDocumentMultiStringProp";
     private static final String TEST_DOCUMENT_MY_INT_PROP_ID = "MyCustomDocumentIntProp";
     private static final String TEST_DOCUMENT_MY_INT_PROP_ID_MANDATORY_DEFAULT = "MyCustomDocumentIntPropMandatoryDefault";
+    private static final String TEST_FOLDER_MY_MULTI_STRING_PROP_ID = "MyCustomDocumentMultiStringProp";
+    private static final String TEST_FOLDER_MY_INT_PROP_ID = "MyCustomDocumentIntProp";
+    private static final String TEST_FOLDER_MY_INT_PROP_ID_MANDATORY_DEFAULT = "MyCustomDocumentIntPropMandatoryDefault";
     private static final String TEST_DOCUMENT_MY_SUB_STRING_PROP_ID = "MyInheritedStringProp";
     private static final String TEST_DOCUMENT_MY_SUB_INT_PROP_ID = "MyInheritedIntProp";
 
@@ -715,9 +719,9 @@ public class ObjectServiceTest extends A
     }
 
     @Test
-    public void testDefaultProperties() {
-        log.info("starting testDefaultProperties() ...");
-        String id = createDocument("DefPropDoc", fRootFolderId, TEST_DEFAULT_TYPE_ID, false);
+    public void testDefaultPropertiesDocument() {
+        log.info("starting testDefaultPropertiesDocument() ...");
+        String id = createDocument("DefPropDoc", fRootFolderId, TEST_DOC_TYPE_WITH_DEFAULTS_ID, false);
         if (id != null)
             log.info("createDocument succeeded with created id: " + id);
         ObjectData res = getDocumentObjectData(id);
@@ -741,9 +745,39 @@ public class ObjectServiceTest extends A
         assertNotNull(bi);
         assertEquals(BigInteger.valueOf(100), bi);
    
-        log.info("... testDefaultProperties() finished.");
+        log.info("... testDefaultPropertiesDocument() finished.");
     }
     
+    @Test
+    public void testDefaultPropertiesFolder() {
+        log.info("starting testDefaultPropertiesFolder() ...");
+        String id = createFolder("DefPropFolder", fRootFolderId, TEST_FOLDER_TYPE_WITH_DEFAULTS_ID);
+        if (id != null)
+            log.info("createDocument succeeded with created id: " + id);
+        ObjectData res = getDocumentObjectData(id);
+        Map<String, PropertyData<?>> props = res.getProperties().getProperties();
+        PropertyData<?> pd =  props.get(TEST_FOLDER_MY_INT_PROP_ID);
+        assertNotNull(pd);
+        Object bi = pd.getFirstValue();
+        assertNotNull(bi);
+        assertEquals(BigInteger.valueOf(100), bi);
+        
+        pd =  props.get(TEST_FOLDER_MY_MULTI_STRING_PROP_ID);
+        assertNotNull(pd);
+        List<String> valueList = (List<String>) pd.getValues();
+        assertNotNull(valueList);
+        assertTrue(valueList.contains("Apache"));
+        assertTrue(valueList.contains("CMIS"));
+        
+        pd =  props.get(TEST_FOLDER_MY_INT_PROP_ID_MANDATORY_DEFAULT);
+        assertNotNull(pd);
+        bi = pd.getFirstValue();
+        assertNotNull(bi);
+        assertEquals(BigInteger.valueOf(100), bi);
+   
+        log.info("... testDefaultPropertiesFolder() finished.");
+    }
+
     private void verifyAllowableActionsDocument(Set<Action> actions, boolean isVersioned, boolean hasContent) {
         assertTrue(actions.contains(Action.CAN_DELETE_OBJECT));
         assertTrue(actions.contains(Action.CAN_UPDATE_PROPERTIES));
@@ -995,7 +1029,8 @@ public class ObjectServiceTest extends A
             typesList.add(cmisFolderType);
             typesList.add(customDocType);
             typesList.add(createCustomInheritedType(customDocType));
-            typesList.add(createTypeWithDefault());
+            typesList.add(createDocumentTypeWithDefault());
+            typesList.add(createFolderTypeWithDefault());
             return typesList;
         }
 
@@ -1037,9 +1072,9 @@ public class ObjectServiceTest extends A
             return cmisDocumentType;
         }
         
-        private static InMemoryDocumentTypeDefinition createTypeWithDefault() {
+        private static InMemoryDocumentTypeDefinition createDocumentTypeWithDefault() {
             InMemoryDocumentTypeDefinition cmisDocumentType = new InMemoryDocumentTypeDefinition(
-                    TEST_DEFAULT_TYPE_ID, "Document Type With default values", InMemoryDocumentTypeDefinition
+                    TEST_DOC_TYPE_WITH_DEFAULTS_ID, "Document Type With default values", InMemoryDocumentTypeDefinition
                     .getRootDocumentType());
             Map<String, PropertyDefinition<?>> propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
             PropertyStringDefinitionImpl prop = PropertyCreationHelper.createStringMultiDefinition(
@@ -1068,6 +1103,36 @@ public class ObjectServiceTest extends A
             return cmisDocumentType;
         }
 
+        private static InMemoryFolderTypeDefinition createFolderTypeWithDefault() {
+            InMemoryFolderTypeDefinition cmisFolderType = new InMemoryFolderTypeDefinition(
+                    TEST_FOLDER_TYPE_WITH_DEFAULTS_ID, "Folder Type With default values", InMemoryFolderTypeDefinition.
+                    getRootFolderType());
+            Map<String, PropertyDefinition<?>> propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
+            PropertyStringDefinitionImpl prop = PropertyCreationHelper.createStringMultiDefinition(
+                    TEST_FOLDER_MY_MULTI_STRING_PROP_ID, "Test Multi String Property");
+            prop.setIsRequired(false);
+            List<String> defValS = new ArrayList<String>() {{ add("Apache"); add("CMIS"); }};
+            prop.setDefaultValue(defValS);
+            propertyDefinitions.put(prop.getId(), prop);
+
+            PropertyIntegerDefinitionImpl prop2 = PropertyCreationHelper.createIntegerDefinition(
+                    TEST_FOLDER_MY_INT_PROP_ID, "Test Integer Property");
+            prop2.setIsRequired(false);
+            List<BigInteger> defVal = new ArrayList<BigInteger>() {{ add(BigInteger.valueOf(100)); }};
+            prop2.setDefaultValue(defVal);
+            propertyDefinitions.put(prop2.getId(), prop2);
+            
+            PropertyIntegerDefinitionImpl prop3 = PropertyCreationHelper.createIntegerDefinition(
+                    TEST_FOLDER_MY_INT_PROP_ID_MANDATORY_DEFAULT, "Test Integer Property Mandatory default");
+            prop3.setIsRequired(true);
+            List<BigInteger> defVal2 = new ArrayList<BigInteger>() {{ add(BigInteger.valueOf(100)); }};
+            prop3.setDefaultValue(defVal2);
+            propertyDefinitions.put(prop3.getId(), prop3);          
+
+            cmisFolderType.addCustomPropertyDefinitions(propertyDefinitions);
+            
+            return cmisFolderType;
+        }
     }
 
 }