chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lgr...@apache.org
Subject svn commit: r1578378 [2/2] - in /chemistry/objectivecmis/trunk/ObjectiveCMIS: Bindings/ Bindings/AtomPub/ Bindings/AtomPub/AtomPubParser/ Client/ Common/ Utils/
Date Mon, 17 Mar 2014 13:53:06 GMT
Modified: chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISHttpUploadRequest.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISHttpUploadRequest.m?rev=1578378&r1=1578377&r2=1578378&view=diff
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISHttpUploadRequest.m (original)
+++ chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISHttpUploadRequest.m Mon Mar 17 13:53:05
2014
@@ -27,6 +27,8 @@
 #import "CMISBase64Encoder.h"
 #import "CMISAtomEntryWriter.h"
 #import "CMISLog.h"
+#import "CMISErrors.h"
+
 /**
  this is the buffer size for the input/output stream pair containing the base64 encoded data
  */
@@ -82,7 +84,7 @@ const NSUInteger kRawBufferSize = 24576;
 @interface CMISHttpUploadRequest ()
 
 @property (nonatomic, assign) unsigned long long bytesUploaded;
-@property (nonatomic, copy) void (^progressBlock)(unsigned long long bytesUploaded, unsigned
long long bytesTotal);
+@property (nonatomic, copy) void (^progressBlock)(unsigned long long bytesUploaded, unsigned
long long bytesTotal, BOOL *stop);
 @property (nonatomic, assign) BOOL base64Encoding;
 @property (nonatomic, strong) NSInputStream *base64InputStream;
 @property (nonatomic, strong) NSOutputStream *encoderStream;
@@ -100,7 +102,7 @@ const NSUInteger kRawBufferSize = 24576;
 
 - (id)initWithHttpMethod:(CMISHttpRequestMethod)httpRequestMethod
          completionBlock:(void (^)(CMISHttpResponse *httpResponse, NSError *error))completionBlock
-           progressBlock:(void (^)(unsigned long long bytesUploaded, unsigned long long bytesTotal))progressBlock;
+           progressBlock:(void (^)(unsigned long long bytesUploaded, unsigned long long bytesTotal,
BOOL *stop))progressBlock;
 
 @end
 
@@ -114,7 +116,7 @@ const NSUInteger kRawBufferSize = 24576;
                          bytesExpected:(unsigned long long)bytesExpected
                 authenticationProvider:(id<CMISAuthenticationProvider>) authenticationProvider
                        completionBlock:(void (^)(CMISHttpResponse *httpResponse, NSError
*error))completionBlock
-                         progressBlock:(void (^)(unsigned long long bytesUploaded, unsigned
long long bytesTotal))progressBlock
+                         progressBlock:(void (^)(unsigned long long bytesUploaded, unsigned
long long bytesTotal, BOOL *stop))progressBlock
 {
     CMISHttpUploadRequest *httpRequest = [[self alloc] initWithHttpMethod:httpRequestMethod
                                                           completionBlock:completionBlock
@@ -143,7 +145,7 @@ authenticationProvider:(id<CMISAuthentic
     cmisProperties:(CMISProperties *)cmisProperties
           mimeType:(NSString *)mimeType
    completionBlock:(void (^)(CMISHttpResponse *httpResponse, NSError *error))completionBlock
-     progressBlock:(void (^)(unsigned long long bytesUploaded, unsigned long long bytesTotal))progressBlock
+     progressBlock:(void (^)(unsigned long long bytesUploaded, unsigned long long bytesTotal,
BOOL *stop))progressBlock
 {
     CMISHttpUploadRequest *httpRequest = [[self alloc] initWithHttpMethod:httpRequestMethod
                                                           completionBlock:completionBlock
@@ -167,7 +169,7 @@ authenticationProvider:(id<CMISAuthentic
 
 - (id)initWithHttpMethod:(CMISHttpRequestMethod)httpRequestMethod
          completionBlock:(void (^)(CMISHttpResponse *httpResponse, NSError *error))completionBlock
-           progressBlock:(void (^)(unsigned long long bytesUploaded, unsigned long long bytesTotal))progressBlock
+           progressBlock:(void (^)(unsigned long long bytesUploaded, unsigned long long bytesTotal,
BOOL *stop))progressBlock
 {
     self = [super initWithHttpMethod:httpRequestMethod
                      completionBlock:completionBlock];
@@ -241,10 +243,17 @@ totalBytesExpectedToWrite:(NSInteger)tot
             }
         }
         
+        BOOL cancelled = NO;
         if (self.bytesExpected == 0) {
-            self.progressBlock((unsigned long long)totalBytesWritten, (unsigned long long)totalBytesExpectedToWrite);
+            self.progressBlock((unsigned long long)totalBytesWritten, (unsigned long long)totalBytesExpectedToWrite,
&cancelled);
         } else {
-            self.progressBlock((unsigned long long)totalBytesWritten, self.bytesExpected);
+            self.progressBlock((unsigned long long)totalBytesWritten, self.bytesExpected,
&cancelled);
+        }
+        
+        // Cancel Upload Request if requested
+        if (cancelled == YES) {
+            [self cancel];
+            self.progressBlock((unsigned long long)totalBytesWritten, self.bytesExpected,
&cancelled);
         }
     }
 }
@@ -385,6 +394,8 @@ totalBytesExpectedToWrite:(NSInteger)tot
                 bytesWritten = [self.encoderStream write:&buffer[self.bufferOffset] maxLength:self.bufferLimit
- self.bufferOffset];
                 if (bytesWritten <= 0) {
                     [self stopSendWithStatus:@"Network write error"];
+                    NSError *cmisError = [CMISErrors createCMISErrorWithCode:kCMISErrorCodeConnection
detailedDescription:@"Network write error"];
+                    [self connection:nil didFailWithError:cmisError];
                 } else {
                     self.bufferOffset += bytesWritten;
                 }
@@ -430,8 +441,8 @@ totalBytesExpectedToWrite:(NSInteger)tot
     self.streamEndData = [end dataUsingEncoding:NSUTF8StringEncoding];
     
     unsigned long long encodedLength = [CMISHttpUploadRequest base64EncodedLength:self.bytesExpected];
-    encodedLength += start.length;
-    encodedLength += end.length;
+    encodedLength += self.streamStartData.length;
+    encodedLength += self.streamEndData.length;
     self.encodedLength = encodedLength;
 }
 

Modified: chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISObjectConverter.m
URL: http://svn.apache.org/viewvc/chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISObjectConverter.m?rev=1578378&r1=1578377&r2=1578378&view=diff
==============================================================================
--- chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISObjectConverter.m (original)
+++ chemistry/objectivecmis/trunk/ObjectiveCMIS/Utils/CMISObjectConverter.m Mon Mar 17 13:53:05
2014
@@ -25,6 +25,7 @@
 #import "CMISPropertyDefinition.h"
 #import "CMISSession.h"
 #import "CMISDateUtil.h"
+#import "CMISConstants.h"
 
 @interface CMISObjectConverter ()
 @property (nonatomic, weak) CMISSession *session;
@@ -63,15 +64,19 @@
 {
     [self convertObject:[objectDatas objectAtIndex:position]
         completionBlock:^(CMISObject *object, NSError *error) {
-            if (position == 0) {
-                NSMutableArray *objects = [[NSMutableArray alloc] initWithCapacity:objectDatas.count];
-                [objects addObject:object];
-                completionBlock(objects, error);
+            if(error){
+                completionBlock(nil, error);
             } else {
-                [self internalConvertObject:objectDatas position:(position - 1) completionBlock:^(NSMutableArray
*objects, NSError *error) {
+                if (position == 0) {
+                    NSMutableArray *objects = [[NSMutableArray alloc] initWithCapacity:objectDatas.count];
                     [objects addObject:object];
                     completionBlock(objects, error);
-                }];
+                } else {
+                    [self internalConvertObject:objectDatas position:(position - 1) completionBlock:^(NSMutableArray
*objects, NSError *error) {
+                        [objects addObject:object];
+                        completionBlock(objects, error);
+                    }];
+                }
             }
         }];
 }
@@ -99,8 +104,15 @@
 }
 
 
-- (void)internalNormalConvertProperties:(NSDictionary *)properties 
-                         typeDefinition:(CMISTypeDefinition *)typeDefinition 
+- (void)internalNormalConvertProperties:(NSDictionary *)properties
+                         typeDefinition:(CMISTypeDefinition *)typeDefinition
+                        completionBlock:(void (^)(CMISProperties *convertedProperties, NSError
*error))completionBlock
+{
+    [self internalNormalConvertProperties:properties typeDefinitions:[NSArray arrayWithObject:typeDefinition]
completionBlock:completionBlock];
+}
+
+- (void)internalNormalConvertProperties:(NSDictionary *)properties
+                         typeDefinitions:(NSArray *)typeDefinitions
                         completionBlock:(void (^)(CMISProperties *convertedProperties, NSError
*error))completionBlock
 {
     CMISProperties *convertedProperties = [[CMISProperties alloc] init];
@@ -111,7 +123,7 @@
             [convertedProperties addProperty:(CMISPropertyData *)propertyValue];
         } else {
             // Convert to CMISPropertyData based on the string
-            CMISPropertyDefinition *propertyDefinition = [typeDefinition propertyDefinitionForId:propertyId];
+            CMISPropertyDefinition *propertyDefinition = [self propertyDefinitionFromTypeDefinitions:typeDefinitions
propertyId:propertyId];
             
             if (propertyDefinition == nil) {
                 NSError *error = [CMISErrors createCMISErrorWithCode:kCMISErrorCodeInvalidArgument
@@ -310,6 +322,18 @@
     completionBlock(convertedProperties, nil);
 }
 
+-(CMISPropertyDefinition*)propertyDefinitionFromTypeDefinitions:(NSArray *)typeDefinitions
propertyId:(NSString*)propertyId
+{
+    for (CMISTypeDefinition* typeDefinition in typeDefinitions) {
+        CMISPropertyDefinition *propertyDefinition = [typeDefinition propertyDefinitionForId:propertyId];
+        
+        if (propertyDefinition) {
+            return propertyDefinition;
+        }
+    }
+    return nil;
+}
+
 
 - (void)internalNormalConvertProperties:(NSDictionary *)properties
                            objectTypeId:(NSString *)objectTypeId
@@ -346,16 +370,94 @@
                               completionBlock:completionBlock];
         
     } else {
-        [self.session retrieveTypeDefinition:objectTypeId
-                             completionBlock:^(CMISTypeDefinition *typeDefinition, NSError
*error) {
-                                 if (error) {
-                                     completionBlock(nil, [CMISErrors cmisError:error cmisErrorCode:kCMISErrorCodeRuntime]);
-                                 } else {
-                                     [self internalNormalConvertProperties:properties
-                                                            typeDefinition:typeDefinition
-                                                           completionBlock:completionBlock];
-                                 }
-                             }];
+        
+        //get secondary object type definitions - if available
+        NSString *propertyId = kCMISPropertySecondaryObjectTypeIds;
+        id secondaryObjectTypeIds = [properties valueForKey:propertyId];
+        if(secondaryObjectTypeIds) {
+            Class expectedType = nil;
+            BOOL validType = YES;
+            
+            //verify types
+            expectedType = [NSArray class];
+            if([secondaryObjectTypeIds isKindOfClass:expectedType]){
+                expectedType = [NSString class];
+                for (id secondaryObjectTypeId in secondaryObjectTypeIds) {
+                    propertyId = secondaryObjectTypeId;
+                    if(![secondaryObjectTypeId isKindOfClass:expectedType]){
+                        validType = NO;
+                        break;
+                    }
+                }
+            } else {
+                validType = NO;
+            }
+            
+            if (!validType) {
+                NSError *error = [CMISErrors createCMISErrorWithCode:kCMISErrorCodeInvalidArgument
+                                                 detailedDescription:[NSString stringWithFormat:@"Property
value for %@ should be of type '%@'", propertyId, expectedType]];
+                completionBlock(nil, error);
+                return;
+            }
+            
+            NSMutableArray *objectTypeIds = [NSMutableArray arrayWithObject:objectTypeId];
+            [objectTypeIds addObjectsFromArray:secondaryObjectTypeIds];
+            [self retrieveTypeDefinitions:objectTypeIds
+                          completionBlock:^(NSArray *typeDefinitions, NSError *error) {
+                              if (error) {
+                                  completionBlock(nil, [CMISErrors cmisError:error cmisErrorCode:kCMISErrorCodeRuntime]);
+                              } else {
+                                  [self internalNormalConvertProperties:properties
+                                                         typeDefinitions:typeDefinitions
+                                                        completionBlock:completionBlock];
+                              }
+            }];
+        } else {
+            [self.session retrieveTypeDefinition:objectTypeId
+                                 completionBlock:^(CMISTypeDefinition *typeDefinition, NSError
*error) {
+                                     if (error) {
+                                         completionBlock(nil, [CMISErrors cmisError:error
cmisErrorCode:kCMISErrorCodeRuntime]);
+                                     } else {
+                                         [self internalNormalConvertProperties:properties
+                                                                typeDefinition:typeDefinition
+                                                               completionBlock:completionBlock];
+                                     }
+                                 }];
+        }
+    }
+}
+
+- (void)retrieveTypeDefinitions:(NSArray *)objectTypeIds position:(NSInteger)position completionBlock:(void
(^)(NSMutableArray *typeDefinitions, NSError *error))completionBlock
+{
+    [self.session retrieveTypeDefinition:[objectTypeIds objectAtIndex:position]
+                         completionBlock:^(CMISTypeDefinition *typeDefinition, NSError *error)
{
+            if(error){
+                completionBlock(nil, error);
+            } else {
+                if (position == 0) {
+                    NSMutableArray *typeDefinitions = [[NSMutableArray alloc] initWithCapacity:objectTypeIds.count];
+                    [typeDefinitions addObject:typeDefinition];
+                    completionBlock(typeDefinitions, error);
+                } else {
+                    [self retrieveTypeDefinitions:objectTypeIds position:(position - 1) completionBlock:^(NSMutableArray
*typeDefinitions, NSError *error) {
+                        [typeDefinitions addObject:typeDefinition];
+                        completionBlock(typeDefinitions, error);
+                    }];
+                }
+            }
+        }];
+}
+
+- (void)retrieveTypeDefinitions:(NSArray *)objectTypeIds completionBlock:(void (^)(NSArray
*typeDefinitions, NSError *error))completionBlock
+{
+    if (objectTypeIds.count > 0) {
+        [self retrieveTypeDefinitions:objectTypeIds
+                           position:(objectTypeIds.count - 1) // start recursion with last
item
+                    completionBlock:^(NSMutableArray *typeDefinitions, NSError *error) {
+                        completionBlock(typeDefinitions, error);
+                    }];
+    } else {
+        completionBlock([[NSArray alloc] init], nil);
     }
 }
 



Mime
View raw message