diff --git a/openbis-ipad/BisKit/Classes/CISDOBIpadService.h b/openbis-ipad/BisKit/Classes/CISDOBIpadService.h index 8598743e09412420eb736ed888bb490f02ecf3d6..66d4f20eadbd573690f4d57eda6d305c99b7a9fd 100644 --- a/openbis-ipad/BisKit/Classes/CISDOBIpadService.h +++ b/openbis-ipad/BisKit/Classes/CISDOBIpadService.h @@ -36,20 +36,23 @@ enum CISOBIpadServiceErrorCode { * * All calls to the connection are made asynchronously. Thus, the calls all return async call objects which can be configured. */ -@class CISDOBConnection, CISDOBAsyncCall; +@class CISDOBConnection, CISDOBAsyncCall, CISDOBClientPreferences; @interface CISDOBIpadService : NSObject { @private // Internal State BOOL _isLoggedIn; - NSDictionary* _ipadReadService; + NSDictionary *_ipadReadService; + + CISDOBClientPreferences *_clientPreferences; } @property(readonly) CISDOBConnection *connection; +@property(readonly) CISDOBClientPreferences *clientPreferences; //! Designated initializer. - (id)initWithConnection:(CISDOBConnection *)connection; -//! Log the user into the openBIS instance +//! Log the user into the openBIS instance. The login procedure reqests the client preferences as well. - (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 block will be invoked with a collection of CISDOBIpadRawEntity objects. @@ -97,3 +100,20 @@ enum CISOBIpadServiceErrorCode { @property(readonly) NSString *rootLevel; @end + +/** + * \brief The preferences for client behavior, as defined by the server. + */ +@interface CISDOBClientPreferences : NSObject { +@private + // Internal state + NSDictionary *_preferences; +} + +@property(readonly) NSTimeInterval rootRefreshInterval; //<! The min interval (in seconds) to wait between refreshes of the root data set. + +@property(readonly) NSDictionary *preferences; //<! Used to access the raw preferences dictionary. The recommended way to get preferences is with the above accessors. + +- (id)initWithRawPreferences:(NSDictionary *)rawPreferences; + +@end diff --git a/openbis-ipad/BisKit/Classes/CISDOBIpadService.m b/openbis-ipad/BisKit/Classes/CISDOBIpadService.m index f48755e80f8dd03d13b0243b2b750cd626eead87..85d10ff5f110c571d5d790d5127e4efc81b6f74d 100644 --- a/openbis-ipad/BisKit/Classes/CISDOBIpadService.m +++ b/openbis-ipad/BisKit/Classes/CISDOBIpadService.m @@ -63,6 +63,30 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain"; - (BOOL)isIpadSupported { return _ipadReadService != nil; } +- (void)rememberClientPreferences:(NSDictionary *)clientPreferences notifying:(CISDOBIpadServiceCall *)iPadCall +{ + _clientPreferences = [[CISDOBClientPreferences alloc] initWithRawPreferences: clientPreferences]; + if (iPadCall.success) iPadCall.success(_connection.sessionToken); + +} + +- (void)retrieveClientPreferences:(CISDOBIpadServiceCall *)iPadCall +{ + NSDictionary *parameters = [NSDictionary dictionaryWithObject: @"ROOT" forKey: @"requestKey"]; + CISDOBAsyncCall *connectionCall = + [_connection + createReportFromDataStore: [_ipadReadService objectForKey: @"dataStoreCode"] + aggregationService: [_ipadReadService objectForKey: @"serviceKey"] + parameters: parameters]; + + iPadCall.connectionCall = connectionCall; + connectionCall.success = ^(id result) { + [self rememberClientPreferences: result notifying: iPadCall]; + }; + connectionCall.fail = ^(NSError *error) { if (iPadCall.fail) iPadCall.fail(error); }; + [connectionCall start]; +} + - (void)rememberIpadService:(NSArray *)services notifying:(CISDOBIpadServiceCall *)iPadCall { for (NSDictionary *service in services) { @@ -81,8 +105,7 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain"; return; } - if (iPadCall.success) iPadCall.success(_connection.sessionToken); - + [self retrieveClientPreferences: iPadCall]; } - (void)determineIsIpadSupported:(CISDOBIpadServiceCall *)iPadCall @@ -291,3 +314,24 @@ NSString *const CISDOBIpadServiceErrorDomain = @"CISDOBIpadServiceErrorDomain"; - (NSString *)rootLevel { return [self stringContentValueAtName: @"ROOT_LEVEL"]; } @end + +@implementation CISDOBClientPreferences + +- (id)initWithRawPreferences:(NSDictionary *)rawPreferences +{ + if (!(self = [super init])) return nil; + + _preferences = rawPreferences; + + return self; +} + +- (NSTimeInterval)rootRefreshInterval +{ + // TODO Implement this by reading the value from the dictionary and converting it to a time interval + + // The default value is once every 30 min + return 60. * 30.; +} + +@end diff --git a/openbis-ipad/BisKit/Tests/CISDOBIpadServiceTest.m b/openbis-ipad/BisKit/Tests/CISDOBIpadServiceTest.m index e653c264290cff0dea28509a621a9ed6c6d6049c..e88540809f3fbb32280ccf39e8482a4c1ec1126f 100644 --- a/openbis-ipad/BisKit/Tests/CISDOBIpadServiceTest.m +++ b/openbis-ipad/BisKit/Tests/CISDOBIpadServiceTest.m @@ -59,6 +59,8 @@ CISDOBAsyncCall *call; call = [_service loginUser: GetDefaultUserName() password: GetDefaultUserPassword()]; [self configureAndRunCallSynchronously: call]; + STAssertNotNil(_service.clientPreferences, @"The client preferences should have been initialized"); + STAssertEquals(_service.clientPreferences.rootRefreshInterval, 60. * 30., @"The default root refresh interval should be 30 min"); call = [_service listRootLevelEntities]; [self configureAndRunCallSynchronously: call]; diff --git a/openbis-ipad/Research/BisMac.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate b/openbis-ipad/Research/BisMac.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate index c986ceab3fc0bd17e4db956a12998033770d3c6c..91f18b3f11d9e0ec6832f2cb550b90c13b41dd77 100644 Binary files a/openbis-ipad/Research/BisMac.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate and b/openbis-ipad/Research/BisMac.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate differ