Author: jens
Date: Sun Dec  9 21:53:42 2012
New Revision: 1419171

URL: http://svn.apache.org/viewvc?rev=1419171&view=rev
Log:
InMemory: more secondary types support

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

Modified: 
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/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java?rev=1419171&r1=1419170&r2=1419171&view=diff
==============================================================================
--- 
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
 (original)
+++ 
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
 Sun Dec  9 21:53:42 2012
@@ -629,10 +629,14 @@ public class InMemoryObjectServiceImpl e
                        }
 
                        PropertyData<?> value = 
properties.getProperties().get(key);
-                       PropertyDefinition<?> propDef = 
typeDef.getPropertyDefinitions().get(key);
-                       if (null == propDef) {
-                           throw new CmisInvalidArgumentException("Cannot 
update property " + key + ": not contained in type");
+                PropertyDefinition<?> propDef = 
typeDef.getPropertyDefinitions().get(key);
+                       if (null == propDef && cmis11) {
+                           TypeDefinition typeDefSecondary= 
getSecondaryTypeDefinition(so, key);
+                           if (null == typeDefSecondary)
+                               throw new CmisInvalidArgumentException("Cannot 
update property " + key + ": not contained in type");
+                           propDef = 
typeDefSecondary.getPropertyDefinitions().get(key);
                        }
+
                        if (value.getValues() == null || value.getFirstValue() 
== null) {
                                // delete property
                                // check if a required a property
@@ -1243,4 +1247,21 @@ public class InMemoryObjectServiceImpl e
             }
         }
     }
+    
+    private TypeDefinition getSecondaryTypeDefinition(StoredObject so, String 
propertyId) {
+        List<String> secondaryTypeIds = so.getSecondaryTypeIds();
+        if (null == secondaryTypeIds || secondaryTypeIds.isEmpty())
+            return null;
+        
+        for (String typeId : secondaryTypeIds) {
+            TypeDefinitionContainer typeDefC = 
fStoreManager.getTypeById(so.getRepositoryId(), typeId);
+            TypeDefinition typeDef = typeDefC.getTypeDefinition();
+
+            if (TypeValidator.typeContainsProperty(typeDef, propertyId)) {
+                return typeDef;
+            }
+        }
+
+        return null;
+    }
 }

Modified: 
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/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java?rev=1419171&r1=1419170&r2=1419171&view=diff
==============================================================================
--- 
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java
 (original)
+++ 
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java
 Sun Dec  9 21:53:42 2012
@@ -1214,20 +1214,20 @@ public class ObjectServiceTest extends A
         final String primaryPropVal2 = "Sample Doc String Property updated";
         properties = new ArrayList<PropertyData<?>>();
         
properties.add(fFactory.createPropertyStringData(SECONDARY_STRING_PROP, 
strPropVal2));
-        
properties.add(fFactory.createPropertyStringData(TEST_DOCUMENT_STRING_PROP_ID, 
primaryPropVal));
+        
properties.add(fFactory.createPropertyStringData(TEST_DOCUMENT_STRING_PROP_ID, 
primaryPropVal2));
         props = fFactory.createPropertiesData(properties);
-//        fObjSvc.updateProperties(fRepositoryId, new Holder<String>(id), new 
Holder<String>(), props, null);
-//        
-//        res = fObjSvc.getProperties(fRepositoryId, id, "*", null);
-//        assertNotNull(res.getProperties());
-//        returnedProps = res.getProperties();
-//        assertNotNull(returnedProps);
-//        returnedValueStr = (String) 
returnedProps.get(SECONDARY_STRING_PROP).getFirstValue();
-//        returnedValueInt = (BigInteger) 
returnedProps.get(SECONDARY_INTEGER_PROP).getFirstValue();
-//        assertEquals(strPropVal2, returnedValueStr);
-//        assertEquals(intPropVal, returnedValueInt);
-//        returnedPrimaryPropVal = (String) 
returnedProps.get(TEST_DOCUMENT_STRING_PROP_ID).getFirstValue();
-//        assertEquals(primaryPropVal2, returnedPrimaryPropVal);
+        fObjSvc.updateProperties(fRepositoryId, new Holder<String>(id), new 
Holder<String>(), props, null);
+        
+        res = fObjSvc.getProperties(fRepositoryId, id, "*", null);
+        assertNotNull(res.getProperties());
+        returnedProps = res.getProperties();
+        assertNotNull(returnedProps);
+        returnedValueStr = (String) 
returnedProps.get(SECONDARY_STRING_PROP).getFirstValue();
+        returnedValueInt = (BigInteger) 
returnedProps.get(SECONDARY_INTEGER_PROP).getFirstValue();
+        assertEquals(strPropVal2, returnedValueStr);
+        assertEquals(intPropVal, returnedValueInt);
+        returnedPrimaryPropVal = (String) 
returnedProps.get(TEST_DOCUMENT_STRING_PROP_ID).getFirstValue();
+        assertEquals(primaryPropVal2, returnedPrimaryPropVal);
       
         log.info("... finished testSecondaryTypes()");        
     }


Reply via email to