chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1387342 - in /chemistry/opencmis/trunk/chemistry-opencmis-server: chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/ chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmi...
Date Tue, 18 Sep 2012 20:22:51 GMT
Author: jens
Date: Tue Sep 18 20:22:50 2012
New Revision: 1387342

URL: http://svn.apache.org/viewvc?rev=1387342&view=rev
Log:
InMemory: verify if content is allowed/required on document type on create

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
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.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=1387342&r1=1387341&r2=1387342&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 Sep 18 20:22:50 2012
@@ -549,6 +549,12 @@ public class InMemoryObjectServiceImpl e
                     + " does not refer to a document, but only documents can have content");
         }
 
+        // validate content allowed
+        TypeDefinition typeDef = getTypeDefinition(repositoryId, so);
+        if (!(typeDef instanceof DocumentTypeDefinition))
+            throw new CmisInvalidArgumentException("Object does not refer to a document,
can't set content");
+        TypeValidator.validateContentAllowed((DocumentTypeDefinition) typeDef , null != contentStream);
+
         if (so instanceof Document) {
             content = ((Document) so);
         } else if (so instanceof DocumentVersion) {
@@ -719,7 +725,7 @@ public class InMemoryObjectServiceImpl e
 
         // validate ACL
         TypeValidator.validateAcl(typeDef, addACEs, removeACEs);
-
+        
         Folder folder = null;
         if (null != folderId) {
             StoredObject so = objectStore.getObjectById(folderId);
@@ -748,6 +754,9 @@ public class InMemoryObjectServiceImpl e
             throw new CmisInvalidArgumentException(NameValidator.ERROR_ILLEGAL_NAME + " Name
is: " + name);
         }
 
+        // validate content allowed
+        TypeValidator.validateContentAllowed((DocumentTypeDefinition) typeDef, null != contentStream);
+
         TypeValidator.validateVersionStateForCreate((DocumentTypeDefinition) typeDef, versioningState);
 
         // set properties that are not set but have a default:

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=1387342&r1=1387341&r2=1387342&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
Tue Sep 18 20:22:50 2012
@@ -46,6 +46,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
 import org.apache.chemistry.opencmis.commons.enums.Action;
+import org.apache.chemistry.opencmis.commons.enums.ContentStreamAllowed;
 import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
 import org.apache.chemistry.opencmis.commons.enums.UnfileObject;
 import org.apache.chemistry.opencmis.commons.enums.Updatability;
@@ -86,6 +87,8 @@ public class ObjectServiceTest extends A
     public static final String TEST_DOCUMENT_STRING_PROP_ID = "MyDocumentStringProp";
     private static final String TEST_CUSTOM_DOCUMENT_TYPE_ID = "MyCustomDocumentType";
     private static final String TEST_INHERITED_CUSTOM_DOCUMENT_TYPE_ID = "MyCustomInheritedDocType";
+    private static final String TEST_CUSTOM_NO_CONTENT_TYPE_ID = "NoContentType";
+    private static final String TEST_CUSTOM_MUST_CONTENT_TYPE_ID = "MustHaveContentType";
     private static final String TEST_DOCUMENT_MY_STRING_PROP_ID = "MyCustomDocumentStringProp";
     private static final String TEST_DOCUMENT_MY_MULTI_STRING_PROP_ID = "MyCustomDocumentMultiStringProp";
     private static final String TEST_DOCUMENT_MY_INT_PROP_ID = "MyCustomDocumentIntProp";
@@ -95,7 +98,6 @@ public class ObjectServiceTest extends A
     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";
-
     private static final String DOCUMENT_TYPE_ID = InMemoryDocumentTypeDefinition.getRootDocumentType().getId();
     private static final String DOCUMENT_ID = "Document_1";
     private static final String FOLDER_TYPE_ID = InMemoryFolderTypeDefinition.getRootFolderType().getId();
@@ -910,6 +912,67 @@ public class ObjectServiceTest extends A
                 fail("getObject() failed with exception: " + e);
             }
     }
+    
+    @Test
+    public void testNoContentAllowed() {
+        log.info("starting testNoContentAllowed() ...");
+        String id = createDocument("NoContentAllowedDoc1", fRootFolderId, TEST_CUSTOM_NO_CONTENT_TYPE_ID,
false);
+        assertNotNull (id);
+
+        try {
+            id = createDocumentNoCatch("NoContentAllowedDoc2", fRootFolderId, TEST_CUSTOM_NO_CONTENT_TYPE_ID,
VersioningState.NONE, true);
+            fail("Creating  document with content and type allows no content should fail.");
+        } catch (Exception e) {
+            assertTrue(e instanceof CmisConstraintException);
+            log.info("Creating  document with content for no-content type failed as expected.");
+        }
+        log.info("... testNoContentAllowed finished.");
+    }
+
+    @Test
+    public void testMustHaveContent() {
+        log.info("starting testMustHaveContent() ...");
+        String id = createDocument("MustHaveContentAllowedDoc1", fRootFolderId, TEST_CUSTOM_MUST_CONTENT_TYPE_ID,
true);
+        assertNotNull (id);
+
+        try {
+            id = createDocumentNoCatch("MustHaveContentAllowedDoc2", fRootFolderId, TEST_CUSTOM_MUST_CONTENT_TYPE_ID,
VersioningState.NONE, false);
+            fail("Creating document without content and type requires content should fail.");
+        } catch (Exception e) {
+            assertTrue(e instanceof CmisConstraintException);
+            log.info("Creating document with content for must-have-content type failed as
expected.");
+        }
+        log.info("... testMustHaveContent finished.");
+    }
+    
+    @Test
+    public void testMaxContentSize() {
+        log.info("starting testMaxContentSize() ...");
+        try {
+            createContent(MAX_SIZE + 1, MAX_SIZE);
+            fail("createContent with exceeded content size should fail.");
+        } catch (CmisInvalidArgumentException e) {
+            log.debug("createDocument with exceeded failed as excpected.");
+        } catch (Exception e1) {
+            log.debug("createDocument with exceeded failed with wrong exception (expected
CmisInvalidArgumentException, got "
+                    + e1.getClass().getName() + ").");
+        }
+
+        try {
+            ContentStream contentStream = createContent(MAX_SIZE + 1);
+            Properties props = createDocumentProperties("TestMaxContentSize", DOCUMENT_TYPE_ID);
+            fObjSvc.createDocument(fRepositoryId, props, fRootFolderId, contentStream, VersioningState.NONE,
null,
+                    null, null, null);
+            fail("createDocument with exceeded content size should fail.");
+        } catch (CmisInvalidArgumentException e) {
+            log.debug("createDocument with exceeded failed as excpected.");
+        } catch (Exception e1) {
+            log.debug("createDocument with exceeded failed with wrong exception (expected
CmisInvalidArgumentException, got "
+                    + e1.getClass().getName() + ").");
+        }
+    }
+
+
 
     private static void verifyAllowableActionsDocument(Set<Action> actions, boolean
isVersioned, boolean hasContent) {
         assertTrue(actions.contains(Action.CAN_DELETE_OBJECT));
@@ -1167,10 +1230,15 @@ public class ObjectServiceTest extends A
             cmisFolderType.addCustomPropertyDefinitions(propertyDefinitions);
 
             InMemoryDocumentTypeDefinition customDocType = createCustomTypeWithStringIntProperty();
+            InMemoryDocumentTypeDefinition noContentType = createCustomTypeNoContent();
+            InMemoryDocumentTypeDefinition mustHaveContentType = createCustomTypeMustHaveContent();
+
             // add type to types collection
             typesList.add(cmisDocumentType);
             typesList.add(cmisFolderType);
             typesList.add(customDocType);
+            typesList.add(noContentType);
+            typesList.add(mustHaveContentType);
             typesList.add(createCustomInheritedType(customDocType));
             typesList.add(createDocumentTypeWithDefault());
             typesList.add(createFolderTypeWithDefault());
@@ -1246,6 +1314,24 @@ public class ObjectServiceTest extends A
             return cmisDocumentType;
         }
 
+        private static InMemoryDocumentTypeDefinition createCustomTypeNoContent() {
+            InMemoryDocumentTypeDefinition cmisDocumentType = new InMemoryDocumentTypeDefinition(
+                    TEST_CUSTOM_NO_CONTENT_TYPE_ID, "No Content Document Type", InMemoryDocumentTypeDefinition
+                            .getRootDocumentType());
+            Map<String, PropertyDefinition<?>> propertyDefinitions = new HashMap<String,
PropertyDefinition<?>>();
+            cmisDocumentType.addCustomPropertyDefinitions(propertyDefinitions);
+            cmisDocumentType.setContentStreamAllowed(ContentStreamAllowed.NOTALLOWED);
+            return cmisDocumentType;
+        }
+        
+        private static InMemoryDocumentTypeDefinition createCustomTypeMustHaveContent() {
+            InMemoryDocumentTypeDefinition cmisDocumentType = new InMemoryDocumentTypeDefinition(
+                    TEST_CUSTOM_MUST_CONTENT_TYPE_ID, "Must Have Content Document Type",
InMemoryDocumentTypeDefinition
+                            .getRootDocumentType());
+            cmisDocumentType.setContentStreamAllowed(ContentStreamAllowed.REQUIRED);
+            return cmisDocumentType;
+        }
+        
         private static InMemoryFolderTypeDefinition createFolderTypeWithDefault() {
             InMemoryFolderTypeDefinition cmisFolderType = new InMemoryFolderTypeDefinition(
                     TEST_FOLDER_TYPE_WITH_DEFAULTS_ID, "Folder Type With default values",
InMemoryFolderTypeDefinition.
@@ -1278,31 +1364,4 @@ public class ObjectServiceTest extends A
         }
     }
 
-    @Test
-    public void testMaxContentSize() {
-        log.info("starting testMaxContentSize() ...");
-        try {
-            createContent(MAX_SIZE + 1, MAX_SIZE);
-            fail("createContent with exceeded content size should fail.");
-        } catch (CmisInvalidArgumentException e) {
-            log.debug("createDocument with exceeded failed as excpected.");
-        } catch (Exception e1) {
-            log.debug("createDocument with exceeded failed with wrong exception (expected
CmisInvalidArgumentException, got "
-                    + e1.getClass().getName() + ").");
-        }
-
-        try {
-            ContentStream contentStream = createContent(MAX_SIZE + 1);
-            Properties props = createDocumentProperties("TestMaxContentSize", DOCUMENT_TYPE_ID);
-            fObjSvc.createDocument(fRepositoryId, props, fRootFolderId, contentStream, VersioningState.NONE,
null,
-                    null, null, null);
-            fail("createDocument with exceeded content size should fail.");
-        } catch (CmisInvalidArgumentException e) {
-            log.debug("createDocument with exceeded failed as excpected.");
-        } catch (Exception e1) {
-            log.debug("createDocument with exceeded failed with wrong exception (expected
CmisInvalidArgumentException, got "
-                    + e1.getClass().getName() + ").");
-        }
-    }
-
 }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java?rev=1387342&r1=1387341&r2=1387342&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java
Tue Sep 18 20:22:50 2012
@@ -39,6 +39,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
 import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
 import org.apache.chemistry.opencmis.commons.enums.Cardinality;
+import org.apache.chemistry.opencmis.commons.enums.ContentStreamAllowed;
 import org.apache.chemistry.opencmis.commons.enums.VersioningState;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
@@ -325,6 +326,15 @@ public class TypeValidator {
     		throw new CmisConstraintException("acl set for type: " + typeDef.getDisplayName() +
" that is not controllableACL");
     	}
     }
+    
+    public static void validateContentAllowed(DocumentTypeDefinition typeDef, boolean hasContent)
{
+        ContentStreamAllowed contentAllowed = typeDef.getContentStreamAllowed();
+        if (ContentStreamAllowed.REQUIRED == contentAllowed && !hasContent) {
+            throw new CmisConstraintException("Type " + typeDef.getId() + " requires content
but document has no content.");
+        } else if (ContentStreamAllowed.NOTALLOWED == contentAllowed && hasContent)
{
+            throw new CmisConstraintException("Type " + typeDef.getId() + " does not allow
content but document has content.");
+        }
+    }
 
     private static List<String> getMandatoryPropDefs(Map<String, PropertyDefinition<?>>
propDefs) {
         List<String> res = new ArrayList<String>();



Mime
View raw message