diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index aa096b4..b06322b 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -25,7 +25,6 @@ 016FF6F2259A4FCC00F5E4AA /* ClientParameterModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016FF6F1259A4FCC00F5E4AA /* ClientParameterModel.swift */; }; 016FF6F6259B9AED00F5E4AA /* ClientParameterRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016FF6F5259B9AED00F5E4AA /* ClientParameterRegistry.swift */; }; 016FF6FC259BA27E00F5E4AA /* ClientParameterProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016FF6FB259BA27E00F5E4AA /* ClientParameterProtocol.swift */; }; - 016FF706259D180000F5E4AA /* ActionHandler+ClientParameters.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016FF705259D180000F5E4AA /* ActionHandler+ClientParameters.swift */; }; 01934FE725A4FFC2003DCD67 /* ClientParameterActionProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01934FE625A4FFC2003DCD67 /* ClientParameterActionProtocol.swift */; }; 01C851CF23CF7B260021F976 /* JSONMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C851CE23CF7B260021F976 /* JSONMap.swift */; }; 01C851D123CF97FE0021F976 /* ActionBackModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C851D023CF97FE0021F976 /* ActionBackModel.swift */; }; @@ -154,7 +153,6 @@ 016FF6F1259A4FCC00F5E4AA /* ClientParameterModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientParameterModel.swift; sourceTree = ""; }; 016FF6F5259B9AED00F5E4AA /* ClientParameterRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientParameterRegistry.swift; sourceTree = ""; }; 016FF6FB259BA27E00F5E4AA /* ClientParameterProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientParameterProtocol.swift; sourceTree = ""; }; - 016FF705259D180000F5E4AA /* ActionHandler+ClientParameters.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ActionHandler+ClientParameters.swift"; sourceTree = ""; }; 01934FE625A4FFC2003DCD67 /* ClientParameterActionProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientParameterActionProtocol.swift; sourceTree = ""; }; 01C851CE23CF7B260021F976 /* JSONMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONMap.swift; sourceTree = ""; }; 01C851D023CF97FE0021F976 /* ActionBackModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionBackModel.swift; sourceTree = ""; }; @@ -585,7 +583,6 @@ AFBB96B51FBA3CEC0008D868 /* MVMCoreActionDelegateProtocol.h */, AFBB96B61FBA3CEC0008D868 /* MVMCoreActionHandler.h */, AFBB96B71FBA3CEC0008D868 /* MVMCoreActionHandler.m */, - 016FF705259D180000F5E4AA /* ActionHandler+ClientParameters.swift */, ); path = ActionHandling; sourceTree = ""; @@ -810,7 +807,6 @@ buildActionMask = 2147483647; files = ( AFED77A71FCCA29400BAE689 /* MVMCoreViewControllerProgrammaticMappingObject.m in Sources */, - 016FF706259D180000F5E4AA /* ActionHandler+ClientParameters.swift in Sources */, 946EE1A7237B5B1C0036751F /* ModelRegistry.swift in Sources */, AFBB96641FBA3A570008D868 /* MVMCoreLoadHandler.m in Sources */, AFFCFA671FCCC0D700FD0730 /* MVMCoreLoadingOverlayHandler.m in Sources */, diff --git a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift deleted file mode 100644 index a2c3841..0000000 --- a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift +++ /dev/null @@ -1,56 +0,0 @@ -// -// ActionHandler+ClientParameters.swift -// MVMCore -// -// Created by Suresh, Kamlesh on 12/30/20. -// Copyright © 2020 myverizon. All rights reserved. -// - -import Foundation - -public extension MVMCoreActionHandler { - - /// Iterates through the clientParameters list. Gets values from the individual handlers and attaches the parameters to extraParameters. - @objc func setClientParameter(with actionMap: [String: Any]?, completionHandler: @escaping ([String : Any]?) -> ()) { - - guard let actionMapWithClientParameters = actionMap, let clientParameters = actionMapWithClientParameters.optionalDictionaryForKey("clientParameters") else { - completionHandler(actionMap) - return - } - - let isBackgroudRequest = actionMapWithClientParameters.boolForKey("background") - - if !isBackgroudRequest { - MVMCoreLoadingOverlayHandler.sharedLoadingOverlay()?.startLoading() - } - - let stopLoadingOverlay = {() in - if !isBackgroudRequest { - MVMCoreLoadingOverlayHandler.sharedLoadingOverlay()?.stopLoading(true) - } - } - - do { - try MVMCoreObject.sharedInstance()?.clientParameterRegistry?.getParameters(with: clientParameters) { (clientParams) in - guard let clientParams = clientParams else { - stopLoadingOverlay() - completionHandler(actionMapWithClientParameters) - return - } - - var extraParams: [String : Any] = actionMapWithClientParameters.dictionaryForKey(KeyExtraParameters) - extraParams.merge(clientParams) { (_, new) in new } - var actionMapM = actionMapWithClientParameters - actionMapM[KeyExtraParameters] = extraParams - - stopLoadingOverlay() - completionHandler(actionMapM) - } - } catch { - stopLoadingOverlay() - completionHandler(actionMapWithClientParameters) - MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Error clientParamters: \(error)") - } - - } -} diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h index c677e53..374b968 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h @@ -158,4 +158,6 @@ extern NSString * _Nonnull const KeyActionTypeOpen; // By default, throws an error, calling defaultHandleActionError. + (void)defaultHandleUnknownActionType:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; +// Iterates through the clientParameters list. Gets values from the individual handlers and attaches the parameters to extraParameters. +- (void)setClientParameter:(nullable NSDictionary *)actionInformation completionHandler:(nonnull void (^)(NSDictionary * _Nullable jsonDictionary))completionHandler; @end diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 9362dd6..fa98ee6 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -26,6 +26,7 @@ #import "MVMCorePresentationDelegateProtocol.h" #import #import +#import "MVMCoreLoadingOverlayHandler.h" NSString * const KeyActionType = @"actionType"; NSString * const KeyActionTypeLinkAway = @"openURL"; @@ -128,7 +129,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; }]; }; - [self setClientParameterWith:actionInformation completionHandler:performAction]; + [self setClientParameter:actionInformation completionHandler:performAction]; } - (void)shareAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { @@ -293,7 +294,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; [weakSelf prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionMap additionalData:additionalData delegateObject:delegateObject]; }; - [self setClientParameterWith:actionInformation completionHandler:performAction]; + [self setClientParameter:actionInformation completionHandler:performAction]; } - (void)prepareLinkAwayWithURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { @@ -443,7 +444,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; }]; }; - [self setClientParameterWith:actionInformation completionHandler:performAction]; + [self setClientParameter:actionInformation completionHandler:performAction]; } - (void)restartAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { @@ -562,7 +563,55 @@ NSString * const KeyActionTypeOpen = @"openPage"; [weakSelf prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionMap additionalData:additionalData delegate:delegate]; }; - [self setClientParameterWith:actionInformation completionHandler:performAction]; + [self setClientParameter:actionInformation completionHandler:performAction]; +} + +- (void)setClientParameter:(nullable NSDictionary *)actionInformation completionHandler:(nonnull void (^)(NSDictionary * _Nullable jsonDictionary))completionHandler { + + NSDictionary *clientParametersMap = [actionInformation dict:KeyClientParameters]; + if (!clientParametersMap) { + completionHandler(actionInformation); + return; + } + + BOOL isBackgroudRequest = [actionInformation boolForKey:@"background"]; + + if (!isBackgroudRequest) { + [[MVMCoreLoadingOverlayHandler sharedLoadingOverlay] startLoading]; + } + + void (^stopLoadingOverlay)(void) = ^(void) { + if (!isBackgroudRequest) { + [[MVMCoreLoadingOverlayHandler sharedLoadingOverlay] stopLoading:true]; + } + }; + + NSError *error = nil; + [MVMCoreLoggingHandler logDebugMessageWithDelegate:@"Fetching client parameters"]; + [[[MVMCoreObject sharedInstance] clientParameterRegistry] getParametersWith:clientParametersMap + error:&error + completionHandler:^(NSDictionary * _Nullable clientParameters) { + [MVMCoreLoggingHandler logDebugMessageWithDelegate:@"Finshed fetching client parameters"]; + if (clientParameters) { + NSMutableDictionary *actionWithClientParameters = [actionInformation mutableCopy]; + NSMutableDictionary *extraParameters = [clientParameters mutableCopy]; + [extraParameters addEntriesFromDictionary:[actionWithClientParameters dictionaryForKey:KeyExtraParameters]]; + actionWithClientParameters[KeyExtraParameters] = extraParameters; + + stopLoadingOverlay(); + completionHandler(actionWithClientParameters); + } else { + [MVMCoreLoggingHandler logDebugMessageWithDelegate:@"No client parameters"]; + stopLoadingOverlay(); + completionHandler(actionInformation); + } + }]; + + if (error) { + stopLoadingOverlay(); + completionHandler(actionInformation); + [MVMCoreLoggingHandler addErrorToLog:[MVMCoreErrorObject createErrorObjectForNSError:error location:@"MVMCoreActionHandler->setClientParameter"]]; + } } - (void)prepareLinkAwayWithURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { diff --git a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h index f3d84ac..220b180 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h +++ b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h @@ -51,6 +51,8 @@ extern NSString * const KeyContextRoot; extern NSString * const KeyType; extern NSString * const KeyMVMRC; +extern NSString * const KeyClientParameters; + #pragma mark - JSON Values // Server driven response type diff --git a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m index 71cccac..2127e2e 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m +++ b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m @@ -51,6 +51,8 @@ NSString * const KeyContextRoot = @"appContext"; NSString * const KeyType = @"type"; NSString * const KeyMVMRC = @"LaunchMVMRC"; +NSString * const KeyClientParameters = @"clientParameters"; + #pragma mark - JSON Values // Server driven response type diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift index ba698f4..1a4160d 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift @@ -47,7 +47,7 @@ import Foundation /// ] ///} /// completionHandler can return flat dictinary or a map. It depends on the paramters handler - func getParameters(with clientParameters: [String: Any], completionHandler:@escaping ([String: Any]?) -> ()) throws { + open func getParameters(with clientParameters: [String: Any], completionHandler:@escaping ([String: Any]?) -> ()) throws { guard let clientParameterModel = try ClientParameterRegistry.getClientParameterModel(clientParameters) else { completionHandler(nil)