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

Wrap iPad service results in nicer to use objects.

SVN: 26949
parent 487c5804
No related branches found
No related tags found
No related merge requests found
...@@ -32,7 +32,7 @@ enum CISOBIpadServiceErrorCode { ...@@ -32,7 +32,7 @@ enum CISOBIpadServiceErrorCode {
}; };
/** /**
* A facade for accessing openBIS iPad UI module. * \brief A facade for accessing openBIS iPad UI module.
* *
* All calls to the connection are made asynchronously. Thus, the calls all return async call objects which can be configured. * All calls to the connection are made asynchronously. Thus, the calls all return async call objects which can be configured.
*/ */
...@@ -52,7 +52,27 @@ enum CISOBIpadServiceErrorCode { ...@@ -52,7 +52,27 @@ enum CISOBIpadServiceErrorCode {
//! Log the user into the openBIS instance //! Log the user into the openBIS instance
- (CISDOBAsyncCall *)loginUser:(NSString *)user password:(NSString *)password; - (CISDOBAsyncCall *)loginUser:(NSString *)user password:(NSString *)password;
//! Get all entities from the openBIS ipad service. //! Get all entities from the openBIS ipad service. The success message will be invoked with a collection of CISDOBIpadRawEntity objects.
- (CISDOBAsyncCall *)listAllEntities; - (CISDOBAsyncCall *)listAllEntities;
@end @end
/**
* \brief An abstraction of the data returned from the ipad module of the openBIS server.
*/
@interface CISDOBIpadRawEntity : NSObject {
@private
// Internal state
NSArray* _content;
}
@property(readonly) NSString *summaryHeader;
@property(readonly) NSString *summary;
@property(readonly) NSString *identifier;
@property(readonly) NSString *permId;
@property(readonly) NSString *entityKind;
@property(readonly) NSString *entityType;
@property(readonly) NSDictionary *properties;
@end
...@@ -41,6 +41,13 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain"; ...@@ -41,6 +41,13 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain";
@end @end
// Internal methods
@interface CISDOBIpadRawEntity (CISDOBIpadRawEntityPrivate)
- (id)initWithContent:(NSArray *)content;
@end
@implementation CISDOBIpadService @implementation CISDOBIpadService
...@@ -98,10 +105,31 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain"; ...@@ -98,10 +105,31 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain";
[connectionCall start]; [connectionCall start];
} }
- (CISDOBIpadServiceCall *)iPadCallWrappingConnectionCall:(CISDOBAsyncCall *)connectionCall
{
CISDOBIpadServiceCall *iPadCall = [[CISDOBIpadServiceCall alloc] initWithService: self connectionCall: connectionCall];
connectionCall.fail = ^(NSError *error) { if (iPadCall.fail) iPadCall.fail(error); };
return iPadCall;
}
- (NSArray *)rawEntitiesFromResult:(NSDictionary *)result
{
NSMutableArray *rawEntities = [[NSMutableArray alloc] init];
NSArray *rows = [result objectForKey: @"rows"];
for (NSArray *row in rows) {
CISDOBIpadRawEntity* rawEntity = [[CISDOBIpadRawEntity alloc] initWithContent: row];
[rawEntities addObject: rawEntity];
}
return rawEntities;
}
- (CISDOBAsyncCall *)loginUser:(NSString *)user password:(NSString *)password - (CISDOBAsyncCall *)loginUser:(NSString *)user password:(NSString *)password
{ {
CISDOBAsyncCall *connectionCall = [_connection loginUser: user password: password]; CISDOBAsyncCall *connectionCall = [_connection loginUser: user password: password];
CISDOBIpadServiceCall *iPadCall = [[CISDOBIpadServiceCall alloc] initWithService: self connectionCall: connectionCall]; CISDOBIpadServiceCall *iPadCall = [self iPadCallWrappingConnectionCall: connectionCall];
connectionCall.success = ^(id result) { connectionCall.success = ^(id result) {
// Note that we are logged in, but wait until we figure out if the ipad is supported // Note that we are logged in, but wait until we figure out if the ipad is supported
...@@ -109,18 +137,25 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain"; ...@@ -109,18 +137,25 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain";
_isLoggedIn = YES; _isLoggedIn = YES;
[self determineIsIpadSupported: iPadCall]; [self determineIsIpadSupported: iPadCall];
}; };
connectionCall.fail = ^(NSError *error) { if (iPadCall.fail) iPadCall.fail(error); };
return iPadCall; return iPadCall;
} }
- (CISDOBAsyncCall *)listAllEntities; - (CISDOBAsyncCall *)listAllEntities;
{ {
CISDOBAsyncCall *call = [_connection CISDOBAsyncCall *connectionCall = [_connection
createReportFromDataStore: [_ipadReadService objectForKey: @"dataStoreCode"] createReportFromDataStore: [_ipadReadService objectForKey: @"dataStoreCode"]
aggregationService: [_ipadReadService objectForKey: @"serviceKey"] aggregationService: [_ipadReadService objectForKey: @"serviceKey"]
parameters: nil]; parameters: nil];
return call; CISDOBIpadServiceCall *iPadCall = [self iPadCallWrappingConnectionCall: connectionCall];
connectionCall.success = ^(id result) {
if (iPadCall.success) {
iPadCall.success([self rawEntitiesFromResult: result]);
}
};
return iPadCall;
} }
@end @end
...@@ -143,3 +178,24 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain"; ...@@ -143,3 +178,24 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain";
} }
@end @end
@implementation CISDOBIpadRawEntity
- (id)initWithContent:(NSArray *)content
{
if (!(self = [super init])) return nil;
_content = content;
return self;
}
- (NSString *)summaryHeader { return [_content objectAtIndex: 0]; }
- (NSString *)summary { return [_content objectAtIndex: 1]; }
- (NSString *)identifier { return [_content objectAtIndex: 2]; }
- (NSString *)permId { return [_content objectAtIndex: 3]; }
- (NSString *)entityKind { return [_content objectAtIndex: 4]; }
- (NSString *)entityType { return [_content objectAtIndex: 5]; }
- (NSDictionary *)properties { return [_content objectAtIndex: 6]; }
@end
...@@ -59,12 +59,12 @@ ...@@ -59,12 +59,12 @@
call = [_service loginUser: GetDefaultUserName() password: GetDefaultUserPassword()]; call = [_service loginUser: GetDefaultUserName() password: GetDefaultUserPassword()];
[self configureAndRunCallSynchronously: call]; [self configureAndRunCallSynchronously: call];
// call = [_service listAllEntities]; call = [_service listAllEntities];
// [self configureAndRunCallSynchronously: call]; [self configureAndRunCallSynchronously: call];
// STAssertNotNil(_callResult, @"The iPad service should have returned some entities."); STAssertNotNil(_callResult, @"The iPad service should have returned some entities.");
// NSArray *rows = [_callResult objectForKey: @"rows"]; NSArray *rawEntities = _callResult;
// STAssertTrue([rows count] > 0, @"The Pad service should have returned some entities."); STAssertTrue([rawEntities count] > 0, @"The Pad service should have returned some entities.");
} }
@end @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