chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1063665 - in /incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server: chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/ chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemist...
Date Wed, 26 Jan 2011 09:59:30 GMT
Author: jens
Date: Wed Jan 26 09:59:29 2011
New Revision: 1063665

URL: http://svn.apache.org/viewvc?rev=1063665&view=rev
Log:
Support type deletion in InMemory repository if type is unused
change repo info feature id to be a URN

Modified:
    incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeManagerImpl.java
    incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryRepositoryServiceImpl.java
    incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/ObjectStore.java
    incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java
    incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java
    incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTst.java
    incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/RepositoryServiceTest.java
    incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeManager.java

Modified: incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeManagerImpl.java?rev=1063665&r1=1063664&r2=1063665&view=diff
==============================================================================
--- incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeManagerImpl.java
(original)
+++ incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeManagerImpl.java
Wed Jan 26 09:59:29 2011
@@ -155,7 +155,11 @@ public class TypeManagerImpl implements 
         fTypesMap.put(cmisType.getId(), typeContainer);
     }
 
-    /**
+	public void deleteTypeDefinition(String typeId) {
+        fTypesMap.remove(typeId);		
+	}
+
+	/**
      * Remove all types from the type system. After this call only the default
      * CMIS types are present in the type system. Use this method with care, its
      * mainly intended for unit tests
@@ -228,18 +232,4 @@ public class TypeManagerImpl implements 
         return clone;
     }
 
-    // private static PropertyDefinition<?>
-    // clonePropertyDefinition2(PropertyDefinition<?> src)
-    // throws IOException, ClassNotFoundException {
-    // ByteArrayOutputStream bout = new ByteArrayOutputStream();
-    // ObjectOutputStream oout = new ObjectOutputStream(bout);
-    // oout.writeObject(src);
-    // byte[] bytes = bout.toByteArray();
-    //
-    // ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
-    // ObjectInputStream oin = new ObjectInputStream(bin);
-    // PropertyDefinition<?> clone = (PropertyDefinition<?>) oin.readObject();
-    // return clone;
-    // }
-
 }

Modified: incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryRepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryRepositoryServiceImpl.java?rev=1063665&r1=1063664&r2=1063665&view=diff
==============================================================================
--- incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryRepositoryServiceImpl.java
(original)
+++ incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryRepositoryServiceImpl.java
Wed Jan 26 09:59:29 2011
@@ -29,15 +29,15 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer;
 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionList;
-import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeDefinitionListImpl;
 import org.apache.chemistry.opencmis.commons.server.CallContext;
 import org.apache.chemistry.opencmis.commons.spi.Holder;
-import org.apache.chemistry.opencmis.inmemory.TypeManagerImpl;
+import org.apache.chemistry.opencmis.inmemory.storedobj.api.ObjectStore;
 import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoreManager;
+import org.apache.chemistry.opencmis.server.support.TypeManager;
 
 public class InMemoryRepositoryServiceImpl extends InMemoryAbstractServiceImpl {
 
@@ -140,7 +140,7 @@ public class InMemoryRepositoryServiceIm
 
     public void createTypeDefinition(String repositoryId, Holder<TypeDefinition> type,
ExtensionsData extension) {
 
-    	TypeManagerImpl typeManager = (TypeManagerImpl) fStoreManager.getTypeManager(repositoryId);
+    	TypeManager typeManager = fStoreManager.getTypeManager(repositoryId);
         if (null == typeManager)
             throw new CmisInvalidArgumentException("Unknown repository " + repositoryId);
         
@@ -170,7 +170,26 @@ public class InMemoryRepositoryServiceIm
     }
 
     public void deleteTypeDefinition(String repositoryId, String typeId, ExtensionsData extension)
{
-    	throw new CmisNotSupportedException("deleting TypeDefinition is not supported.");
+    	
+    	TypeManager typeManager = fStoreManager.getTypeManager(repositoryId);
+        if (null == typeManager)
+            throw new CmisInvalidArgumentException("Unknown repository " + repositoryId);
+        
+        TypeDefinitionContainer typeDefC = typeManager.getTypeById(typeId);
+        if (null == typeDefC)
+            throw new CmisInvalidArgumentException("Cannot delete type unknown type id: "
+ typeId);
+
+        TypeDefinition typeDef =  typeDefC.getTypeDefinition();
+        if (!typeDef.getTypeMutability().supportsDelete()) {
+        	throw new CmisInvalidArgumentException("type definition " + typeId + " cannot be
deleted, deletion is not supported for type id " + typeId);        	
+        }
+
+        ObjectStore objectStore = fStoreManager.getObjectStore(repositoryId);
+        if (objectStore.isTypeInUse(typeId)) {
+        	throw new CmisInvalidArgumentException("type definition " + typeId + " cannot be
deleted, type is in use.");        	
+        }
+        
+        typeManager.deleteTypeDefinition(typeId);        
     }
     
     private RepositoryInfo getRepositoryInfoFromStoreManager(String repositoryId) {

Modified: incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/ObjectStore.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/ObjectStore.java?rev=1063665&r1=1063664&r2=1063665&view=diff
==============================================================================
--- incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/ObjectStore.java
(original)
+++ incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/api/ObjectStore.java
Wed Jan 26 09:59:29 2011
@@ -109,4 +109,16 @@ public interface ObjectStore {
      * @return list of checked out documents in the repository
      */
     List<VersionedDocument> getCheckedOutDocuments(String orderBy);
+    
+    /**
+     * Check if this store contains any object with the given type id
+     * 
+     * @param typeId
+     * 		id of type definition to check
+     * @return
+     * 		true if at least one object in the store has the given type, false
+     *      if no objects exist having this type
+     */
+    boolean isTypeInUse(String typeId);
+
 }
\ No newline at end of file

Modified: incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java?rev=1063665&r1=1063664&r2=1063665&view=diff
==============================================================================
--- incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java
(original)
+++ incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java
Wed Jan 26 09:59:29 2011
@@ -294,6 +294,16 @@ public class ObjectStoreImpl implements 
 
         return res;
     }
+    
+    public boolean isTypeInUse(String typeId) {
+        // iterate over all the objects and check for each if the type matches
+        for (String objectId : getIds()) {
+            StoredObject so = getObjectById(objectId);
+            if (so.getTypeId().equals(typeId))
+            	return true;
+        }
+        return false;
+    }
 
     private void deleteFolder(String folderId) {
         StoredObject folder = fStoredObjectMap.get(folderId);

Modified: incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java?rev=1063665&r1=1063664&r2=1063665&view=diff
==============================================================================
--- incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java
(original)
+++ incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java
Wed Jan 26 09:59:29 2011
@@ -353,7 +353,8 @@ public class StoreManagerImpl implements
         FeatureImpl feature = new FeatureImpl();
         feature.setCommonName("License");
         feature.setDescription("The License under which this repository is distributed");
-        feature.setId("License");
+        // use a dummy URN as id:
+        feature.setId("urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66");
         feature.setUrl("http://www.apache.org/licenses/LICENSE-2.0");
         feature.setVersionLabel("2.0");
 		List<FeatureKeyValuePair> keyVal = Collections

Modified: incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTst.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTst.java?rev=1063665&r1=1063664&r2=1063665&view=diff
==============================================================================
--- incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTst.java
(original)
+++ incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTst.java
Wed Jan 26 09:59:29 2011
@@ -387,4 +387,9 @@ public class AbstractServiceTst /* exten
         assertTrue(pd.getFirstValue() instanceof String);
         return (String) pd.getFirstValue();
     }
+
+    protected void deleteDocument(String docId) {
+        fObjSvc.deleteObject(fRepositoryId, docId, true, null);
+    }
+
 }

Modified: incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/RepositoryServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/RepositoryServiceTest.java?rev=1063665&r1=1063664&r2=1063665&view=diff
==============================================================================
--- incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/RepositoryServiceTest.java
(original)
+++ incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/RepositoryServiceTest.java
Wed Jan 26 09:59:29 2011
@@ -47,6 +47,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.enums.CapabilityJoin;
 import org.apache.chemistry.opencmis.commons.enums.CapabilityQuery;
 import org.apache.chemistry.opencmis.commons.enums.CapabilityRenditions;
+import org.apache.chemistry.opencmis.commons.enums.VersioningState;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
@@ -79,6 +80,7 @@ public class RepositoryServiceTest exten
 
     private static Log log = LogFactory.getLog(RepositoryServiceTest.class);
     private static final String REPOSITORY_ID = "UnitTestRepository";
+    private static final String TYPE_ID_MUTABILITY = "BookTypeAddedLater";
 
     static public class UnitTestRepositoryInfo implements RepositoryInfoCreator {
 
@@ -522,13 +524,44 @@ public class RepositoryServiceTest exten
         TypeDefinition typeDefRef = getTypeForAddingAtRuntime();
         String repositoryId = getRepositoryId();
         fRepSvc.createTypeDefinition(repositoryId, new Holder<TypeDefinition>(typeDefRef),
null);
-        // delete type.
+        
+        String docId = createDocument("Book1", getRootFolderId(REPOSITORY_ID), TYPE_ID_MUTABILITY,
false);
+        
+        // try deleting type, should fail, because in use.
         try {
-        	fRepSvc.deleteTypeDefinition(repositoryId, typeDefRef.getId(), null);
-        	fail("deleting a type should throw exception.");
+        	fRepSvc.deleteTypeDefinition(repositoryId, TYPE_ID_MUTABILITY, null);
+        	fail("deleting a type which is in use should throw exception.");
         } catch (Exception e) {
-        	assert(e instanceof CmisNotSupportedException);
+        	assert(e instanceof CmisInvalidArgumentException);
+        }
+
+        deleteDocument(docId);
+        
+        try {
+        	fRepSvc.deleteTypeDefinition(repositoryId, TYPE_ID_MUTABILITY, null);
+        } catch (Exception e) {
+        	fail("deleting a type which is in not in use should not throw exception! Exception
is: " + e);
+        }
+        
+        try {
+            fRepSvc.getTypeDefinition(repositoryId, TYPE_ID_MUTABILITY, null);
+        	fail("getting a type after it was deleted should fail.");
+        } catch (Exception e) {
+        }
+
+        try {
+        	fRepSvc.deleteTypeDefinition(repositoryId, BaseTypeId.CMIS_DOCUMENT.name(), null);
+        	fail("deleting a CMIS base type throw exception.");
+        } catch (Exception e) {
+        	assert(e instanceof CmisInvalidArgumentException);
         }
+        try {
+        	fRepSvc.deleteTypeDefinition(repositoryId, BaseTypeId.CMIS_FOLDER.name(), null);
+        	fail("deleting a CMIS base type throw exception.");
+        } catch (Exception e) {
+        	assert(e instanceof CmisInvalidArgumentException);
+        }
+
         log.info("... testTypeMutabilityDeletion() finished.");
     }
 
@@ -539,14 +572,11 @@ public class RepositoryServiceTest exten
         return repository.getId();
     }
 
-    // private boolean containsTypeById(String typeId,
-    // List<TypeDefinitionContainer> types) {
-    // for (TypeDefinitionContainer type : types) {
-    // if (type.getTypeDefinition().getId().equals(typeId))
-    // return true;
-    // }
-    // return false;
-    // }
+    private String getRootFolderId(String repositoryId) {
+    	RepositoryInfo repository = fRepSvc.getRepositoryInfo(repositoryId, null);
+        assertNotNull(repository);
+        return repository.getRootFolderId();
+    }
 
     private boolean containsTypeByIdRecursive(String typeId, List<TypeDefinitionContainer>
types) {
         for (TypeDefinitionContainer type : types) {
@@ -623,7 +653,7 @@ public class RepositoryServiceTest exten
 
     private TypeDefinition getTypeForAddingAtRuntime() {
         
-        InMemoryDocumentTypeDefinition cmisLaterType = new InMemoryDocumentTypeDefinition("BookTypeAddedLater",
+        InMemoryDocumentTypeDefinition cmisLaterType = new InMemoryDocumentTypeDefinition(TYPE_ID_MUTABILITY,
                 "Type with two properties", InMemoryDocumentTypeDefinition.getRootDocumentType());
 
         Map<String, PropertyDefinition<?>> propertyDefinitions = new HashMap<String,
PropertyDefinition<?>>();

Modified: incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeManager.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeManager.java?rev=1063665&r1=1063664&r2=1063665&view=diff
==============================================================================
--- incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeManager.java
(original)
+++ incubator/chemistry/opencmis-cmis11/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeManager.java
Wed Jan 26 09:59:29 2011
@@ -71,4 +71,21 @@ public interface TypeManager {
      */
     public abstract String getPropertyIdForQueryName(TypeDefinition typeDefinition, String
propQueryName);
 
+    /**
+     * Add a type to the type system. Add all properties from inherited types,
+     * add type to children of parent types.
+     * 
+     * @param cmisType
+     *            new type to add
+     */
+    public abstract void addTypeDefinition(TypeDefinition typeDefinition);
+    
+    /**
+     * Delete a type from the type system. Delete will succeed only if type is not in use.
+     * Otherwise an exception is thrown
+     * 
+     * @param cmisType
+     *            type to delete
+     */
+    public abstract void deleteTypeDefinition(String typeId);
 }
\ No newline at end of file



Mime
View raw message