Skip to content

Commit

Permalink
Merge branch 'originalFork'
Browse files Browse the repository at this point in the history
Conflicts:
	Code/Network/RKClient.h
	Code/Network/RKResponse.m
	Code/ObjectMapping/RKObjectManager.h
	Code/ObjectMapping/RKObjectMapper.m
	Code/ObjectMapping/RKObjectMapping.m
	Code/ObjectMapping/RKObjectMappingProvider.h
	Code/ObjectMapping/RKObjectMappingProvider.m
	Docs/Object Mapping.md
	RestKit.xcodeproj/project.pbxproj
	Specs/Fixtures/JSON/Dynamic/boy.json
	Specs/Models/RKDynamicMappingModels.h
	Specs/Models/RKDynamicMappingModels.m
	Specs/Network/RKClientSpec.m
	Specs/ObjectMapping/RKObjectManagerSpec.m
	Specs/ObjectMapping/RKObjectMappingNextGenSpec.m
  • Loading branch information
Edubits committed Aug 1, 2011
2 parents db59e9b + 9e56cfa commit 11a9c09
Show file tree
Hide file tree
Showing 80 changed files with 3,901 additions and 3,758 deletions.
23 changes: 0 additions & 23 deletions Code/CoreData/RKManagedObjectFactory.h

This file was deleted.

80 changes: 0 additions & 80 deletions Code/CoreData/RKManagedObjectFactory.m

This file was deleted.

9 changes: 0 additions & 9 deletions Code/CoreData/RKManagedObjectLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#import "RKManagedObjectLoader.h"
#import "RKURL.h"
#import "RKObjectMapper.h"
#import "RKManagedObjectFactory.h"
#import "RKManagedObjectThreadSafeInvocation.h"
#import "NSManagedObject+ActiveRecord.h"
#import "../ObjectMapping/RKObjectLoader_Internals.h"
Expand Down Expand Up @@ -150,14 +149,6 @@ - (void)processMappingResult:(RKObjectMappingResult*)result {
[invocation invokeOnMainThread];
}

- (id<RKObjectFactory>)createObjectFactory {
if (self.objectManager.objectStore) {
return [RKManagedObjectFactory objectFactoryWithObjectStore:self.objectStore];
}

return nil;
}

// Overloaded to handle deleting an object orphaned by a failed postObject:
- (void)handleResponseError {
[super handleResponseError];
Expand Down
47 changes: 47 additions & 0 deletions Code/CoreData/RKManagedObjectMapping.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#import "RKManagedObjectMapping.h"
#import "NSManagedObject+ActiveRecord.h"
#import "RKObjectManager.h"
#import "RKManagedObjectStore.h"

@implementation RKManagedObjectMapping

Expand Down Expand Up @@ -78,4 +80,49 @@ - (id)defaultValueForMissingAttribute:(NSString*)attributeName {
return [desc defaultValue];
}

- (id)mappableObjectForData:(id)mappableData {
NSAssert(mappableData, @"Mappable data cannot be nil");

// TODO: We do not want to be using this singleton reference to the object store.
// Clean this up when we update the Core Data internals
RKManagedObjectStore* objectStore = [RKObjectManager sharedManager].objectStore;
NSAssert(objectStore, @"Object store cannot be nil");

id object = nil;
id primaryKeyValue = nil;
NSString* primaryKeyAttribute;

NSEntityDescription* entity = [self entity];
RKObjectAttributeMapping* primaryKeyAttributeMapping = nil;

primaryKeyAttribute = [self primaryKeyAttribute];
if (primaryKeyAttribute) {
// If a primary key has been set on the object mapping, find the attribute mapping
// so that we can extract any existing primary key from the mappable data
for (RKObjectAttributeMapping* attributeMapping in self.attributeMappings) {
if ([attributeMapping.destinationKeyPath isEqualToString:primaryKeyAttribute]) {
primaryKeyAttributeMapping = attributeMapping;
break;
}
}

// Get the primary key value out of the mappable data (if any)
NSString* keyPathForPrimaryKeyElement = primaryKeyAttributeMapping.sourceKeyPath;
if (keyPathForPrimaryKeyElement) {
primaryKeyValue = [mappableData valueForKeyPath:keyPathForPrimaryKeyElement];
}
}

// If we have found the primary key attribute & value, try to find an existing instance to update
if (primaryKeyAttribute && primaryKeyValue) {
object = [objectStore findOrCreateInstanceOfEntity:entity withPrimaryKeyAttribute:primaryKeyAttribute andValue:primaryKeyValue];
NSAssert2(object, @"Failed creation of managed object with entity '%@' and primary key value '%@'", entity.name, primaryKeyValue);
} else {
object = [[[NSManagedObject alloc] initWithEntity:entity
insertIntoManagedObjectContext:objectStore.managedObjectContext] autorelease];
}

return object;
}

@end
27 changes: 17 additions & 10 deletions Code/CoreData/RKManagedObjectMappingOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "RKManagedObjectMappingOperation.h"
#import "RKManagedObjectMapping.h"
#import "NSManagedObject+ActiveRecord.h"
#import "../Support/RKLog.h"

/**
Progressively enhance the RKObjectMappingOperation base class to inject Core Data
Expand All @@ -20,12 +21,12 @@ @implementation RKObjectMappingOperation (CoreData)
Trampoline the initialization through RKManagedObjectMapping so the mapper uses RKManagedObjectMappingOperation
at the right moments
*/
+ (RKObjectMappingOperation*)mappingOperationFromObject:(id)sourceObject toObject:(id)destinationObject withObjectMapping:(RKObjectMapping*)objectMapping {
+ (RKObjectMappingOperation*)mappingOperationFromObject:(id)sourceObject toObject:(id)destinationObject withMapping:(RKObjectMapping*)objectMapping {
if ([objectMapping isKindOfClass:[RKManagedObjectMapping class]]) {
return [[[RKManagedObjectMappingOperation alloc] initWithSourceObject:sourceObject destinationObject:destinationObject objectMapping:objectMapping] autorelease];
return [[[RKManagedObjectMappingOperation alloc] initWithSourceObject:sourceObject destinationObject:destinationObject mapping:objectMapping] autorelease];
}

return [[[RKObjectMappingOperation alloc] initWithSourceObject:sourceObject destinationObject:destinationObject objectMapping:objectMapping] autorelease];
return [[[RKObjectMappingOperation alloc] initWithSourceObject:sourceObject destinationObject:destinationObject mapping:objectMapping] autorelease];
}

@end
Expand All @@ -48,15 +49,21 @@ - (void)connectRelationships {
NSDictionary* relationshipsAndPrimaryKeyAttributes = [(RKManagedObjectMapping*)self.objectMapping relationshipsAndPrimaryKeyAttributes];
for (NSString* relationshipName in relationshipsAndPrimaryKeyAttributes) {
NSString* primaryKeyAttribute = [relationshipsAndPrimaryKeyAttributes objectForKey:relationshipName];
RKObjectRelationshipMapping* mapping = [self.objectMapping mappingForKeyPath:relationshipName];
NSAssert(mapping, @"Unable to find relationship mapping '%@' to connect by primaryKey", relationshipName);
NSAssert([mapping isKindOfClass:[RKObjectRelationshipMapping class]], @"Expected mapping for %@ to be a relationship mapping", relationshipName);
NSAssert([mapping.objectMapping isKindOfClass:[RKManagedObjectMapping class]], @"Can only connect RKManagedObjectMapping relationships");
NSString* primaryKeyAttributeOfRelatedObject = [(RKManagedObjectMapping*)mapping.objectMapping primaryKeyAttribute];
NSAssert(primaryKeyAttributeOfRelatedObject, @"Cannot connect relationship: mapping for %@ has no primary key attribute specified", NSStringFromClass(mapping.objectMapping.objectClass));
RKObjectRelationshipMapping* relationshipMapping = [self.objectMapping mappingForKeyPath:relationshipName];
id<RKObjectMappingDefinition> mapping = relationshipMapping.mapping;
if (! [mapping isKindOfClass:[RKObjectMapping class]]) {
RKLogWarning(@"Can only connect relationships for RKObjectMapping relationships. Found %@: Skipping...", NSStringFromClass([mapping class]));
continue;
}
RKObjectMapping* objectMapping = (RKObjectMapping*)mapping;
NSAssert(relationshipMapping, @"Unable to find relationship mapping '%@' to connect by primaryKey", relationshipName);
NSAssert([relationshipMapping isKindOfClass:[RKObjectRelationshipMapping class]], @"Expected mapping for %@ to be a relationship mapping", relationshipName);
NSAssert([relationshipMapping.mapping isKindOfClass:[RKManagedObjectMapping class]], @"Can only connect RKManagedObjectMapping relationships");
NSString* primaryKeyAttributeOfRelatedObject = [(RKManagedObjectMapping*)objectMapping primaryKeyAttribute];
NSAssert(primaryKeyAttributeOfRelatedObject, @"Cannot connect relationship: mapping for %@ has no primary key attribute specified", NSStringFromClass(objectMapping.objectClass));
id valueOfLocalPrimaryKeyAttribute = [self.destinationObject valueForKey:primaryKeyAttribute];
if (valueOfLocalPrimaryKeyAttribute) {
id relatedObject = [mapping.objectMapping.objectClass findFirstByAttribute:primaryKeyAttributeOfRelatedObject withValue:valueOfLocalPrimaryKeyAttribute];
id relatedObject = [objectMapping.objectClass findFirstByAttribute:primaryKeyAttributeOfRelatedObject withValue:valueOfLocalPrimaryKeyAttribute];
[self.destinationObject setValue:relatedObject forKey:relationshipName];
// TODO: Logging
}
Expand Down
4 changes: 1 addition & 3 deletions Code/CoreData/RKManagedObjectSeeder.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#import "RKManagedObjectSeeder.h"
#import "RKManagedObjectStore.h"
#import "RKManagedObjectFactory.h"
#import "../ObjectMapping/RKParserRegistry.h"
#import "RKLog.h"

Expand Down Expand Up @@ -114,13 +113,12 @@ - (void)seedObjectsFromFile:(NSString*)fileName withObjectMapping:(RKObjectMappi
RKObjectMappingProvider* mappingProvider = nil;
if (nilOrObjectMapping) {
mappingProvider = [[RKObjectMappingProvider new] autorelease];
[mappingProvider setObjectMapping:nilOrObjectMapping forKeyPath:@""];
[mappingProvider setMapping:nilOrObjectMapping forKeyPath:@""];
} else {
mappingProvider = _manager.mappingProvider;
}

RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:parsedData mappingProvider:mappingProvider];
mapper.objectFactory = [RKManagedObjectFactory objectFactoryWithObjectStore:_manager.objectStore];
RKObjectMappingResult* result = [mapper performMapping];
if (result == nil) {
RKLogError(@"Database seeding from file '%@' failed due to object mapping errors: %@", fileName, mapper.errors);
Expand Down
28 changes: 28 additions & 0 deletions Code/Network/RKClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
BOOL _serviceUnavailableAlertEnabled;
RKRequestCache* _cache;
RKRequestCachePolicy _cachePolicy;
NSMutableSet *_additionalRootCertificates;
BOOL _disableCertificateValidation;

id<ZanoxAuthDelegate> _zanoxAuth;
}
Expand All @@ -157,6 +159,22 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
*/
@property(nonatomic, readonly) NSMutableDictionary* HTTPHeaders;

#ifdef RESTKIT_SSL_VALIDATION
/**
* A set of additional certificates to be used in evaluating server
* SSL certificates.
*/
@property(nonatomic, readonly) NSSet* additionalRootCertificates;
#endif

/**
* Accept all SSL certificates. This is a potential security exposure,
* and should be used ONLY while debugging in a controlled environment.
*
* *Default*: _NO_
*/
@property(nonatomic, assign) BOOL disableCertificateValidation;

/**
* Will check for network connectivity to the host specified in the baseURL
*
Expand All @@ -175,6 +193,16 @@ NSString* RKPathAppendQueryParams(NSString* resourcePath, NSDictionary* queryPar
*/
- (void)setValue:(NSString*)value forHTTPHeaderField:(NSString*)header;

#ifdef RESTKIT_SSL_VALIDATION
/**
* Adds an additional certificate that will be used to evaluate server SSL certs
*
* @param cert The HTTP header to add
* @see additionalRootCertificates
*/
- (void)addRootCertificate:(SecCertificateRef)cert;
#endif

/////////////////////////////////////////////////////////////////////////
/// @name HTTP Authentication
/////////////////////////////////////////////////////////////////////////
Expand Down
12 changes: 12 additions & 0 deletions Code/Network/RKClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ @implementation RKClient
@synthesize password = _password;
@synthesize forceBasicAuthentication = _forceBasicAuthentication;
@synthesize HTTPHeaders = _HTTPHeaders;
#ifdef RESTKIT_SSL_VALIDATION
@synthesize additionalRootCertificates = _additionalRootCertificates;
#endif
@synthesize disableCertificateValidation = _disableCertificateValidation;
@synthesize baseURLReachabilityObserver = _baseURLReachabilityObserver;
@synthesize serviceUnavailableAlertTitle = _serviceUnavailableAlertTitle;
@synthesize serviceUnavailableAlertMessage = _serviceUnavailableAlertMessage;
Expand Down Expand Up @@ -123,6 +127,7 @@ - (id)init {
self = [super init];
if (self) {
_HTTPHeaders = [[NSMutableDictionary alloc] init];
_additionalRootCertificates = [[NSMutableSet alloc] init];
self.serviceUnavailableAlertEnabled = NO;
self.serviceUnavailableAlertTitle = NSLocalizedString(@"Service Unavailable", nil);
self.serviceUnavailableAlertMessage = NSLocalizedString(@"The remote resource is unavailable. Please try again later.", nil);
Expand Down Expand Up @@ -160,6 +165,7 @@ - (void)dealloc {
self.serviceUnavailableAlertMessage = nil;
self.cache = nil;
[_HTTPHeaders release];
[_additionalRootCertificates release];
[_baseURLReachabilityObserver release];

[super dealloc];
Expand Down Expand Up @@ -211,6 +217,12 @@ - (void)setValue:(NSString*)value forHTTPHeaderField:(NSString*)header {
[_HTTPHeaders setValue:value forKey:header];
}

#ifdef RESTKIT_SSL_VALIDATION
- (void)addRootCertificate:(SecCertificateRef)cert {
[_additionalRootCertificates addObject:(id)cert];
}
#endif

- (void)setBaseURL:(NSString*)baseURL {
[_baseURL release];
_baseURL = nil;
Expand Down
5 changes: 5 additions & 0 deletions Code/Network/RKParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@
*/
- (RKParamsAttachment*)setFile:(NSString*)filePath MIMEType:(NSString*)MIMEType fileName:(NSString*)fileName forParam:(NSString*)param DEPRECATED_ATTRIBUTE;

/**
* Resets the state of the RKParams stream
*/
- (void)reset;

@end
6 changes: 6 additions & 0 deletions Code/Network/RKParams.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ - (NSUInteger)HTTPHeaderValueForContentLength {
return _length;
}

- (void)reset {
_bytesDelivered = 0;
_length = 0;
_streamStatus = NSStreamStatusNotOpen;
}

- (NSInputStream*)HTTPBodyStream {
// Open each of our attachments
[_attachments makeObjectsPerformSelector:@selector(open)];
Expand Down
Loading

0 comments on commit 11a9c09

Please sign in to comment.