Merge branch 'feature/action_client_parameters_map' into 'feature/action_client_parameters'

map

See merge request BPHV_MIPS/mvm_core!133
This commit is contained in:
Hedden, Kyle Matthew 2021-01-19 12:28:45 -05:00
commit 72bd5edc20
4 changed files with 29 additions and 41 deletions

View File

@ -10,7 +10,8 @@ import Foundation
public extension MVMCoreActionHandler { public extension MVMCoreActionHandler {
@objc func setClientParameter(with actionMap: [String: Any]?, completionHandler: @escaping ([String : Any]?) -> ()) throws { /// Iterates throw the clientParameters list. Gets values from the individul handlers and attaches the paramters to extraParameters.
@objc func setClientParameter(with actionMap: [String: Any]?, completionHandler: @escaping ([String : Any]?) -> ()) {
guard let clientParameters = actionMap?.optionalDictionaryForKey("clientParameters") else { guard let clientParameters = actionMap?.optionalDictionaryForKey("clientParameters") else {
completionHandler(actionMap) completionHandler(actionMap)
@ -29,20 +30,27 @@ public extension MVMCoreActionHandler {
} }
} }
try ClientParameterRegistry.injectParameters(with: clientParameters) { (clientParams) in do {
guard let clientParams = clientParams else { try ClientParameterRegistry.injectParameters(with: clientParameters) { (clientParams) in
guard let clientParams = clientParams else {
stopLoadingOverlay()
completionHandler(actionMap)
return
}
var extraParams: [String : Any] = actionMap?.optionalDictionaryForKey(KeyExtraParameters) ?? [:]
extraParams.merge(clientParams) { (_, new) in new }
var actionMapM = actionMap
actionMapM?[KeyExtraParameters] = extraParams
stopLoadingOverlay() stopLoadingOverlay()
completionHandler(actionMap) completionHandler(actionMapM)
return
} }
} catch {
var extraParams: [String : Any] = actionMap?.optionalDictionaryForKey(KeyExtraParameters) ?? [:]
extraParams.merge(clientParams) { (_, new) in new }
var actionMapM = actionMap
actionMapM?[KeyExtraParameters] = extraParams
stopLoadingOverlay() stopLoadingOverlay()
completionHandler(actionMapM) completionHandler(actionMap)
MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Error clientParamters: \(error)")
} }
} }
} }

View File

@ -128,7 +128,7 @@ NSString * const KeyActionTypeOpen = @"openPage";
}]; }];
}; };
[self preprocessRequest:actionInformation actionBlock:performAction]; [self setClientParameterWith:actionInformation completionHandler:performAction];
} }
- (void)shareAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { - (void)shareAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
@ -293,7 +293,7 @@ NSString * const KeyActionTypeOpen = @"openPage";
[weakSelf prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionMap additionalData:additionalData delegateObject:delegateObject]; [weakSelf prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionMap additionalData:additionalData delegateObject:delegateObject];
}; };
[self preprocessRequest:actionInformation actionBlock:performAction]; [self setClientParameterWith:actionInformation completionHandler:performAction];
} }
- (void)prepareLinkAwayWithURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { - (void)prepareLinkAwayWithURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
@ -443,27 +443,7 @@ NSString * const KeyActionTypeOpen = @"openPage";
}]; }];
}; };
[self preprocessRequest:actionInformation actionBlock:performAction]; [self setClientParameterWith:actionInformation completionHandler:performAction];
}
- (void)preprocessRequest:(nullable NSDictionary *)actionInformation actionBlock:(nullable void (^)(NSDictionary*))actionBlock {
// Check for client params and fetch the parameters
if ([actionInformation dict:@"clientParameters"]) {
NSError *error = nil;
[self setClientParameterWith:actionInformation error:&error completionHandler:^(NSDictionary<NSString *,id> * _Nullable actionDict) {
actionBlock(actionDict);
}];
if (error) {
//MVMCoreLoggingHandler.logDebugMessage(withDelegate: "JS function reult: \(String(describing: result))")
MVMCoreLog(@"Error clientParamters %@", error);
actionBlock(actionInformation);
}
} else {
actionBlock(actionInformation);
}
} }
- (void)restartAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate { - (void)restartAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {
@ -582,7 +562,7 @@ NSString * const KeyActionTypeOpen = @"openPage";
[weakSelf prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionMap additionalData:additionalData delegate:delegate]; [weakSelf prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionMap additionalData:additionalData delegate:delegate];
}; };
[self preprocessRequest:actionInformation actionBlock:performAction]; [self setClientParameterWith:actionInformation completionHandler:performAction];
} }
- (void)prepareLinkAwayWithURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate { - (void)prepareLinkAwayWithURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {

View File

@ -11,5 +11,5 @@ import Foundation
public protocol ClientParameterProtocol { public protocol ClientParameterProtocol {
init() init()
static var name: String { get } static var name: String { get }
func fetchClientParameters(for paramModel: ClientParameterModelProtocol, timingOutIn timeout: Double, completionHandler:@escaping ([String: Any]?) -> ()) func fetchClientParameters(for paramModel: ClientParameterModelProtocol, timingOutIn timeout: Double, completionHandler:@escaping (AnyHashable?) -> ())
} }

View File

@ -73,11 +73,11 @@ import Foundation
parametersList[parameterModel.type] = ["error": defaultErrorString] parametersList[parameterModel.type] = ["error": defaultErrorString]
group.enter() group.enter()
// Dispatch asynchronous injection. // Dispatch asynchronous injection.
clientParameterRegistry.injectParameter(parameterModel, before: timeout) { (clientParam) in clientParameterRegistry.injectParameter(parameterModel, before: timeout) { (receivedParameter) in
// Queue the results for merge. // Queue the results for merge.
parametersWorkQueue.async { parametersWorkQueue.async {
if let clientParam = clientParam { if let receivedParameter = receivedParameter {
parametersList.merge(clientParam) { (_, new) in new } parametersList[parameterModel.type] = receivedParameter
} }
group.leave() // Leaving is only done after setup (barriered). group.leave() // Leaving is only done after setup (barriered).
} }
@ -89,7 +89,7 @@ import Foundation
} }
} }
func injectParameter( _ parameterModel: ClientParameterModelProtocol, before timeout: Double, completionHandler:@escaping ([String: Any]?) -> ()) { func injectParameter( _ parameterModel: ClientParameterModelProtocol, before timeout: Double, completionHandler:@escaping (AnyHashable?) -> ()) {
guard let parammeterHandler = createParametersHandler(parameterModel.type) else { guard let parammeterHandler = createParametersHandler(parameterModel.type) else {
return completionHandler(nil) return completionHandler(nil)
} }