chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1512023 - in /chemistry/opencmis/trunk: chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/ chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/j...
Date Thu, 08 Aug 2013 20:40:12 GMT
Author: fmui
Date: Thu Aug  8 20:40:11 2013
New Revision: 1512023

URL: http://svn.apache.org/r1512023
Log:
added createTypeDescendants to TypeDefinitionFactory

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/TypeMutabilityImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeDefinitionFactory.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/TypeDefinitionFactoryTest.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/TypeMutabilityImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/TypeMutabilityImpl.java?rev=1512023&r1=1512022&r2=1512023&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/TypeMutabilityImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/TypeMutabilityImpl.java
Thu Aug  8 20:40:11 2013
@@ -52,4 +52,9 @@ public class TypeMutabilityImpl extends 
         this.canDelete = canDelete;
     }
 
+    @Override
+    public String toString() {
+        return "TypeMutability [canCreate=" + canCreate + ", canUpdate=" + canUpdate + ",
canDelete=" + canDelete + "]"
+                + super.toString();
+    }
 }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeDefinitionFactory.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/TypeDefinitionFactory.java?rev=1512023&r1=1512022&r2=1512023&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeDefinitionFactory.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeDefinitionFactory.java
Thu Aug  8 20:40:11 2013
@@ -22,7 +22,6 @@ package org.apache.chemistry.opencmis.se
 
 import java.math.BigInteger;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -55,6 +54,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.definitions.PropertyUriDefinition;
 import org.apache.chemistry.opencmis.commons.definitions.RelationshipTypeDefinition;
 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.definitions.TypeMutability;
 import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
@@ -63,6 +63,8 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.enums.ContentStreamAllowed;
 import org.apache.chemistry.opencmis.commons.enums.PropertyType;
 import org.apache.chemistry.opencmis.commons.enums.Updatability;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.ChoiceImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl;
@@ -80,8 +82,10 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyUriDefinitionImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.RelationshipTypeDefinitionImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.SecondaryTypeDefinitionImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeDefinitionContainerImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeDefinitionListImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeMutabilityImpl;
+import org.apache.chemistry.opencmis.commons.spi.RepositoryService;
 
 /**
  * Type definition factory.
@@ -607,8 +611,17 @@ public class TypeDefinitionFactory {
         return childType;
     }
 
-    public TypeDefinitionList createTypeDefinitionList(Collection<TypeDefinition> allTypes,
String typeId,
+    /**
+     * Creates a {@link TypeDefinitionList} for
+     * {@link RepositoryService#getTypeChildren(String, String, Boolean, BigInteger, BigInteger,
ExtensionsData)}
+     * .
+     */
+    public TypeDefinitionList createTypeDefinitionList(Map<String, TypeDefinition>
allTypes, String typeId,
             Boolean includePropertyDefinitions, BigInteger maxItems, BigInteger skipCount)
{
+        if (typeId != null && !allTypes.containsKey(typeId)) {
+            throw new CmisObjectNotFoundException("Type '" + typeId + "' does not exist!");
+        }
+
         TypeDefinitionListImpl result = new TypeDefinitionListImpl(Collections.<TypeDefinition>
emptyList());
         result.setHasMoreItems(false);
         result.setNumItems(BigInteger.ZERO);
@@ -634,7 +647,7 @@ public class TypeDefinitionFactory {
                 : includePropertyDefinitions.booleanValue());
 
         List<TypeDefinition> targetList = new ArrayList<TypeDefinition>();
-        for (TypeDefinition typeDef : allTypes) {
+        for (TypeDefinition typeDef : allTypes.values()) {
             if ((typeId == null && typeDef.getParentTypeId() == null)
                     || (typeId != null && typeId.equals(typeDef.getParentTypeId())))
{
                 if (includePropertyDefinitionsBool) {
@@ -677,6 +690,72 @@ public class TypeDefinitionFactory {
         return result;
     }
 
+    /**
+     * Creates a list of {@link TypeDefinitionContainer} for
+     * {@link RepositoryService#getTypeDescendants(String, String, BigInteger, Boolean, ExtensionsData)}
+     * .
+     */
+    public List<TypeDefinitionContainer> createTypeDescendants(Map<String, TypeDefinition>
allTypes, String typeId,
+            BigInteger depth, Boolean includePropertyDefinitions) {
+        int depthInt = (depth == null ? -1 : depth.intValue());
+        if (depthInt == 0) {
+            throw new CmisInvalidArgumentException("Depth must not be 0!");
+        }
+
+        if (typeId != null && !allTypes.containsKey(typeId)) {
+            throw new CmisObjectNotFoundException("Type '" + typeId + "' does not exist!");
+        }
+
+        if (allTypes == null || allTypes.isEmpty()) {
+            return Collections.<TypeDefinitionContainer> emptyList();
+        }
+
+        boolean includePropertyDefinitionsBool = (includePropertyDefinitions == null ? false
+                : includePropertyDefinitions.booleanValue());
+
+        Map<String, Set<String>> typeDefChildren = new HashMap<String, Set<String>>();
+
+        for (TypeDefinition typeDef : allTypes.values()) {
+            Set<String> children = typeDefChildren.get(typeDef.getParentTypeId());
+            if (children == null) {
+                children = new HashSet<String>();
+                typeDefChildren.put(typeDef.getParentTypeId(), children);
+            }
+            children.add(typeDef.getId());
+        }
+
+        Set<String> children = typeDefChildren.get(typeId);
+        if (children == null) {
+            return Collections.<TypeDefinitionContainer> emptyList();
+        }
+
+        List<TypeDefinitionContainer> result = new ArrayList<TypeDefinitionContainer>();
+        for (String child : children) {
+            result.add(createTypeDefinitionContainer(allTypes, typeDefChildren, child, depthInt
- 1,
+                    includePropertyDefinitionsBool));
+        }
+
+        return result;
+    }
+
+    private TypeDefinitionContainer createTypeDefinitionContainer(Map<String, TypeDefinition>
allTypes,
+            Map<String, Set<String>> typeDefChildren, String typeId, int depth,
boolean includePropertyDefinitions) {
+        TypeDefinitionContainerImpl result = new TypeDefinitionContainerImpl();
+        result.setTypeDefinition(includePropertyDefinitions ? allTypes.get(typeId) : copy(allTypes.get(typeId),
false));
+
+        if (depth != 0) {
+            if (typeDefChildren.containsKey(typeId)) {
+                for (String child : typeDefChildren.get(typeId)) {
+                    result.getChildren().add(
+                            createTypeDefinitionContainer(allTypes, typeDefChildren, child,
depth < 0 ? -1 : depth - 1,
+                                    includePropertyDefinitions));
+                }
+            }
+        }
+
+        return result;
+    }
+
     // --- copy methods ---
 
     /**

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/TypeDefinitionFactoryTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/TypeDefinitionFactoryTest.java?rev=1512023&r1=1512022&r2=1512023&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/TypeDefinitionFactoryTest.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/TypeDefinitionFactoryTest.java
Thu Aug  8 20:40:11 2013
@@ -24,9 +24,11 @@ import static org.junit.Assert.*;
 
 import java.math.BigInteger;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 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.CmisVersion;
 import org.junit.Test;
@@ -89,7 +91,7 @@ public class TypeDefinitionFactoryTest {
         folderType = tdf.createBaseFolderTypeDefinition(cmisVersion);
         types.put(folderType.getId(), folderType);
 
-        TypeDefinitionList tdl1 = tdf.createTypeDefinitionList(types.values(), null, true,
null, null);
+        TypeDefinitionList tdl1 = tdf.createTypeDefinitionList(types, null, true, null, null);
         assertNotNull(tdl1);
         assertEquals(2, tdl1.getList().size());
         assertEquals(2, tdl1.getNumItems().intValue());
@@ -97,29 +99,33 @@ public class TypeDefinitionFactoryTest {
 
         assertEquals("cmis:document", tdl1.getList().get(0).getId());
         assertEquals("cmis:folder", tdl1.getList().get(1).getId());
+        assertEquals(26, tdl1.getList().get(0).getPropertyDefinitions().size());
+        assertEquals(14, tdl1.getList().get(1).getPropertyDefinitions().size());
 
-        TypeDefinitionList tdl2 = tdf.createTypeDefinitionList(types.values(), "cmis:document",
true, null, null);
+        TypeDefinitionList tdl2 = tdf.createTypeDefinitionList(types, "cmis:document", false,
null, null);
         assertNotNull(tdl2);
         assertEquals(5, tdl2.getList().size());
         assertEquals(5, tdl2.getNumItems().intValue());
         assertEquals(Boolean.FALSE, tdl2.hasMoreItems());
+        assertTrue(tdl2.getList().get(0).getPropertyDefinitions().isEmpty());
 
-        TypeDefinitionList tdl3 = tdf.createTypeDefinitionList(types.values(), "cmis:document",
true,
-                BigInteger.valueOf(3), BigInteger.ZERO);
+        TypeDefinitionList tdl3 = tdf.createTypeDefinitionList(types, "cmis:document", true,
BigInteger.valueOf(3),
+                BigInteger.ZERO);
         assertNotNull(tdl3);
         assertEquals(3, tdl3.getList().size());
         assertEquals(5, tdl3.getNumItems().intValue());
         assertEquals(Boolean.TRUE, tdl3.hasMoreItems());
+        assertFalse(tdl3.getList().get(0).getPropertyDefinitions().isEmpty());
 
-        TypeDefinitionList tdl4 = tdf.createTypeDefinitionList(types.values(), "cmis:document",
true,
-                BigInteger.valueOf(3), BigInteger.valueOf(2));
+        TypeDefinitionList tdl4 = tdf.createTypeDefinitionList(types, "cmis:document", true,
BigInteger.valueOf(3),
+                BigInteger.valueOf(2));
         assertNotNull(tdl4);
         assertEquals(3, tdl4.getList().size());
         assertEquals(5, tdl4.getNumItems().intValue());
         assertEquals(Boolean.FALSE, tdl4.hasMoreItems());
 
-        TypeDefinitionList tdl5 = tdf.createTypeDefinitionList(types.values(), "cmis:document",
true,
-                BigInteger.valueOf(2), BigInteger.valueOf(2));
+        TypeDefinitionList tdl5 = tdf.createTypeDefinitionList(types, "cmis:document", true,
BigInteger.valueOf(2),
+                BigInteger.valueOf(2));
         assertNotNull(tdl5);
         assertEquals(2, tdl5.getList().size());
         assertEquals(5, tdl5.getNumItems().intValue());
@@ -137,6 +143,52 @@ public class TypeDefinitionFactoryTest {
         assertEquals(tdl4.getList().get(0).getId(), tdl5.getList().get(0).getId());
     }
 
+    @Test
+    public void testCreateTypeDescendants() {
+        TypeDefinitionFactory tdf = TypeDefinitionFactory.newInstance();
+        CmisVersion cmisVersion = CmisVersion.CMIS_1_1;
+        Map<String, TypeDefinition> types = new HashMap<String, TypeDefinition>();
+
+        TypeDefinition type;
+        TypeDefinition type2;
+        TypeDefinition docType;
+        TypeDefinition folderType;
+
+        docType = tdf.createBaseDocumentTypeDefinition(cmisVersion);
+        types.put(docType.getId(), docType);
+
+        type = tdf.createChildTypeDefinition(docType, "test:docType1");
+        types.put(type.getId(), type);
+
+        type2 = tdf.createChildTypeDefinition(docType, "test:docType2");
+        types.put(type2.getId(), type2);
+
+        type = tdf.createChildTypeDefinition(type2, "test:docType2-1");
+        types.put(type.getId(), type);
+
+        type = tdf.createChildTypeDefinition(type2, "test:docType2-2");
+        types.put(type.getId(), type);
+
+        type = tdf.createChildTypeDefinition(type2, "test:docType2-3");
+        types.put(type.getId(), type);
+
+        folderType = tdf.createBaseFolderTypeDefinition(cmisVersion);
+        types.put(folderType.getId(), folderType);
+
+        List<TypeDefinitionContainer> typeDefs;
+
+        typeDefs = tdf.createTypeDescendants(types, null, BigInteger.valueOf(-1), null);
+        assertNotNull(typeDefs);
+        assertEquals(2, typeDefs.size());
+
+        typeDefs = tdf.createTypeDescendants(types, null, BigInteger.valueOf(1), null);
+        assertNotNull(typeDefs);
+        assertEquals(2, typeDefs.size());
+        assertEquals(0, typeDefs.get(0).getChildren().size());
+        assertEquals(0, typeDefs.get(1).getChildren().size());
+
+    }
+
     private void assertTypeDefinition(TypeDefinition typeDef) {
         assertNotNull(typeDef);
         assertNotNull(typeDef.getBaseTypeId());



Mime
View raw message