chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1526855 - in /chemistry/opencmis/trunk: chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main...
Date Fri, 27 Sep 2013 11:34:44 GMT
Author: fmui
Date: Fri Sep 27 11:34:43 2013
New Revision: 1526855

URL: http://svn.apache.org/r1526855
Log:
tweaked the change log token handling and tests

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomPubParser.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/DiscoveryServiceImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/ChangeEventImpl.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-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/DiscoveryService.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryDiscoveryServiceImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomPubParser.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/atompub/AtomPubParser.java?rev=1526855&r1=1526854&r2=1526855&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomPubParser.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomPubParser.java
Fri Sep 27 11:34:43 2013
@@ -244,6 +244,8 @@ public class AtomPubParser {
                     } else {
                         XMLUtils.skip(parser);
                     }
+                } else if (XMLConstants.NAMESPACE_APACHE_CHEMISTRY.equals(name.getNamespaceURI()))
{
+                    result.addElement(parseText(parser));
                 } else {
                     XMLUtils.skip(parser);
                 }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/DiscoveryServiceImpl.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/atompub/DiscoveryServiceImpl.java?rev=1526855&r1=1526854&r2=1526855&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/DiscoveryServiceImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/DiscoveryServiceImpl.java
Fri Sep 27 11:34:43 2013
@@ -98,6 +98,7 @@ public class DiscoveryServiceImpl extend
         // read and parse
         Response resp = read(url);
         AtomFeed feed = parse(resp.getStream(), AtomFeed.class);
+        String lastChangeLogToken = null;
 
         // handle top level
         String nextLink = null;
@@ -109,6 +110,8 @@ public class DiscoveryServiceImpl extend
                 }
             } else if (isInt(NAME_NUM_ITEMS, element)) {
                 result.setNumItems((BigInteger) element.getObject());
+            } else if (isStr("changeLogToken", element)) {
+                lastChangeLogToken = (String) element.getObject();
             }
         }
 
@@ -133,8 +136,9 @@ public class DiscoveryServiceImpl extend
         }
 
         if (changeLogToken != null) {
-            // the AtomPub binding cannot return a new change log token
-            changeLogToken.setValue(null);
+            // the AtomPub binding cannot return a new change log token,
+            // but an OpenCMIS server uses a proprietary tag
+            changeLogToken.setValue(lastChangeLogToken);
 
             // but we can provide the link to the next Atom feed
             if (changeLogToken instanceof ExtendedHolder && nextLink != null) {

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/ChangeEventImpl.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/ChangeEventImpl.java?rev=1526855&r1=1526854&r2=1526855&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/ChangeEventImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/ChangeEventImpl.java
Fri Sep 27 11:34:43 2013
@@ -83,4 +83,11 @@ public class ChangeEventImpl extends Cha
     public void setAcl(Acl acl) {
         this.acl = acl;
     }
+
+    @Override
+    public String toString() {
+        return "Change Event [change type=" + getChangeType() + ", change time=" + getChangeTime()
+ ", object id="
+                + objectId + ", properties=" + properties + ", policy ids=" + policyIds +
", ACL=" + acl + "]"
+                + super.toString();
+    }
 }

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=1526855&r1=1526854&r2=1526855&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
Fri Sep 27 11:34:43 2013
@@ -353,7 +353,7 @@ public class SessionImpl implements Sess
         final ObjectFactory of = this.getObjectFactory();
         final OperationContext ctxt = new OperationContextImpl(context);
 
-        return new CollectionIterable<ChangeEvent>(new AbstractPageFetcher<ChangeEvent>(ctxt.getMaxItemsPerPage())
{
+        return new CollectionIterable<ChangeEvent>(new AbstractPageFetcher<ChangeEvent>(Integer.MAX_VALUE)
{
 
             private String token = changeLogToken;
             private String nextLink = null;
@@ -379,9 +379,9 @@ public class SessionImpl implements Sess
                     page.add(of.convertChangeEvent(objectData));
                 }
 
-                if (!firstPage && nextLink == null) {
-                    // the web services and the browser binding repeat the last
-                    // entry of the previous page -> remove the first entry
+                if (!firstPage) {
+                    // the last entry of the previous page is repeated
+                    // -> remove the first entry
                     page.removeFirst();
                 }
                 firstPage = false;

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/DiscoveryService.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/atompub/DiscoveryService.java?rev=1526855&r1=1526854&r2=1526855&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/DiscoveryService.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/DiscoveryService.java
Fri Sep 27 11:34:43 2013
@@ -25,6 +25,7 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.chemistry.opencmis.commons.data.ObjectData;
 import org.apache.chemistry.opencmis.commons.data.ObjectList;
@@ -265,14 +266,25 @@ public class DiscoveryService {
             feed.writeSelfLink(selfLink.toString(), null);
 
             if (changeLogTokenHolder.getValue() != null) {
-                UrlBuilder nextLink = compileUrlBuilder(baseUrl, RESOURCE_CHANGES, null);
-                nextLink.addParameter(Constants.PARAM_CHANGE_LOG_TOKEN, changeLogTokenHolder.getValue());
-                nextLink.addParameter(Constants.PARAM_PROPERTIES, includeProperties);
-                nextLink.addParameter(Constants.PARAM_FILTER, filter);
-                nextLink.addParameter(Constants.PARAM_POLICY_IDS, includePolicyIds);
-                nextLink.addParameter(Constants.PARAM_ACL, includeAcl);
-                nextLink.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
-                feed.writeNextLink(nextLink.toString());
+                if (Boolean.TRUE.equals(changes.hasMoreItems())) {
+                    UrlBuilder nextLink = compileUrlBuilder(baseUrl, RESOURCE_CHANGES, null);
+                    nextLink.addParameter(Constants.PARAM_CHANGE_LOG_TOKEN, changeLogTokenHolder.getValue());
+                    nextLink.addParameter(Constants.PARAM_PROPERTIES, includeProperties);
+                    nextLink.addParameter(Constants.PARAM_FILTER, filter);
+                    nextLink.addParameter(Constants.PARAM_POLICY_IDS, includePolicyIds);
+                    nextLink.addParameter(Constants.PARAM_ACL, includeAcl);
+                    nextLink.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
+                    feed.writeNextLink(nextLink.toString());
+                }
+
+                // The CMIS spec says that the AtomPub binding doesn't provide
+                // the change log token. We are doing it anyway.
+                XMLStreamWriter writer = feed.getWriter();
+                writer.writeStartElement(XMLConstants.PREFIX_APACHE_CHEMISTY, "changeLogToken",
+                        XMLConstants.NAMESPACE_APACHE_CHEMISTRY);
+                writer.writeNamespace(XMLConstants.PREFIX_APACHE_CHEMISTY, XMLConstants.NAMESPACE_APACHE_CHEMISTRY);
+                writer.writeCharacters(changeLogTokenHolder.getValue());
+                writer.writeEndElement();
             }
 
             // write entries

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryDiscoveryServiceImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryDiscoveryServiceImpl.java?rev=1526855&r1=1526854&r2=1526855&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryDiscoveryServiceImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryDiscoveryServiceImpl.java
Fri Sep 27 11:34:43 2013
@@ -20,10 +20,8 @@ package org.apache.chemistry.opencmis.in
 
 import java.math.BigInteger;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.List;
-import java.util.UUID;
 
 import org.apache.chemistry.opencmis.commons.PropertyIds;
 import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
@@ -34,6 +32,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
 import org.apache.chemistry.opencmis.commons.enums.ChangeType;
 import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.ChangeEventInfoDataImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectDataImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectListImpl;
@@ -60,26 +59,43 @@ public class InMemoryDiscoveryServiceImp
             BigInteger maxItems, ExtensionsData extension, ObjectInfoHandler objectInfos)
{
         // dummy implementation using hard coded values
         final int ITEMS_AVAILABLE = 25;
-        
+
+        int token = 0;
+        if (changeLogToken != null && changeLogToken.getValue() != null) {
+            if (!changeLogToken.getValue().startsWith("token-")) {
+                throw new CmisInvalidArgumentException("Unknown change log token!");
+            }
+
+            try {
+                token = Integer.parseInt(changeLogToken.getValue().substring(6));
+            } catch (NumberFormatException nfe) {
+                throw new CmisInvalidArgumentException("Unknown change log token!", nfe);
+            }
+
+            if (token < 0 || token > ITEMS_AVAILABLE) {
+                throw new CmisInvalidArgumentException("Unknown change log token!");
+            }
+        }
+
         ObjectListImpl objList = new ObjectListImpl();
-        GregorianCalendar timestamp = new GregorianCalendar();
-        timestamp.add(GregorianCalendar.MINUTE, -1);
+        long timestamp = System.currentTimeMillis() - 60 * 1000;
         // convert ObjectInFolderContainerList to objectList
         List<ObjectData> lod = new ArrayList<ObjectData>();
-        int count = Math.min(ITEMS_AVAILABLE, maxItems.intValue());
-        
-        for (int i=0; i<count; i++) {
+        int last = Math.min(ITEMS_AVAILABLE, token + maxItems.intValue());
+
+        for (int i = token; i < last; i++) {
             // add a dummy delete event
             ObjectDataImpl odImpl = new ObjectDataImpl();
             PropertiesImpl props = new PropertiesImpl();
-            props.addProperty(new PropertyIdImpl(PropertyIds.OBJECT_ID, UUID.randomUUID().toString()));
+            props.addProperty(new PropertyIdImpl(PropertyIds.OBJECT_ID, "cl-" + i));
             props.addProperty(new PropertyIdImpl(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_DOCUMENT.value()));
             props.addProperty(new PropertyIdImpl(PropertyIds.BASE_TYPE_ID, BaseTypeId.CMIS_DOCUMENT.value()));
             odImpl.setProperties(props);
             ChangeEventInfoDataImpl changeEventInfo = new ChangeEventInfoDataImpl();
             changeEventInfo.setChangeType(ChangeType.DELETED);
-            timestamp.add(GregorianCalendar.SECOND, 1);
-            changeEventInfo.setChangeTime(timestamp);
+            GregorianCalendar eventTimestamp = new GregorianCalendar();
+            eventTimestamp.setTimeInMillis(timestamp + i * 1000);
+            changeEventInfo.setChangeTime(eventTimestamp);
             odImpl.setChangeEventInfo(changeEventInfo);
             if (includePolicyIds != null && includePolicyIds) {
                 PolicyIdList policies = new PolicyIdListImpl();
@@ -89,10 +105,10 @@ public class InMemoryDiscoveryServiceImp
         }
 
         objList.setObjects(lod);
-        objList.setNumItems(BigInteger.valueOf(lod.size()));
-        objList.setHasMoreItems(ITEMS_AVAILABLE > lod.size());
+        objList.setNumItems(BigInteger.valueOf(ITEMS_AVAILABLE - token));
+        objList.setHasMoreItems(false);
 
-        String changeToken = Long.valueOf(new Date().getTime()).toString();
+        String changeToken = "token-" + (token + lod.size() - 1);
         changeLogToken.setValue(changeToken);
 
         // To be able to provide all Atom links in the response we need

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java?rev=1526855&r1=1526854&r2=1526855&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java
Fri Sep 27 11:34:43 2013
@@ -351,7 +351,7 @@ public class StoreManagerImpl implements
         repoInfo.setPrincipalAnyone(InMemoryAce.getAnyoneUser());
         repoInfo.setThinClientUri("");
         repoInfo.setChangesIncomplete(Boolean.TRUE);
-        repoInfo.setLatestChangeLogToken(Long.valueOf(new Date(0).getTime()).toString());
+        repoInfo.setLatestChangeLogToken("token-24");
         repoInfo.setVendorName("Apache Chemistry");
         repoInfo.setProductName(OPENCMIS_SERVER);
         repoInfo.setProductVersion(OPENCMIS_VERSION);



Mime
View raw message