chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1044039 - in /incubator/chemistry/opencmis-browser-binding/trunk/src/main: java/org/apache/chemistry/opencmis/server/impl/browser/ java/org/apache/chemistry/opencmis/server/impl/browser/json/ webapp/
Date Thu, 09 Dec 2010 17:09:59 GMT
Author: fmui
Date: Thu Dec  9 17:09:59 2010
New Revision: 1044039

URL: http://svn.apache.org/viewvc?rev=1044039&view=rev
Log:
- added type discovery to browser binding

Modified:
    incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/RepositoryService.java
    incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConstants.java
    incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConverter.java
    incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/demo.html

Modified: incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/RepositoryService.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/RepositoryService.java?rev=1044039&r1=1044038&r2=1044039&view=diff
==============================================================================
--- incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/RepositoryService.java
(original)
+++ incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/RepositoryService.java
Thu Dec  9 17:09:59 2010
@@ -18,16 +18,27 @@
  */
 package org.apache.chemistry.opencmis.server.impl.browser;
 
+import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getBigIntegerParameter;
+import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getBooleanParameter;
+import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getStringParameter;
+
+import java.math.BigInteger;
 import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
+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.exceptions.CmisRuntimeException;
+import org.apache.chemistry.opencmis.commons.impl.Constants;
 import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
 import org.apache.chemistry.opencmis.commons.server.CallContext;
 import org.apache.chemistry.opencmis.commons.server.CmisService;
 import org.apache.chemistry.opencmis.server.impl.browser.json.JSONConverter;
+import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
 
 public final class RepositoryService {
@@ -69,13 +80,44 @@ public final class RepositoryService {
      */
     public static void getTypeChildren(CallContext context, CmisService service, String repositoryId,
             HttpServletRequest request, HttpServletResponse response) throws Exception {
+        // get parameters
+        String typeId = getStringParameter(request, Constants.PARAM_TYPE_ID);
+        boolean includePropertyDefinitions = getBooleanParameter(request, Constants.PARAM_PROPERTY_DEFINITIONS,
false);
+        BigInteger maxItems = getBigIntegerParameter(request, Constants.PARAM_MAX_ITEMS);
+        BigInteger skipCount = getBigIntegerParameter(request, Constants.PARAM_SKIP_COUNT);
+
+        // execute
+        TypeDefinitionList typeList = service.getTypeChildren(repositoryId, typeId, includePropertyDefinitions,
+                maxItems, skipCount, null);
+
+        BrowserBindingUtils.writeJSON(JSONConverter.convert(typeList), request, response);
     }
 
     /**
      * getTypeDescendants.
      */
+    @SuppressWarnings("unchecked")
     public static void getTypeDescendants(CallContext context, CmisService service, String
repositoryId,
             HttpServletRequest request, HttpServletResponse response) throws Exception {
+        // get parameters
+        String typeId = getStringParameter(request, Constants.PARAM_TYPE_ID);
+        BigInteger depth = getBigIntegerParameter(request, Constants.PARAM_DEPTH);
+        boolean includePropertyDefinitions = getBooleanParameter(request, Constants.PARAM_PROPERTY_DEFINITIONS,
false);
+
+        // execute
+        List<TypeDefinitionContainer> typeTree = service.getTypeDescendants(repositoryId,
typeId, depth,
+                includePropertyDefinitions, null);
+
+        if (typeTree == null) {
+            throw new CmisRuntimeException("Type tree is null!");
+        }
+
+        JSONArray jsonTypeTree = new JSONArray();
+        for (TypeDefinitionContainer container : typeTree) {
+            jsonTypeTree.add(JSONConverter.convert(container));
+        }
+
+        BrowserBindingUtils.writeJSON(jsonTypeTree, request, response);
     }
 
     /**
@@ -83,5 +125,12 @@ public final class RepositoryService {
      */
     public static void getTypeDefintion(CallContext context, CmisService service, String
repositoryId,
             HttpServletRequest request, HttpServletResponse response) throws Exception {
+        // get parameters
+        String typeId = getStringParameter(request, Constants.PARAM_TYPE_ID);
+
+        // execute
+        TypeDefinition type = service.getTypeDefinition(repositoryId, typeId, null);
+
+        BrowserBindingUtils.writeJSON(JSONConverter.convert(type), request, response);
     }
 }

Modified: incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConstants.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConstants.java?rev=1044039&r1=1044038&r2=1044039&view=diff
==============================================================================
--- incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConstants.java
(original)
+++ incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConstants.java
Thu Dec  9 17:09:59 2010
@@ -84,9 +84,9 @@ public class JSONConstants {
     public final static String JSON_OBJECTPARENTS_RELATIVE_PATH_SEGMENT = "relativePathSegment";
 
     public final static String JSON_PROPERTY_ID = "id";
-    public final static String JSON_PROPERTY_LOCAL_NAME = "localName";
-    public final static String JSON_PROPERTY_DISPLAY_NAME = "displayName";
-    public final static String JSON_PROPERTY_QUERY_NAME = "queryName";
+    public final static String JSON_PROPERTY_LOCALNAME = "localName";
+    public final static String JSON_PROPERTY_DISPLAYNAME = "displayName";
+    public final static String JSON_PROPERTY_QUERYNAME = "queryName";
     public final static String JSON_PROPERTY_VALUE = "value";
     public final static String JSON_PROPERTY_DATATYPE = "type";
     public final static String JSON_PROPERTY_CARDINALITY = "cardinality";
@@ -135,8 +135,8 @@ public class JSONConstants {
     public final static String JSON_TYPE_QUERYABLE = "queryable";
     public final static String JSON_TYPE_FULLTEXT_INDEXED = "fulltextIndexed";
     public final static String JSON_TYPE_INCLUDE_IN_SUPERTYPE_QUERY = "includedInSupertypeQuery";
-    public final static String JSON_TYPE_INCLUDE_CONTROLABLE_POLICY = "controllablePolicy";
-    public final static String JSON_TYPE_INCLUDE_CONTROLABLE_ACL = "controllableACL";
+    public final static String JSON_TYPE_CONTROLABLE_POLICY = "controllablePolicy";
+    public final static String JSON_TYPE_CONTROLABLE_ACL = "controllableACL";
     public final static String JSON_TYPE_PROPERTY_DEFINITIONS = "propertyDefinitions";
 
     public final static String JSON_TYPE_VERSIONABLE = "versionable"; // document
@@ -155,6 +155,7 @@ public class JSONConstants {
     public final static String JSON_PROPERTYTYPE_CARDINALITY = "cardinality";
     public final static String JSON_PROPERTYTYPE_UPDATABILITY = "updatability";
     public final static String JSON_PROPERTYTYPE_INHERITED = "inherited";
+    public final static String JSON_PROPERTYTYPE_REQUIRED = "required";
     public final static String JSON_PROPERTYTYPE_QUERYABLE = "queryable";
     public final static String JSON_PROPERTYTYPE_OPENCHOICE = "openChoice";
 
@@ -169,4 +170,11 @@ public class JSONConstants {
     public final static String JSON_PROPERTYTYPE_CHOICE_DISPLAYNAME = "displayName";
     public final static String JSON_PROPERTYTYPE_CHOICE_VALUE = "value";
     public final static String JSON_PROPERTYTYPE_CHOICE_CHOICE = "choice";
+
+    public final static String JSON_TYPESLIST_TYPES = "types";
+    public final static String JSON_TYPESLIST_HAS_MORE_ITEMS = "hasMoreItems";
+    public final static String JSON_TYPESLIST_NUM_ITEMS = "numItems";
+
+    public final static String JSON_TYPESCONTAINER_TYPE = "type";
+    public final static String JSON_TYPESCONTAINER_CHILDREN = "children";
 }

Modified: incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConverter.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConverter.java?rev=1044039&r1=1044038&r2=1044039&view=diff
==============================================================================
--- incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConverter.java
(original)
+++ incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConverter.java
Thu Dec  9 17:09:59 2010
@@ -19,6 +19,7 @@
 package org.apache.chemistry.opencmis.server.impl.browser.json;
 
 import java.util.GregorianCalendar;
+import java.util.List;
 import java.util.Set;
 
 import org.apache.chemistry.opencmis.commons.data.Ace;
@@ -45,9 +46,13 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.data.RenditionData;
 import org.apache.chemistry.opencmis.commons.data.RepositoryCapabilities;
 import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
+import org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition;
 import org.apache.chemistry.opencmis.commons.definitions.PermissionDefinition;
 import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
+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.enums.Action;
 import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
 import org.apache.chemistry.opencmis.commons.enums.Cardinality;
@@ -301,9 +306,9 @@ public class JSONConverter extends JSONC
         JSONObject result = new JSONObject();
 
         result.put(JSON_PROPERTY_ID, property.getId());
-        result.put(JSON_PROPERTY_LOCAL_NAME, property.getLocalName());
-        result.put(JSON_PROPERTY_DISPLAY_NAME, property.getDisplayName());
-        result.put(JSON_PROPERTY_QUERY_NAME, property.getQueryName());
+        result.put(JSON_PROPERTY_LOCALNAME, property.getLocalName());
+        result.put(JSON_PROPERTY_DISPLAYNAME, property.getDisplayName());
+        result.put(JSON_PROPERTY_QUERYNAME, property.getQueryName());
 
         if (propDef != null) {
             result.put(JSON_PROPERTY_DATATYPE, propDef.getPropertyType().value());
@@ -526,6 +531,139 @@ public class JSONConverter extends JSONC
         return result;
     }
 
+    /**
+     * Converts a type definition.
+     */
+    @SuppressWarnings("unchecked")
+    public static JSONObject convert(TypeDefinition type) {
+        if (type == null) {
+            return null;
+        }
+
+        JSONObject result = new JSONObject();
+        result.put(JSON_TYPE_ID, type.getId());
+        result.put(JSON_TYPE_LOCALNAME, type.getLocalName());
+        result.put(JSON_TYPE_LOCALNAMESPACE, type.getLocalNamespace());
+        result.put(JSON_TYPE_DISPLAYNAME, type.getDisplayName());
+        result.put(JSON_TYPE_QUERYNAME, type.getQueryName());
+        result.put(JSON_TYPE_DESCRIPTION, type.getDescription());
+        result.put(JSON_TYPE_BASE_ID, type.getBaseTypeId().value());
+        result.put(JSON_TYPE_PARENT_ID, type.getParentTypeId());
+        result.put(JSON_TYPE_CREATABLE, type.isCreatable());
+        result.put(JSON_TYPE_FILEABLE, type.isFileable());
+        result.put(JSON_TYPE_QUERYABLE, type.isQueryable());
+        result.put(JSON_TYPE_FULLTEXT_INDEXED, type.isFulltextIndexed());
+        result.put(JSON_TYPE_INCLUDE_IN_SUPERTYPE_QUERY, type.isIncludedInSupertypeQuery());
+        result.put(JSON_TYPE_CONTROLABLE_POLICY, type.isControllablePolicy());
+        result.put(JSON_TYPE_CONTROLABLE_ACL, type.isControllableAcl());
+
+        if (type instanceof DocumentTypeDefinition) {
+            result.put(JSON_TYPE_VERSIONABLE, ((DocumentTypeDefinition) type).isVersionable());
+            result.put(JSON_TYPE_CONTENTSTREAM_ALLOWED, ((DocumentTypeDefinition) type).getContentStreamAllowed()
+                    .value());
+        }
+
+        if (type instanceof RelationshipTypeDefinition) {
+            result.put(JSON_TYPE_ALLOWED_SOURCE_TYPES,
+                    getJSONArrayFromList(((RelationshipTypeDefinition) type).getAllowedSourceTypeIds()));
+            result.put(JSON_TYPE_ALLOWED_TARGET_TYPES,
+                    getJSONArrayFromList(((RelationshipTypeDefinition) type).getAllowedTargetTypeIds()));
+        }
+
+        if ((type.getPropertyDefinitions() != null) && (!type.getPropertyDefinitions().isEmpty()))
{
+            JSONObject propertyDefs = new JSONObject();
+
+            for (PropertyDefinition<?> pd : type.getPropertyDefinitions().values())
{
+                propertyDefs.put(pd.getId(), convert(pd));
+            }
+
+            result.put(JSON_TYPE_PROPERTY_DEFINITIONS, propertyDefs);
+        }
+
+        return result;
+    }
+
+    /**
+     * Converts a property type definition.
+     */
+    @SuppressWarnings("unchecked")
+    public static JSONObject convert(PropertyDefinition<?> propertyDef) {
+        if (propertyDef == null) {
+            return null;
+        }
+
+        JSONObject result = new JSONObject();
+        result.put(JSON_PROPERTYTYPE_ID, propertyDef.getId());
+        result.put(JSON_PROPERTYTYPE_LOCALNAME, propertyDef.getLocalName());
+        result.put(JSON_PROPERTYTYPE_LOCALNAMESPACE, propertyDef.getLocalName());
+        result.put(JSON_PROPERTYTYPE_DISPLAYNAME, propertyDef.getDisplayName());
+        result.put(JSON_PROPERTYTYPE_QUERYNAME, propertyDef.getQueryName());
+        result.put(JSON_PROPERTYTYPE_DESCRIPTION, propertyDef.getDescription());
+        result.put(JSON_PROPERTYTYPE_PROPERTY_TYPE, propertyDef.getPropertyType().value());
+        result.put(JSON_PROPERTYTYPE_CARDINALITY, propertyDef.getCardinality().value());
+        result.put(JSON_PROPERTYTYPE_UPDATABILITY, propertyDef.getUpdatability().value());
+        result.put(JSON_PROPERTYTYPE_INHERITED, propertyDef.isInherited());
+        result.put(JSON_PROPERTYTYPE_REQUIRED, propertyDef.isRequired());
+        result.put(JSON_PROPERTYTYPE_REQUIRED, propertyDef.isQueryable());
+        result.put(JSON_PROPERTYTYPE_OPENCHOICE, propertyDef.isOpenChoice());
+
+        // TODO: add type specific details
+        // TODO: add choice
+
+        return result;
+    }
+
+    /**
+     * Converts a type definition list.
+     */
+    @SuppressWarnings("unchecked")
+    public static JSONObject convert(TypeDefinitionList list) {
+        if (list == null) {
+            return null;
+        }
+
+        JSONObject result = new JSONObject();
+
+        if (list.getList() != null) {
+            JSONArray objects = new JSONArray();
+
+            for (TypeDefinition type : list.getList()) {
+                objects.add(convert(type));
+            }
+
+            result.put(JSON_TYPESLIST_TYPES, objects);
+        }
+
+        result.put(JSON_TYPESLIST_HAS_MORE_ITEMS, list.hasMoreItems());
+        result.put(JSON_TYPESLIST_NUM_ITEMS, list.getNumItems());
+
+        return result;
+    }
+
+    /**
+     * Converts a type definition container.
+     */
+    @SuppressWarnings("unchecked")
+    public static JSONObject convert(TypeDefinitionContainer container) {
+        if (container == null) {
+            return null;
+        }
+
+        JSONObject result = new JSONObject();
+        result.put(JSON_TYPESCONTAINER_TYPE, convert(container.getTypeDefinition()));
+
+        if ((container.getChildren() != null) && (container.getChildren().size()
> 0)) {
+            JSONArray children = new JSONArray();
+            for (TypeDefinitionContainer child : container.getChildren()) {
+                children.add(JSONConverter.convert(child));
+            }
+
+            result.put(JSON_TYPESCONTAINER_CHILDREN, children);
+        }
+
+        return result;
+    }
+
     // -----------------------------------------------------------------
 
     public static String getJSONStringValue(Object obj) {
@@ -544,6 +682,18 @@ public class JSONConverter extends JSONC
         return value;
     }
 
+    @SuppressWarnings("unchecked")
+    public static JSONArray getJSONArrayFromList(List<?> list) {
+        if (list == null) {
+            return null;
+        }
+
+        JSONArray result = new JSONArray();
+        result.addAll(list);
+
+        return result;
+    }
+
     public static String getJSONPropertyDataType(PropertyData<?> property) {
         if (property instanceof PropertyBoolean) {
             return PropertyType.BOOLEAN.value();

Modified: incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/demo.html
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/demo.html?rev=1044039&r1=1044038&r2=1044039&view=diff
==============================================================================
--- incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/demo.html (original)
+++ incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/demo.html Thu Dec 
9 17:09:59 2010
@@ -56,6 +56,11 @@ function printRepositoryInfos(infos) {
     script2.setAttribute("src", rootFolderUrl + rootFolder + "?selector=children&clientToken=printChildren");
     script2.setAttribute("type","text/javascript");                
     document.body.appendChild(script2);
+
+    var script3 = document.createElement("script");        
+    script3.setAttribute("src", repositoryUrl + "?selector=typeChildren&clientToken=printTypes");
+    script3.setAttribute("type","text/javascript");                
+    document.body.appendChild(script3);
 }
 
 function printObject(obj) {
@@ -127,6 +132,26 @@ function printChildren(children) {
     
     document.getElementById('folderInfo').innerHTML = s;
 }
+
+function printTypes(types) {
+    var s = '<h2>Base Types</h2>';
+    
+    for(var index in types.types) {
+        var type = types.types[index];
+
+        s = s + '<h3>' + type.id + '</h3>';
+        s = s + '<ul>';
+
+        for(var propId in type.propertyDefinitions) {
+            var propType = type.propertyDefinitions[propId];
+            s = s + '<li>' + propType.id + '</li>';
+        }
+
+        s = s + '</ul>';
+    }
+    
+    document.getElementById('typeInfo').innerHTML = s;
+}
 </script>
 
 
@@ -140,6 +165,8 @@ function printChildren(children) {
 <br />
 <div id="folderInfo" class="box">folderInfo</div>
 <br />
+<div id="typeInfo" class="box">typeInfo</div>
+<br />
 <div id="query" class="box">
 <h2>Query</h2>
 <form id="queryForm" action="" method="POST">



Mime
View raw message