From 45b84ae2e09eb1e015d5745d0bdae8aca70045cb Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 21 Jan 2021 13:00:29 -0500 Subject: [PATCH] redone in objecitve c --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 4 - .../ActionHandler+ClientParameters.swift | 56 ----------- .../ActionHandling/MVMCoreActionHandler.m | 93 +++++++++++-------- .../ClientParameterRegistry.swift | 2 +- .../MFHardCodedServerResponse.h | 2 +- 5 files changed, 56 insertions(+), 101 deletions(-) delete mode 100644 MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift 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 abeec70..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(KeyClientParameters) 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.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index d069404..3b2d704 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,16 +129,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; }]; }; - /* - BAU dictionary comparsion breaks if client parameters sets the dictionary. - For now we will set client parameters only when its sent in the action map. - We can move the code to Objective-C if required. - */ - if ([actionInformation dict:KeyClientParameters]) { - [self setClientParameterWith:actionInformation completionHandler:performAction]; - } else { - performAction(actionInformation); - } + [self setClientParameter:actionInformation completionHandler:performAction]; } - (void)shareAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { @@ -302,16 +294,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; [weakSelf prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionMap additionalData:additionalData delegateObject:delegateObject]; }; - /* - BAU dictionary comparsion breaks if client parameters sets the dictionary. - For now we will set client parameters only when its sent in the action map. - We can move the code to Objective-C if required. - */ - if ([actionInformation dict:KeyClientParameters]) { - [self setClientParameterWith:actionInformation completionHandler:performAction]; - } else { - performAction(actionInformation); - } + [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 { @@ -461,16 +444,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; }]; }; - /* - BAU dictionary comparsion breaks if client parameters sets the dictionary. - For now we will set client parameters only when its sent in the action map. - We can move the code to Objective-C if required. - */ - if ([actionInformation dict:KeyClientParameters]) { - [self setClientParameterWith:actionInformation completionHandler:performAction]; - } else { - performAction(actionInformation); - } + [self setClientParameter:actionInformation completionHandler:performAction]; } - (void)restartAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { @@ -589,15 +563,56 @@ NSString * const KeyActionTypeOpen = @"openPage"; [weakSelf prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionMap additionalData:additionalData delegate:delegate]; }; - /* - BAU dictionary comparsion breaks if client parameters sets the dictionary. - For now we will set client parameters only when its sent in the action map. - We can move the code to Objective-C if required. - */ - if ([actionInformation dict:KeyClientParameters]) { - [self setClientParameterWith:actionInformation completionHandler:performAction]; - } else { - performAction(actionInformation); + [self setClientParameter:actionInformation completionHandler:performAction]; +} + +/// 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 { + + 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 paramnters"]; + stopLoadingOverlay(); + completionHandler(actionInformation); + } + }]; + + if (error) { + stopLoadingOverlay(); + completionHandler(actionInformation); + [MVMCoreLoggingHandler logDebugMessageWithDelegate:@"Error clientparameters"]; + [MVMCoreLoggingHandler logDebugMessageWithDelegate:error.debugDescription]; } } 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) diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index eb9fba9..efa33b6 100644 --- a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h +++ b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h @@ -9,7 +9,7 @@ #import #import "MVMCoreRequestParameters.h" -#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 1 && DEBUG #if ENABLE_HARD_CODED_RESPONSE