You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by je...@apache.org on 2012/02/08 13:03:56 UTC
svn commit: r1241876 - in
/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src:
main/java/org/apache/chemistry/opencmis/inmemory/server/
test/java/org/apache/chemistry/opencmis/inmemory/
Author: jens
Date: Wed Feb 8 12:03:56 2012
New Revision: 1241876
URL: http://svn.apache.org/viewvc?rev=1241876&view=rev
Log:
More change token verifications [CMIS-499]
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.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/InMemoryObjectServiceImpl.java?rev=1241876&r1=1241875&r2=1241876&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java Wed Feb 8 12:03:56 2012
@@ -18,11 +18,9 @@
*/
package org.apache.chemistry.opencmis.inmemory.server;
-import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -46,7 +44,6 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
import org.apache.chemistry.opencmis.commons.enums.Cardinality;
import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
-import org.apache.chemistry.opencmis.commons.enums.PropertyType;
import org.apache.chemistry.opencmis.commons.enums.UnfileObject;
import org.apache.chemistry.opencmis.commons.enums.Updatability;
import org.apache.chemistry.opencmis.commons.enums.VersioningState;
@@ -239,6 +236,9 @@ public class InMemoryObjectServiceImpl e
throw new CmisObjectNotFoundException("Unknown object id: " + objectId);
}
+ if ( so.getChangeToken() != null && ( changeToken == null || !so.getChangeToken().equals( changeToken.getValue() ) ) )
+ throw new CmisUpdateConflictException( "deleteContentStream failed, ChangeToken does not match." );
+
if (!(so instanceof Content)) {
throw new CmisObjectNotFoundException("Id" + objectId
+ " does not refer to a document, but only documents can have content");
@@ -540,6 +540,9 @@ public class InMemoryObjectServiceImpl e
StoredObject so = validator.setContentStream(context, repositoryId, objectId, overwriteFlag, extension);
+ if ( so.getChangeToken() != null && ( changeToken == null || !so.getChangeToken().equals( changeToken.getValue() ) ) )
+ throw new CmisUpdateConflictException( "setContentStream failed, ChangeToken does not match." );
+
if (!(so instanceof Document || so instanceof VersionedDocument || so instanceof DocumentVersion)) {
throw new CmisObjectNotFoundException("Id" + objectId
+ " does not refer to a document, but only documents can have content");
@@ -586,7 +589,7 @@ public class InMemoryObjectServiceImpl e
if (changeToken != null && changeToken.getValue() != null
&& Long.valueOf(so.getChangeToken()) > Long.valueOf(changeToken.getValue())) {
- throw new CmisUpdateConflictException(" updateProperties failed: outdated changeToken");
+ throw new CmisUpdateConflictException("updateProperties failed: changeToken does not match");
}
// update properties
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java?rev=1241876&r1=1241875&r2=1241876&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectServiceTest.java Wed Feb 8 12:03:56 2012
@@ -297,24 +297,35 @@ public class ObjectServiceTest extends A
// delete content again
Holder<String> idHolder = new Holder<String>(id);
- fObjSvc.deleteContentStream(fRepositoryId, idHolder, null, null);
- try {
+ Properties props = fObjSvc.getProperties(fRepositoryId, id, PropertyIds.CHANGE_TOKEN, null);
+ String changeToken = (String) props.getProperties().get(PropertyIds.CHANGE_TOKEN).getFirstValue();
+ Holder<String> tokenHolder = new Holder<String>(changeToken);
+ fObjSvc.deleteContentStream(fRepositoryId, idHolder, tokenHolder, null);
+
+ try {
+ props = fObjSvc.getProperties(fRepositoryId, id, PropertyIds.CHANGE_TOKEN, null);
+ changeToken = (String) props.getProperties().get(PropertyIds.CHANGE_TOKEN).getFirstValue();
+ tokenHolder = new Holder<String>(changeToken);
sd = fObjSvc.getContentStream(fRepositoryId, id, null, BigInteger.valueOf(-1) /* offset */, BigInteger
.valueOf(-1) /* length */, null);
fail("getContentStream with non existing content should raise a CmisConstraintException");
} catch (Exception e) {
assertTrue(e instanceof CmisConstraintException);
}
+
// create content again in a second call
ContentStream contentStream = createContent();
- fObjSvc.setContentStream(fRepositoryId, idHolder, true, null, contentStream, null);
+ fObjSvc.setContentStream(fRepositoryId, idHolder, true, tokenHolder, contentStream, null);
sd = fObjSvc.getContentStream(fRepositoryId, id, null, BigInteger.valueOf(-1) /* offset */, BigInteger
.valueOf(-1) /* length */, null);
verifyContentResult(sd);
// update content and do not set overwrite flag, expect failure
try {
- fObjSvc.setContentStream(fRepositoryId, idHolder, false, null, contentStream, null);
+ props = fObjSvc.getProperties(fRepositoryId, id, PropertyIds.CHANGE_TOKEN, null);
+ changeToken = (String) props.getProperties().get(PropertyIds.CHANGE_TOKEN).getFirstValue();
+ tokenHolder = new Holder<String>(changeToken);
+ fObjSvc.setContentStream(fRepositoryId, idHolder, false, tokenHolder, contentStream, null);
fail("setContentStream with existing content and no overWriteFlag should fail");
} catch (Exception e) {
assertTrue(e instanceof CmisContentAlreadyExistsException);