chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r918361 - in /incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src: main/java/org/apache/opencmis/inmemory/ main/java/org/apache/opencmis/inmemory/server/ test/java/org/apache/opencmis/inmemory/
Date Wed, 03 Mar 2010 08:11:02 GMT
Author: jens
Date: Wed Mar  3 08:11:02 2010
New Revision: 918361

URL: http://svn.apache.org/viewvc?rev=918361&view=rev
Log:
InMemoryProvider: Fix an issue with the hierarchy structure in getTypesDescendants

Modified:
    incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/TypeManager.java
    incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/InMemoryRepositoryServiceImpl.java
    incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/RepositoryServiceTest.java

Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/TypeManager.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/TypeManager.java?rev=918361&r1=918360&r2=918361&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/TypeManager.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/TypeManager.java
Wed Mar  3 08:11:02 2010
@@ -69,7 +69,15 @@
    * @return
    */
   public synchronized Collection<TypeDefinitionContainer> getTypeDefinitionList() {
-    return fTypesMap.values();
+    
+    List<TypeDefinitionContainer> typeRoots = new ArrayList<TypeDefinitionContainer>();
+    // iterate types map and return a list collecting the root types:
+    for (TypeDefinitionContainer typeDef : fTypesMap.values()) {
+      if (typeDef.getTypeDefinition().getParentId()==null)
+        typeRoots.add(typeDef);
+    }
+    
+    return typeRoots;
   }
 
   /**

Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/InMemoryRepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/InMemoryRepositoryServiceImpl.java?rev=918361&r1=918360&r2=918361&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/InMemoryRepositoryServiceImpl.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/main/java/org/apache/opencmis/inmemory/server/InMemoryRepositoryServiceImpl.java
Wed Mar  3 08:11:02 2010
@@ -134,55 +134,61 @@
       // spec says that depth must be ignored in this case
         Collection<TypeDefinitionContainer> typeColl = fStoreManager.getTypeDefinitionList(repositoryId);
         result = new ArrayList<TypeDefinitionContainer>(typeColl);
+        if (!includePropertyDefinitions) {
+          // copy list and omit properties
+          for (TypeDefinitionContainer c : result) {
+            AbstractTypeDefinition td = ((AbstractTypeDefinition)c.getTypeDefinition()).clone();
+            TypeDefinitionContainerImpl tdc = new TypeDefinitionContainerImpl(td);
+            tdc.setChildren(c.getChildren());
+            td.setPropertyDefinitions(null);
+          }
+        }
     }
     else {
       TypeDefinitionContainer tc = fStoreManager.getTypeById(repositoryId, typeId);
       if (tc != null) {
-        if (null==depth || depth.intValue() == -1)
+        if (null==depth || depth.intValue() == -1) {
           result = tc.getChildren();
+          if (!includePropertyDefinitions)
+            cloneTypeList(depth.intValue()-1, false, result);
+        } else if (depth.intValue() == 0 || depth.intValue() < -1)
+          throw new CmisInvalidArgumentException("illegal depth value: " + depth.intValue());
       
         else {
-          result = getLimitedChildrenTypeList(depth.intValue(), tc.getChildren());
+          result = tc.getChildren();
+          cloneTypeList(depth.intValue()-1, includePropertyDefinitions, result);
         }
       }
       else
         throw new CmisInvalidArgumentException("unknown type id: " + typeId);        
     }
     
-    if (!includePropertyDefinitions) {
-      // copy list and omit properties
-      List<TypeDefinitionContainer> newResult = new ArrayList<TypeDefinitionContainer>(result.size());
-      for (TypeDefinitionContainer c : result) {
-        AbstractTypeDefinition td = ((AbstractTypeDefinition)c.getTypeDefinition()).clone();
-        TypeDefinitionContainerImpl tdc = new TypeDefinitionContainerImpl(td);
-        tdc.setChildren(c.getChildren());
-        td.setPropertyDefinitions(null);
-        newResult.add(tdc);
-      }
-      result = newResult;
-    }
     return result;
   }
 
-  private List<TypeDefinitionContainer> getLimitedChildrenTypeList(int depth,
+  /**
+   * traverse tree and replace each need node with a clone. remove properties on 
+   * clone if requested, cut children of clone if depth is exceeded.
+   * @param depth
+   * @param types
+   */
+  private void cloneTypeList(int depth, boolean includePropertyDefinitions,
       List<TypeDefinitionContainer> types) {
-    List<TypeDefinitionContainer> result = new ArrayList<TypeDefinitionContainer>();
-
-    for (TypeDefinitionContainer type : types) {
-      result.addAll(getLimitedChildrenTypeList(depth, type));
-    }
-    return result;
-  }
-
-  private List<TypeDefinitionContainer> getLimitedChildrenTypeList(int depth,
-      TypeDefinitionContainer root) {
-    List<TypeDefinitionContainer> typeDescs = new ArrayList<TypeDefinitionContainer>();
-    if (depth > 0 && root != null) {
-      typeDescs.add(root);
-      for (TypeDefinitionContainer c : root.getChildren()) {
-        typeDescs.addAll(getLimitedChildrenTypeList(depth - 1, c));
+  
+    ListIterator<TypeDefinitionContainer> it = types.listIterator();
+    while (it.hasNext()) {
+      TypeDefinitionContainer tdc = it.next();
+      AbstractTypeDefinition td = ((AbstractTypeDefinition)tdc.getTypeDefinition()).clone();
+      if (!includePropertyDefinitions)
+        td.setPropertyDefinitions(null);
+      TypeDefinitionContainerImpl tdcClone = new TypeDefinitionContainerImpl(td);
+      if (depth > 0) {
+        ArrayList<TypeDefinitionContainer> children = new ArrayList<TypeDefinitionContainer>(tdc.getChildren().size());
+        children.addAll(tdc.getChildren());
+        tdcClone.setChildren(children);
+        cloneTypeList(depth-1, includePropertyDefinitions, children);
       }
+      it.set(tdcClone);       
     }
-    return typeDescs;
   }
 
   private RepositoryInfoData getRepositoryInfoFromStoreManager(String repositoryId ) {

Modified: incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/RepositoryServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/RepositoryServiceTest.java?rev=918361&r1=918360&r2=918361&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/RepositoryServiceTest.java
(original)
+++ incubator/chemistry/trunk/opencmis/opencmis-server/opencmis-server-inmemory/src/test/java/org/apache/opencmis/inmemory/RepositoryServiceTest.java
Wed Mar  3 08:11:02 2010
@@ -174,10 +174,15 @@
         repositoryId, null/* all types */, BigInteger.valueOf(-1), Boolean.TRUE, null);
     assertNotNull(types);
     log.info("Repository " + repositoryId + " contains " + types.size() + " type(s).");
+    
+    
     // check that we got all types
     int expectedSize = RepositoryTestTypeSystemCreator.getTypesList().size()
         + DocumentTypeCreationHelper.getDefaultTypes().size();
-    assertEquals(expectedSize, types.size());
+    int totalSize = getRecursiveSize(types);
+
+    assertEquals(expectedSize, totalSize);
+    assertEquals(2, types.size());
 
     for (TypeDefinitionContainer type : types) {
       assertNotNull(type);
@@ -203,9 +208,9 @@
     String repositoryId = getRepositoryId();
 
     // get types
-    int depth = 2;
+    int depth = 1;
     List<TypeDefinitionContainer> types = fRepSvc.getTypeDescendants(
-        repositoryId, null/* all types */, BigInteger.valueOf(depth), Boolean.TRUE, null);
+        repositoryId, BaseObjectTypeIds.CMIS_DOCUMENT.value(), BigInteger.valueOf(depth),
Boolean.TRUE, null);
     assertNotNull(types);
     log.info("Found in repository " + repositoryId + " " + types.size() + " type(s) with
depth "
         + depth + ".");
@@ -218,15 +223,15 @@
       containsAllBasePropertyDefinitions(typeDef);
     }
 
-    assertEquals(21, types.size()); // Note that spec says that has to be ignored if type
is null.
-    assertTrue(containsTypeById(BaseObjectTypeIds.CMIS_DOCUMENT.value(), types));
-    assertTrue(containsTypeById(BaseObjectTypeIds.CMIS_FOLDER.value(), types));
-    // Commented out, because spec requires not to deliver these types if policies and relations
-    // are not supported
-//    assertTrue(containsTypeById(BaseObjectTypeIds.CMIS_RELATIONSHIP.value(), types));
-//    assertTrue(containsTypeById(BaseObjectTypeIds.CMIS_POLICY.value(), types));
-    assertTrue(containsTypeById("MyDocType1", types));
-    assertTrue(containsTypeById("MyDocType2", types));
+    int totalSize = getRecursiveSize(types);
+    assertEquals(4, totalSize); // all RepositoryTestTypeSystemCreator types minus one in
level two plus cmis.docment
+    assertFalse(containsTypeByIdRecursive(BaseObjectTypeIds.CMIS_DOCUMENT.value(), types));
+    assertFalse(containsTypeByIdRecursive(BaseObjectTypeIds.CMIS_FOLDER.value(), types));
+    
+    assertTrue(containsTypeByIdRecursive("MyDocType1", types));
+    assertTrue(containsTypeByIdRecursive("MyDocType2", types));
+
+    assertFalse(containsTypeByIdRecursive(RepositoryTestTypeSystemCreator.LEVEL2_TYPE, types));
 
     for (TypeDefinitionContainer type : types) {
       assertNotNull(type);
@@ -254,12 +259,11 @@
     log.info("Found in repository " + repositoryId + " for type " + typeId + ", " + types.size()
         + " type(s) with depth " + depth + ".");
 
-    assertEquals(4, types.size());
-    assertTrue(containsTypeById("MyDocType1.1", types));
-    assertTrue(containsTypeById("MyDocType1.1.1", types));
-    assertTrue(containsTypeById("MyDocType1.1.2", types));
-    assertTrue(containsTypeById("MyDocType1.2", types));
-
+    assertEquals(4, getRecursiveSize(types));
+    assertTrue(containsTypeByIdRecursive("MyDocType1.1", types));
+    assertTrue(containsTypeByIdRecursive("MyDocType1.2", types));
+    assertTrue(containsTypeByIdRecursive("MyDocType1.1.1", types));
+    assertTrue(containsTypeByIdRecursive("MyDocType1.1.2", types));
     for (TypeDefinitionContainer type : types) {
       assertNotNull(type);
       TypeDefinition typeDef = type.getTypeDefinition();
@@ -493,6 +497,25 @@
     return false;
   }
   
+  private boolean containsTypeByIdRecursive(String typeId, List<TypeDefinitionContainer>
types) {
+    for (TypeDefinitionContainer type : types) {
+      if (containsTypeByIdRecursive(typeId, type))
+        return true;
+    }
+    return false;
+  }
+  
+  private boolean containsTypeByIdRecursive(String typeId, TypeDefinitionContainer typeContainer)
{
+    if (typeId.equals(typeContainer.getTypeDefinition().getId()))
+      return true;
+    
+    for (TypeDefinitionContainer type : typeContainer.getChildren()) {
+      if (containsTypeByIdRecursive(typeId, type))
+        return true;      
+    }
+    return false;
+  }
+
   private void containsAllBasePropertyDefinitions(TypeDefinition typeDef) {
     Map<String, PropertyDefinition<?>> propDefs = typeDef.getPropertyDefinitions();
     String baseTypeId = typeDef.getBaseId().value();
@@ -536,6 +559,17 @@
       fail("Unknown base type id in type definition");
   }
   
+  private int getRecursiveSize(List<TypeDefinitionContainer> types) {
+    if (null == types)
+      return 0;
+    
+    int size = types.size();
+    for (TypeDefinitionContainer type: types)
+      size += getRecursiveSize(type.getChildren());
+    
+    return size;
+  }
+  
   public static class RepositoryTestTypeSystemCreator implements TypeCreator {
 
     public static final String COMPLEX_TYPE = "ComplexType";



Mime
View raw message