chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1371244 [2/2] - in /chemistry/opencmis/trunk: chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/ chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/j...
Date Thu, 09 Aug 2012 15:04:47 GMT
Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ServerTypeCacheImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ServerTypeCacheImpl.java?rev=1371244&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ServerTypeCacheImpl.java
(added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ServerTypeCacheImpl.java
Thu Aug  9 15:04:46 2012
@@ -0,0 +1,84 @@
+/*
+ * 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.impl.browser;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.apache.chemistry.opencmis.commons.data.ObjectData;
+import org.apache.chemistry.opencmis.commons.data.PropertyData;
+import org.apache.chemistry.opencmis.commons.data.PropertyId;
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
+import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
+import org.apache.chemistry.opencmis.commons.impl.TypeCache;
+import org.apache.chemistry.opencmis.commons.server.CmisService;
+
+/**
+ * Temporary type cache used for one call.
+ */
+public class ServerTypeCacheImpl implements TypeCache {
+
+    private final String repositoryId;
+    private final CmisService service;
+    private final Map<String, TypeDefinition> typeDefinitions;
+    private final Map<String, TypeDefinition> objectToTypeDefinitions;
+
+    public ServerTypeCacheImpl(String repositoryId, CmisService service) {
+        this.repositoryId = repositoryId;
+        this.service = service;
+        typeDefinitions = new HashMap<String, TypeDefinition>();
+        objectToTypeDefinitions = new HashMap<String, TypeDefinition>();
+    }
+
+    public TypeDefinition getTypeDefinition(String typeId) {
+        TypeDefinition type = typeDefinitions.get(typeId);
+        if (type == null) {
+            type = service.getTypeDefinition(repositoryId, typeId, null);
+            if (type != null) {
+                typeDefinitions.put(type.getId(), type);
+            }
+        }
+
+        return type;
+    }
+
+    public TypeDefinition getTypeDefinitionForObject(String objectId) {
+        TypeDefinition type = objectToTypeDefinitions.get(objectId);
+        if (type == null) {
+            ObjectData obj = service.getObject(repositoryId, objectId,
+                    "cmis:objectId,cmis:objectTypeId,cmis:baseTypeId", false, IncludeRelationships.NONE,
"cmis:none",
+                    false, false, null);
+
+            if (obj != null && obj.getProperties() != null) {
+                PropertyData<?> typeProp = obj.getProperties().getProperties().get(PropertyIds.OBJECT_TYPE_ID);
+                if (typeProp instanceof PropertyId) {
+                    String typeId = ((PropertyId) typeProp).getFirstValue();
+                    if (typeId != null) {
+                        type = getTypeDefinition(typeId);
+                    }
+                }
+            }
+
+            objectToTypeDefinitions.put(objectId, type);
+        }
+
+        return type;
+    }
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ServerTypeCacheImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/VersioningService.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/VersioningService.java?rev=1371244&r1=1371243&r2=1371244&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/VersioningService.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/VersioningService.java
Thu Aug  9 15:04:46 2012
@@ -54,7 +54,6 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.impl.TypeCache;
 import org.apache.chemistry.opencmis.commons.impl.json.JSONArray;
 import org.apache.chemistry.opencmis.commons.impl.json.JSONObject;
-import org.apache.chemistry.opencmis.commons.impl.server.TypeCacheImpl;
 import org.apache.chemistry.opencmis.commons.server.CallContext;
 import org.apache.chemistry.opencmis.commons.server.CmisService;
 import org.apache.chemistry.opencmis.commons.spi.Holder;
@@ -87,7 +86,7 @@ public class VersioningService {
         }
 
         // return object
-        TypeCache typeCache = new TypeCacheImpl(repositoryId, service);
+        TypeCache typeCache = new ServerTypeCacheImpl(repositoryId, service);
         JSONObject jsonObject = JSONConverter.convert(object, typeCache, false, succinct);
 
         // set headers
@@ -132,7 +131,7 @@ public class VersioningService {
 
         // execute
         ControlParser cp = new ControlParser(request);
-        TypeCache typeCache = new TypeCacheImpl(repositoryId, service);
+        TypeCache typeCache = new ServerTypeCacheImpl(repositoryId, service);
         Holder<String> objectIdHolder = new Holder<String>(objectId);
 
         service.checkIn(repositoryId, objectIdHolder, major, createProperties(cp, typeId,
typeCache),
@@ -179,7 +178,7 @@ public class VersioningService {
             throw new CmisRuntimeException("Versions are null!");
         }
 
-        TypeCache typeCache = new TypeCacheImpl(repositoryId, service);
+        TypeCache typeCache = new ServerTypeCacheImpl(repositoryId, service);
         JSONArray jsonVersions = new JSONArray();
         for (ObjectData version : versions) {
             jsonVersions.add(JSONConverter.convert(version, typeCache, false, succinct));



Mime
View raw message