You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2012/09/04 16:48:19 UTC

svn commit: r1380670 - in /chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/scripts: script-library.properties stats.groovy

Author: fmui
Date: Tue Sep  4 14:48:19 2012
New Revision: 1380670

URL: http://svn.apache.org/viewvc?rev=1380670&view=rev
Log:
Workbench: added object counting script

Added:
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/scripts/stats.groovy
Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/scripts/script-library.properties

Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/scripts/script-library.properties
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/scripts/script-library.properties?rev=1380670&r1=1380669&r2=1380670&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/scripts/script-library.properties (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/scripts/script-library.properties Tue Sep  4 14:48:19 2012
@@ -32,3 +32,4 @@ query.groovy = Execute a query
 counttypes.groovy = Count types and sub types
 upload.groovy = Upload a local folder to the repository
 ping.groovy = Ping the repository
+stats.groovy = Count objects and bytes

Added: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/scripts/stats.groovy
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/scripts/stats.groovy?rev=1380670&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/scripts/stats.groovy (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/scripts/stats.groovy Tue Sep  4 14:48:19 2012
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+import org.apache.chemistry.opencmis.commons.*
+import org.apache.chemistry.opencmis.commons.data.*
+import org.apache.chemistry.opencmis.commons.enums.*
+import org.apache.chemistry.opencmis.client.api.*
+
+
+Folder folder = (Folder) session.getObjectByPath("/");
+
+
+def stats = count(folder, true);
+
+println "Folder " + folder.getName();
+println "----------------------------------------------";
+println "Folders:   " + stats["folders"];
+println "Documents: " + stats["documents"];
+println "Policies:  " + stats["policies"];
+println "Content:   " + stats["bytes"] + " bytes";
+
+
+
+def count(Folder folder, boolean tree = false) {
+    def stats = [:];
+    stats["folders"] = 0;
+    stats["documents"] = 0;
+    stats["policies"] = 0;
+    stats["bytes"] = 0;
+
+    OperationContext oc = session.createOperationContext();
+    oc.setFilterString("cmis:objectId,cmis:contentStreamLength");
+    oc.setIncludeAllowableActions(false);
+    oc.setMaxItemsPerPage(10000);
+
+    countInternal(folder, tree, oc, stats);
+    
+    return stats;
+}
+
+def countInternal(Folder folder, boolean tree, OperationContext oc, def stats) {
+    for(CmisObject child: folder.getChildren(oc)) {
+        if(child instanceof Folder) {
+            stats["folders"]++;
+            if (tree) { countInternal(child, true, oc, stats); }
+        } else if(child instanceof Document) {
+            stats["documents"]++;  
+            long size =((Document) child).getContentStreamLength();
+            if (size > 0) { stats["bytes"] += size; }
+        } else if(child instanceof Policy) {
+            stats["policies"]++;
+        }
+    }
+}
\ No newline at end of file