You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by ga...@apache.org on 2014/03/31 17:36:58 UTC

svn commit: r1583350 - in /chemistry/objectivecmis/trunk: ObjectiveCMIS/Client/CMISSession.m ObjectiveCMIS/Common/CMISErrors.h ObjectiveCMIS/Common/CMISErrors.m ObjectiveCMISTests/ObjectiveCMISTests.m

Author: gavincornwell
Date: Mon Mar 31 15:36:58 2014
New Revision: 1583350

URL: http://svn.apache.org/r1583350
Log:
Fixed issue with canceling create operations, calling cancel on the returned request object for create folder and create document methods had no effect.

Modified:
    chemistry/objectivecmis/trunk/ObjectiveCMIS/Client/CMISSession.m
    chemistry/objectivecmis/trunk/ObjectiveCMIS/Common/CMISErrors.h
    chemistry/objectivecmis/trunk/ObjectiveCMIS/Common/CMISErrors.m
    chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests.m

Modified: chemistry/objectivecmis/trunk/ObjectiveCMIS/Client/CMISSession.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMIS/Client/CMISSession.m?rev=1583350&r1=1583349&r2=1583350&view=diff
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMIS/Client/CMISSession.m (original)
+++ chemistry/objectivecmis/trunk/ObjectiveCMIS/Client/CMISSession.m Mon Mar 31 15:36:58 2014
@@ -428,11 +428,13 @@
                                if (error) {
                                    completionBlock(nil, [CMISErrors cmisError:error cmisErrorCode:kCMISErrorCodeRuntime]);
                                } else {
-                                  request = [self.binding.objectService createFolderInParentFolder:folderObjectId
+                                  CMISRequest *createRequest = [self.binding.objectService createFolderInParentFolder:folderObjectId
                                                                                properties:convertedProperties
                                                                           completionBlock:^(NSString *objectId, NSError *error) {
                                                                               completionBlock(objectId, error);
                                                                           }];
+                                   // set the underlying request object on the object returned to the original caller
+                                   request.httpRequest = createRequest.httpRequest;
                                }
                            }];
     return request;
@@ -513,12 +515,14 @@
                 completionBlock(nil, [CMISErrors cmisError:error cmisErrorCode:kCMISErrorCodeRuntime]);
             }
         } else {
-            request = [self.binding.objectService createDocumentFromFilePath:filePath
+            CMISRequest *createRequest = [self.binding.objectService createDocumentFromFilePath:filePath
                                                                     mimeType:mimeType
                                                                   properties:convertedProperties
                                                                     inFolder:folderObjectId
                                                              completionBlock:completionBlock
                                                                progressBlock:progressBlock];
+            // set the underlying request object on the object returned to the original caller
+            request.httpRequest = createRequest.httpRequest;
         }
     }];
     return request;
@@ -542,13 +546,15 @@
                 completionBlock(nil, [CMISErrors cmisError:error cmisErrorCode:kCMISErrorCodeRuntime]);
             }
         } else {
-            request = [self.binding.objectService createDocumentFromInputStream:inputStream
+            CMISRequest *createRequest = [self.binding.objectService createDocumentFromInputStream:inputStream
                                                              mimeType:mimeType
                                                            properties:convertedProperties
                                                              inFolder:folderObjectId
                                                         bytesExpected:bytesExpected
                                                       completionBlock:completionBlock
                                                         progressBlock:progressBlock];
+            // set the underlying request object on the object returned to the original caller
+            request.httpRequest = createRequest.httpRequest;
         }
     }];
     return request;

Modified: chemistry/objectivecmis/trunk/ObjectiveCMIS/Common/CMISErrors.h
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMIS/Common/CMISErrors.h?rev=1583350&r1=1583349&r2=1583350&view=diff
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMIS/Common/CMISErrors.h (original)
+++ chemistry/objectivecmis/trunk/ObjectiveCMIS/Common/CMISErrors.h Mon Mar 31 15:36:58 2014
@@ -79,6 +79,7 @@ extern NSString * const kCMISErrorDescri
 extern NSString * const kCMISErrorDescriptionUnauthorized;
 extern NSString * const kCMISErrorDescriptionNoRootFolderFound;
 extern NSString * const kCMISErrorDescriptionRepositoryNotFound;
+extern NSString * const kCMISErrorDescriptionCancelled;
 //General errors as defined in 2.2.1.4.1 of spec
 extern NSString * const kCMISErrorDescriptionInvalidArgument;
 extern NSString * const kCMISErrorDescriptionObjectNotFound;

Modified: chemistry/objectivecmis/trunk/ObjectiveCMIS/Common/CMISErrors.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMIS/Common/CMISErrors.m?rev=1583350&r1=1583349&r2=1583350&view=diff
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMIS/Common/CMISErrors.m (original)
+++ chemistry/objectivecmis/trunk/ObjectiveCMIS/Common/CMISErrors.m Mon Mar 31 15:36:58 2014
@@ -36,6 +36,7 @@ NSString * const kCMISErrorDescriptionPr
 NSString * const kCMISErrorDescriptionUnauthorized = @"Unauthorized access error";
 NSString * const kCMISErrorDescriptionNoRootFolderFound =  @"Root Folder Not Found Error";
 NSString * const kCMISErrorDescriptionRepositoryNotFound =  @"Repository Not Found Error";
+NSString * const kCMISErrorDescriptionCancelled = @"Operation Cancelled";
 
 //General errors as defined in 2.2.1.4.1 of spec
 NSString * const kCMISErrorDescriptionInvalidArgument = @"Invalid Argument Error";
@@ -100,6 +101,8 @@ NSString * const kCMISErrorDescriptionVe
             return kCMISErrorDescriptionNoRootFolderFound;
         case kCMISErrorCodeNoRepositoryFound:
             return kCMISErrorDescriptionRepositoryNotFound;
+        case kCMISErrorCodeCancelled:
+            return kCMISErrorDescriptionCancelled;
         case kCMISErrorCodeInvalidArgument:
             return kCMISErrorDescriptionInvalidArgument;
         case kCMISErrorCodeObjectNotFound:

Modified: chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests.m?rev=1583350&r1=1583349&r2=1583350&view=diff
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests.m (original)
+++ chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests.m Mon Mar 31 15:36:58 2014
@@ -394,8 +394,10 @@
 
                  self.testCompleted = YES;
              } progressBlock:^(unsigned long long bytesDownloaded, unsigned long long bytesTotal) {
+                 CMISLogDebug(@"download progress %i/%i", bytesDownloaded, bytesTotal);
                  if (bytesDownloaded > 0) { // as soon as some data was downloaded cancel the request
                      [self.request cancel];
+                     CMISLogDebug(@"download cancelled");
                      self.request = nil;
                  }
              }];
@@ -403,6 +405,59 @@
      }];
 }
 
+- (void)testCancelCreate
+{
+    [self runTest:^ {
+        // Set properties on test file
+        NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"cmis-spec-v1.0.pdf" ofType:nil];
+        NSString *documentName = [NSString stringWithFormat:@"cmis_10_spec_%f.txt", [[NSDate date] timeIntervalSince1970]];
+        NSMutableDictionary *documentProperties = [NSMutableDictionary dictionary];
+        [documentProperties setObject:documentName forKey:kCMISPropertyName];
+        [documentProperties setObject:kCMISPropertyObjectTypeIdValueDocument forKey:kCMISPropertyObjectTypeId];
+        
+        // Upload test file
+        self.request = [self.session createDocumentFromFilePath:filePath
+                                        mimeType:@"application/pdf"
+                                      properties:documentProperties
+                                        inFolder:self.rootFolder.identifier
+                                 completionBlock: ^ (NSString *newObjectId, NSError *error) {
+                                     
+                                     XCTAssertNotNil(error, @"Failed to cancel upload");
+                                     XCTAssertTrue(error.code == kCMISErrorCodeCancelled, @"Expected error code to be 6 (kCMISErrorCodeCancelled) but it was %ld", (long)error.code);
+                                     XCTAssertNil(newObjectId, @"Did not expect to recieve a new object id");
+                                     
+                                     // ensure the object was not created on the server
+                                     NSString *path = [NSString stringWithFormat:@"/%@", documentName];
+                                     [self.session retrieveObjectByPath:path completionBlock:^(CMISObject *object, NSError *error) {
+                                         XCTAssertNotNil(error, @"Expected to get an error when attempting to retrieve cancelled upload");
+                                         XCTAssertTrue(error.code == kCMISErrorCodeObjectNotFound, @"Expected error code to be 257 (kCMISErrorCodeObjectNotFound) but it was %ld", (long)error.code);
+                                         XCTAssertNil(object, @"Did not expect the object to be created on the server");
+                                         
+                                         if (object != nil)
+                                         {
+                                             // if object was created, cleanup
+                                             [self deleteDocumentAndVerify:(CMISDocument *)object completionBlock:^{
+                                                 self.testCompleted = YES;
+                                             }];
+                                         }
+                                         else
+                                         {
+                                             self.testCompleted = YES;
+                                         }
+                                     }];
+                                 }
+                                   progressBlock: ^ (unsigned long long uploadedBytes, unsigned long long totalBytes) {
+                                       CMISLogDebug(@"upload progress %i/%i", uploadedBytes, totalBytes);
+                                       if (uploadedBytes > 0) {
+                                           // as soon as some data was uploaded cancel the request
+                                           [self.request cancel];
+                                           CMISLogDebug(@"create cancelled");
+                                           self.request = nil;
+                                       }
+                                   }];
+    }];
+}
+
 - (void)testCreateAndDeleteDocument
 {
     [self runTest:^ {