chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1511471 - in /chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src: main/java/org/apache/chemistry/opencmis/server/support/ test/java/org/apache/chemistry/opencmis/server/support/
Date Wed, 07 Aug 2013 20:22:42 GMT
Author: fmui
Date: Wed Aug  7 20:22:42 2013
New Revision: 1511471

URL: http://svn.apache.org/r1511471
Log:
added createTypeDefinitionList to TypeDefinitionFactory

Added:
    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-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeDefinitionFactory.java

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=1511471&r1=1511470&r2=1511471&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
Wed Aug  7 20:22:42 2013
@@ -20,7 +20,11 @@
  */
 package org.apache.chemistry.opencmis.server.support;
 
+import java.math.BigInteger;
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -51,6 +55,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.TypeDefinitionList;
 import org.apache.chemistry.opencmis.commons.definitions.TypeMutability;
 import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
 import org.apache.chemistry.opencmis.commons.enums.Cardinality;
@@ -75,6 +80,7 @@ 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.TypeDefinitionListImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeMutabilityImpl;
 
 /**
@@ -601,6 +607,74 @@ public class TypeDefinitionFactory {
         return childType;
     }
 
+    public TypeDefinitionList createTypeDefinitionList(Collection<TypeDefinition> allTypes,
String typeId,
+            Boolean includePropertyDefinitions, BigInteger maxItems, BigInteger skipCount)
{
+        TypeDefinitionListImpl result = new TypeDefinitionListImpl(Collections.<TypeDefinition>
emptyList());
+        result.setHasMoreItems(false);
+        result.setNumItems(BigInteger.ZERO);
+
+        if (allTypes == null || allTypes.isEmpty()) {
+            return result;
+        }
+
+        int maxItemsInt = (maxItems == null ? Integer.MAX_VALUE : maxItems.intValue());
+        if (maxItemsInt <= 0) {
+            return result;
+        }
+
+        int skipCountInt = (skipCount == null ? 0 : skipCount.intValue());
+        if (skipCountInt < 0) {
+            skipCountInt = 0;
+        }
+        if (skipCountInt > allTypes.size()) {
+            return result;
+        }
+
+        boolean includePropertyDefinitionsBool = (includePropertyDefinitions == null ? false
+                : includePropertyDefinitions.booleanValue());
+
+        List<TypeDefinition> targetList = new ArrayList<TypeDefinition>();
+        for (TypeDefinition typeDef : allTypes) {
+            if ((typeId == null && typeDef.getParentTypeId() == null)
+                    || (typeId != null && typeId.equals(typeDef.getParentTypeId())))
{
+                if (includePropertyDefinitionsBool) {
+                    targetList.add(typeDef);
+                } else {
+                    targetList.add(copy(typeDef, false));
+                }
+            }
+        }
+
+        Collections.sort(targetList, new Comparator<TypeDefinition>() {
+            public int compare(TypeDefinition td1, TypeDefinition td2) {
+                String pid1 = td1.getParentTypeId();
+                String pid2 = td2.getParentTypeId();
+                if (pid1 == null && pid2 != null) {
+                    return -1;
+                }
+                if (pid1 != null && pid2 == null) {
+                    return 1;
+                }
+                if (pid1 == null && pid2 == null) {
+                    return td1.getId().compareTo(td2.getId());
+                }
+
+                int c = pid1.compareTo(pid2);
+                if (c == 0) {
+                    return td1.getId().compareTo(td2.getId());
+                }
+
+                return c;
+            }
+        });
+
+        result.setList(targetList.subList(skipCountInt, Math.min(skipCountInt + maxItemsInt,
targetList.size())));
+        result.setNumItems(BigInteger.valueOf(targetList.size()));
+        result.setHasMoreItems(targetList.size() > skipCountInt + maxItemsInt);
+
+        return result;
+    }
+
     // --- copy methods ---
 
     /**

Added: 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=1511471&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/TypeDefinitionFactoryTest.java
(added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/TypeDefinitionFactoryTest.java
Wed Aug  7 20:22:42 2013
@@ -0,0 +1,146 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.chemistry.opencmis.server.support;
+
+import static org.junit.Assert.*;
+
+import java.math.BigInteger;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionList;
+import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
+import org.junit.Test;
+
+public class TypeDefinitionFactoryTest {
+
+    @Test
+    public void testTypeDefinitionFactory() {
+        TypeDefinitionFactory tdf = TypeDefinitionFactory.newInstance();
+        assertNotNull(tdf);
+        assertNotNull(tdf.getDocumentTypeDefinitionClass());
+        assertNotNull(tdf.getFolderTypeDefinitionClass());
+        assertNotNull(tdf.getPolicyTypeDefinitionClass());
+        assertNotNull(tdf.getRelationshipTypeDefinitionClass());
+        assertNotNull(tdf.getItemTypeDefinitionClass());
+        assertNotNull(tdf.getSecondaryTypeDefinitionClass());
+    }
+
+    @Test
+    public void testCreateBaseTypes() {
+        TypeDefinitionFactory tdf = TypeDefinitionFactory.newInstance();
+        CmisVersion cmisVersion = CmisVersion.CMIS_1_1;
+
+        assertTypeDefinition(tdf.createBaseDocumentTypeDefinition(cmisVersion));
+        assertTypeDefinition(tdf.createBaseFolderTypeDefinition(cmisVersion));
+        assertTypeDefinition(tdf.createBasePolicyTypeDefinition(cmisVersion));
+        assertTypeDefinition(tdf.createBaseRelationshipTypeDefinition(cmisVersion));
+        assertTypeDefinition(tdf.createBaseItemTypeDefinition(cmisVersion));
+        assertTypeDefinition(tdf.createBaseSecondaryTypeDefinition(cmisVersion));
+    }
+
+    @Test
+    public void testCreateTypeDefinitionList() {
+        TypeDefinitionFactory tdf = TypeDefinitionFactory.newInstance();
+        CmisVersion cmisVersion = CmisVersion.CMIS_1_1;
+        Map<String, TypeDefinition> types = new HashMap<String, TypeDefinition>();
+
+        TypeDefinition type;
+        TypeDefinition docType;
+        TypeDefinition folderType;
+
+        docType = tdf.createBaseDocumentTypeDefinition(cmisVersion);
+        types.put(docType.getId(), docType);
+
+        type = tdf.createChildTypeDefinition(docType, "test:docType1");
+        types.put(type.getId(), type);
+
+        type = tdf.createChildTypeDefinition(docType, "test:docType2");
+        types.put(type.getId(), type);
+
+        type = tdf.createChildTypeDefinition(docType, "test:docType3");
+        types.put(type.getId(), type);
+
+        type = tdf.createChildTypeDefinition(docType, "test:docType4");
+        types.put(type.getId(), type);
+
+        type = tdf.createChildTypeDefinition(docType, "test:docType5");
+        types.put(type.getId(), type);
+
+        folderType = tdf.createBaseFolderTypeDefinition(cmisVersion);
+        types.put(folderType.getId(), folderType);
+
+        TypeDefinitionList tdl1 = tdf.createTypeDefinitionList(types.values(), null, true,
null, null);
+        assertNotNull(tdl1);
+        assertEquals(2, tdl1.getList().size());
+        assertEquals(2, tdl1.getNumItems().intValue());
+        assertEquals(Boolean.FALSE, tdl1.hasMoreItems());
+
+        assertEquals("cmis:document", tdl1.getList().get(0).getId());
+        assertEquals("cmis:folder", tdl1.getList().get(1).getId());
+
+        TypeDefinitionList tdl2 = tdf.createTypeDefinitionList(types.values(), "cmis:document",
true, null, null);
+        assertNotNull(tdl2);
+        assertEquals(5, tdl2.getList().size());
+        assertEquals(5, tdl2.getNumItems().intValue());
+        assertEquals(Boolean.FALSE, tdl2.hasMoreItems());
+
+        TypeDefinitionList tdl3 = tdf.createTypeDefinitionList(types.values(), "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());
+
+        TypeDefinitionList tdl4 = tdf.createTypeDefinitionList(types.values(), "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));
+        assertNotNull(tdl5);
+        assertEquals(2, tdl5.getList().size());
+        assertEquals(5, tdl5.getNumItems().intValue());
+        assertEquals(Boolean.TRUE, tdl5.hasMoreItems());
+
+        assertEquals("test:docType1", tdl2.getList().get(0).getId());
+        assertEquals("test:docType2", tdl2.getList().get(1).getId());
+        assertEquals("test:docType3", tdl2.getList().get(2).getId());
+        assertEquals("test:docType4", tdl2.getList().get(3).getId());
+        assertEquals("test:docType5", tdl2.getList().get(4).getId());
+
+        assertEquals(tdl2.getList().get(0).getId(), tdl3.getList().get(0).getId());
+        assertEquals(tdl2.getList().get(2).getId(), tdl4.getList().get(0).getId());
+        assertEquals(tdl2.getList().get(2).getId(), tdl5.getList().get(0).getId());
+        assertEquals(tdl4.getList().get(0).getId(), tdl5.getList().get(0).getId());
+    }
+
+    private void assertTypeDefinition(TypeDefinition typeDef) {
+        assertNotNull(typeDef);
+        assertNotNull(typeDef.getBaseTypeId());
+        assertNotNull(typeDef.getId());
+
+    }
+}



Mime
View raw message