chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lgr...@apache.org
Subject svn commit: r1587473 - in /chemistry/objectivecmis/trunk: ObjectiveCMIS/Bindings/ ObjectiveCMIS/Bindings/AtomPub/ ObjectiveCMIS/Bindings/AtomPub/AtomPubParser/ ObjectiveCMIS/Client/ ObjectiveCMISTests/
Date Tue, 15 Apr 2014 08:29:08 GMT
Author: lgross
Date: Tue Apr 15 08:29:08 2014
New Revision: 1587473

URL: http://svn.apache.org/r1587473
Log:
CMIS-778: Implementation of moveObject in object services of the atomPub binding

Modified:
    chemistry/objectivecmis/trunk/ObjectiveCMIS/Bindings/AtomPub/AtomPubParser/CMISAtomPubConstants.h
    chemistry/objectivecmis/trunk/ObjectiveCMIS/Bindings/AtomPub/AtomPubParser/CMISAtomPubConstants.m
    chemistry/objectivecmis/trunk/ObjectiveCMIS/Bindings/AtomPub/CMISAtomPubObjectService.m
    chemistry/objectivecmis/trunk/ObjectiveCMIS/Bindings/CMISObjectService.h
    chemistry/objectivecmis/trunk/ObjectiveCMIS/Client/CMISFileableObject.h
    chemistry/objectivecmis/trunk/ObjectiveCMIS/Client/CMISFileableObject.m
    chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests.m

Modified: chemistry/objectivecmis/trunk/ObjectiveCMIS/Bindings/AtomPub/AtomPubParser/CMISAtomPubConstants.h
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMIS/Bindings/AtomPub/AtomPubParser/CMISAtomPubConstants.h?rev=1587473&r1=1587472&r2=1587473&view=diff
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMIS/Bindings/AtomPub/AtomPubParser/CMISAtomPubConstants.h
(original)
+++ chemistry/objectivecmis/trunk/ObjectiveCMIS/Bindings/AtomPub/AtomPubParser/CMISAtomPubConstants.h
Tue Apr 15 08:29:08 2014
@@ -88,6 +88,7 @@ extern NSString * const kCMISParameterRe
 extern NSString * const kCMISParameterMajor;
 extern NSString * const kCMISParameterCheckin;
 extern NSString * const kCMISParameterCheckinComment;
+extern NSString * const kCMISParameterSourceFolderId;
 
 // Parameter Values
 extern NSString * const kCMISParameterValueTrue;

Modified: chemistry/objectivecmis/trunk/ObjectiveCMIS/Bindings/AtomPub/AtomPubParser/CMISAtomPubConstants.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMIS/Bindings/AtomPub/AtomPubParser/CMISAtomPubConstants.m?rev=1587473&r1=1587472&r2=1587473&view=diff
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMIS/Bindings/AtomPub/AtomPubParser/CMISAtomPubConstants.m
(original)
+++ chemistry/objectivecmis/trunk/ObjectiveCMIS/Bindings/AtomPub/AtomPubParser/CMISAtomPubConstants.m
Tue Apr 15 08:29:08 2014
@@ -88,6 +88,7 @@ NSString * const kCMISParameterRelativeP
 NSString * const kCMISParameterMajor = @"major";
 NSString * const kCMISParameterCheckin = @"checkin";
 NSString * const kCMISParameterCheckinComment = @"checkinComment";
+NSString * const kCMISParameterSourceFolderId = @"sourceFolderId";
 
 // Parameter Values
 NSString * const kCMISParameterValueTrue = @"true";

Modified: chemistry/objectivecmis/trunk/ObjectiveCMIS/Bindings/AtomPub/CMISAtomPubObjectService.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMIS/Bindings/AtomPub/CMISAtomPubObjectService.m?rev=1587473&r1=1587472&r2=1587473&view=diff
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMIS/Bindings/AtomPub/CMISAtomPubObjectService.m
(original)
+++ chemistry/objectivecmis/trunk/ObjectiveCMIS/Bindings/AtomPub/CMISAtomPubObjectService.m
Tue Apr 15 08:29:08 2014
@@ -524,6 +524,63 @@
     return request;
 }
 
+- (CMISRequest*)moveObject:(NSString *)objectId
+                fromFolder:(NSString *)sourceFolderId
+                  toFolder:(NSString *)targetFolderId
+           completionBlock:(void (^)(CMISObjectData *objectData, NSError *error))completionBlock
+{
+    // Validate params
+    if (!objectId) {
+        CMISLogError(@"Must provide an object id when moving it");
+        completionBlock(nil, [CMISErrors createCMISErrorWithCode:kCMISErrorCodeObjectNotFound
detailedDescription:nil]);
+        return nil;
+    }
+    
+    if (!sourceFolderId) {
+        CMISLogError(@"Must provide a source folder id when moving an object");
+        completionBlock(nil, [CMISErrors createCMISErrorWithCode:kCMISErrorCodeObjectNotFound
detailedDescription:nil]);
+        return nil;
+    }
+    
+    if (!targetFolderId) {
+        CMISLogError(@"Must provide a target folder id when moving an object");
+        completionBlock(nil, [CMISErrors createCMISErrorWithCode:kCMISErrorCodeObjectNotFound
detailedDescription:nil]);
+        return nil;
+    }
+    
+    // Build property for objectId
+    CMISPropertyData *objectIdPropertyData = [CMISPropertyData createPropertyForId:kCMISPropertyObjectId
idValue:objectId];
+    CMISProperties *properties = [[CMISProperties alloc] init];
+    [properties addProperty:objectIdPropertyData];
+    
+    
+    CMISRequest *request = [[CMISRequest alloc] init];
+    // Get Down link
+    [self loadLinkForObjectId:targetFolderId
+                     relation:kCMISLinkRelationDown
+                         type:kCMISMediaTypeChildren
+                  cmisRequest:request
+              completionBlock:^(NSString *downLink, NSError *error) {
+                  if (error) {
+                      CMISLogError(@"Could not retrieve down link: %@", error.description);
+                      if (completionBlock) {
+                          completionBlock(nil, [CMISErrors cmisError:error cmisErrorCode:kCMISErrorCodeObjectNotFound]);
+                      }
+                  } else {
+                      
+                      downLink = [CMISURLUtil urlStringByAppendingParameter:kCMISParameterSourceFolderId
value:sourceFolderId urlString:downLink];
+                      
+                      [self sendAtomEntryXmlToLink:downLink
+                                 httpRequestMethod:HTTP_POST
+                                        properties:properties
+                                       cmisRequest:request
+                                   completionBlock:completionBlock];
+                  }
+              }];
+    return request;
+}
+
+
 - (CMISRequest*)deleteTree:(NSString *)folderObjectId
                 allVersion:(BOOL)allVersions
              unfileObjects:(CMISUnfileObject)unfileObjects

Modified: chemistry/objectivecmis/trunk/ObjectiveCMIS/Bindings/CMISObjectService.h
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMIS/Bindings/CMISObjectService.h?rev=1587473&r1=1587472&r2=1587473&view=diff
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMIS/Bindings/CMISObjectService.h (original)
+++ chemistry/objectivecmis/trunk/ObjectiveCMIS/Bindings/CMISObjectService.h Tue Apr 15 08:29:08
2014
@@ -163,7 +163,7 @@
  * uploads the file from the given path to the given folder.
  *
  * completionBlock - returns NSError nil if successful
-*/
+ */
 - (CMISRequest*)createDocumentFromFilePath:(NSString *)filePath
                                   mimeType:(NSString *)mimeType
                                 properties:(CMISProperties *)properties
@@ -185,6 +185,16 @@
                                 progressBlock:(void (^)(unsigned long long bytesUploaded,
unsigned long long bytesTotal))progressBlock;
 
 /**
+ * Moves the given object from the source folder to the target folder.
+ *
+ * completionBlock - returns NSError nil if successful
+ */
+- (CMISRequest*)moveObject:(NSString *)objectId
+                fromFolder:(NSString *)sourceFolderId
+                  toFolder:(NSString *)targetFolderId
+           completionBlock:(void (^)(CMISObjectData *objectData, NSError *error))completionBlock;
+
+/**
  * Deletes the given object.
  *
  * The allVersions parameter is currently ignored.

Modified: chemistry/objectivecmis/trunk/ObjectiveCMIS/Client/CMISFileableObject.h
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMIS/Client/CMISFileableObject.h?rev=1587473&r1=1587472&r2=1587473&view=diff
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMIS/Client/CMISFileableObject.h (original)
+++ chemistry/objectivecmis/trunk/ObjectiveCMIS/Client/CMISFileableObject.h Tue Apr 15 08:29:08
2014
@@ -38,5 +38,15 @@
 - (CMISRequest*)retrieveParentsWithOperationContext:(CMISOperationContext *)operationContext

                             completionBlock:(void (^)(NSArray *parentFolders, NSError *error))completionBlock;
 
+/**
+ * Returns all the parents of this object as an array of CMISFolder objects with paging options
+ * CompletionBlock will return array or nil if unsuccessful
+ * CompletionBlock will return nil for root folder and non-fileable objects.
+ */
+- (CMISRequest*)moveFromFolderWithId:(NSString *)sourceFolderId
+                      toFolderWithId:(NSString *)targetFolderId
+                     completionBlock:(void (^)(CMISObject *object, NSError *error))completionBlock;
+
+
 
 @end

Modified: chemistry/objectivecmis/trunk/ObjectiveCMIS/Client/CMISFileableObject.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMIS/Client/CMISFileableObject.m?rev=1587473&r1=1587472&r2=1587473&view=diff
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMIS/Client/CMISFileableObject.m (original)
+++ chemistry/objectivecmis/trunk/ObjectiveCMIS/Client/CMISFileableObject.m Tue Apr 15 08:29:08
2014
@@ -47,4 +47,18 @@
                                              }];
 }
 
+- (CMISRequest *)moveFromFolderWithId:(NSString *)sourceFolderId
+                       toFolderWithId:(NSString *)targetFolderId
+                      completionBlock:(void (^)(CMISObject *, NSError *))completionBlock
+{
+    return [self.binding.objectService moveObject:self.identifier
+                                       fromFolder:sourceFolderId
+                                         toFolder:targetFolderId
+                                  completionBlock:^(CMISObjectData *objectData, NSError *error)
{
+                                      
+                                      [self.session.objectConverter convertObject:objectData
completionBlock:completionBlock];
+                                  }];
+}
+
+
 @end

Modified: chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests.m?rev=1587473&r1=1587472&r2=1587473&view=diff
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests.m (original)
+++ chemistry/objectivecmis/trunk/ObjectiveCMISTests/ObjectiveCMISTests.m Tue Apr 15 08:29:08
2014
@@ -713,6 +713,159 @@
     }];
 }
 
+- (void)testMoveDocument
+{
+    [self runTest:^ {
+        
+        [self setupMoveTestFoldersAndDocumentWithCompletionBlock:^(NSString *containerFolderId,
CMISFolder *folder1, CMISFolder *folder2, CMISDocument *document) {
+            
+            [document moveFromFolderWithId:folder1.identifier toFolderWithId:folder2.identifier
completionBlock:^(CMISObject *object, NSError *error) {
+                XCTAssertNil(error, @"Error while moving document: %@", [error description]);
+                XCTAssertNotNil(object, @"Moved document is nil but should not");
+                
+                [folder2 retrieveChildrenWithCompletionBlock:^(CMISPagedResult *result, NSError
*error) {
+                    XCTAssertNil(error, @"Got error while retrieving children: %@", [error
description]);
+                    XCTAssertNotNil(result, @"Return result should not be nil");
+                    
+                    NSArray *children = result.resultArray;
+                    XCTAssertNotNil(children, @"children should not be nil");
+                    CMISLogDebug(@"There are %d children", [children count]);
+                    XCTAssertTrue([children count] == 1, @"There should be at least 3 children");
+                    
+                    CMISObject *child = children[0];
+                    XCTAssertTrue([child isKindOfClass:[CMISDocument class]], @"The child
of folder2 is not a CMISDocument but should be");
+                    CMISDocument *retrievedDocument = (CMISDocument *)child;
+                    XCTAssertTrue([retrievedDocument.name isEqualToString:document.name],
@"Moved document's name is not equal to original");
+                    
+                    [self.session.binding.objectService deleteTree:containerFolderId
+                                                        allVersion:YES
+                                                     unfileObjects:CMISDelete
+                                                 continueOnFailure:YES
+                                                   completionBlock:^(NSArray *failedObjects,
NSError *error) {
+                                                       XCTAssertNil(error, @"Error while
move test folders and document: %@", [error description]);
+                                                       
+                                                       self.testCompleted = YES;
+                                                   }];
+                }];
+            }];
+        }];
+    }];
+}
+
+- (void)testMoveFolder
+{
+    [self runTest:^ {
+        
+        [self setupMoveTestFoldersAndDocumentWithCompletionBlock:^(NSString *containerFolderId,
CMISFolder *folder1, CMISFolder *folder2, CMISDocument *document) {
+            
+            [folder1 moveFromFolderWithId:containerFolderId toFolderWithId:folder2.identifier
completionBlock:^(CMISObject *object, NSError *error) {
+                XCTAssertNil(error, @"Error while moving document: %@", [error description]);
+                XCTAssertNotNil(object, @"Moved document is nil but should not");
+                
+                [folder2 retrieveChildrenWithCompletionBlock:^(CMISPagedResult *result, NSError
*error) {
+                    XCTAssertNil(error, @"Got error while retrieving children: %@", [error
description]);
+                    XCTAssertNotNil(result, @"Return result should not be nil");
+                    
+                    NSArray *children = result.resultArray;
+                    XCTAssertNotNil(children, @"children should not be nil");
+                    CMISLogDebug(@"There are %d children", [children count]);
+                    XCTAssertTrue([children count] == 1, @"There should be at least 3 children");
+                    
+                    CMISObject *child = children[0];
+                    XCTAssertTrue([child isKindOfClass:[CMISFolder class]], @"The child of
folder2 is not a CMISFolder but should be");
+                    CMISFolder *retrievedFolder = (CMISFolder *)child;
+                    XCTAssertTrue([retrievedFolder.name isEqualToString:folder1.name], @"Moved
folder's name is not equal to original");
+                    
+                    [self.session.binding.objectService deleteTree:containerFolderId
+                                                        allVersion:YES
+                                                     unfileObjects:CMISDelete
+                                                 continueOnFailure:YES
+                                                   completionBlock:^(NSArray *failedObjects,
NSError *error) {
+                                                       XCTAssertNil(error, @"Error while
move test folders and document: %@", [error description]);
+                                                       
+                                                       self.testCompleted = YES;
+                                                   }];
+                }];
+            }];
+        }];
+    }];
+}
+
+- (void)setupMoveTestFoldersAndDocumentWithCompletionBlock:(void (^)(NSString *containerFolderId,
CMISFolder *folder1, CMISFolder *folder2, CMISDocument *document))completionBlock
+{
+    // Setup test folder container
+    NSMutableDictionary *containerFolderProperties = [NSMutableDictionary dictionary];
+    NSString *containerFolderName = [NSString stringWithFormat:@"test-moveObject-%@", [self
stringFromCurrentDate]];
+    [containerFolderProperties setObject:containerFolderName forKey:kCMISPropertyName];
+    [containerFolderProperties setObject:kCMISPropertyObjectTypeIdValueFolder forKey:kCMISPropertyObjectTypeId];
+    
+    NSMutableDictionary *propertiesFolder1 = [NSMutableDictionary dictionary];
+    NSString *folder1Name = [NSString stringWithFormat:@"folder1"];
+    [propertiesFolder1 setObject:folder1Name forKey:kCMISPropertyName];
+    [propertiesFolder1 setObject:kCMISPropertyObjectTypeIdValueFolder forKey:kCMISPropertyObjectTypeId];
+    
+    NSMutableDictionary *propertiesFolder2 = [NSMutableDictionary dictionary];
+    NSString *folder2Name = [NSString stringWithFormat:@"folder2"];
+    [propertiesFolder2 setObject:folder2Name forKey:kCMISPropertyName];
+    [propertiesFolder2 setObject:kCMISPropertyObjectTypeIdValueFolder forKey:kCMISPropertyObjectTypeId];
+    
+    // Setup test file
+    // Check if test file exists
+    NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"test_file.txt"
ofType:nil];
+    XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:filePath],
+                  @"Test file 'test_file.txt' cannot be found as resource for the test");
+    
+    // Upload test file
+    NSString *documentName = [NSString stringWithFormat:@"test_file_%@.txt", [self stringFromCurrentDate]];
+    NSMutableDictionary *documentProperties = [NSMutableDictionary dictionary];
+    [documentProperties setObject:documentName forKey:kCMISPropertyName];
+    [documentProperties setObject:kCMISPropertyObjectTypeIdValueDocument forKey:kCMISPropertyObjectTypeId];
+    
+    // Create container folder
+    [self.rootFolder createFolder:containerFolderProperties completionBlock:^(NSString *containerFolderId,
NSError *error) {
+        XCTAssertNil(error, @"Error while creating containerFolder in root folder: %@", [error
description]);
+        
+        // Create folder 1
+        [self.session createFolder:propertiesFolder1 inFolder:containerFolderId completionBlock:^(NSString
*folder1Id, NSError *error) {
+            XCTAssertNil(error, @"Error while creating folder1 in container folder: %@",
[error description]);
+            
+            [self.session retrieveObject:folder1Id completionBlock:^(CMISObject *object,
NSError *error) {
+                CMISFolder *folder1 = (CMISFolder *)object;
+                XCTAssertNil(error, @"Error while retrieving newly created folder: %@", [error
description]);
+                XCTAssertNotNil(folder1, @"New folder should not be nil");
+                
+                // Create folder 2
+                [self.session createFolder:propertiesFolder2 inFolder:containerFolderId completionBlock:^(NSString
*folder2Id, NSError *error) {
+                    XCTAssertNil(error, @"Error while creating folder2 in container folder:
%@", [error description]);
+                    
+                    [self.session retrieveObject:folder2Id completionBlock:^(CMISObject *object,
NSError *error) {
+                        CMISFolder *folder2 = (CMISFolder *)object;
+                        XCTAssertNil(error, @"Error while retrieving newly created folder:
%@", [error description]);
+                        XCTAssertNotNil(folder2, @"New folder should not be nil");
+                        
+                        
+                        [self.session createDocumentFromFilePath:filePath mimeType:@"text/plain"
+                                                      properties:documentProperties
+                                                        inFolder:folder1Id
+                                                 completionBlock:^(NSString *objectId, NSError
*error) {
+                                                     XCTAssertNil(error, @"Error while creating
document in folder1 folder: %@", [error description]);
+                                                     
+                                                     [self.session retrieveObject:objectId
completionBlock:^(CMISObject *object, NSError *error) {
+                                                         CMISDocument *document = (CMISDocument
*)object;
+                                                         XCTAssertNil(error, @"Error while
retrieving newly created document: %@", [error description]);
+                                                         XCTAssertNotNil(document, @"New
document should not be nil");
+                                                         
+                                                         completionBlock(containerFolderId,
folder1, folder2, document);
+                                                     }];
+                                                 } progressBlock:nil];
+                    }];
+                }];
+                
+            }];
+        }];
+    }];
+}
+
 - (void)testRetrieveAllVersionsOfDocument
 {
     [self runTest:^ {



Mime
View raw message