Skip to content
Snippets Groups Projects
Commit f2497e91 authored by cramakri's avatar cramakri
Browse files

Retrieve raw entity values more dynamically

SVN: 27270
parent e9bbd361
No related branches found
No related tags found
No related merge requests found
......@@ -27,15 +27,24 @@
/**
* \brief A persistent version of an entity from the iPad server.
*
* Since information for the entities are downloaded progressively, users of this
* class should treat all properties EXCEPT permId and refcon as being potentially
* nil. A nil value means that the true value is not known. An empty string signifies
* an empty value for string properties and an empty array signifies an empty value
* for array properties.
*/
@class CISDOBIpadRawEntity;
@interface CISDOBIpadEntity : NSManagedObject
// Non-nil properties
@property (nonatomic, retain) NSString * permId;
@property (nonatomic, retain) NSString * refcon;
// Potentially nil properties
@property (nonatomic, retain) NSString * summaryHeader;
@property (nonatomic, retain) NSString * summary;
@property (nonatomic, retain) NSString * identifier;
@property (nonatomic, retain) NSString * permId;
@property (nonatomic, retain) NSString * refcon;
@property (nonatomic, retain) NSString * category;
@property (nonatomic, retain) NSString * imageUrl;
......
......@@ -64,7 +64,8 @@ enum CISOBIpadServiceErrorCode {
@interface CISDOBIpadRawEntity : NSObject {
@private
// Internal state
NSArray* _content;
NSArray *_content;
NSDictionary *_fieldMap;
}
@property(readonly) NSString *permId;
......@@ -76,5 +77,6 @@ enum CISOBIpadServiceErrorCode {
@property(readonly) NSString *identifier;
@property(readonly) NSString *imageUrl;
@property(readonly) NSString *properties; //<! The properties as a JSON string.
@property(readonly) NSString *rootLevel;
@end
......@@ -44,7 +44,7 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain";
// Internal methods
@interface CISDOBIpadRawEntity (CISDOBIpadRawEntityPrivate)
- (id)initWithContent:(NSArray *)content;
- (id)initWithContent:(NSArray *)content fieldMap:(NSDictionary *)fieldMap;
@end
......@@ -114,12 +114,28 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain";
return iPadCall;
}
- (NSDictionary *)computeColumnsFieldMapFromColumns:(NSArray *)columns
{
// Convert the array to a map indexed by field name.
NSMutableDictionary *fieldMap = [[NSMutableDictionary alloc] initWithCapacity: [columns count]];
NSUInteger i = 0;
for (NSDictionary *col in columns) {
[fieldMap
setObject: [NSNumber numberWithUnsignedInteger: i++]
forKey: [col objectForKey: @"title"]];
}
return fieldMap;
}
- (NSArray *)rawEntitiesFromResult:(NSDictionary *)result
{
NSArray *columns = [result objectForKey: @"columns"];
NSDictionary *fieldMap = [self computeColumnsFieldMapFromColumns: columns];
NSMutableArray *rawEntities = [[NSMutableArray alloc] init];
NSArray *rows = [result objectForKey: @"rows"];
for (NSArray *row in rows) {
CISDOBIpadRawEntity* rawEntity = [[CISDOBIpadRawEntity alloc] initWithContent: row];
CISDOBIpadRawEntity* rawEntity = [[CISDOBIpadRawEntity alloc] initWithContent: row fieldMap: fieldMap];
[rawEntities addObject: rawEntity];
}
......@@ -182,25 +198,32 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain";
@implementation CISDOBIpadRawEntity
- (id)initWithContent:(NSArray *)content
- (id)initWithContent:(NSArray *)content fieldMap:(NSDictionary *)fieldMap
{
if (!(self = [super init])) return nil;
_content = content;
_fieldMap = fieldMap;
return self;
}
- (NSString *)stringContentValueAtIndex:(NSUInteger)index { return [[_content objectAtIndex: index] objectForKey: @"value"]; }
- (NSString *)permId { return [self stringContentValueAtIndex: 0]; }
- (NSString *)refcon { return [self stringContentValueAtIndex: 1]; }
- (NSString *)category { return [self stringContentValueAtIndex: 2]; }
- (NSString *)summaryHeader { return [self stringContentValueAtIndex: 3]; }
- (NSString *)summary { return [self stringContentValueAtIndex: 4]; }
- (NSString *)children { return [self stringContentValueAtIndex: 5]; }
- (NSString *)identifier { return [self stringContentValueAtIndex: 6]; }
- (NSString *)imageUrl { return [self stringContentValueAtIndex: 7]; }
- (NSString *)properties { return [self stringContentValueAtIndex: 8]; }
- (NSString *)stringContentValueAtName:(NSString *)name
{
// Look up the index in the map
NSUInteger index = [[_fieldMap objectForKey: name] unsignedIntegerValue];
return [[_content objectAtIndex: index] objectForKey: @"value"];
}
- (NSString *)permId { return [self stringContentValueAtName: @"PERM_ID"]; }
- (NSString *)refcon { return [self stringContentValueAtName: @"REFCON"]; }
- (NSString *)category { return [self stringContentValueAtName: @"CATEGORY"]; }
- (NSString *)summaryHeader { return [self stringContentValueAtName: @"SUMMARY_HEADER"]; }
- (NSString *)summary { return [self stringContentValueAtName: @"SUMMARY"]; }
- (NSString *)children { return [self stringContentValueAtName: @"CHILDREN"]; }
- (NSString *)identifier { return [self stringContentValueAtName: @"IDENTIFIER"]; }
- (NSString *)imageUrl { return [self stringContentValueAtName: @"IMAGE_URL"]; }
- (NSString *)properties { return [self stringContentValueAtName: @"PROPERTIES"]; }
- (NSString *)rootLevel { return [self stringContentValueAtName: @"ROOT_LEVEL"]; }
@end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment