diff --git a/openbis-ipad/BisKit/Classes/CISDOBIpadService.h b/openbis-ipad/BisKit/Classes/CISDOBIpadService.h index 71d2e19f421303d8830c5a2264ffe043002d1bae..6e779fddb1956c08ae1bde84df1ebc44ad7a4147 100644 --- a/openbis-ipad/BisKit/Classes/CISDOBIpadService.h +++ b/openbis-ipad/BisKit/Classes/CISDOBIpadService.h @@ -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. */ @@ -52,7 +52,27 @@ enum CISOBIpadServiceErrorCode { //! Log the user into the openBIS instance - (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; @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 diff --git a/openbis-ipad/BisKit/Classes/CISDOBIpadService.m b/openbis-ipad/BisKit/Classes/CISDOBIpadService.m index e299ee667d5b102702a72a15f3e61517907fe865..a068daf7d4e19b17b4da3d2bd42235bfc3281fe0 100644 --- a/openbis-ipad/BisKit/Classes/CISDOBIpadService.m +++ b/openbis-ipad/BisKit/Classes/CISDOBIpadService.m @@ -41,6 +41,13 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain"; @end +// Internal methods +@interface CISDOBIpadRawEntity (CISDOBIpadRawEntityPrivate) + +- (id)initWithContent:(NSArray *)content; + +@end + @implementation CISDOBIpadService @@ -98,10 +105,31 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain"; [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 *connectionCall = [_connection loginUser: user password: password]; - CISDOBIpadServiceCall *iPadCall = [[CISDOBIpadServiceCall alloc] initWithService: self connectionCall: connectionCall]; + CISDOBIpadServiceCall *iPadCall = [self iPadCallWrappingConnectionCall: connectionCall]; connectionCall.success = ^(id result) { // 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"; _isLoggedIn = YES; [self determineIsIpadSupported: iPadCall]; }; - connectionCall.fail = ^(NSError *error) { if (iPadCall.fail) iPadCall.fail(error); }; - + return iPadCall; } - (CISDOBAsyncCall *)listAllEntities; { - CISDOBAsyncCall *call = [_connection + CISDOBAsyncCall *connectionCall = [_connection createReportFromDataStore: [_ipadReadService objectForKey: @"dataStoreCode"] aggregationService: [_ipadReadService objectForKey: @"serviceKey"] parameters: nil]; - return call; + CISDOBIpadServiceCall *iPadCall = [self iPadCallWrappingConnectionCall: connectionCall]; + + connectionCall.success = ^(id result) { + if (iPadCall.success) { + iPadCall.success([self rawEntitiesFromResult: result]); + } + }; + + return iPadCall; } @end @@ -143,3 +178,24 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain"; } @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 diff --git a/openbis-ipad/BisKit/Tests/CISDOBIpadServiceTest.m b/openbis-ipad/BisKit/Tests/CISDOBIpadServiceTest.m index 905589cbbb807655d33529e5b0c3d1db2860aec7..c029168bb6e469f9364aab9b6c4c6485bf7ef4f3 100644 --- a/openbis-ipad/BisKit/Tests/CISDOBIpadServiceTest.m +++ b/openbis-ipad/BisKit/Tests/CISDOBIpadServiceTest.m @@ -59,12 +59,12 @@ call = [_service loginUser: GetDefaultUserName() password: GetDefaultUserPassword()]; [self configureAndRunCallSynchronously: call]; -// call = [_service listAllEntities]; -// [self configureAndRunCallSynchronously: call]; + call = [_service listAllEntities]; + [self configureAndRunCallSynchronously: call]; -// STAssertNotNil(_callResult, @"The iPad service should have returned some entities."); -// NSArray *rows = [_callResult objectForKey: @"rows"]; -// STAssertTrue([rows count] > 0, @"The Pad service should have returned some entities."); + STAssertNotNil(_callResult, @"The iPad service should have returned some entities."); + NSArray *rawEntities = _callResult; + STAssertTrue([rawEntities count] > 0, @"The Pad service should have returned some entities."); } @end