Author: jens
Date: Tue Apr 19 11:51:35 2016
New Revision: 1739911

URL: http://svn.apache.org/viewvc?rev=1739911&view=rev
Log:
Avoid inconsistent state in InMemory server when creating a document in 
checked-out state (by not allowing this)

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/VersioningTest.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=1739911&r1=1739910&r2=1739911&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
 Tue Apr 19 11:51:35 2016
@@ -894,7 +894,12 @@ public class InMemoryObjectServiceImpl e
         // validate content allowed
         TypeValidator.validateContentAllowed((DocumentTypeDefinition) typeDef, 
null != contentStream);
 
+        // Check that documents are not created as checked-out as this results 
in an inconsistent state
         TypeValidator.validateVersionStateForCreate((DocumentTypeDefinition) 
typeDef, versioningState);
+        if (typeDef instanceof DocumentTypeDefinition && 
((DocumentTypeDefinition) typeDef).isVersionable() 
+                       && null != versioningState && 
versioningState.equals(VersioningState.CHECKEDOUT)) {
+            throw new CmisConstraintException("Creating of checked-out 
documents is not supported.");
+        }
 
         // set properties that are not set but have a default:
         Map<String, PropertyData<?>> propMapNew = 
setDefaultProperties(typeDef, propMap);

Modified: 
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/VersioningTest.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/VersioningTest.java?rev=1739911&r1=1739910&r2=1739911&view=diff
==============================================================================
--- 
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/VersioningTest.java
 (original)
+++ 
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/VersioningTest.java
 Tue Apr 19 11:51:35 2016
@@ -98,7 +98,12 @@ public class VersioningTest extends Abst
 
     @Test
     public void testCreateVersionedDocumentCheckedOut() {
-        createVersionedDocument(VersioningState.CHECKEDOUT);
+        try {
+            createVersionedDocument(VersioningState.CHECKEDOUT);
+            fail("creating a document of a versionable type with state 
VersioningState.CHECKEDOUT should fail.");
+        } catch (Exception e) {
+            assertEquals(CmisConstraintException.class, e.getClass());
+        }
     }
 
     @Test


Reply via email to