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

Refactored out common code in invoking the various services

SVN: 27279
parent 9b985f3c
No related branches found
No related tags found
No related merge requests found
...@@ -52,15 +52,21 @@ enum CISOBIpadServiceErrorCode { ...@@ -52,15 +52,21 @@ 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 root-level entities from the openBIS ipad service, possibly along with some children as well. The success message will be invoked with a collection of CISDOBIpadRawEntity objects. //! Get all root-level entities from the openBIS ipad service, possibly along with some children as well. The success block will be invoked with a collection of CISDOBIpadRawEntity objects.
- (CISDOBAsyncCall *)listRootLevelEntities; - (CISDOBAsyncCall *)listRootLevelEntities;
//! Get drill information from the openBIS ipad service -- this will include information about the children of the entity and possibly their children as well. The two collections must have the same cardinality. The success message will be invoked with a collection of CISDOBIpadRawEntity objects. //! Get drill information from the openBIS ipad service -- this will include information about the children of the entity and possibly their children as well. The permIds and refcons collections must have the same cardinality. The success block will be invoked with a collection of CISDOBIpadRawEntity objects.
- (CISDOBAsyncCall *)drillOnEntities:(NSArray *)permIds refcons:(NSArray *)refcons; - (CISDOBAsyncCall *)drillOnEntities:(NSArray *)permIds refcons:(NSArray *)refcons;
//! A convenience version of drillOnEntities:refcons: for one entity. //! A convenience version of drillOnEntities:refcons: for one entity.
- (CISDOBAsyncCall *)drillOnEntityWithPermId:(NSString *)permId refcon:(id)refcon; - (CISDOBAsyncCall *)drillOnEntityWithPermId:(NSString *)permId refcon:(id)refcon;
//! Get detail information from the openBIS ipad service. The permIds and refcons collections must have the same cardinality. The success block will be invoked with a collection of CISDOBIpadRawEntity objects.
- (CISDOBAsyncCall *)detailsForEntities:(NSArray *)permIds refcons:(NSArray *)refcons;
//! A convenience version of detailsForEntities:refcons: for one entity.
- (CISDOBAsyncCall *)detailsForEntityWithPermId:(NSString *)permId refcon:(id)refcon;
@end @end
......
...@@ -157,13 +157,13 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain"; ...@@ -157,13 +157,13 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain";
return iPadCall; return iPadCall;
} }
- (CISDOBAsyncCall *)listRootLevelEntities; - (CISDOBIpadServiceCall *)createIpadServiceCallWithParameters:(NSDictionary *)parameters
{ {
NSDictionary *parameters = [NSDictionary dictionaryWithObject: @"ROOT" forKey: @"requestKey"]; CISDOBAsyncCall *connectionCall =
CISDOBAsyncCall *connectionCall = [_connection [_connection
createReportFromDataStore: [_ipadReadService objectForKey: @"dataStoreCode"] createReportFromDataStore: [_ipadReadService objectForKey: @"dataStoreCode"]
aggregationService: [_ipadReadService objectForKey: @"serviceKey"] aggregationService: [_ipadReadService objectForKey: @"serviceKey"]
parameters: parameters]; parameters: parameters];
CISDOBIpadServiceCall *iPadCall = [self iPadCallWrappingConnectionCall: connectionCall]; CISDOBIpadServiceCall *iPadCall = [self iPadCallWrappingConnectionCall: connectionCall];
connectionCall.success = ^(id result) { connectionCall.success = ^(id result) {
...@@ -171,41 +171,40 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain"; ...@@ -171,41 +171,40 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain";
iPadCall.success([self rawEntitiesFromResult: result]); iPadCall.success([self rawEntitiesFromResult: result]);
} }
}; };
return iPadCall; return iPadCall;
} }
- (CISDOBAsyncCall *)drillOnEntities:(NSArray *)permIds refcons:(NSArray *)refcons - (CISDOBAsyncCall *)listRootLevelEntities;
{
NSDictionary *parameters = [NSDictionary dictionaryWithObject: @"ROOT" forKey: @"requestKey"];
return [self createIpadServiceCallWithParameters: parameters];
}
- (NSMutableArray *)convertToEntitiesPermIds:(NSArray *)permIds refcons:(NSArray *)refcons count:(NSUInteger)count
{ {
NSUInteger count = [permIds count];
NSAssert([refcons count] == count, @"Drilling requires permIds and refcons. There must be an equal number of these.");
NSMutableArray *entities = [[NSMutableArray alloc] initWithCapacity: [permIds count]]; NSMutableArray *entities = [[NSMutableArray alloc] initWithCapacity: [permIds count]];
for (NSUInteger i = 0; i < count; ++i) { for (NSUInteger i = 0; i < count; ++i) {
NSDictionary *entity = NSDictionary *entity =
[NSDictionary dictionaryWithObjectsAndKeys: [NSDictionary dictionaryWithObjectsAndKeys:
[permIds objectAtIndex: i], @"PERM_ID", [permIds objectAtIndex: i], @"PERM_ID",
[refcons objectAtIndex: i], @"REFCON", nil]; [refcons objectAtIndex: i], @"REFCON", nil];
[entities addObject: entity]; [entities addObject: entity];
} }
return entities;
}
- (CISDOBAsyncCall *)drillOnEntities:(NSArray *)permIds refcons:(NSArray *)refcons
{
NSUInteger count = [permIds count];
NSAssert([refcons count] == count, @"Drilling requires permIds and refcons. There must be an equal number of these.");
NSMutableArray *entities;
entities = [self convertToEntitiesPermIds: permIds refcons: refcons count: count];
NSDictionary *parameters = NSDictionary *parameters =
[NSDictionary dictionaryWithObjectsAndKeys: [NSDictionary dictionaryWithObjectsAndKeys:
@"DRILL", @"requestKey", @"DRILL", @"requestKey",
entities, @"entities", nil]; entities, @"entities", nil];
CISDOBAsyncCall *connectionCall = return [self createIpadServiceCallWithParameters: parameters];
[_connection
createReportFromDataStore: [_ipadReadService objectForKey: @"dataStoreCode"]
aggregationService: [_ipadReadService objectForKey: @"serviceKey"]
parameters: parameters];
CISDOBIpadServiceCall *iPadCall = [self iPadCallWrappingConnectionCall: connectionCall];
connectionCall.success = ^(id result) {
if (iPadCall.success) {
iPadCall.success([self rawEntitiesFromResult: result]);
}
};
return iPadCall;
} }
- (CISDOBAsyncCall *)drillOnEntityWithPermId:(NSString *)permId refcon:(id)refcon - (CISDOBAsyncCall *)drillOnEntityWithPermId:(NSString *)permId refcon:(id)refcon
...@@ -215,6 +214,27 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain"; ...@@ -215,6 +214,27 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain";
return [self drillOnEntities: permIds refcons: refcons]; return [self drillOnEntities: permIds refcons: refcons];
} }
- (CISDOBAsyncCall *)detailsForEntities:(NSArray *)permIds refcons:(NSArray *)refcons
{
NSUInteger count = [permIds count];
NSAssert([refcons count] == count, @"Drilling requires permIds and refcons. There must be an equal number of these.");
NSMutableArray *entities;
entities = [self convertToEntitiesPermIds: permIds refcons: refcons count: count];
NSDictionary *parameters =
[NSDictionary dictionaryWithObjectsAndKeys:
@"DETAIL", @"requestKey",
entities, @"entities", nil];
return [self createIpadServiceCallWithParameters: parameters];
}
- (CISDOBAsyncCall *)detailsForEntityWithPermId:(NSString *)permId refcon:(id)refcon
{
NSArray *permIds = [NSArray arrayWithObject: permId];
NSArray *refcons = [NSArray arrayWithObject: refcon];
return [self detailsForEntities: permIds refcons: refcons];
}
@end @end
@implementation CISDOBIpadServiceCall @implementation CISDOBIpadServiceCall
......
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