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/02/26 10:42:05 UTC

svn commit: r1571980 - in /chemistry/opencmis/trunk/chemistry-opencmis-client: chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/ chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/

Author: fmui
Date: Wed Feb 26 09:42:05 2014
New Revision: 1571980

URL: http://svn.apache.org/r1571980
Log:
improved getLatestDocumentVersion

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-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/DocumentImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionImpl.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=1571980&r1=1571979&r2=1571980&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 Feb 26 09:42:05 2014
@@ -492,6 +492,23 @@ public interface Session extends Seriali
      * 
      * @param objectId
      *            the document ID of an arbitrary version in the version series
+     * @param major
+     *            if {@code true} the latest major version will be returned,
+     *            otherwise the very last version will be returned
+     * @param context
+     *            the {@link OperationContext} to use
+     * 
+     * @return the latest document version
+     * 
+     * @cmis 1.0
+     */
+    Document getLatestDocumentVersion(ObjectId objectId, boolean major, OperationContext context);
+
+    /**
+     * /** Returns the latest version in a version series.
+     * 
+     * @param objectId
+     *            the document ID of an arbitrary version in the version series
      * 
      * @return the latest document version
      * 
@@ -514,6 +531,23 @@ public interface Session extends Seriali
     Document getLatestDocumentVersion(String objectId, OperationContext context);
 
     /**
+     * Returns the latest version in a version series.
+     * 
+     * @param objectId
+     *            the document ID of an arbitrary version in the version series
+     * @param major
+     *            if {@code true} the latest major version will be returned,
+     *            otherwise the very last version will be returned
+     * @param context
+     *            the {@link OperationContext} to use
+     * 
+     * @return the latest document version
+     * 
+     * @cmis 1.0
+     */
+    Document getLatestDocumentVersion(String objectId, boolean major, OperationContext context);
+
+    /**
      * Removes the given object from the cache.
      * 
      * @param objectId

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/DocumentImpl.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/DocumentImpl.java?rev=1571980&r1=1571979&r2=1571980&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/DocumentImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/DocumentImpl.java Wed Feb 26 09:42:05 2014
@@ -314,34 +314,7 @@ public class DocumentImpl extends Abstra
     }
 
     public Document getObjectOfLatestVersion(boolean major, OperationContext context) {
-        String objectId;
-        String versionSeriesId;
-
-        readLock();
-        try {
-            objectId = getObjectId();
-            versionSeriesId = getVersionSeriesId();
-        } finally {
-            readUnlock();
-        }
-
-        if (versionSeriesId == null) {
-            throw new CmisRuntimeException("Version series id is unknown!");
-        }
-
-        ObjectData objectData = getBinding().getVersioningService().getObjectOfLatestVersion(getRepositoryId(),
-                objectId, versionSeriesId, major, context.getFilterString(), context.isIncludeAllowableActions(),
-                context.getIncludeRelationships(), context.getRenditionFilterString(), context.isIncludePolicies(),
-                context.isIncludeAcls(), null);
-
-        ObjectFactory objectFactory = getSession().getObjectFactory();
-
-        CmisObject result = objectFactory.convertObject(objectData, context);
-        if (!(result instanceof Document)) {
-            throw new CmisRuntimeException("Latest version is not a document!");
-        }
-
-        return (Document) result;
+        return getSession().getLatestDocumentVersion(this, major, context);
     }
 
     // content operations

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=1571980&r1=1571979&r2=1571980&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 Feb 26 09:42:05 2014
@@ -565,7 +565,7 @@ public class SessionImpl implements Sess
     }
 
     public Document getLatestDocumentVersion(ObjectId objectId) {
-        return getLatestDocumentVersion(objectId, getDefaultContext());
+        return getLatestDocumentVersion(objectId, false, getDefaultContext());
     }
 
     public Document getLatestDocumentVersion(String objectId, OperationContext context) {
@@ -573,7 +573,15 @@ public class SessionImpl implements Sess
             throw new IllegalArgumentException("Object ID must be set!");
         }
 
-        return getLatestDocumentVersion(createObjectId(objectId), context);
+        return getLatestDocumentVersion(createObjectId(objectId), false, context);
+    }
+
+    public Document getLatestDocumentVersion(String objectId, boolean major, OperationContext context) {
+        if (objectId == null) {
+            throw new IllegalArgumentException("Object ID must be set!");
+        }
+
+        return getLatestDocumentVersion(createObjectId(objectId), major, context);
     }
 
     public Document getLatestDocumentVersion(String objectId) {
@@ -581,10 +589,14 @@ public class SessionImpl implements Sess
             throw new IllegalArgumentException("Object ID must be set!");
         }
 
-        return getLatestDocumentVersion(createObjectId(objectId), getDefaultContext());
+        return getLatestDocumentVersion(createObjectId(objectId), false, getDefaultContext());
     }
 
     public Document getLatestDocumentVersion(ObjectId objectId, OperationContext context) {
+        return getLatestDocumentVersion(objectId, false, context);
+    }
+
+    public Document getLatestDocumentVersion(ObjectId objectId, boolean major, OperationContext context) {
         if (objectId == null || objectId.getId() == null) {
             throw new IllegalArgumentException("Object ID must be set!");
         }
@@ -596,27 +608,36 @@ public class SessionImpl implements Sess
         CmisObject result = null;
 
         String versionSeriesId = null;
-        BindingType bindingType = getBinding().getBindingType();
-        if (bindingType == BindingType.WEBSERVICES || bindingType == BindingType.CUSTOM) {
-            if (objectId instanceof Document) {
-                versionSeriesId = ((Document) objectId).getVersionSeriesId();
-            }
 
-            if (versionSeriesId == null) {
-                // ask the cache
-                if (context.isCacheEnabled()) {
-                    CmisObject sourceDoc = cache.getById(objectId.getId(), context.getCacheKey());
-                    if (sourceDoc instanceof Document) {
-                        versionSeriesId = ((Document) sourceDoc).getVersionSeriesId();
-                    }
+        // first attempt: if we got a Document object, try getting the version
+        // series ID from it
+        if (objectId instanceof Document) {
+            versionSeriesId = ((Document) objectId).getVersionSeriesId();
+        }
+
+        // second attempt: if we have a Document object in the cache, retrieve
+        // the version series ID form there
+        if (versionSeriesId == null) {
+            if (context.isCacheEnabled()) {
+                CmisObject sourceDoc = cache.getById(objectId.getId(), context.getCacheKey());
+                if (sourceDoc instanceof Document) {
+                    versionSeriesId = ((Document) sourceDoc).getVersionSeriesId();
                 }
             }
+        }
+
+        // third attempt (Web Services only): get the version series ID from the
+        // repository
+        // (the AtomPub and Browser binding don't need the version series ID ->
+        // avoid roundtrip)
+        if (versionSeriesId == null) {
+            BindingType bindingType = getBinding().getBindingType();
+            if (bindingType == BindingType.WEBSERVICES || bindingType == BindingType.CUSTOM) {
 
-            if (versionSeriesId == null) {
                 // get the document to find the version series ID
-                ObjectData sourceObjectData = binding.getObjectService().getObject(getRepositoryId(),
-                        objectId.getId(), PropertyIds.OBJECT_ID + "," + PropertyIds.VERSION_SERIES_ID, false,
-                        IncludeRelationships.NONE, "cmis:none", false, false, null);
+                ObjectData sourceObjectData = binding.getObjectService().getObject(getRepositoryId(), objectId.getId(),
+                        PropertyIds.OBJECT_ID + "," + PropertyIds.VERSION_SERIES_ID, false, IncludeRelationships.NONE,
+                        "cmis:none", false, false, null);
 
                 if (sourceObjectData.getProperties() != null
                         && sourceObjectData.getProperties().getProperties() != null) {
@@ -626,16 +647,17 @@ public class SessionImpl implements Sess
                         versionSeriesId = (String) verionsSeriesIdProp.getFirstValue();
                     }
                 }
-            }
 
-            if (versionSeriesId == null) {
-                throw new IllegalArgumentException("Object is not a document or not versionable!");
+                // the Web Services binding needs the version series ID -> fail
+                if (versionSeriesId == null) {
+                    throw new IllegalArgumentException("Object is not a document or not versionable!");
+                }
             }
         }
 
         // get the object
         ObjectData objectData = binding.getVersioningService().getObjectOfLatestVersion(getRepositoryId(),
-                objectId.getId(), versionSeriesId, false, context.getFilterString(),
+                objectId.getId(), versionSeriesId, major, context.getFilterString(),
                 context.isIncludeAllowableActions(), context.getIncludeRelationships(),
                 context.getRenditionFilterString(), context.isIncludePolicies(), context.isIncludeAcls(), null);
 
@@ -648,7 +670,7 @@ public class SessionImpl implements Sess
 
         // check result
         if (!(result instanceof Document)) {
-            throw new IllegalArgumentException("Object is not a document!");
+            throw new IllegalArgumentException("Latest version is not a document!");
         }
 
         return (Document) result;