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 2014/05/14 12:35:53 UTC

svn commit: r1594533 - in /chemistry/opencmis/trunk: chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/ chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/c...

Author: fmui
Date: Wed May 14 10:35:52 2014
New Revision: 1594533

URL: http://svn.apache.org/r1594533
Log:
CMIS-800: handling of type definition changes in an open client session

Added:
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/ExtendedRepositoryService.java   (with props)
Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/impl/RepositoryServiceImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/ClientTypeCacheImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractCmisObject.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/repository/ObjectFactoryImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/TypeCache.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ServerTypeCacheImpl.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java?rev=1594533&r1=1594532&r2=1594533&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java Wed May 14 10:35:52 2014
@@ -207,6 +207,24 @@ public interface Session extends Seriali
     ObjectType getTypeDefinition(String typeId);
 
     /**
+     * Gets the definition of a type.
+     * 
+     * @param typeId
+     *            the ID of the type
+     * @param useCache
+     *            specifies whether the type definition should be looked up in
+     *            the type definition cache first or not
+     * 
+     * @return the type definition
+     * 
+     * @throws CmisObjectNotFoundException
+     *             if a type with the given type ID doesn't exist
+     * 
+     * @cmis 1.0
+     */
+    ObjectType getTypeDefinition(String typeId, boolean useCache);
+
+    /**
      * Gets the type children of a type.
      * 
      * @param typeId

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/impl/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/impl/RepositoryServiceImpl.java?rev=1594533&r1=1594532&r2=1594533&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/impl/RepositoryServiceImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/impl/RepositoryServiceImpl.java Wed May 14 10:35:52 2014
@@ -31,6 +31,7 @@ import org.apache.chemistry.opencmis.com
 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.spi.ExtendedRepositoryService;
 import org.apache.chemistry.opencmis.commons.spi.RepositoryService;
 
 /**
@@ -38,7 +39,7 @@ import org.apache.chemistry.opencmis.com
  * 
  * Passes requests to the SPI and handles caching.
  */
-public class RepositoryServiceImpl implements RepositoryService, Serializable {
+public class RepositoryServiceImpl implements RepositoryService, ExtendedRepositoryService, Serializable {
 
     private static final long serialVersionUID = 1L;
 
@@ -122,13 +123,19 @@ public class RepositoryServiceImpl imple
     }
 
     public TypeDefinition getTypeDefinition(String repositoryId, String typeId, ExtensionsData extension) {
+        return getTypeDefinition(repositoryId, typeId, extension, true);
+    }
+
+    public TypeDefinition getTypeDefinition(String repositoryId, String typeId, ExtensionsData extension,
+            boolean useCache) {
         TypeDefinition result = null;
         boolean hasExtension = (extension != null) && (!extension.getExtensions().isEmpty());
 
         TypeDefinitionCache cache = CmisBindingsHelper.getTypeDefinitionCache(session);
 
-        // if extension is not set, check the cache first
-        if (!hasExtension) {
+        // if the cache should be used and the extension is not set,
+        // check the cache first
+        if (useCache && !hasExtension) {
             result = cache.get(repositoryId, typeId);
             if (result != null) {
                 return result;

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/ClientTypeCacheImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/ClientTypeCacheImpl.java?rev=1594533&r1=1594532&r2=1594533&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/ClientTypeCacheImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/ClientTypeCacheImpl.java Wed May 14 10:35:52 2014
@@ -49,6 +49,18 @@ public class ClientTypeCacheImpl impleme
         return type;
     }
 
+    public TypeDefinition reloadTypeDefinition(String typeId) {
+
+        TypeDefinitionCache cache = CmisBindingsHelper.getTypeDefinitionCache(service.getSession());
+
+        TypeDefinition type = service.getTypeDefinitionInternal(repositoryId, typeId);
+        if (type != null) {
+            cache.put(repositoryId, type);
+        }
+
+        return type;
+    }
+
     public TypeDefinition getTypeDefinitionForObject(String objectId) {
         // not used
         assert false;

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractCmisObject.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractCmisObject.java?rev=1594533&r1=1594532&r2=1594533&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractCmisObject.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/AbstractCmisObject.java Wed May 14 10:35:52 2014
@@ -666,7 +666,7 @@ public abstract class AbstractCmisObject
                             oc.isIncludeAcls(), null);
 
             // reset this object
-            initialize(getSession(), getObjectType(), objectData, this.creationContext);
+            initialize(session, session.getTypeDefinition(objectType.getId()), objectData, creationContext);
         } finally {
             writeUnlock();
         }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionImpl.java?rev=1594533&r1=1594532&r2=1594533&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionImpl.java Wed May 14 10:35:52 2014
@@ -91,6 +91,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.spi.DiscoveryService;
 import org.apache.chemistry.opencmis.commons.spi.ExtendedAclService;
 import org.apache.chemistry.opencmis.commons.spi.ExtendedHolder;
+import org.apache.chemistry.opencmis.commons.spi.ExtendedRepositoryService;
 import org.apache.chemistry.opencmis.commons.spi.Holder;
 import org.apache.chemistry.opencmis.commons.spi.NavigationService;
 import org.apache.chemistry.opencmis.commons.spi.RelationshipService;
@@ -746,6 +747,19 @@ public class SessionImpl implements Sess
         return convertTypeDefinition(typeDefinition);
     }
 
+    public ObjectType getTypeDefinition(String typeId, boolean useCache) {
+        RepositoryService service = getBinding().getRepositoryService();
+        if (!(service instanceof ExtendedRepositoryService)) {
+            throw new CmisRuntimeException(
+                    "Internal error: Repository Service does not implement ExtendedRepositoryService!");
+        }
+
+        ExtendedRepositoryService extRepSrv = (ExtendedRepositoryService) service;
+        TypeDefinition typeDefinition = extRepSrv.getTypeDefinition(getRepositoryId(), typeId, null, useCache);
+
+        return convertTypeDefinition(typeDefinition);
+    }
+
     public List<Tree<ObjectType>> getTypeDescendants(String typeId, int depth, boolean includePropertyDefinitions) {
         List<TypeDefinitionContainer> descendants = getBinding().getRepositoryService().getTypeDescendants(
                 getRepositoryId(), typeId, BigInteger.valueOf(depth), includePropertyDefinitions, null);

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/repository/ObjectFactoryImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/repository/ObjectFactoryImpl.java?rev=1594533&r1=1594532&r2=1594533&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/repository/ObjectFactoryImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/repository/ObjectFactoryImpl.java Wed May 14 10:35:52 2014
@@ -283,6 +283,27 @@ public class ObjectFactoryImpl implement
             }
         }
 
+        // the type might have changed -> reload type definitions
+        if (definition == null) {
+            TypeDefinition reloadedObjectType = session.getTypeDefinition(objectType.getId(), false);
+            definition = (PropertyDefinition<T>) reloadedObjectType.getPropertyDefinitions().get(pd.getId());
+
+            if (definition == null && secondaryTypes != null) {
+                for (SecondaryType secondaryType : secondaryTypes) {
+                    if (secondaryType != null) {
+                        TypeDefinition reloadedSecondaryType = session.getTypeDefinition(secondaryType.getId(), false);
+                        if (reloadedSecondaryType.getPropertyDefinitions() != null) {
+                            definition = (PropertyDefinition<T>) reloadedSecondaryType.getPropertyDefinitions().get(
+                                    pd.getId());
+                            if (definition != null) {
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
         if (definition == null) {
             // property without definition
             throw new CmisRuntimeException("Property '" + pd.getId() + "' doesn't exist!");

Added: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/ExtendedRepositoryService.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/ExtendedRepositoryService.java?rev=1594533&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/ExtendedRepositoryService.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/ExtendedRepositoryService.java Wed May 14 10:35:52 2014
@@ -0,0 +1,47 @@
+/*
+ * 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.commons.spi;
+
+import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
+
+/**
+ * Extended Repository Service interface.
+ * 
+ * This interface has NO equivalent in the CMIS specification. It contains
+ * repository convenience operations for clients and is built on top of the CMIS
+ * specified operations.
+ * 
+ * This interface need not to be implemented by CMIS servers.
+ */
+public interface ExtendedRepositoryService {
+
+    /**
+     * Gets the definition of the specified object type.
+     * 
+     * @param repositoryId
+     *            the identifier for the repository
+     * @param typeId
+     *            typeId of an object type specified in the repository
+     * @param useCache
+     *            specifies whether the type definition should be looked up in
+     *            the type definition cache first or not
+     */
+    TypeDefinition getTypeDefinition(String repositoryId, String typeId, ExtensionsData extension, boolean useCache);
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/ExtendedRepositoryService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.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/JSONConverter.java?rev=1594533&r1=1594532&r2=1594533&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java Wed May 14 10:35:52 2014
@@ -2126,9 +2126,11 @@ public final class JSONConverter {
 
             if (propDef == null && secTypeDefs != null) {
                 for (TypeDefinition secTypeDef : secTypeDefs) {
-                    propDef = secTypeDef.getPropertyDefinitions().get(id);
-                    if (propDef != null) {
-                        break;
+                    if (secTypeDef != null && secTypeDef.getPropertyDefinitions() != null) {
+                        propDef = secTypeDef.getPropertyDefinitions().get(id);
+                        if (propDef != null) {
+                            break;
+                        }
                     }
                 }
             }
@@ -2142,6 +2144,25 @@ public final class JSONConverter {
                 propDef = typeCache.getTypeDefinition(BaseTypeId.CMIS_FOLDER.value()).getPropertyDefinitions().get(id);
             }
 
+            if (propDef == null && typeDef != null) {
+                TypeDefinition reloadedTypeDef = typeCache.reloadTypeDefinition(typeDef.getId());
+                if (reloadedTypeDef != null) {
+                    propDef = reloadedTypeDef.getPropertyDefinitions().get(id);
+                }
+            }
+
+            if (propDef == null && secTypeDefs != null) {
+                for (TypeDefinition secTypeDef : secTypeDefs) {
+                    TypeDefinition reloadedTypeDef = typeCache.reloadTypeDefinition(secTypeDef.getId());
+                    if (reloadedTypeDef != null && reloadedTypeDef.getPropertyDefinitions() != null) {
+                        propDef = reloadedTypeDef.getPropertyDefinitions().get(id);
+                        if (propDef != null) {
+                            break;
+                        }
+                    }
+                }
+            }
+
             List<Object> values = null;
             if (entry.getValue() instanceof List) {
                 values = (List<Object>) entry.getValue();

Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/TypeCache.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/TypeCache.java?rev=1594533&r1=1594532&r2=1594533&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/TypeCache.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/TypeCache.java Wed May 14 10:35:52 2014
@@ -27,11 +27,16 @@ import org.apache.chemistry.opencmis.com
 public interface TypeCache {
 
     /**
-     * Gets the type definition by type id.
+     * Gets the type definition by type ID.
      */
     TypeDefinition getTypeDefinition(String typeId);
 
     /**
+     * Reloads the type definition by type ID.
+     */
+    TypeDefinition reloadTypeDefinition(String typeId);
+    
+    /**
      * Gets the type definition of an object.
      */
     TypeDefinition getTypeDefinitionForObject(String objectId);

Modified: 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=1594533&r1=1594532&r2=1594533&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ServerTypeCacheImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ServerTypeCacheImpl.java Wed May 14 10:35:52 2014
@@ -60,6 +60,15 @@ public class ServerTypeCacheImpl impleme
         return type;
     }
 
+    public TypeDefinition reloadTypeDefinition(String typeId) {
+        TypeDefinition 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) {