From a5960728c4503f6947173ae51f4600c10942c877 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 5 Jan 2021 22:26:21 -0500 Subject: [PATCH 01/44] WIP: basic implmentation --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 32 ++++ .../ActionHandler+ClientParameters.swift | 41 +++++ .../ActionHandling/MVMCoreActionHandler.m | 140 +++++++++++------- .../ActionType/ActionOpenPageModel.swift | 5 +- .../ActionType/ActionOpenUrlModel.swift | 3 +- .../ClientParameterActionProtocol.swift | 13 ++ .../ClientParameterModel.swift | 31 ++++ .../ClientParameterModelProtocol.swift | 29 ++++ .../ClientParameterProtocol.swift | 35 +++++ .../ClientParameterRegistry.swift | 79 ++++++++++ .../MVMCore/Session/MVMCoreSessionObject.m | 1 + .../MFHardCodedServerResponse.h | 2 +- 12 files changed, 354 insertions(+), 57 deletions(-) create mode 100644 MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift create mode 100644 MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterActionProtocol.swift create mode 100644 MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterModel.swift create mode 100644 MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterModelProtocol.swift create mode 100644 MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift create mode 100644 MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index fc17f77..aa096b4 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -21,6 +21,12 @@ /* End PBXAggregateTarget section */ /* Begin PBXBuildFile section */ + 016FF6EE259A4E6300F5E4AA /* ClientParameterModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016FF6ED259A4E6300F5E4AA /* ClientParameterModelProtocol.swift */; }; + 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 */; }; 01DF561421F90ADC00CC099B /* Dictionary+MFConvenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */; }; @@ -144,6 +150,12 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 016FF6ED259A4E6300F5E4AA /* ClientParameterModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientParameterModelProtocol.swift; sourceTree = ""; }; + 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 = ""; }; 01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Dictionary+MFConvenience.swift"; sourceTree = ""; }; @@ -286,6 +298,18 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 016FF6EC259A4E3E00F5E4AA /* Client Parameters */ = { + isa = PBXGroup; + children = ( + 016FF6FB259BA27E00F5E4AA /* ClientParameterProtocol.swift */, + 016FF6ED259A4E6300F5E4AA /* ClientParameterModelProtocol.swift */, + 016FF6F1259A4FCC00F5E4AA /* ClientParameterModel.swift */, + 016FF6F5259B9AED00F5E4AA /* ClientParameterRegistry.swift */, + 01934FE625A4FFC2003DCD67 /* ClientParameterActionProtocol.swift */, + ); + path = "Client Parameters"; + sourceTree = ""; + }; 8876D5BF1FB50A9E00EB2E3D = { isa = PBXGroup; children = ( @@ -405,6 +429,7 @@ 946EE1B6237B66630036751F /* ActionType */ = { isa = PBXGroup; children = ( + 016FF6EC259A4E3E00F5E4AA /* Client Parameters */, 01F2A03523A80A7300D954D8 /* ActionModelProtocol.swift */, 946EE1BB237B691A0036751F /* ActionOpenPageModel.swift */, 01F2A03823A812DD00D954D8 /* ActionOpenUrlModel.swift */, @@ -560,6 +585,7 @@ AFBB96B51FBA3CEC0008D868 /* MVMCoreActionDelegateProtocol.h */, AFBB96B61FBA3CEC0008D868 /* MVMCoreActionHandler.h */, AFBB96B71FBA3CEC0008D868 /* MVMCoreActionHandler.m */, + 016FF705259D180000F5E4AA /* ActionHandler+ClientParameters.swift */, ); path = ActionHandling; sourceTree = ""; @@ -784,6 +810,7 @@ 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 */, @@ -820,6 +847,7 @@ AFED77A31FCCA29400BAE689 /* MVMCoreViewControllerNibMappingObject.m in Sources */, 8876D5EB1FB50AB000EB2E3D /* NSDecimalNumber+MFConvenience.m in Sources */, 01F2A03923A812DD00D954D8 /* ActionOpenUrlModel.swift in Sources */, + 01934FE725A4FFC2003DCD67 /* ClientParameterActionProtocol.swift in Sources */, AFBB96351FBA34310008D868 /* MVMCoreErrorConstants.m in Sources */, AF43A5881FBB67D6008E9347 /* MVMCoreActionUtility.m in Sources */, AFED77A61FCCA29400BAE689 /* MVMCoreViewControllerStoryBoardMappingObject.m in Sources */, @@ -830,6 +858,7 @@ 8876D5F51FB50AB000EB2E3D /* UILabel+MFCustom.m in Sources */, AFBB96B31FBA3B590008D868 /* MVMCoreGetterUtility.m in Sources */, AF43A7071FC4D7A2008E9347 /* MVMCoreObject.m in Sources */, + 016FF6F6259B9AED00F5E4AA /* ClientParameterRegistry.swift in Sources */, 94C014D924212360005811A9 /* ActionSettingModel.swift in Sources */, D2DEDCB723C63F3B00C44CC4 /* Clamping.swift in Sources */, 01DF561421F90ADC00CC099B /* Dictionary+MFConvenience.swift in Sources */, @@ -845,10 +874,13 @@ AFBB96941FBA3A9A0008D868 /* MVMCorePresentAnimationOperation.m in Sources */, 94C014D524211AF0005811A9 /* ActionCancelModel.swift in Sources */, AF43A5841FBB66DE008E9347 /* MVMCoreConstants.m in Sources */, + 016FF6F2259A4FCC00F5E4AA /* ClientParameterModel.swift in Sources */, D2DEDCBB23C65BC300C44CC4 /* Percent.swift in Sources */, AFBB966A1FBA3A570008D868 /* MVMCoreLoadRequestOperation.m in Sources */, + 016FF6FC259BA27E00F5E4AA /* ClientParameterProtocol.swift in Sources */, 8876D5F31FB50AB000EB2E3D /* UIFont+MFSpacing.m in Sources */, D282AAB82240342D00C46919 /* NSNumber+Extension.swift in Sources */, + 016FF6EE259A4E6300F5E4AA /* ClientParameterModelProtocol.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift new file mode 100644 index 0000000..fbbb8ca --- /dev/null +++ b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift @@ -0,0 +1,41 @@ +// +// ActionHandler+ClientParameters.swift +// MVMCore +// +// Created by Suresh, Kamlesh on 12/30/20. +// Copyright © 2020 myverizon. All rights reserved. +// + +import Foundation + +//- (void)handleActionWithDictionary:(nullable NSDictionary *)dictionary additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { +// +// NSString *action = [dictionary stringForKey:KeyActionType]; +// [self handleAction:action actionInformation:dictionary additionalData:additionalData delegate:delegate]; +//} + +public extension MVMCoreActionHandler { + + @objc func setClientParameter(with actionMap: [String: Any]?, completionHandler: @escaping ([String : Any]?) -> ()) { + + guard let paramsList = actionMap?.optionalArrayForChainOfKeysOrIndexes(["clientParameters", "list"]) as? [[String : Any]] else { + completionHandler(actionMap) + return + } + + MVMCoreLoadingOverlayHandler.sharedLoadingOverlay()?.startLoading() + ClientParameterRegistry.injectParams(with: paramsList) { (clientParams) in + guard let clientParams = clientParams else { + completionHandler(actionMap) + return + } + var extraParams:[String : Any] = actionMap?.optionalDictionaryForKey(KeyExtraParameters) ?? [:] + extraParams.merge(clientParams) { (_, new) in new } + var actionMapM = actionMap + actionMapM?[KeyExtraParameters] = extraParams + + MVMCoreLoadingOverlayHandler.sharedLoadingOverlay()?.stopLoading(true) + completionHandler(actionMapM) + } + } +} diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index ee539d0..68cfc07 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -107,22 +107,28 @@ NSString * const KeyActionTypeOpen = @"openPage"; // Loads the given page type. NSString *pageType = [actionInformation stringForKey:KeyPageType]; - if (pageType.length > 0) { - MVMCoreRequestParameters *requestParameters = [[MVMCoreRequestParameters alloc] initWithActionMap:actionInformation]; - - [self updateRequestParametersBeforeHandleOpenPageAction:requestParameters callBack:^(MVMCoreRequestParameters * _Nonnull requestParameters) { + + if (pageType.length == 0) { + // No page type to load, show error. + MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeNoPageType domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@_%@",NSStringFromClass([delegateObject.actionDelegate class]),KeyActionTypeOpen]]; + [self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]; + return; + } + + __weak typeof(self) weakSelf = self; + void (^performAction)(NSDictionary*) = ^(NSDictionary* actionMap) { + MVMCoreRequestParameters *requestParameters = [[MVMCoreRequestParameters alloc] initWithActionMap:actionMap]; + + [weakSelf updateRequestParametersBeforeHandleOpenPageAction:requestParameters callBack:^(MVMCoreRequestParameters * _Nonnull requestParameters) { if ([delegateObject.actionDelegate respondsToSelector:@selector(handleOpenPageForRequestParameters:actionInformation:additionalData:)]) { [delegateObject.actionDelegate handleOpenPageForRequestParameters:requestParameters actionInformation:actionInformation additionalData:additionalData]; } else { [MVMCoreActionHandler defaultHandleOpenPageForRequestParameters:requestParameters additionalData:additionalData delegateObject:delegateObject]; } }]; - } else { - - // No page type to load, show error. - MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeNoPageType domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@_%@",NSStringFromClass([delegateObject.actionDelegate class]),KeyActionTypeOpen]]; - [self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]; - } + }; + + [self preprocessRequest:actionInformation actionBlock:performAction]; } - (void)shareAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { @@ -266,23 +272,28 @@ NSString * const KeyActionTypeOpen = @"openPage"; #pragma mark - open url functions - (void)linkAwayAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { - - // Gets the app url - NSURL *appURL = nil; - NSString *appURLString = [actionInformation string:KeyLinkAwayAppURL]; - if (appURLString.length > 0) { - appURL = [NSURL URLWithString:appURLString]; - } - - // Gets the browser url - NSURL *otherURL = nil; - NSString *otherURLString = [actionInformation string:KeyLinkAwayURL]; - if (otherURLString.length > 0) { - otherURL = [NSURL URLWithString:otherURLString]; - } - - // Provide the URL and App URL to be modified if needed by a subclass or delegate. - [self prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]; + + __weak typeof(self) weakSelf = self; + void (^performAction)(NSDictionary*) = ^(NSDictionary* actionMap) { + // Gets the app url + NSURL *appURL = nil; + NSString *appURLString = [actionMap string:KeyLinkAwayAppURL]; + if (appURLString.length > 0) { + appURL = [NSURL URLWithString:appURLString]; + } + + // Gets the browser url + NSURL *otherURL = nil; + NSString *otherURLString = [actionMap string:KeyLinkAwayURL]; + if (otherURLString.length > 0) { + otherURL = [NSURL URLWithString:otherURLString]; + } + + // Provide the URL and App URL to be modified if needed by a subclass or delegate. + [self prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionMap additionalData:additionalData delegateObject:delegateObject]; + }; + + [self preprocessRequest:actionInformation actionBlock:performAction]; } - (void)prepareLinkAwayWithURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { @@ -411,21 +422,39 @@ NSString * const KeyActionTypeOpen = @"openPage"; // Loads the given page type. NSString *pageType = [actionInformation stringForKey:KeyPageType]; - if (pageType.length > 0) { - MVMCoreRequestParameters *requestParameters = [[MVMCoreRequestParameters alloc] initWithActionMap:actionInformation]; - - [self updateRequestParametersBeforeHandleOpenPageAction:requestParameters callBack:^(MVMCoreRequestParameters * _Nonnull requestParameters) { + + if (pageType.length == 0) { + // No page type to load, show error. + MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeNoPageType domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@_%@",NSStringFromClass([delegate class]),KeyActionTypeOpen]]; + [self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegate:delegate]; + return; + } + + __weak typeof(self) weakSelf = self; + void (^performAction)(NSDictionary*) = ^(NSDictionary* actionMap) { + MVMCoreRequestParameters *requestParameters = [[MVMCoreRequestParameters alloc] initWithActionMap:actionMap]; + + [weakSelf updateRequestParametersBeforeHandleOpenPageAction:requestParameters callBack:^(MVMCoreRequestParameters * _Nonnull requestParameters) { if ([delegate respondsToSelector:@selector(handleOpenPageForRequestParameters:actionInformation:additionalData:)]) { - [delegate handleOpenPageForRequestParameters:requestParameters actionInformation:actionInformation additionalData:additionalData]; + [delegate handleOpenPageForRequestParameters:requestParameters actionInformation:actionMap additionalData:additionalData]; } else { [MVMCoreActionHandler defaultHandleOpenPageForRequestParameters:requestParameters additionalData:additionalData delegate:delegate]; } }]; + }; + + [self preprocessRequest:actionInformation actionBlock:performAction]; +} + +- (void)preprocessRequest:(nullable NSDictionary *)actionInformation actionBlock:(nullable void (^)(NSDictionary*))actionBlock { + // Check for client params and fetch the parameters + if ([actionInformation dict:@"clientParameters"]) { + [self setClientParameterWith:actionInformation + completionHandler:^(NSDictionary * _Nullable actionDict) { + actionBlock(actionDict); + }]; } else { - - // No page type to load, show error. - MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeNoPageType domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@_%@",NSStringFromClass([delegate class]),KeyActionTypeOpen]]; - [self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegate:delegate]; + actionBlock(actionInformation); } } @@ -524,23 +553,28 @@ NSString * const KeyActionTypeOpen = @"openPage"; } - (void)linkAwayAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - - // Gets the app url - NSURL *appURL = nil; - NSString *appURLString = [actionInformation string:KeyLinkAwayAppURL]; - if (appURLString.length > 0) { - appURL = [NSURL URLWithString:appURLString]; - } - - // Gets the browser url - NSURL *otherURL = nil; - NSString *otherURLString = [actionInformation string:KeyLinkAwayURL]; - if (otherURLString.length > 0) { - otherURL = [NSURL URLWithString:otherURLString]; - } - - // Provide the URL and App URL to be modified if needed by a subclass or delegate. - [self prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionInformation additionalData:additionalData delegate:delegate]; + + __weak typeof(self) weakSelf = self; + void (^performAction)(NSDictionary*) = ^(NSDictionary* actionMap) { + // Gets the app url + NSURL *appURL = nil; + NSString *appURLString = [actionMap string:KeyLinkAwayAppURL]; + if (appURLString.length > 0) { + appURL = [NSURL URLWithString:appURLString]; + } + + // Gets the browser url + NSURL *otherURL = nil; + NSString *otherURLString = [actionMap string:KeyLinkAwayURL]; + if (otherURLString.length > 0) { + otherURL = [NSURL URLWithString:otherURLString]; + } + + // Provide the URL and App URL to be modified if needed by a subclass or delegate. + [self prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionMap additionalData:additionalData delegate:delegate]; + }; + + [self preprocessRequest:actionInformation actionBlock:performAction]; } - (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/Models/ActionType/ActionOpenPageModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift index 40e7312..52af9f0 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift @@ -7,7 +7,7 @@ // -@objcMembers open class ActionOpenPageModel: ActionModelProtocol { +@objcMembers open class ActionOpenPageModel: ActionModelProtocol, ClientParameterActionProtocol { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- @@ -20,7 +20,8 @@ public var presentationStyle: String? public var tabBarIndex: Int? public var background: Bool? - + public var clientParameterModel: ClientParameterModel? + //-------------------------------------------------- // MARK: - Initialzier //-------------------------------------------------- diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift index 03a1e95..998716b 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift @@ -7,7 +7,7 @@ // -@objcMembers public class ActionOpenUrlModel: ActionModelProtocol { +@objcMembers public class ActionOpenUrlModel: ActionModelProtocol, ClientParameterActionProtocol { //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- @@ -30,6 +30,7 @@ public var dontShowProgress: Bool? public var headerParameters: JSONValueDictionary? public var enableNativeScroll: Bool? + public var clientParameterModel: ClientParameterModel? //-------------------------------------------------- // MARK: - Initialzier diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterActionProtocol.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterActionProtocol.swift new file mode 100644 index 0000000..51fb71a --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterActionProtocol.swift @@ -0,0 +1,13 @@ +// +// ClientParameterActionProtocol.swift +// MVMCore +// +// Created by Suresh, Kamlesh on 1/5/21. +// Copyright © 2021 myverizon. All rights reserved. +// + +import Foundation + +public protocol ClientParameterActionProtocol { + var clientParameterModel: ClientParameterModel? { get set } +} diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterModel.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterModel.swift new file mode 100644 index 0000000..8686d71 --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterModel.swift @@ -0,0 +1,31 @@ +// +// ClientParameterModel.swift +// MVMCore +// +// Created by Suresh, Kamlesh on 12/28/20. +// Copyright © 2020 myverizon. All rights reserved. +// + +import Foundation + +public class ClientParameterModel: Codable { + var timeout: Double? + var list: [ClientParameterModelProtocol] + + private enum CodingKeys: String, CodingKey { + case timeout + case list + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + timeout = try typeContainer.decodeIfPresent(Double.self, forKey: .timeout) + list = try typeContainer.decodeModels(codingKey: .list) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(timeout, forKey: .timeout) + try container.encodeModels(list, forKey: .list) + } +} diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterModelProtocol.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterModelProtocol.swift new file mode 100644 index 0000000..2dd6731 --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterModelProtocol.swift @@ -0,0 +1,29 @@ +// +// ClientParameterProtocol.swift +// MVMCore +// +// Created by Suresh, Kamlesh on 12/28/20. +// Copyright © 2020 myverizon. All rights reserved. +// + +import Foundation + +public protocol ClientParameterModelProtocol: ModelProtocol { + var type: String { get } + var inputParameters: JSONValueDictionary? { get set } +} + +public extension ClientParameterModelProtocol { + + var type: String { + get { Self.identifier } + } + + static var categoryCodingKey: String { + return "type" + } + + static var categoryName: String { + return "\(ClientParameterModelProtocol.self)" + } +} diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift new file mode 100644 index 0000000..5f36f30 --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift @@ -0,0 +1,35 @@ +// +// ClientParameterProtocol.swift +// MVMCore +// +// Created by Suresh, Kamlesh on 12/29/20. +// Copyright © 2020 myverizon. All rights reserved. +// + +import Foundation + +public protocol ClientParameterProtocol { + init() + static var name: String { get } + func clientParameter(with paramModel: ClientParameterModelProtocol?) -> [String: Any]? +} + +extension ClientParameterProtocol { + /// Handle encoding and errors + public func getJSON(with paramModel: ClientParameterModelProtocol?) -> JSONDictionary? { + guard let dataModel = paramModel, + let json = dataModel.toJSON() else { + // JSON parsing failed + if let errorObject = MVMCoreErrorObject(title: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorTitle), + message: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess), + messageToLog: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess), + code: ErrorCode.parsingJSON.rawValue, + domain: ErrorDomainNative, + location: String(describing: Self.name)) { + //MFLoggingHandler.addError(toLog: errorObject) + } + return nil + } + return json + } +} diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift new file mode 100644 index 0000000..be0285e --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift @@ -0,0 +1,79 @@ +// +// ClientParameterRegistry.swift +// MVMCore +// +// Created by Suresh, Kamlesh on 12/29/20. +// Copyright © 2020 myverizon. All rights reserved. +// + +import Foundation + + +@objcMembers open class ClientParameterRegistry: NSObject { + + public static let shared = ClientParameterRegistry() + private var mapping: [String: ClientParameterProtocol.Type] = [:] + + public func register(param: T.Type) { + mapping[T.name] = param + } + + public func createParam(_ actionType: String) -> ClientParameterProtocol? { + guard let patamType = mapping[actionType] else { return nil } + return patamType.init() + } + + static func injectParams(with paramsModelList: [[String: Any]]?, + completionHandler:@escaping ([String: Any]?) -> ()) { + + let clientParameterRegistry = ClientParameterRegistry.shared + guard let paramsModelList = paramsModelList else { + completionHandler(nil) + return + } + + var paramsList: [String: Any] = [:] + MVMCoreDispatchUtility.performSyncBlock( inBackground: { () -> Void in + for param in paramsModelList { + if let clientParam = clientParameterRegistry.injectParam(param) { + paramsList.merge(clientParam) { (_, new) in new } + } + } + }) + completionHandler(paramsList) + print("") + } + + func injectParam( _ param: [String: Any]) -> [String: Any]? { + if let paramModel = try? ClientParameterRegistry.getModel(param), + let param = ClientParameterRegistry.shared.createParam(paramModel.type) { + return param.clientParameter(with: paramModel) + } + return nil + } + + + /// Add all registry here. + public static func registerParameters() { + + } + + /// Register Default Core Bridge Objects + public static func register(parameter: T.Type, type: M.Type) { + try? ModelRegistry.register(type) + ClientParameterRegistry.shared.register(param: parameter) + } + + public static func getModel(_ json: [String: Any]) throws -> ClientParameterModelProtocol { + guard let paramType = json.optionalStringForKey("type") else { + throw ModelRegistry.Error.other(message: "parameterType missing") + } + guard let type = ModelRegistry.getType(for: paramType, with: ClientParameterModelProtocol.self) else { + throw ModelRegistry.Error.decoderErrorModelNotMapped() + } + guard let model = try type.decode(jsonDict: json) as? ClientParameterModelProtocol else { + throw ModelRegistry.Error.decoderError + } + return model + } +} diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionObject.m b/MVMCore/MVMCore/Session/MVMCoreSessionObject.m index 7134c59..8650972 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionObject.m +++ b/MVMCore/MVMCore/Session/MVMCoreSessionObject.m @@ -17,6 +17,7 @@ if (self = [super init]) { self.session = [self createNSURLSession]; [ModelMapping registerObjects]; + [ClientParameterRegistry registerParameters]; } return self; } 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 From d49111766bb8275b35413b05532ef03b05f0fe73 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 6 Jan 2021 20:53:40 -0500 Subject: [PATCH 02/44] concurrent queue and timout --- .../ActionHandler+ClientParameters.swift | 5 +-- .../ClientParameterRegistry.swift | 36 +++++++++++++------ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift index fbbb8ca..53acc76 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift @@ -18,13 +18,14 @@ public extension MVMCoreActionHandler { @objc func setClientParameter(with actionMap: [String: Any]?, completionHandler: @escaping ([String : Any]?) -> ()) { - guard let paramsList = actionMap?.optionalArrayForChainOfKeysOrIndexes(["clientParameters", "list"]) as? [[String : Any]] else { + guard let clientParameters = actionMap?.optionalDictionaryForKey("clientParameters") else { completionHandler(actionMap) return } MVMCoreLoadingOverlayHandler.sharedLoadingOverlay()?.startLoading() - ClientParameterRegistry.injectParams(with: paramsList) { (clientParams) in + + ClientParameterRegistry.injectParams(with: clientParameters) { (clientParams) in guard let clientParams = clientParams else { completionHandler(actionMap) return diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift index be0285e..31fd7e0 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift @@ -23,25 +23,41 @@ import Foundation return patamType.init() } - static func injectParams(with paramsModelList: [[String: Any]]?, + static func injectParams(with clientParameters: [String: Any]?, completionHandler:@escaping ([String: Any]?) -> ()) { let clientParameterRegistry = ClientParameterRegistry.shared - guard let paramsModelList = paramsModelList else { + guard let clientParameters = clientParameters, + let paramsModelList = clientParameters.optionalArrayForKey("list") as? [[String: Any]] else { completionHandler(nil) return } var paramsList: [String: Any] = [:] - MVMCoreDispatchUtility.performSyncBlock( inBackground: { () -> Void in + + DispatchQueue.global(qos: .userInitiated).async { + + let concurrentQueue = DispatchQueue(label: "com.mva.clientparam", attributes: .concurrent) + let group = DispatchGroup() for param in paramsModelList { - if let clientParam = clientParameterRegistry.injectParam(param) { - paramsList.merge(clientParam) { (_, new) in new } + group.enter() + concurrentQueue.async(flags: .barrier) { + if let clientParam = clientParameterRegistry.injectParam(param) { + paramsList.merge(clientParam) { (_, new) in new } + } + group.leave() } } - }) - completionHandler(paramsList) - print("") + + if let timeout = clientParameters.optionalCGFloatForKey("timeout") { + let dispatchAfterTime = DispatchTimeInterval.seconds(Int(timeout)) + _ = group.wait(timeout: .now() + dispatchAfterTime) + } else { + group.wait() + } + + completionHandler(paramsList) + } } func injectParam( _ param: [String: Any]) -> [String: Any]? { @@ -54,9 +70,7 @@ import Foundation /// Add all registry here. - public static func registerParameters() { - - } + public static func registerParameters() { } /// Register Default Core Bridge Objects public static func register(parameter: T.Type, type: M.Type) { From d65351cabb6723aa75a9317e21a69ecf4c05a1df Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 7 Jan 2021 09:59:10 -0500 Subject: [PATCH 03/44] remove hardcode --- .../Utility/HardCodedServerResponse/MFHardCodedServerResponse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index efa33b6..eb9fba9 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 1 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG #if ENABLE_HARD_CODED_RESPONSE From 9538b50f84ea1e9151bd34d60421804df0676a51 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 7 Jan 2021 14:51:54 -0500 Subject: [PATCH 04/44] passing completion handler and timout --- .../ClientParameterProtocol.swift | 3 +- .../ClientParameterRegistry.swift | 37 +++++++++++-------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift index 5f36f30..53dd12d 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift @@ -11,10 +11,11 @@ import Foundation public protocol ClientParameterProtocol { init() static var name: String { get } - func clientParameter(with paramModel: ClientParameterModelProtocol?) -> [String: Any]? + func clientParameter(with paramModel: ClientParameterModelProtocol, _ timout: CGFloat?, completionHandler:@escaping ([String: Any]?) -> ()) } extension ClientParameterProtocol { + /// Handle encoding and errors public func getJSON(with paramModel: ClientParameterModelProtocol?) -> JSONDictionary? { guard let dataModel = paramModel, diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift index 31fd7e0..3be23bd 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift @@ -37,35 +37,40 @@ import Foundation DispatchQueue.global(qos: .userInitiated).async { + let timeout = clientParameters.optionalCGFloatForKey("timeout") ?? 60.0 + let concurrentQueue = DispatchQueue(label: "com.mva.clientparam", attributes: .concurrent) let group = DispatchGroup() for param in paramsModelList { group.enter() - concurrentQueue.async(flags: .barrier) { - if let clientParam = clientParameterRegistry.injectParam(param) { - paramsList.merge(clientParam) { (_, new) in new } + + clientParameterRegistry.injectParam(param, timeout-1) { (clientParam) in + guard let clientParam = clientParam else { + group.leave() + return + } + concurrentQueue.async(flags: .barrier) { + paramsList.merge(clientParam) { (_, new) in new } + group.leave() } - group.leave() } } - if let timeout = clientParameters.optionalCGFloatForKey("timeout") { - let dispatchAfterTime = DispatchTimeInterval.seconds(Int(timeout)) - _ = group.wait(timeout: .now() + dispatchAfterTime) - } else { - group.wait() - } - + let dispatchAfterTime = DispatchTimeInterval.seconds(Int(timeout)) + _ = group.wait(timeout: .now() + dispatchAfterTime) + completionHandler(paramsList) } } - func injectParam( _ param: [String: Any]) -> [String: Any]? { - if let paramModel = try? ClientParameterRegistry.getModel(param), - let param = ClientParameterRegistry.shared.createParam(paramModel.type) { - return param.clientParameter(with: paramModel) + func injectParam( _ param: [String: Any], _ timout: CGFloat, completionHandler:@escaping ([String: Any]?) -> ()) { + + guard let paramModel = try? ClientParameterRegistry.getModel(param), + let param = ClientParameterRegistry.shared.createParam(paramModel.type) else { + return completionHandler(nil) } - return nil + + param.clientParameter(with: paramModel, timout, completionHandler: completionHandler) } From e71f6cd7d7ef805c7dcac3e11445f76578ece7b6 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Fri, 8 Jan 2021 17:02:10 -0500 Subject: [PATCH 05/44] timer --- .../ClientParameterRegistry.swift | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift index 3be23bd..6fe5f38 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift @@ -37,10 +37,19 @@ import Foundation DispatchQueue.global(qos: .userInitiated).async { - let timeout = clientParameters.optionalCGFloatForKey("timeout") ?? 60.0 + let timeout = clientParameters.optionalCGFloatForKey("timeout") ?? 30.0 let concurrentQueue = DispatchQueue(label: "com.mva.clientparam", attributes: .concurrent) let group = DispatchGroup() + + + let completionItem = DispatchWorkItem { + completionHandler(paramsList); + } + + let dispatchAfterTime = DispatchTimeInterval.seconds(Int(timeout)) + concurrentQueue.asyncAfter(deadline: .now() + dispatchAfterTime, execute: completionItem) + for param in paramsModelList { group.enter() @@ -55,11 +64,7 @@ import Foundation } } } - - let dispatchAfterTime = DispatchTimeInterval.seconds(Int(timeout)) - _ = group.wait(timeout: .now() + dispatchAfterTime) - - completionHandler(paramsList) + group.notify(queue: concurrentQueue, work: completionItem); } } From 2bfca1cfcdb40fc52f2a0881fb1e7c98d5bb035d Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Mon, 11 Jan 2021 11:40:18 -0500 Subject: [PATCH 06/44] remove timer for now --- .../Client Parameters/ClientParameterRegistry.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift index 6fe5f38..cc98d1a 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift @@ -47,8 +47,8 @@ import Foundation completionHandler(paramsList); } - let dispatchAfterTime = DispatchTimeInterval.seconds(Int(timeout)) - concurrentQueue.asyncAfter(deadline: .now() + dispatchAfterTime, execute: completionItem) +// let dispatchAfterTime = DispatchTimeInterval.seconds(Int(timeout)) +// concurrentQueue.asyncAfter(deadline: .now() + dispatchAfterTime, execute: completionItem) for param in paramsModelList { group.enter() From 4805c1ed43fe21bfb7098e0621b9c43e959b40de Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Tue, 12 Jan 2021 16:36:09 -0500 Subject: [PATCH 07/44] polish, re-enable timeout --- .../ActionHandler+ClientParameters.swift | 6 -- .../ActionType/ActionOpenPageModel.swift | 2 +- .../ActionType/ActionOpenUrlModel.swift | 2 +- .../ClientParameterActionProtocol.swift | 2 +- .../ClientParameterModelProtocol.swift | 1 - .../ClientParameterProtocol.swift | 2 +- .../ClientParameterRegistry.swift | 89 +++++++++++-------- 7 files changed, 56 insertions(+), 48 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift index 53acc76..fe52f39 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift @@ -8,12 +8,6 @@ import Foundation -//- (void)handleActionWithDictionary:(nullable NSDictionary *)dictionary additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { -// -// NSString *action = [dictionary stringForKey:KeyActionType]; -// [self handleAction:action actionInformation:dictionary additionalData:additionalData delegate:delegate]; -//} - public extension MVMCoreActionHandler { @objc func setClientParameter(with actionMap: [String: Any]?, completionHandler: @escaping ([String : Any]?) -> ()) { diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift index 52af9f0..a20d343 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift @@ -20,7 +20,7 @@ public var presentationStyle: String? public var tabBarIndex: Int? public var background: Bool? - public var clientParameterModel: ClientParameterModel? + public var clientParameters: ClientParameterModel? //-------------------------------------------------- // MARK: - Initialzier diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift index 998716b..96e51f5 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift @@ -18,6 +18,7 @@ public var browserUrl: String public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? + public var clientParameters: ClientParameterModel? public var appURL: String? //TODO: Should be removed in future releases. This should be MF specific. @@ -30,7 +31,6 @@ public var dontShowProgress: Bool? public var headerParameters: JSONValueDictionary? public var enableNativeScroll: Bool? - public var clientParameterModel: ClientParameterModel? //-------------------------------------------------- // MARK: - Initialzier diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterActionProtocol.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterActionProtocol.swift index 51fb71a..f969a95 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterActionProtocol.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterActionProtocol.swift @@ -9,5 +9,5 @@ import Foundation public protocol ClientParameterActionProtocol { - var clientParameterModel: ClientParameterModel? { get set } + var clientParameters: ClientParameterModel? { get set } } diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterModelProtocol.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterModelProtocol.swift index 2dd6731..b742170 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterModelProtocol.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterModelProtocol.swift @@ -10,7 +10,6 @@ import Foundation public protocol ClientParameterModelProtocol: ModelProtocol { var type: String { get } - var inputParameters: JSONValueDictionary? { get set } } public extension ClientParameterModelProtocol { diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift index 53dd12d..3420cf9 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift @@ -11,7 +11,7 @@ import Foundation public protocol ClientParameterProtocol { init() static var name: String { get } - func clientParameter(with paramModel: ClientParameterModelProtocol, _ timout: CGFloat?, completionHandler:@escaping ([String: Any]?) -> ()) + func fetchClientParameters(for paramModel: ClientParameterModelProtocol, timingOutIn timeout: Double, completionHandler:@escaping ([String: Any]?) -> ()) } extension ClientParameterProtocol { diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift index cc98d1a..7cdcefa 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift @@ -14,11 +14,11 @@ import Foundation public static let shared = ClientParameterRegistry() private var mapping: [String: ClientParameterProtocol.Type] = [:] - public func register(param: T.Type) { - mapping[T.name] = param + public func register(_ handler: T.Type) { + mapping[T.name] = handler } - public func createParam(_ actionType: String) -> ClientParameterProtocol? { + public func createParamHandler(_ actionType: String) -> ClientParameterProtocol? { guard let patamType = mapping[actionType] else { return nil } return patamType.init() } @@ -34,58 +34,73 @@ import Foundation } var paramsList: [String: Any] = [:] - - DispatchQueue.global(qos: .userInitiated).async { - - let timeout = clientParameters.optionalCGFloatForKey("timeout") ?? 30.0 - - let concurrentQueue = DispatchQueue(label: "com.mva.clientparam", attributes: .concurrent) - let group = DispatchGroup() - - - let completionItem = DispatchWorkItem { + let timeout = clientParameters["timeout"] as? Double ?? 30.0 + + let parametersWorkQueue = DispatchQueue(label: "com.mva.clientparam") + let group = DispatchGroup() + let defaultErrorString = "Failed to collect." + + // Dispatch setup on queue to ensure setup is complete before completion callbacks. + parametersWorkQueue.async(group: group, qos: .userInitiated) { + // Setup completion handlers. Barriered to ensure one happens after the other. + var complete = false + let timeoutWorkItem = DispatchWorkItem(qos: .userInitiated) { completionHandler(paramsList); + complete = true } - -// let dispatchAfterTime = DispatchTimeInterval.seconds(Int(timeout)) -// concurrentQueue.asyncAfter(deadline: .now() + dispatchAfterTime, execute: completionItem) - + let completionWorkItem = DispatchWorkItem(qos: .userInitiated) { + timeoutWorkItem.cancel() + if !complete { // In the case of firing after timeout. + completionHandler(paramsList); + complete = true + } + } + + // Setup timeout. + parametersWorkQueue.asyncAfter(deadline: .now() + .seconds(Int(timeout)), execute: timeoutWorkItem) + + // Setup the parameter execution. for param in paramsModelList { - group.enter() - - clientParameterRegistry.injectParam(param, timeout-1) { (clientParam) in - guard let clientParam = clientParam else { - group.leave() - return + guard let paramModel = try? Self.getModel(param) else { + if let paramType = param.optionalStringForKey("type") { + paramsList[paramType] = ["error": "Parsing error."] } - concurrentQueue.async(flags: .barrier) { - paramsList.merge(clientParam) { (_, new) in new } - group.leave() + continue + } + // Setup default timeout / nil error. This will be replaced as parameters are collected. + paramsList[paramModel.type] = ["error": defaultErrorString] + group.enter() + // Dispatch asynchronous injection. + clientParameterRegistry.injectParam(paramModel, before: timeout) { (clientParam) in + // Queue the results for merge. + parametersWorkQueue.async { + if let clientParam = clientParam { + paramsList[paramModel.type] = clientParam + } + group.leave() // Leaving is only done after setup (barriered). } } } - group.notify(queue: concurrentQueue, work: completionItem); + + // Callback when all parameters have been merged. + group.notify(queue: parametersWorkQueue, work: completionWorkItem); } } - func injectParam( _ param: [String: Any], _ timout: CGFloat, completionHandler:@escaping ([String: Any]?) -> ()) { - - guard let paramModel = try? ClientParameterRegistry.getModel(param), - let param = ClientParameterRegistry.shared.createParam(paramModel.type) else { + func injectParam( _ paramModel: ClientParameterModelProtocol, before timeout: Double, completionHandler:@escaping ([String: Any]?) -> ()) { + guard let paramHandler = ClientParameterRegistry.shared.createParamHandler(paramModel.type) else { return completionHandler(nil) } - - param.clientParameter(with: paramModel, timout, completionHandler: completionHandler) + paramHandler.fetchClientParameters(for: paramModel, timingOutIn: timeout, completionHandler: completionHandler) } - /// Add all registry here. public static func registerParameters() { } /// Register Default Core Bridge Objects - public static func register(parameter: T.Type, type: M.Type) { - try? ModelRegistry.register(type) - ClientParameterRegistry.shared.register(param: parameter) + public static func register(handler: T.Type, for model: M.Type) { + try? ModelRegistry.register(model) + ClientParameterRegistry.shared.register(handler) } public static func getModel(_ json: [String: Any]) throws -> ClientParameterModelProtocol { From 2426b626fe8e68aadbb4a55ce27b42c029f488de Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 14 Jan 2021 19:18:32 -0500 Subject: [PATCH 08/44] code review --- .../ActionHandler+ClientParameters.swift | 20 ++++- .../ActionHandling/MVMCoreActionHandler.m | 4 +- .../ClientParameterProtocol.swift | 11 +-- .../ClientParameterRegistry.swift | 75 +++++++++---------- .../MVMCore/Models/Model/ModelRegistry.swift | 16 ++++ .../MFHardCodedServerResponse.h | 2 +- 6 files changed, 73 insertions(+), 55 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift index fe52f39..bbd951a 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift @@ -17,19 +17,31 @@ public extension MVMCoreActionHandler { return } - MVMCoreLoadingOverlayHandler.sharedLoadingOverlay()?.startLoading() + let isBackgroudRequest = actionMap?.boolForKey("background") ?? false - ClientParameterRegistry.injectParams(with: clientParameters) { (clientParams) in + if !isBackgroudRequest { + MVMCoreLoadingOverlayHandler.sharedLoadingOverlay()?.startLoading() + } + + let stopLoadingOverlay = {() in + if !isBackgroudRequest { + MVMCoreLoadingOverlayHandler.sharedLoadingOverlay()?.stopLoading(true) + } + } + + ClientParameterRegistry.injectParameters(with: clientParameters) { (clientParams) in guard let clientParams = clientParams else { + stopLoadingOverlay() completionHandler(actionMap) return } - var extraParams:[String : Any] = actionMap?.optionalDictionaryForKey(KeyExtraParameters) ?? [:] + + var extraParams: [String : Any] = actionMap?.optionalDictionaryForKey(KeyExtraParameters) ?? [:] extraParams.merge(clientParams) { (_, new) in new } var actionMapM = actionMap actionMapM?[KeyExtraParameters] = extraParams - MVMCoreLoadingOverlayHandler.sharedLoadingOverlay()?.stopLoading(true) + stopLoadingOverlay() completionHandler(actionMapM) } } diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 68cfc07..90374e5 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -290,7 +290,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; } // Provide the URL and App URL to be modified if needed by a subclass or delegate. - [self 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]; @@ -571,7 +571,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; } // Provide the URL and App URL to be modified if needed by a subclass or delegate. - [self 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]; diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift index 3420cf9..a954ac4 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift @@ -21,15 +21,8 @@ extension ClientParameterProtocol { guard let dataModel = paramModel, let json = dataModel.toJSON() else { // JSON parsing failed - if let errorObject = MVMCoreErrorObject(title: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorTitle), - message: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess), - messageToLog: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess), - code: ErrorCode.parsingJSON.rawValue, - domain: ErrorDomainNative, - location: String(describing: Self.name)) { - //MFLoggingHandler.addError(toLog: errorObject) - } - return nil + MVMCoreLoggingHandler.logDebugMessage(withDelegate: "ClientParameterProtocol JSON parsing failed") + return nil } return json } diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift index 7cdcefa..fe91785 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift @@ -18,25 +18,35 @@ import Foundation mapping[T.name] = handler } - public func createParamHandler(_ actionType: String) -> ClientParameterProtocol? { - guard let patamType = mapping[actionType] else { return nil } - return patamType.init() + public func createParametersHandler(_ actionType: String) -> ClientParameterProtocol? { + guard let parameterType = mapping[actionType] else { return nil } + return parameterType.init() } - static func injectParams(with clientParameters: [String: Any]?, + static func getClientParameterModel(_ clientParameters: [String: Any]) -> ClientParameterModel? { + do { + let data = try JSONSerialization.data(withJSONObject: clientParameters) + return try JSONDecoder().decode(ClientParameterModel.self, from: data) + } catch { + MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Error parsing getClientParameterModel: \(error)") + return nil + } + } + + static func injectParameters(with clientParameters: [String: Any], completionHandler:@escaping ([String: Any]?) -> ()) { let clientParameterRegistry = ClientParameterRegistry.shared - guard let clientParameters = clientParameters, - let paramsModelList = clientParameters.optionalArrayForKey("list") as? [[String: Any]] else { + + guard let clientParameterModel = ClientParameterRegistry.getClientParameterModel(clientParameters) else { completionHandler(nil) return } - var paramsList: [String: Any] = [:] - let timeout = clientParameters["timeout"] as? Double ?? 30.0 - - let parametersWorkQueue = DispatchQueue(label: "com.mva.clientparam") + var parametersList: [String: Any] = [:] + let timeout = clientParameterModel.timeout ?? 30.0 + + let parametersWorkQueue = DispatchQueue(label: "com.mva.clientparameter") let group = DispatchGroup() let defaultErrorString = "Failed to collect." @@ -45,13 +55,13 @@ import Foundation // Setup completion handlers. Barriered to ensure one happens after the other. var complete = false let timeoutWorkItem = DispatchWorkItem(qos: .userInitiated) { - completionHandler(paramsList); + completionHandler(parametersList); complete = true } let completionWorkItem = DispatchWorkItem(qos: .userInitiated) { timeoutWorkItem.cancel() if !complete { // In the case of firing after timeout. - completionHandler(paramsList); + completionHandler(parametersList); complete = true } } @@ -60,38 +70,33 @@ import Foundation parametersWorkQueue.asyncAfter(deadline: .now() + .seconds(Int(timeout)), execute: timeoutWorkItem) // Setup the parameter execution. - for param in paramsModelList { - guard let paramModel = try? Self.getModel(param) else { - if let paramType = param.optionalStringForKey("type") { - paramsList[paramType] = ["error": "Parsing error."] - } - continue - } + for parameterModel in clientParameterModel.list { // Setup default timeout / nil error. This will be replaced as parameters are collected. - paramsList[paramModel.type] = ["error": defaultErrorString] + parametersList[parameterModel.type] = ["error": defaultErrorString] group.enter() // Dispatch asynchronous injection. - clientParameterRegistry.injectParam(paramModel, before: timeout) { (clientParam) in + clientParameterRegistry.injectParameter(parameterModel, before: timeout) { (clientParam) in // Queue the results for merge. parametersWorkQueue.async { if let clientParam = clientParam { - paramsList[paramModel.type] = clientParam + parametersList[parameterModel.type] = clientParam } group.leave() // Leaving is only done after setup (barriered). } } } + // Callback when all parameters have been merged. group.notify(queue: parametersWorkQueue, work: completionWorkItem); } } - func injectParam( _ paramModel: ClientParameterModelProtocol, before timeout: Double, completionHandler:@escaping ([String: Any]?) -> ()) { - guard let paramHandler = ClientParameterRegistry.shared.createParamHandler(paramModel.type) else { + func injectParameter( _ parameterModel: ClientParameterModelProtocol, before timeout: Double, completionHandler:@escaping ([String: Any]?) -> ()) { + guard let parammeterHandler = ClientParameterRegistry.shared.createParametersHandler(parameterModel.type) else { return completionHandler(nil) } - paramHandler.fetchClientParameters(for: paramModel, timingOutIn: timeout, completionHandler: completionHandler) + parammeterHandler.fetchClientParameters(for: parameterModel, timingOutIn: timeout, completionHandler: completionHandler) } /// Add all registry here. @@ -99,20 +104,12 @@ import Foundation /// Register Default Core Bridge Objects public static func register(handler: T.Type, for model: M.Type) { - try? ModelRegistry.register(model) + + do { + try ModelRegistry.register(model) + } catch { + MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Error registering: \(error)") + } ClientParameterRegistry.shared.register(handler) } - - public static func getModel(_ json: [String: Any]) throws -> ClientParameterModelProtocol { - guard let paramType = json.optionalStringForKey("type") else { - throw ModelRegistry.Error.other(message: "parameterType missing") - } - guard let type = ModelRegistry.getType(for: paramType, with: ClientParameterModelProtocol.self) else { - throw ModelRegistry.Error.decoderErrorModelNotMapped() - } - guard let model = try type.decode(jsonDict: json) as? ClientParameterModelProtocol else { - throw ModelRegistry.Error.decoderError - } - return model - } } diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index 93407d1..59dc0c7 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -66,6 +66,22 @@ public struct ModelRegistry { return AnyCodingKey(category.codingKey) } + + + public static func getModelFor(json: [String: Any], type: T.Type) throws -> ModelProtocol? { + + guard let categoryKey = ModelRegistry.getCategory(for: type)?.codingKey else { + throw ModelRegistry.Error.other(message: "coding key missing") + } + guard let parameterType = json.optionalStringForKey(categoryKey) else { + throw ModelRegistry.Error.other(message: "type missing") + } + + guard let type = ModelRegistry.getType(for: parameterType, with: type) else { + throw ModelRegistry.Error.decoderErrorModelNotMapped() + } + return try type.decode(jsonDict: json) + } } extension KeyedDecodingContainer where Key: CodingKey { 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 From 2eb640e8fa631b505e41c128e159ffece2de522e Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Fri, 15 Jan 2021 16:32:36 -0500 Subject: [PATCH 09/44] review changes --- .../ActionHandler+ClientParameters.swift | 4 +- .../ActionHandling/MVMCoreActionHandler.m | 12 +++++- .../ClientParameterProtocol.swift | 14 ------ .../ClientParameterRegistry.swift | 43 +++++++------------ MVMCore/MVMCore/Singletons/MVMCoreObject.h | 3 ++ MVMCore/MVMCore/Singletons/MVMCoreObject.m | 2 + 6 files changed, 33 insertions(+), 45 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift index bbd951a..360546d 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift @@ -10,7 +10,7 @@ import Foundation public extension MVMCoreActionHandler { - @objc func setClientParameter(with actionMap: [String: Any]?, completionHandler: @escaping ([String : Any]?) -> ()) { + @objc func setClientParameter(with actionMap: [String: Any]?, completionHandler: @escaping ([String : Any]?) -> ()) throws { guard let clientParameters = actionMap?.optionalDictionaryForKey("clientParameters") else { completionHandler(actionMap) @@ -29,7 +29,7 @@ public extension MVMCoreActionHandler { } } - ClientParameterRegistry.injectParameters(with: clientParameters) { (clientParams) in + try ClientParameterRegistry.injectParameters(with: clientParameters) { (clientParams) in guard let clientParams = clientParams else { stopLoadingOverlay() completionHandler(actionMap) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 90374e5..837cadf 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -449,10 +449,18 @@ NSString * const KeyActionTypeOpen = @"openPage"; - (void)preprocessRequest:(nullable NSDictionary *)actionInformation actionBlock:(nullable void (^)(NSDictionary*))actionBlock { // Check for client params and fetch the parameters if ([actionInformation dict:@"clientParameters"]) { - [self setClientParameterWith:actionInformation - completionHandler:^(NSDictionary * _Nullable actionDict) { + + NSError *error = nil; + + [self setClientParameterWith:actionInformation error:&error completionHandler:^(NSDictionary * _Nullable actionDict) { actionBlock(actionDict); }]; + + if (error) { + //MVMCoreLoggingHandler.logDebugMessage(withDelegate: "JS function reult: \(String(describing: result))") + MVMCoreLog(@"Error clientParamters %@", error); + actionBlock(actionInformation); + } } else { actionBlock(actionInformation); } diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift index a954ac4..e2a8129 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift @@ -13,17 +13,3 @@ public protocol ClientParameterProtocol { static var name: String { get } func fetchClientParameters(for paramModel: ClientParameterModelProtocol, timingOutIn timeout: Double, completionHandler:@escaping ([String: Any]?) -> ()) } - -extension ClientParameterProtocol { - - /// Handle encoding and errors - public func getJSON(with paramModel: ClientParameterModelProtocol?) -> JSONDictionary? { - guard let dataModel = paramModel, - let json = dataModel.toJSON() else { - // JSON parsing failed - MVMCoreLoggingHandler.logDebugMessage(withDelegate: "ClientParameterProtocol JSON parsing failed") - return nil - } - return json - } -} diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift index fe91785..69ea2c4 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift @@ -9,9 +9,9 @@ import Foundation -@objcMembers open class ClientParameterRegistry: NSObject { +@objcMembers public class ClientParameterRegistry: NSObject { + - public static let shared = ClientParameterRegistry() private var mapping: [String: ClientParameterProtocol.Type] = [:] public func register(_ handler: T.Type) { @@ -23,22 +23,16 @@ import Foundation return parameterType.init() } - static func getClientParameterModel(_ clientParameters: [String: Any]) -> ClientParameterModel? { - do { - let data = try JSONSerialization.data(withJSONObject: clientParameters) - return try JSONDecoder().decode(ClientParameterModel.self, from: data) - } catch { - MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Error parsing getClientParameterModel: \(error)") - return nil - } + static func getClientParameterModel(_ clientParameters: [String: Any]) throws -> ClientParameterModel? { + let data = try JSONSerialization.data(withJSONObject: clientParameters) + return try JSONDecoder().decode(ClientParameterModel.self, from: data) } - static func injectParameters(with clientParameters: [String: Any], - completionHandler:@escaping ([String: Any]?) -> ()) { + static func injectParameters(with clientParameters: [String: Any], completionHandler:@escaping ([String: Any]?) -> ()) throws { - let clientParameterRegistry = ClientParameterRegistry.shared + let clientParameterRegistry = MVMCoreObject.sharedInstance()?.clientParameterRegistry - guard let clientParameterModel = ClientParameterRegistry.getClientParameterModel(clientParameters) else { + guard let clientParameterModel = try ClientParameterRegistry.getClientParameterModel(clientParameters) else { completionHandler(nil) return } @@ -48,7 +42,7 @@ import Foundation let parametersWorkQueue = DispatchQueue(label: "com.mva.clientparameter") let group = DispatchGroup() - let defaultErrorString = "Failed to collect." + let defaultErrorString = "failed_to_collect." // Dispatch setup on queue to ensure setup is complete before completion callbacks. parametersWorkQueue.async(group: group, qos: .userInitiated) { @@ -75,25 +69,25 @@ import Foundation parametersList[parameterModel.type] = ["error": defaultErrorString] group.enter() // Dispatch asynchronous injection. - clientParameterRegistry.injectParameter(parameterModel, before: timeout) { (clientParam) in + clientParameterRegistry?.injectParameter(parameterModel, before: timeout) { (clientParam) in // Queue the results for merge. parametersWorkQueue.async { if let clientParam = clientParam { - parametersList[parameterModel.type] = clientParam + parametersList.merge(clientParam) { (_, new) in new } + //parametersList[parameterModel.type] = clientParam } group.leave() // Leaving is only done after setup (barriered). } } } - // Callback when all parameters have been merged. group.notify(queue: parametersWorkQueue, work: completionWorkItem); } } func injectParameter( _ parameterModel: ClientParameterModelProtocol, before timeout: Double, completionHandler:@escaping ([String: Any]?) -> ()) { - guard let parammeterHandler = ClientParameterRegistry.shared.createParametersHandler(parameterModel.type) else { + guard let parammeterHandler = createParametersHandler(parameterModel.type) else { return completionHandler(nil) } parammeterHandler.fetchClientParameters(for: parameterModel, timingOutIn: timeout, completionHandler: completionHandler) @@ -103,13 +97,8 @@ import Foundation public static func registerParameters() { } /// Register Default Core Bridge Objects - public static func register(handler: T.Type, for model: M.Type) { - - do { - try ModelRegistry.register(model) - } catch { - MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Error registering: \(error)") - } - ClientParameterRegistry.shared.register(handler) + public static func register(handler: T.Type, for model: M.Type) throws { + try ModelRegistry.register(model) + MVMCoreObject.sharedInstance()?.clientParameterRegistry?.register(handler) } } diff --git a/MVMCore/MVMCore/Singletons/MVMCoreObject.h b/MVMCore/MVMCore/Singletons/MVMCoreObject.h index 03a8411..023ad63 100644 --- a/MVMCore/MVMCore/Singletons/MVMCoreObject.h +++ b/MVMCore/MVMCore/Singletons/MVMCoreObject.h @@ -18,6 +18,8 @@ #import #import +@class ClientParameterRegistry; + @interface MVMCoreObject : NSObject @property (nullable, strong, nonatomic) MVMCoreSessionObject *session; @@ -26,6 +28,7 @@ @property (nullable, strong, nonatomic) MVMCoreActionHandler *actionHandler; @property (nullable, strong, nonatomic) MVMCoreSessionTimeHandler *sessionHandler; @property (nullable, strong, nonatomic) MVMCoreLoadHandler *loadHandler; +@property (nullable, strong, nonatomic) ClientParameterRegistry *clientParameterRegistry; // The delegates @property (nullable, strong, nonatomic) id globalLoadDelegate; diff --git a/MVMCore/MVMCore/Singletons/MVMCoreObject.m b/MVMCore/MVMCore/Singletons/MVMCoreObject.m index 8ad4cb5..fbb0520 100644 --- a/MVMCore/MVMCore/Singletons/MVMCoreObject.m +++ b/MVMCore/MVMCore/Singletons/MVMCoreObject.m @@ -7,6 +7,7 @@ // #import "MVMCoreObject.h" +#import @implementation MVMCoreObject @@ -27,6 +28,7 @@ self.actionHandler = [[MVMCoreActionHandler alloc] init]; self.loggingDelegate = [[MVMCoreLoggingHandler alloc] init]; self.loadHandler = [[MVMCoreLoadHandler alloc] init]; + self.clientParameterRegistry = [ClientParameterRegistry new]; } @end From 96217a5ad7be39808cac2ab4de8b8bcda01f16d6 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Fri, 15 Jan 2021 16:35:34 -0500 Subject: [PATCH 10/44] ope --- .../ActionType/Client Parameters/ClientParameterRegistry.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift index 69ea2c4..d75bd79 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift @@ -94,7 +94,7 @@ import Foundation } /// Add all registry here. - public static func registerParameters() { } + open static func registerParameters() { } /// Register Default Core Bridge Objects public static func register(handler: T.Type, for model: M.Type) throws { From 2b6bf53cc5c043f83e2b8ab001e98318d91398a6 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Fri, 15 Jan 2021 16:44:36 -0500 Subject: [PATCH 11/44] open --- .../Client Parameters/ClientParameterRegistry.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift index d75bd79..c3775d8 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift @@ -9,16 +9,21 @@ import Foundation -@objcMembers public class ClientParameterRegistry: NSObject { +@objcMembers open class ClientParameterRegistry: NSObject { private var mapping: [String: ClientParameterProtocol.Type] = [:] - public func register(_ handler: T.Type) { + public override init() { + super.init() + registerParameters() + } + + open func register(_ handler: T.Type) { mapping[T.name] = handler } - public func createParametersHandler(_ actionType: String) -> ClientParameterProtocol? { + open func createParametersHandler(_ actionType: String) -> ClientParameterProtocol? { guard let parameterType = mapping[actionType] else { return nil } return parameterType.init() } @@ -94,7 +99,7 @@ import Foundation } /// Add all registry here. - open static func registerParameters() { } + open func registerParameters() { } /// Register Default Core Bridge Objects public static func register(handler: T.Type, for model: M.Type) throws { From 485b16528919125b5a5e949b8b2e4a8dd910f1ff Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Fri, 15 Jan 2021 16:47:41 -0500 Subject: [PATCH 12/44] fix error --- MVMCore/MVMCore/Session/MVMCoreSessionObject.m | 1 - 1 file changed, 1 deletion(-) diff --git a/MVMCore/MVMCore/Session/MVMCoreSessionObject.m b/MVMCore/MVMCore/Session/MVMCoreSessionObject.m index 8650972..7134c59 100644 --- a/MVMCore/MVMCore/Session/MVMCoreSessionObject.m +++ b/MVMCore/MVMCore/Session/MVMCoreSessionObject.m @@ -17,7 +17,6 @@ if (self = [super init]) { self.session = [self createNSURLSession]; [ModelMapping registerObjects]; - [ClientParameterRegistry registerParameters]; } return self; } From 49811999f18a572018c6058988212d10578539fc Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Fri, 15 Jan 2021 17:04:39 -0500 Subject: [PATCH 13/44] fixes --- .../Client Parameters/ClientParameterRegistry.swift | 7 +++---- MVMCore/MVMCore/Singletons/MVMCoreObject.m | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift index c3775d8..a9c3dc2 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift @@ -35,9 +35,8 @@ import Foundation static func injectParameters(with clientParameters: [String: Any], completionHandler:@escaping ([String: Any]?) -> ()) throws { - let clientParameterRegistry = MVMCoreObject.sharedInstance()?.clientParameterRegistry - - guard let clientParameterModel = try ClientParameterRegistry.getClientParameterModel(clientParameters) else { + guard let clientParameterRegistry = MVMCoreObject.sharedInstance()?.clientParameterRegistry, + let clientParameterModel = try ClientParameterRegistry.getClientParameterModel(clientParameters) else { completionHandler(nil) return } @@ -74,7 +73,7 @@ import Foundation parametersList[parameterModel.type] = ["error": defaultErrorString] group.enter() // Dispatch asynchronous injection. - clientParameterRegistry?.injectParameter(parameterModel, before: timeout) { (clientParam) in + clientParameterRegistry.injectParameter(parameterModel, before: timeout) { (clientParam) in // Queue the results for merge. parametersWorkQueue.async { if let clientParam = clientParam { diff --git a/MVMCore/MVMCore/Singletons/MVMCoreObject.m b/MVMCore/MVMCore/Singletons/MVMCoreObject.m index fbb0520..6b60d65 100644 --- a/MVMCore/MVMCore/Singletons/MVMCoreObject.m +++ b/MVMCore/MVMCore/Singletons/MVMCoreObject.m @@ -28,7 +28,7 @@ self.actionHandler = [[MVMCoreActionHandler alloc] init]; self.loggingDelegate = [[MVMCoreLoggingHandler alloc] init]; self.loadHandler = [[MVMCoreLoadHandler alloc] init]; - self.clientParameterRegistry = [ClientParameterRegistry new]; + self.clientParameterRegistry = [[ClientParameterRegistry alloc] init]; } @end From 3344277e357c4f2acfb83263791c954c74919fde Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Fri, 15 Jan 2021 20:59:31 -0500 Subject: [PATCH 14/44] cleanup --- .../Client Parameters/ClientParameterRegistry.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift index a9c3dc2..3119f5a 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift @@ -11,9 +11,9 @@ import Foundation @objcMembers open class ClientParameterRegistry: NSObject { - private var mapping: [String: ClientParameterProtocol.Type] = [:] + public override init() { super.init() registerParameters() @@ -78,7 +78,6 @@ import Foundation parametersWorkQueue.async { if let clientParam = clientParam { parametersList.merge(clientParam) { (_, new) in new } - //parametersList[parameterModel.type] = clientParam } group.leave() // Leaving is only done after setup (barriered). } @@ -100,7 +99,13 @@ import Foundation /// Add all registry here. open func registerParameters() { } - /// Register Default Core Bridge Objects + /// Register Default Core Client Paramter Objects + public func register(handler: T.Type, for model: M.Type) throws { + try ModelRegistry.register(model) + register(handler) + } + + /// Register Default Core Client Paramter Objects public static func register(handler: T.Type, for model: M.Type) throws { try ModelRegistry.register(model) MVMCoreObject.sharedInstance()?.clientParameterRegistry?.register(handler) From 13573eea7f603042c34f0b4a1327f795b31cb5aa Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Fri, 15 Jan 2021 21:59:41 -0500 Subject: [PATCH 15/44] map --- .../ActionHandler+ClientParameters.swift | 31 ++++++++++++------- .../ActionHandling/MVMCoreActionHandler.m | 28 +++-------------- .../ClientParameterProtocol.swift | 2 +- .../ClientParameterRegistry.swift | 8 ++--- 4 files changed, 28 insertions(+), 41 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift index 360546d..2c607b9 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift @@ -10,7 +10,7 @@ import Foundation public extension MVMCoreActionHandler { - @objc func setClientParameter(with actionMap: [String: Any]?, completionHandler: @escaping ([String : Any]?) -> ()) throws { + @objc func setClientParameter(with actionMap: [String: Any]?, completionHandler: @escaping ([String : Any]?) -> ()) { guard let clientParameters = actionMap?.optionalDictionaryForKey("clientParameters") else { completionHandler(actionMap) @@ -29,20 +29,27 @@ public extension MVMCoreActionHandler { } } - try ClientParameterRegistry.injectParameters(with: clientParameters) { (clientParams) in - guard let clientParams = clientParams else { + do { + 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() - completionHandler(actionMap) - return + completionHandler(actionMapM) } - - var extraParams: [String : Any] = actionMap?.optionalDictionaryForKey(KeyExtraParameters) ?? [:] - extraParams.merge(clientParams) { (_, new) in new } - var actionMapM = actionMap - actionMapM?[KeyExtraParameters] = extraParams - + } catch { stopLoadingOverlay() - completionHandler(actionMapM) + completionHandler(actionMap) + MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Error clientParamters: \(error)") } + } } diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 837cadf..9362dd6 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -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 { @@ -293,7 +293,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; [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 { @@ -443,27 +443,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; }]; }; - [self preprocessRequest:actionInformation actionBlock: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 * _Nullable actionDict) { - actionBlock(actionDict); - }]; - - if (error) { - //MVMCoreLoggingHandler.logDebugMessage(withDelegate: "JS function reult: \(String(describing: result))") - MVMCoreLog(@"Error clientParamters %@", error); - actionBlock(actionInformation); - } - } else { - actionBlock(actionInformation); - } + [self setClientParameterWith:actionInformation completionHandler:performAction]; } - (void)restartAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { @@ -582,7 +562,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; [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 *)delegate { diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift index e2a8129..2c689ec 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterProtocol.swift @@ -11,5 +11,5 @@ import Foundation public protocol ClientParameterProtocol { init() 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?) -> ()) } diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift index 3119f5a..a5e527a 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift @@ -73,11 +73,11 @@ import Foundation parametersList[parameterModel.type] = ["error": defaultErrorString] group.enter() // Dispatch asynchronous injection. - clientParameterRegistry.injectParameter(parameterModel, before: timeout) { (clientParam) in + clientParameterRegistry.injectParameter(parameterModel, before: timeout) { (recevedParameter) in // Queue the results for merge. parametersWorkQueue.async { - if let clientParam = clientParam { - parametersList.merge(clientParam) { (_, new) in new } + if let recevedParameter = recevedParameter { + parametersList[parameterModel.type] = recevedParameter } 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 { return completionHandler(nil) } From a5e557ef58d42f52fd7ce3bc698c2cd17a4b3603 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 19 Jan 2021 12:24:33 -0500 Subject: [PATCH 16/44] comments --- .../MVMCore/ActionHandling/ActionHandler+ClientParameters.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift index 2c607b9..5f9cb0a 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift @@ -10,6 +10,7 @@ import Foundation public extension MVMCoreActionHandler { + /// 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 { From cc1a53e21bccbc4f125f781038b358d8a618dfe2 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 19 Jan 2021 12:26:51 -0500 Subject: [PATCH 17/44] typo: receivedParameter --- .../Client Parameters/ClientParameterRegistry.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift index a5e527a..03f1f28 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift @@ -73,11 +73,11 @@ import Foundation parametersList[parameterModel.type] = ["error": defaultErrorString] group.enter() // Dispatch asynchronous injection. - clientParameterRegistry.injectParameter(parameterModel, before: timeout) { (recevedParameter) in + clientParameterRegistry.injectParameter(parameterModel, before: timeout) { (receivedParameter) in // Queue the results for merge. parametersWorkQueue.async { - if let recevedParameter = recevedParameter { - parametersList[parameterModel.type] = recevedParameter + if let receivedParameter = receivedParameter { + parametersList[parameterModel.type] = receivedParameter } group.leave() // Leaving is only done after setup (barriered). } From ef0e5dee1c481932c625369a047cd5d6f7178a33 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 19 Jan 2021 16:25:56 -0500 Subject: [PATCH 18/44] typo --- .../ActionType/Client Parameters/ClientParameterRegistry.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift index 03f1f28..eff2175 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift @@ -90,7 +90,7 @@ import Foundation } func injectParameter( _ parameterModel: ClientParameterModelProtocol, before timeout: Double, completionHandler:@escaping (AnyHashable?) -> ()) { - guard let parammeterHandler = createParametersHandler(parameterModel.type) else { + guard let parameterHandler = createParametersHandler(parameterModel.type) else { return completionHandler(nil) } parammeterHandler.fetchClientParameters(for: parameterModel, timingOutIn: timeout, completionHandler: completionHandler) From 09cf4db857697089f44154bd75a53f49af6c4e95 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 19 Jan 2021 16:30:35 -0500 Subject: [PATCH 19/44] parameterHandler --- .../ActionType/Client Parameters/ClientParameterRegistry.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift index eff2175..273c6a1 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift @@ -93,7 +93,7 @@ import Foundation guard let parameterHandler = createParametersHandler(parameterModel.type) else { return completionHandler(nil) } - parammeterHandler.fetchClientParameters(for: parameterModel, timingOutIn: timeout, completionHandler: completionHandler) + parameterHandler.fetchClientParameters(for: parameterModel, timingOutIn: timeout, completionHandler: completionHandler) } /// Add all registry here. From 0091c419d101c1a2c6f0f53fe0e71137c66e7e17 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 19 Jan 2021 16:42:30 -0500 Subject: [PATCH 20/44] code review --- .../ActionHandling/ActionHandler+ClientParameters.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift index 5f9cb0a..6378cea 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift @@ -10,7 +10,7 @@ import Foundation public extension MVMCoreActionHandler { - /// Iterates throw the clientParameters list. Gets values from the individul handlers and attaches the paramters to extraParameters. + /// Iterates threw 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 clientParameters = actionMap?.optionalDictionaryForKey("clientParameters") else { @@ -38,7 +38,7 @@ public extension MVMCoreActionHandler { return } - var extraParams: [String : Any] = actionMap?.optionalDictionaryForKey(KeyExtraParameters) ?? [:] + var extraParams: [String : Any] = actionMap?.dictionaryForKey(KeyExtraParameters) extraParams.merge(clientParams) { (_, new) in new } var actionMapM = actionMap actionMapM?[KeyExtraParameters] = extraParams From d52b05d0ac1a7806f6417ff9c6c95b926a4cc6d9 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 19 Jan 2021 16:46:39 -0500 Subject: [PATCH 21/44] optionals cleanup --- .../ActionHandler+ClientParameters.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift index 6378cea..dd0471a 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift @@ -13,12 +13,12 @@ public extension MVMCoreActionHandler { /// Iterates threw 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 clientParameters = actionMap?.optionalDictionaryForKey("clientParameters") else { - completionHandler(actionMap) + guard let actionMap = actionMap, let clientParameters = actionMap.optionalDictionaryForKey("clientParameters") else { + completionHandler(nil) return } - let isBackgroudRequest = actionMap?.boolForKey("background") ?? false + let isBackgroudRequest = actionMap.boolForKey("background") if !isBackgroudRequest { MVMCoreLoadingOverlayHandler.sharedLoadingOverlay()?.startLoading() @@ -38,10 +38,10 @@ public extension MVMCoreActionHandler { return } - var extraParams: [String : Any] = actionMap?.dictionaryForKey(KeyExtraParameters) + var extraParams: [String : Any] = actionMap.dictionaryForKey(KeyExtraParameters) extraParams.merge(clientParams) { (_, new) in new } var actionMapM = actionMap - actionMapM?[KeyExtraParameters] = extraParams + actionMapM[KeyExtraParameters] = extraParams stopLoadingOverlay() completionHandler(actionMapM) From 8a9b94bdb0a445ce618af3d3ddaea7928de921a0 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 19 Jan 2021 17:52:16 -0500 Subject: [PATCH 22/44] remove hardcode flag --- .../Utility/HardCodedServerResponse/MFHardCodedServerResponse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index efa33b6..eb9fba9 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 1 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG #if ENABLE_HARD_CODED_RESPONSE From 34c4bd18eeb05515a495385cb4c0425364e0b1e0 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 19 Jan 2021 18:25:35 -0500 Subject: [PATCH 23/44] refactor --- .../ActionHandler+ClientParameters.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift index dd0471a..928c45d 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift @@ -13,12 +13,12 @@ public extension MVMCoreActionHandler { /// Iterates threw 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 actionMap = actionMap, let clientParameters = actionMap.optionalDictionaryForKey("clientParameters") else { - completionHandler(nil) + guard let actionMapWithClientParameters = actionMap, let clientParameters = actionMapWithClientParameters.optionalDictionaryForKey("clientParameters") else { + completionHandler(actionMap) return } - let isBackgroudRequest = actionMap.boolForKey("background") + let isBackgroudRequest = actionMapWithClientParameters.boolForKey("background") if !isBackgroudRequest { MVMCoreLoadingOverlayHandler.sharedLoadingOverlay()?.startLoading() @@ -34,13 +34,13 @@ public extension MVMCoreActionHandler { try ClientParameterRegistry.injectParameters(with: clientParameters) { (clientParams) in guard let clientParams = clientParams else { stopLoadingOverlay() - completionHandler(actionMap) + completionHandler(actionMapWithClientParameters) return } - var extraParams: [String : Any] = actionMap.dictionaryForKey(KeyExtraParameters) + var extraParams: [String : Any] = actionMapWithClientParameters.dictionaryForKey(KeyExtraParameters) extraParams.merge(clientParams) { (_, new) in new } - var actionMapM = actionMap + var actionMapM = actionMapWithClientParameters actionMapM[KeyExtraParameters] = extraParams stopLoadingOverlay() @@ -48,7 +48,7 @@ public extension MVMCoreActionHandler { } } catch { stopLoadingOverlay() - completionHandler(actionMap) + completionHandler(actionMapWithClientParameters) MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Error clientParamters: \(error)") } From f2855f317bc37b4ae4270abe6fcdf25e9b6afe03 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 20 Jan 2021 10:24:00 -0500 Subject: [PATCH 24/44] code review --- .../ActionHandler+ClientParameters.swift | 4 ++-- .../ClientParameterModel.swift | 2 +- .../ClientParameterRegistry.swift | 20 ++++++++++++++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift index 928c45d..85fd4bb 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift @@ -10,7 +10,7 @@ import Foundation public extension MVMCoreActionHandler { - /// Iterates threw the clientParameters list. Gets values from the individual handlers and attaches the parameters to extraParameters. + /// 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 { @@ -31,7 +31,7 @@ public extension MVMCoreActionHandler { } do { - try ClientParameterRegistry.injectParameters(with: clientParameters) { (clientParams) in + try ClientParameterRegistry.getParameters(with: clientParameters) { (clientParams) in guard let clientParams = clientParams else { stopLoadingOverlay() completionHandler(actionMapWithClientParameters) diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterModel.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterModel.swift index 8686d71..37940d7 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterModel.swift @@ -25,7 +25,7 @@ public class ClientParameterModel: Codable { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(timeout, forKey: .timeout) + try container.encodeIfPresent(timeout, forKey: .timeout) try container.encodeModels(list, forKey: .list) } } diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift index 273c6a1..9c4200b 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift @@ -33,7 +33,21 @@ import Foundation return try JSONDecoder().decode(ClientParameterModel.self, from: data) } - static func injectParameters(with clientParameters: [String: Any], completionHandler:@escaping ([String: Any]?) -> ()) throws { + /// Sample clientParameters + ///{ + /// "timeout": 30, + /// "list": [ + /// { + /// "type": "currentLocation", + /// "inputParameters": { + /// "accuracy": 10, + /// "timeThreshold": 600 + /// } + /// } + /// ] + ///} + /// completionHandler can return flat dictinary or a map. It depends on the paramters handler + static func getParameters(with clientParameters: [String: Any], completionHandler:@escaping ([String: Any]?) -> ()) throws { guard let clientParameterRegistry = MVMCoreObject.sharedInstance()?.clientParameterRegistry, let clientParameterModel = try ClientParameterRegistry.getClientParameterModel(clientParameters) else { @@ -73,7 +87,7 @@ import Foundation parametersList[parameterModel.type] = ["error": defaultErrorString] group.enter() // Dispatch asynchronous injection. - clientParameterRegistry.injectParameter(parameterModel, before: timeout) { (receivedParameter) in + clientParameterRegistry.getParameterFromHandler(parameterModel, before: timeout) { (receivedParameter) in // Queue the results for merge. parametersWorkQueue.async { if let receivedParameter = receivedParameter { @@ -89,7 +103,7 @@ import Foundation } } - func injectParameter( _ parameterModel: ClientParameterModelProtocol, before timeout: Double, completionHandler:@escaping (AnyHashable?) -> ()) { + func getParameterFromHandler( _ parameterModel: ClientParameterModelProtocol, before timeout: Double, completionHandler:@escaping (AnyHashable?) -> ()) { guard let parameterHandler = createParametersHandler(parameterModel.type) else { return completionHandler(nil) } From 35962ff9664ceceaf54ba1ce64de5a33256c3091 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 20 Jan 2021 10:52:42 -0500 Subject: [PATCH 25/44] remove static --- .../MVMCore/ActionHandling/ActionHandler+ClientParameters.swift | 2 +- .../ActionType/Client Parameters/ClientParameterRegistry.swift | 2 +- .../Utility/HardCodedServerResponse/MFHardCodedServerResponse.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift index 85fd4bb..9d6deab 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift @@ -31,7 +31,7 @@ public extension MVMCoreActionHandler { } do { - try ClientParameterRegistry.getParameters(with: clientParameters) { (clientParams) in + try ClientParameterRegistry().getParameters(with: clientParameters) { (clientParams) in guard let clientParams = clientParams else { stopLoadingOverlay() completionHandler(actionMapWithClientParameters) diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift index 9c4200b..23f5ca5 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 - static func getParameters(with clientParameters: [String: Any], completionHandler:@escaping ([String: Any]?) -> ()) throws { + func getParameters(with clientParameters: [String: Any], completionHandler:@escaping ([String: Any]?) -> ()) throws { guard let clientParameterRegistry = MVMCoreObject.sharedInstance()?.clientParameterRegistry, let clientParameterModel = try ClientParameterRegistry.getClientParameterModel(clientParameters) else { 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 From 5fda7b15b5222c1b77f14250d5542fa7f376d159 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 20 Jan 2021 10:53:25 -0500 Subject: [PATCH 26/44] remove hardcode --- .../Utility/HardCodedServerResponse/MFHardCodedServerResponse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index efa33b6..eb9fba9 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 1 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG #if ENABLE_HARD_CODED_RESPONSE From dcd2dc4fd8e696c16ce64ca0d939a297bd909366 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 20 Jan 2021 11:52:58 -0500 Subject: [PATCH 27/44] code review --- .../ActionHandling/ActionHandler+ClientParameters.swift | 2 +- .../Client Parameters/ClientParameterRegistry.swift | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift index 9d6deab..a2c3841 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift @@ -31,7 +31,7 @@ public extension MVMCoreActionHandler { } do { - try ClientParameterRegistry().getParameters(with: clientParameters) { (clientParams) in + try MVMCoreObject.sharedInstance()?.clientParameterRegistry?.getParameters(with: clientParameters) { (clientParams) in guard let clientParams = clientParams else { stopLoadingOverlay() completionHandler(actionMapWithClientParameters) diff --git a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift index 23f5ca5..ba698f4 100644 --- a/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift +++ b/MVMCore/MVMCore/Models/ActionType/Client Parameters/ClientParameterRegistry.swift @@ -49,8 +49,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 { - guard let clientParameterRegistry = MVMCoreObject.sharedInstance()?.clientParameterRegistry, - let clientParameterModel = try ClientParameterRegistry.getClientParameterModel(clientParameters) else { + guard let clientParameterModel = try ClientParameterRegistry.getClientParameterModel(clientParameters) else { completionHandler(nil) return } @@ -63,7 +62,8 @@ import Foundation let defaultErrorString = "failed_to_collect." // Dispatch setup on queue to ensure setup is complete before completion callbacks. - parametersWorkQueue.async(group: group, qos: .userInitiated) { + parametersWorkQueue.async(group: group, qos: .userInitiated) { [weak self] in + guard let self = self else { return } // Setup completion handlers. Barriered to ensure one happens after the other. var complete = false let timeoutWorkItem = DispatchWorkItem(qos: .userInitiated) { @@ -87,7 +87,7 @@ import Foundation parametersList[parameterModel.type] = ["error": defaultErrorString] group.enter() // Dispatch asynchronous injection. - clientParameterRegistry.getParameterFromHandler(parameterModel, before: timeout) { (receivedParameter) in + self.getParameterFromHandler(parameterModel, before: timeout) { (receivedParameter) in // Queue the results for merge. parametersWorkQueue.async { if let receivedParameter = receivedParameter { From 8ed40b8a036e3043875666aab8e9f731a9ca6bb7 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Wed, 20 Jan 2021 12:18:11 -0500 Subject: [PATCH 28/44] removed unused code --- MVMCore/MVMCore/Models/Model/ModelRegistry.swift | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift index 59dc0c7..93407d1 100644 --- a/MVMCore/MVMCore/Models/Model/ModelRegistry.swift +++ b/MVMCore/MVMCore/Models/Model/ModelRegistry.swift @@ -66,22 +66,6 @@ public struct ModelRegistry { return AnyCodingKey(category.codingKey) } - - - public static func getModelFor(json: [String: Any], type: T.Type) throws -> ModelProtocol? { - - guard let categoryKey = ModelRegistry.getCategory(for: type)?.codingKey else { - throw ModelRegistry.Error.other(message: "coding key missing") - } - guard let parameterType = json.optionalStringForKey(categoryKey) else { - throw ModelRegistry.Error.other(message: "type missing") - } - - guard let type = ModelRegistry.getType(for: parameterType, with: type) else { - throw ModelRegistry.Error.decoderErrorModelNotMapped() - } - return try type.decode(jsonDict: json) - } } extension KeyedDecodingContainer where Key: CodingKey { From 78749afddc7c26123d3cdee3d77edb889d614a07 Mon Sep 17 00:00:00 2001 From: "Chintakrinda, Arun Kumar (Arun)" Date: Thu, 21 Jan 2021 18:38:19 +0530 Subject: [PATCH 29/44] Added missing key hideUrl --- MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift index 03a1e95..14006a1 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenUrlModel.swift @@ -30,6 +30,7 @@ public var dontShowProgress: Bool? public var headerParameters: JSONValueDictionary? public var enableNativeScroll: Bool? + public var hideUrl: Bool? //-------------------------------------------------- // MARK: - Initialzier From b6e1e84b52a99ad7261063001cd467b902944517 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 21 Jan 2021 10:49:43 -0500 Subject: [PATCH 30/44] CXTDT-149032 --- .../ActionHandling/MVMCoreActionHandler.m | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 9362dd6..5095fc8 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -128,7 +128,12 @@ NSString * const KeyActionTypeOpen = @"openPage"; }]; }; - [self setClientParameterWith:actionInformation completionHandler:performAction]; + // BAU dictionary comparsion breaks if client paramters sets the dictionarr. For now we will set client paramters only when its sent in the action map + if ([actionInformation dict:@"clientParameters"]) { + [self setClientParameterWith:actionInformation completionHandler:performAction]; + } else { + performAction(actionInformation); + } } - (void)shareAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { @@ -293,7 +298,12 @@ NSString * const KeyActionTypeOpen = @"openPage"; [weakSelf prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionMap additionalData:additionalData delegateObject:delegateObject]; }; - [self setClientParameterWith:actionInformation completionHandler:performAction]; + // BAU dictionary comparsion breaks if client paramters sets the dictionarr. For now we will set client paramters only when its sent in the action map + if ([actionInformation dict:@"clientParameters"]) { + [self setClientParameterWith:actionInformation completionHandler:performAction]; + } else { + performAction(actionInformation); + } } - (void)prepareLinkAwayWithURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { @@ -443,7 +453,12 @@ NSString * const KeyActionTypeOpen = @"openPage"; }]; }; - [self setClientParameterWith:actionInformation completionHandler:performAction]; + // BAU dictionary comparsion breaks if client paramters sets the dictionarr. For now we will set client paramters only when its sent in the action map + if ([actionInformation dict:@"clientParameters"]) { + [self setClientParameterWith:actionInformation completionHandler:performAction]; + } else { + performAction(actionInformation); + } } - (void)restartAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { @@ -562,7 +577,12 @@ NSString * const KeyActionTypeOpen = @"openPage"; [weakSelf prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionMap additionalData:additionalData delegate:delegate]; }; - [self setClientParameterWith:actionInformation completionHandler:performAction]; + // BAU dictionary comparsion breaks if client paramters sets the dictionarr. For now we will set client paramters only when its sent in the action map + if ([actionInformation dict:@"clientParameters"]) { + [self setClientParameterWith:actionInformation completionHandler:performAction]; + } else { + performAction(actionInformation); + } } - (void)prepareLinkAwayWithURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { From 93a590fedf059c1a256752ac014ca61b3a9960fb Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 21 Jan 2021 11:00:37 -0500 Subject: [PATCH 31/44] KeyClientParameters --- .../ActionHandling/ActionHandler+ClientParameters.swift | 2 +- MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m | 8 ++++---- MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h | 2 ++ MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m | 2 ++ 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift index a2c3841..abeec70 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionHandler+ClientParameters.swift @@ -13,7 +13,7 @@ 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 { + guard let actionMapWithClientParameters = actionMap, let clientParameters = actionMapWithClientParameters.optionalDictionaryForKey(KeyClientParameters) else { completionHandler(actionMap) return } diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 5095fc8..125e1d5 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -129,7 +129,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; }; // BAU dictionary comparsion breaks if client paramters sets the dictionarr. For now we will set client paramters only when its sent in the action map - if ([actionInformation dict:@"clientParameters"]) { + if ([actionInformation dict:KeyClientParameters]) { [self setClientParameterWith:actionInformation completionHandler:performAction]; } else { performAction(actionInformation); @@ -299,7 +299,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; }; // BAU dictionary comparsion breaks if client paramters sets the dictionarr. For now we will set client paramters only when its sent in the action map - if ([actionInformation dict:@"clientParameters"]) { + if ([actionInformation dict:KeyClientParameters]) { [self setClientParameterWith:actionInformation completionHandler:performAction]; } else { performAction(actionInformation); @@ -454,7 +454,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; }; // BAU dictionary comparsion breaks if client paramters sets the dictionarr. For now we will set client paramters only when its sent in the action map - if ([actionInformation dict:@"clientParameters"]) { + if ([actionInformation dict:KeyClientParameters]) { [self setClientParameterWith:actionInformation completionHandler:performAction]; } else { performAction(actionInformation); @@ -578,7 +578,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; }; // BAU dictionary comparsion breaks if client paramters sets the dictionarr. For now we will set client paramters only when its sent in the action map - if ([actionInformation dict:@"clientParameters"]) { + if ([actionInformation dict:KeyClientParameters]) { [self setClientParameterWith:actionInformation completionHandler:performAction]; } else { performAction(actionInformation); 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 From 5d92df53472b5edddf73ea402d96e19340eefcaf Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 21 Jan 2021 11:13:17 -0500 Subject: [PATCH 32/44] typo --- .../ActionHandling/MVMCoreActionHandler.m | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 125e1d5..d069404 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -128,7 +128,11 @@ NSString * const KeyActionTypeOpen = @"openPage"; }]; }; - // BAU dictionary comparsion breaks if client paramters sets the dictionarr. For now we will set client paramters only when its sent in the action map + /* + 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 { @@ -298,7 +302,11 @@ NSString * const KeyActionTypeOpen = @"openPage"; [weakSelf prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionMap additionalData:additionalData delegateObject:delegateObject]; }; - // BAU dictionary comparsion breaks if client paramters sets the dictionarr. For now we will set client paramters only when its sent in the action map + /* + 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 { @@ -453,7 +461,11 @@ NSString * const KeyActionTypeOpen = @"openPage"; }]; }; - // BAU dictionary comparsion breaks if client paramters sets the dictionarr. For now we will set client paramters only when its sent in the action map + /* + 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 { @@ -577,7 +589,11 @@ NSString * const KeyActionTypeOpen = @"openPage"; [weakSelf prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionMap additionalData:additionalData delegate:delegate]; }; - // BAU dictionary comparsion breaks if client paramters sets the dictionarr. For now we will set client paramters only when its sent in the action map + /* + 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 { From 45b84ae2e09eb1e015d5745d0bdae8aca70045cb Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 21 Jan 2021 13:00:29 -0500 Subject: [PATCH 33/44] 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 From 4e1e563284642f7345eadebe62bbbd5fe7a9fa16 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 21 Jan 2021 13:01:40 -0500 Subject: [PATCH 34/44] remove hardcode --- .../Utility/HardCodedServerResponse/MFHardCodedServerResponse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h b/MVMCore/MVMCore/Utility/HardCodedServerResponse/MFHardCodedServerResponse.h index efa33b6..eb9fba9 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 1 && DEBUG +#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG #if ENABLE_HARD_CODED_RESPONSE From b00e9c48950ef48b816a5dc99e7d8ae27a5da8ee Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 21 Jan 2021 13:27:25 -0500 Subject: [PATCH 35/44] code review --- MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h | 2 ++ MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) 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 3b2d704..a717595 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -566,7 +566,6 @@ NSString * const KeyActionTypeOpen = @"openPage"; [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]; @@ -611,8 +610,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; if (error) { stopLoadingOverlay(); completionHandler(actionInformation); - [MVMCoreLoggingHandler logDebugMessageWithDelegate:@"Error clientparameters"]; - [MVMCoreLoggingHandler logDebugMessageWithDelegate:error.debugDescription]; + [MVMCoreLoggingHandler addErrorToLog:error]; } } From aa3390e501aa5074e98590037df34b865b27c8e3 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 21 Jan 2021 13:30:56 -0500 Subject: [PATCH 36/44] typo --- MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index a717595..d955860 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -601,7 +601,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; stopLoadingOverlay(); completionHandler(actionWithClientParameters); } else { - [MVMCoreLoggingHandler logDebugMessageWithDelegate:@"No client paramnters"]; + [MVMCoreLoggingHandler logDebugMessageWithDelegate:@"No client parameters"]; stopLoadingOverlay(); completionHandler(actionInformation); } From c3fb8aee96023e72d2359f99666df60d2516e0de Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 21 Jan 2021 13:38:56 -0500 Subject: [PATCH 37/44] MVMCoreErrorObject --- MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index d955860..20e0145 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -610,7 +610,8 @@ NSString * const KeyActionTypeOpen = @"openPage"; if (error) { stopLoadingOverlay(); completionHandler(actionInformation); - [MVMCoreLoggingHandler addErrorToLog:error]; + MVMCoreErrorObject* errorObject = [MVMCoreErrorObject createErrorObjectForNSError:error location:@"MVMCoreActionHandler"]; + [MVMCoreLoggingHandler addErrorToLog:errorObject]; } } From b9463930f8d8dec22dcb3825077799c7487318c0 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 21 Jan 2021 13:45:24 -0500 Subject: [PATCH 38/44] code review --- MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 20e0145..fa98ee6 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -610,8 +610,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; if (error) { stopLoadingOverlay(); completionHandler(actionInformation); - MVMCoreErrorObject* errorObject = [MVMCoreErrorObject createErrorObjectForNSError:error location:@"MVMCoreActionHandler"]; - [MVMCoreLoggingHandler addErrorToLog:errorObject]; + [MVMCoreLoggingHandler addErrorToLog:[MVMCoreErrorObject createErrorObjectForNSError:error location:@"MVMCoreActionHandler->setClientParameter"]]; } } From 9c0e4c89d3ed0e3e7b2d770f8b48310b17333028 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 22 Jan 2021 17:09:01 -0500 Subject: [PATCH 39/44] actions action and minor cleanup --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 12 + ...CoreActionDelegateProtocol+Extension.swift | 16 + .../MVMCoreActionHandler+Extension.swift | 39 ++ .../ActionHandling/MVMCoreActionHandler.h | 65 +--- .../ActionHandling/MVMCoreActionHandler.m | 342 +++--------------- .../ActionType/ActionActionsModel.swift | 67 ++++ 6 files changed, 201 insertions(+), 340 deletions(-) create mode 100644 MVMCore/MVMCore/ActionHandling/MVMCoreActionDelegateProtocol+Extension.swift create mode 100644 MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler+Extension.swift create mode 100644 MVMCore/MVMCore/Models/ActionType/ActionActionsModel.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index fc17f77..e8ce53e 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -135,6 +135,9 @@ AFFCFA671FCCC0D700FD0730 /* MVMCoreLoadingOverlayHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = AFFCFA631FCCC0D600FD0730 /* MVMCoreLoadingOverlayHandler.m */; }; AFFCFA681FCCC0D700FD0730 /* MVMCoreLoadingViewControllerProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = AFFCFA641FCCC0D600FD0730 /* MVMCoreLoadingViewControllerProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; BB780ADF250F8C890030BD2F /* ActionNoopModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB780ADE250F8C890030BD2F /* ActionNoopModel.swift */; }; + D27073B725BB45C4001C7246 /* ActionActionsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D27073B625BB45C4001C7246 /* ActionActionsModel.swift */; }; + D27073CD25BB4CEF001C7246 /* MVMCoreActionHandler+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D27073CC25BB4CEF001C7246 /* MVMCoreActionHandler+Extension.swift */; }; + D27073D125BB844B001C7246 /* MVMCoreActionDelegateProtocol+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D27073D025BB844B001C7246 /* MVMCoreActionDelegateProtocol+Extension.swift */; }; D282AAB62240085300C46919 /* MVMCoreGetterUtility+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AAB52240085300C46919 /* MVMCoreGetterUtility+Extension.swift */; }; D282AAB82240342D00C46919 /* NSNumber+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D282AAB72240342D00C46919 /* NSNumber+Extension.swift */; }; D2DEDCB723C63F3B00C44CC4 /* Clamping.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2DEDCB623C63F3B00C44CC4 /* Clamping.swift */; }; @@ -266,6 +269,9 @@ AFFCFA631FCCC0D600FD0730 /* MVMCoreLoadingOverlayHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreLoadingOverlayHandler.m; sourceTree = ""; }; AFFCFA641FCCC0D600FD0730 /* MVMCoreLoadingViewControllerProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreLoadingViewControllerProtocol.h; sourceTree = ""; }; BB780ADE250F8C890030BD2F /* ActionNoopModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionNoopModel.swift; sourceTree = ""; }; + D27073B625BB45C4001C7246 /* ActionActionsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionActionsModel.swift; sourceTree = ""; }; + D27073CC25BB4CEF001C7246 /* MVMCoreActionHandler+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreActionHandler+Extension.swift"; sourceTree = ""; }; + D27073D025BB844B001C7246 /* MVMCoreActionDelegateProtocol+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreActionDelegateProtocol+Extension.swift"; sourceTree = ""; }; D282AAB52240085300C46919 /* MVMCoreGetterUtility+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreGetterUtility+Extension.swift"; sourceTree = ""; }; D282AAB72240342D00C46919 /* NSNumber+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSNumber+Extension.swift"; sourceTree = ""; }; D2DEDCB623C63F3B00C44CC4 /* Clamping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Clamping.swift; sourceTree = ""; }; @@ -416,6 +422,7 @@ 94C014D424211AF0005811A9 /* ActionCancelModel.swift */, 94C014D824212360005811A9 /* ActionSettingModel.swift */, BB780ADE250F8C890030BD2F /* ActionNoopModel.swift */, + D27073B625BB45C4001C7246 /* ActionActionsModel.swift */, ); path = ActionType; sourceTree = ""; @@ -558,8 +565,10 @@ isa = PBXGroup; children = ( AFBB96B51FBA3CEC0008D868 /* MVMCoreActionDelegateProtocol.h */, + D27073D025BB844B001C7246 /* MVMCoreActionDelegateProtocol+Extension.swift */, AFBB96B61FBA3CEC0008D868 /* MVMCoreActionHandler.h */, AFBB96B71FBA3CEC0008D868 /* MVMCoreActionHandler.m */, + D27073CC25BB4CEF001C7246 /* MVMCoreActionHandler+Extension.swift */, ); path = ActionHandling; sourceTree = ""; @@ -813,6 +822,7 @@ D2DEDCB923C6400600C44CC4 /* UnitInterval.swift in Sources */, 94C014D3242119E6005811A9 /* ActionPreviousSubmitModel.swift in Sources */, 8876D5E91FB50AB000EB2E3D /* NSArray+MFConvenience.m in Sources */, + D27073B725BB45C4001C7246 /* ActionActionsModel.swift in Sources */, 946EE1B2237B5F260036751F /* JSONValue.swift in Sources */, AFBB96971FBA3A9A0008D868 /* MVMCorePresentViewControllerOperation.m in Sources */, AF43A5781FBA5B7C008E9347 /* MVMCoreJSONConstants.m in Sources */, @@ -826,6 +836,7 @@ AF43A57C1FBA5E6A008E9347 /* MVMCoreHardcodedStringsConstants.m in Sources */, 0AFF597A23FC6E60005C24E8 /* ActionShareModel.swift in Sources */, AFEEE81F1FCDF3CA00B5EDD0 /* MVMCoreLoggingHandler.m in Sources */, + D27073CD25BB4CEF001C7246 /* MVMCoreActionHandler+Extension.swift in Sources */, 01F2A05223A8325100D954D8 /* ModelMapping.swift in Sources */, 8876D5F51FB50AB000EB2E3D /* UILabel+MFCustom.m in Sources */, AFBB96B31FBA3B590008D868 /* MVMCoreGetterUtility.m in Sources */, @@ -839,6 +850,7 @@ AF43A70A1FC4F415008E9347 /* MVMCoreCache.m in Sources */, AF43A6FF1FBE3252008E9347 /* Reachability.m in Sources */, 01C851D123CF97FE0021F976 /* ActionBackModel.swift in Sources */, + D27073D125BB844B001C7246 /* MVMCoreActionDelegateProtocol+Extension.swift in Sources */, AFBB96921FBA3A9A0008D868 /* MVMCoreNavigationOperation.m in Sources */, AFBB96611FBA3A570008D868 /* MVMCoreLoadObject.m in Sources */, 946EE1B4237B619D0036751F /* Encoder.swift in Sources */, diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionDelegateProtocol+Extension.swift b/MVMCore/MVMCore/ActionHandling/MVMCoreActionDelegateProtocol+Extension.swift new file mode 100644 index 0000000..5a53a0b --- /dev/null +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionDelegateProtocol+Extension.swift @@ -0,0 +1,16 @@ +// +// MVMCoreActionDelegateProtocolExtension.swift +// MVMCore +// +// Created by Scott Pfeil on 1/22/21. +// Copyright © 2021 myverizon. All rights reserved. +// + +import Foundation + +public extension MVMCoreActionDelegateProtocol { + // Handles any action errors. + func handleAction(error: MVMCoreErrorObject, action: ActionModelProtocol, additionalData: [AnyHashable: Any]?) { + MVMCoreActionHandler.shared()?.defaultHandleActionError(error, additionalData: additionalData) + } +} diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler+Extension.swift b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler+Extension.swift new file mode 100644 index 0000000..1df7687 --- /dev/null +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler+Extension.swift @@ -0,0 +1,39 @@ +// +// MVMCoreActionHandler+Extension.swift +// MVMCore +// +// Created by Scott Pfeil on 1/22/21. +// Copyright © 2021 myverizon. All rights reserved. +// + +import Foundation + +public extension MVMCoreActionHandler { + + /// Converts the action to json for old action handler to handle. + func convertActionToJSON(_ model: ActionModelProtocol, delegateObject: DelegateObject?) -> [AnyHashable: Any]? { + do { + let data = try model.encode() + guard let json = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [AnyHashable: Any] else { + throw ModelRegistry.Error.decoderError + } + return json + } catch { + let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: "")! + delegateObject?.actionDelegate?.handleAction(error: errorObject, action: model, additionalData: model.extraParameters) ?? MVMCoreActionHandler.shared()?.defaultHandleActionError(errorObject, additionalData: model.extraParameters) + return nil + } + } + + /// Start action on current thread. + func syncHandleAction(with model: ActionModelProtocol, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) { + guard let json = convertActionToJSON(model, delegateObject: delegateObject) else { return } + synchronouslyHandleAction(model.actionType, actionInformation: json, additionalData: additionalData, delegateObject: delegateObject) + } + + /// Start action on dispatched background thread. + func asyncHandleAction(with model: ActionModelProtocol, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) { + guard let json = convertActionToJSON(model, delegateObject: delegateObject) else { return } + handleAction(model.actionType, actionInformation: json, additionalData: additionalData, delegateObject: delegateObject) + } +} diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h index c677e53..26103f4 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h @@ -25,9 +25,12 @@ extern NSString * _Nonnull const KeyActionTypeOpen; // Convenience function for handling actions. This will pull action and pageInfo out of the dictionary and call handleAction: actionInformation: with those values - (void)handleActionWithDictionary:(nullable NSDictionary *)dictionary additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; -// Handles actions. Used by server driven user actions.. +// Asynchronously handles action (dispatches and calls below function). Used by server driven user actions.. - (void)handleAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; +// Synchronously handles action. Used by server driven user actions.. +- (void)synchronouslyHandleAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; + #pragma mark - Actions // by default, returns the original RequestParameter that passed in. Can be overriden for some generic updates to the RequestParameter before handle open page action gets called. - (void)updateRequestParametersBeforeHandleOpenPageAction:(nonnull MVMCoreRequestParameters *)requestParameters callBack:(void (^_Nonnull)(MVMCoreRequestParameters * _Nonnull requestParameters))callback; @@ -59,6 +62,9 @@ extern NSString * _Nonnull const KeyActionTypeOpen; // Goes to settings app - (void)settingsAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; +/// Performs multiple actions +- (void)actions:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; + // Subclass this to handle other custom actions. Return YES if handled, and NO if not. - (BOOL)handleOtherActions:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; @@ -101,61 +107,4 @@ extern NSString * _Nonnull const KeyActionTypeOpen; // Convenience function for handling actions. This will pull action and pageInfo out of the dictionary and call handleAction: actionInformation: with those values - (void)handleActionWithDictionary:(nullable NSDictionary *)dictionary additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; -// Handles actions. Used by server driven user actions.. -- (void)handleAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; - -// Logs the action. Currently is not action information driven... depends on delegate. -- (void)logAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; - -// Tries to open a page -- (void)openPageAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; - -// restarts the app -- (void)restartAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; - -// Goes back -- (void)backAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; - -// Makes a phone call -- (void)callAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; - -// Makes the previous request, needs the delegate for this -- (void)previousSubmitAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; - -// Redirects to another experience -- (void)redirectAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; - -// Cancels (like in a popup) -- (void)cancelAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; - -// Goes to settings app -- (void)settingsAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; - -// Subclass this to handle other custom actions. Return YES if handled, and NO if not. -- (BOOL)handleOtherActions:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; - -// Last chance to handle unknown actions before throwing an error -- (void)unknownAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; - -// Handles action errors. -- (void)handleActionError:(nullable MVMCoreErrorObject *)error actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; - -// Links away to app or browser -- (void)linkAwayAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; - -// Can subclass to add to urls if needed at global level (delegate is also called) -- (void)prepareLinkAwayWithURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; - -// Opens the url -- (void)openURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; - -// opens the url in a webview. -- (void)openURLInWebView:(nullable NSURL *)url actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; - -// Sends the request to the load handler. -+ (void)defaultHandleOpenPageForRequestParameters:(nonnull MVMCoreRequestParameters *)requestParameters additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject*)delegate __deprecated; - -// 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; - @end diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index ee539d0..4c72157 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -44,50 +44,52 @@ NSString * const KeyActionTypeOpen = @"openPage"; } - (void)handleAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - - // Logs the action. - [self logAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; - - if ([actionType isEqualToString:KeyActionTypeOpen]) { - [self openPageAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; - - } else if ([actionType isEqualToString:KeyActionTypeLinkAway]) { - [self linkAwayAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; - - } else if ([actionType isEqualToString:KeyActionTypeRestart]) { - [self restartAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; - - } else if ([actionType isEqualToString:KeyActionTypeBack]) { - [self backAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; - - } else if ([actionType isEqualToString:KeyActionTypeCall]) { - [self callAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; - - } else if ([actionType isEqualToString:KeyActionTypeShare]) { - [self shareAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; - - } else if ([actionType isEqualToString:KeyActionTypePreviousSubmit]) { - [self previousSubmitAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; - - } else if ([actionType isEqualToString:KeyActionTypeRedirect]) { - [self redirectAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; - - } else if ([actionType isEqualToString:KeyActionTypeCancel]) { - [self cancelAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; - - } else if ([actionType isEqualToString:KeyActionTypeSettings]) { - [self settingsAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; - - } else if ([actionType isEqualToString:KeyActionTypeNoop]){ - } else if (![self handleOtherActions:actionType actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]) { - // not a known action type. - [self unknownAction:actionType actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]; - } + [self synchronouslyHandleAction:actionType actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]; }); } +- (void)synchronouslyHandleAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { + // Logs the action. + [self logAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; + + if ([actionType isEqualToString:KeyActionTypeOpen]) { + [self openPageAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; + + } else if ([actionType isEqualToString:KeyActionTypeLinkAway]) { + [self linkAwayAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; + + } else if ([actionType isEqualToString:KeyActionTypeRestart]) { + [self restartAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; + + } else if ([actionType isEqualToString:KeyActionTypeBack]) { + [self backAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; + + } else if ([actionType isEqualToString:KeyActionTypeCall]) { + [self callAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; + + } else if ([actionType isEqualToString:KeyActionTypeShare]) { + [self shareAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; + + } else if ([actionType isEqualToString:KeyActionTypePreviousSubmit]) { + [self previousSubmitAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; + + } else if ([actionType isEqualToString:KeyActionTypeRedirect]) { + [self redirectAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; + + } else if ([actionType isEqualToString:KeyActionTypeCancel]) { + [self cancelAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; + + } else if ([actionType isEqualToString:KeyActionTypeSettings]) { + [self settingsAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; + + } else if ([actionType isEqualToString:KeyActionTypeNoop]){ + } else if (![self handleOtherActions:actionType actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]) { + // not a known action type. + [self unknownAction:actionType actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]; + } +} + #pragma mark - Actions - (void)updateRequestParametersBeforeHandleOpenPageAction:(nonnull MVMCoreRequestParameters *)requestParameters callBack:(void (^_Nonnull)(MVMCoreRequestParameters * _Nonnull requestParameters))callback { @@ -241,6 +243,19 @@ NSString * const KeyActionTypeOpen = @"openPage"; [MVMCoreActionUtility linkAway:UIApplicationOpenSettingsURLString appURLString:nil]; } +- (void)actions:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { + NSArray *actions = [actionInformation array:@"actions"]; + BOOL concurrent = [actionInformation boolForKey:@"concurrent"]; + for (NSDictionary *action in actions) { + NSString *actionType = [action string:KeyActionType]; + if (concurrent) { + [self handleAction:actionType actionInformation:action additionalData:additionalData delegateObject:delegateObject]; + } else { + [self synchronouslyHandleAction:actionType actionInformation:action additionalData:additionalData delegateObject:delegateObject]; + } + } +} + - (BOOL)handleOtherActions:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { return NO; } @@ -363,248 +378,11 @@ NSString * const KeyActionTypeOpen = @"openPage"; - (void)handleActionWithDictionary:(nullable NSDictionary *)dictionary additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - NSString *action = [dictionary stringForKey:KeyActionType]; - [self handleAction:action actionInformation:dictionary additionalData:additionalData delegate:delegate]; -} - -- (void)handleAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - - // Logs the action. - [self logAction:actionInformation additionalData:additionalData delegate:delegate]; - - if ([actionType isEqualToString:KeyActionTypeOpen]) { - [self openPageAction:actionInformation additionalData:additionalData delegate:delegate]; - } else if ([actionType isEqualToString:KeyActionTypeLinkAway]) { - [self linkAwayAction:actionInformation additionalData:additionalData delegate:delegate]; - } else if ([actionType isEqualToString:KeyActionTypeRestart]) { - [self restartAction:actionInformation additionalData:additionalData delegate:delegate]; - } else if ([actionType isEqualToString:KeyActionTypeBack]) { - [self backAction:actionInformation additionalData:additionalData delegate:delegate]; - } else if ([actionType isEqualToString:KeyActionTypeCall]) { - [self callAction:actionInformation additionalData:additionalData delegate:delegate]; - } else if ([actionType isEqualToString:KeyActionTypePreviousSubmit]) { - [self previousSubmitAction:actionInformation additionalData:additionalData delegate:delegate]; - } else if ([actionType isEqualToString:KeyActionTypeRedirect]) { - [self redirectAction:actionInformation additionalData:additionalData delegate:delegate]; - } else if ([actionType isEqualToString:KeyActionTypeCancel]) { - [self cancelAction:actionInformation additionalData:additionalData delegate:delegate]; - } else if ([actionType isEqualToString:KeyActionTypeSettings]) { - [self settingsAction:actionInformation additionalData:additionalData delegate:delegate]; - } else if (![self handleOtherActions:actionType actionInformation:actionInformation additionalData:additionalData delegate:delegate]) { - // not a known action type. - [self unknownAction:actionType actionInformation:actionInformation additionalData:additionalData delegate:delegate]; - } - }); -} - -- (void)logAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - if ([delegate respondsToSelector:@selector(logActionWithActionInformation:additionalData:)]) { - [delegate logActionWithActionInformation:actionInformation additionalData:additionalData]; - } else { - [MVMCoreActionHandler defaultLogAction:actionInformation additionalData:additionalData delegate:delegate]; - } -} - -- (void)openPageAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - - // Loads the given page type. - NSString *pageType = [actionInformation stringForKey:KeyPageType]; - if (pageType.length > 0) { - MVMCoreRequestParameters *requestParameters = [[MVMCoreRequestParameters alloc] initWithActionMap:actionInformation]; - - [self updateRequestParametersBeforeHandleOpenPageAction:requestParameters callBack:^(MVMCoreRequestParameters * _Nonnull requestParameters) { - if ([delegate respondsToSelector:@selector(handleOpenPageForRequestParameters:actionInformation:additionalData:)]) { - [delegate handleOpenPageForRequestParameters:requestParameters actionInformation:actionInformation additionalData:additionalData]; - } else { - [MVMCoreActionHandler defaultHandleOpenPageForRequestParameters:requestParameters additionalData:additionalData delegate:delegate]; - } - }]; - } else { - - // No page type to load, show error. - MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeNoPageType domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@_%@",NSStringFromClass([delegate class]),KeyActionTypeOpen]]; - [self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegate:delegate]; - } -} - -- (void)restartAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - - // Invalidates the session before restarting. - [[MVMCoreSessionTimeHandler sharedSessionHandler] invalidateSession:^(MVMCoreErrorObject * _Nullable error) { - - // Restarts the app (forcing any passed in page types). - if (error.code != NSURLErrorCancelled) { - - if (error) { - - // Error invalidating. - [self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegate:delegate]; - } else { - - // Restart the application with the page type. - NSString *pageType = [actionInformation string:KeyPageType]; - NSDictionary *parameters = [actionInformation dict:KeyExtraParameters]; - [[MVMCoreSessionObject sharedGlobal] restartSessionWithPageType:pageType parameters:parameters clearAllVariables:YES]; - } - } - }]; -} - -- (void)backAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - // Go back. - if ([delegate respondsToSelector:@selector(handleBackAction:additionalData:)]) { - [delegate handleBackAction:actionInformation additionalData:additionalData]; - } else { - [[MVMCoreNavigationHandler sharedNavigationHandler] removeCurrentViewController]; - } -} - -- (void)callAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - // Call - NSString *callNumber = [actionInformation stringForKey:KeyCallNumber]; - [MVMCoreActionUtility linkAway:[@"tel://" stringByAppendingString:callNumber] appURLString:nil]; -} - -- (void)previousSubmitAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - // Perform the previous submission. - __weak typeof(self) weakSelf = self; - if ([delegate respondsToSelector:@selector(prepareRequestForPreviousSubmission:additionalData:submit:)]) { - [delegate prepareRequestForPreviousSubmission:actionInformation additionalData:additionalData submit:^(MVMCoreRequestParameters * _Nonnull requestParameters, NSDictionary * _Nullable dataForPage) { - - [weakSelf updateRequestParametersBeforeHandleOpenPageAction:requestParameters callBack:^(MVMCoreRequestParameters * _Nonnull requestParameters) { - // Give the delegate a chance to alter the request parameters - if ([delegate respondsToSelector:@selector(handleOpenPageForRequestParameters:actionInformation:additionalData:)]) { - [delegate handleOpenPageForRequestParameters:requestParameters actionInformation:actionInformation additionalData:dataForPage]; - } else { - [MVMCoreActionHandler defaultHandleOpenPageForRequestParameters:requestParameters additionalData:additionalData delegate:delegate]; - } - }]; - }]; - } -} - -- (void)redirectAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - // Have delegate redirect. - [[MVMCoreSessionObject sharedGlobal] redirectWithInfo:actionInformation]; -} - -- (void)cancelAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - if ([delegate respondsToSelector:@selector(handleCancel:additionalData:)]) { - [delegate handleCancel:actionInformation additionalData:additionalData]; - } -} - -- (void)settingsAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - // Opens the settings. - [MVMCoreActionUtility linkAway:UIApplicationOpenSettingsURLString appURLString:nil]; -} - -- (BOOL)handleOtherActions:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - return NO; -} - -- (void)unknownAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - if ([delegate respondsToSelector:@selector(handleUnknownActionType:actionInformation:additionalData:)]) { - [delegate handleUnknownActionType:actionType actionInformation:actionInformation additionalData:additionalData]; - } else { - [MVMCoreActionHandler defaultHandleUnknownActionType:actionType actionInformation:actionInformation additionalData:additionalData delegate:delegate]; - } -} - -- (void)handleActionError:(nullable MVMCoreErrorObject *)error actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - if (error) { - if ([delegate respondsToSelector:@selector(handleActionError:additionalData:)]) { - [delegate handleActionError:error additionalData:additionalData]; - } else { - [self defaultHandleActionError:error additionalData:additionalData]; - } - } -} - -- (void)linkAwayAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - - // Gets the app url - NSURL *appURL = nil; - NSString *appURLString = [actionInformation string:KeyLinkAwayAppURL]; - if (appURLString.length > 0) { - appURL = [NSURL URLWithString:appURLString]; - } - - // Gets the browser url - NSURL *otherURL = nil; - NSString *otherURLString = [actionInformation string:KeyLinkAwayURL]; - if (otherURLString.length > 0) { - otherURL = [NSURL URLWithString:otherURLString]; - } - - // Provide the URL and App URL to be modified if needed by a subclass or delegate. - [self prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionInformation additionalData:additionalData delegate:delegate]; -} - -- (void)prepareLinkAwayWithURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - - void(^openURL)(NSURL *, NSURL *, NSDictionary *, NSDictionary *) = ^(NSURL *appURL, NSURL *URL, NSDictionary *actionInformation, NSDictionary *additionalData) { - [self openURL:url appURL:appURL actionInformation:actionInformation additionalData:additionalData delegate:delegate]; - }; - - // Allow delegate to modify before opening the url. - if ([delegate respondsToSelector:@selector(shouldLinkAwayWithURL:appURL:actionInformation:additionalData:linkAwayBlock:)]) { - [delegate shouldLinkAwayWithURL:url appURL:appURL actionInformation:actionInformation additionalData:additionalData linkAwayBlock:openURL]; - } else { - openURL(appURL,url,actionInformation,additionalData); - } -} - -- (void)openURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - - [MVMCoreDispatchUtility performBlockOnMainThread:^{ - - // First try to open the application. - if (appURL && [[UIApplication sharedApplication] canOpenURL:appURL]) { - [[UIApplication sharedApplication] openURL:appURL options:@{} completionHandler:NULL]; - } else if (url && [[UIApplication sharedApplication] canOpenURL:url]) { - - // Check if we should load in webview - BOOL openInWebview = [actionInformation boolForKey:@"openInWebview"]; - if (openInWebview) { - [self openURLInWebView:url actionInformation:actionInformation additionalData:additionalData delegate:delegate]; - } else { - [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:NULL]; - } - } else { - [MVMCoreDispatchUtility performBlockInBackground:^{ - // Cannot linkaway, show error. - MVMCoreErrorObject *error = error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeLinkawayFailed domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@_%@",NSStringFromClass([delegate class]),KeyActionTypeLinkAway]]; - [self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegate:delegate]; - }]; - } - }]; -} - -- (void)openURLInWebView:(nullable NSURL *)url actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - - // Presents standard webview. - SFSafariViewController *safariViewController = [[SFSafariViewController alloc] initWithURL:url]; - //safariViewController.delegate = self; - safariViewController.preferredBarTintColor = [UIColor whiteColor]; - safariViewController.preferredControlTintColor = [UIColor blackColor]; - [[MVMCoreNavigationHandler sharedNavigationHandler] presentViewController:safariViewController animated:YES]; -} - -+ (void)defaultLogAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate{ - // Currently no default log action but this will eventually be server driven. -} - -+ (void)defaultHandleOpenPageForRequestParameters:(nonnull MVMCoreRequestParameters *)requestParameters additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject*)delegate { - [[MVMCoreLoadHandler sharedGlobal] loadRequest:requestParameters dataForPage:additionalData delegate:delegate]; -} - -+ (void)defaultHandleUnknownActionType:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate { - - MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeUnknownActionType domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@Requests_%@",NSStringFromClass([delegate class]),actionType]]; - [[self sharedActionHandler] defaultHandleActionError:error additionalData:additionalData]; + DelegateObject *delegateObject = [[DelegateObject alloc] init]; + delegateObject.actionDelegate = delegate; + delegateObject.presentationDelegate = delegate; + delegateObject.loadDelegate = delegate; + [self handleActionWithDictionary:dictionary additionalData:additionalData delegateObject:delegateObject]; } @end diff --git a/MVMCore/MVMCore/Models/ActionType/ActionActionsModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionActionsModel.swift new file mode 100644 index 0000000..0638f3e --- /dev/null +++ b/MVMCore/MVMCore/Models/ActionType/ActionActionsModel.swift @@ -0,0 +1,67 @@ +// +// ActionActionsModel.swift +// MVMCore +// +// Created by Scott Pfeil on 1/22/21. +// Copyright © 2021 myverizon. All rights reserved. +// + +import Foundation + +@objcMembers open class ActionActionsModel: ActionModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + + public static var identifier: String = "actions" + public var actionType: String = ActionActionsModel.identifier + public var actions: [ActionModelProtocol] + public var concurrent = true + public var extraParameters: JSONValueDictionary? + public var analyticsData: JSONValueDictionary? + + //-------------------------------------------------- + // MARK: - Initialzier + //-------------------------------------------------- + + public init(actions: [ActionModelProtocol], extraParameters: JSONValueDictionary? = nil, analyticsData: JSONValueDictionary? = nil) { + self.actions = actions + self.extraParameters = extraParameters + self.analyticsData = analyticsData + } + + //-------------------------------------------------- + // MARK: - Keys + //-------------------------------------------------- + + private enum CodingKeys: String, CodingKey { + case actionType + case actions + case concurrent + case extraParameters + case analyticsData + } + + //-------------------------------------------------- + // MARK: - Codec + //-------------------------------------------------- + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + actions = try typeContainer.decodeModels(codingKey: .actions) + if let concurrent = try typeContainer.decodeIfPresent(Bool.self, forKey: .concurrent) { + self.concurrent = concurrent + } + extraParameters = try typeContainer.decodeIfPresent(JSONValueDictionary.self, forKey: .extraParameters) + analyticsData = try typeContainer.decodeIfPresent(JSONValueDictionary.self, forKey: .analyticsData) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(actionType, forKey: .actionType) + try container.encodeModels(actions, forKey: .actions) + try container.encode(concurrent, forKey: .concurrent) + try container.encodeIfPresent(extraParameters, forKey: .extraParameters) + try container.encodeIfPresent(analyticsData, forKey: .analyticsData) + } +} From 6c81a62e5fdf5587d9a43c038352f3339c0f9277 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 25 Jan 2021 09:31:55 -0500 Subject: [PATCH 40/44] review comments --- ...CoreActionDelegateProtocol+Extension.swift | 2 +- .../MVMCoreActionHandler+Extension.swift | 5 +- .../ActionHandling/MVMCoreActionHandler.h | 52 +++++++++---------- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionDelegateProtocol+Extension.swift b/MVMCore/MVMCore/ActionHandling/MVMCoreActionDelegateProtocol+Extension.swift index 5a53a0b..1308ee5 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionDelegateProtocol+Extension.swift +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionDelegateProtocol+Extension.swift @@ -9,7 +9,7 @@ import Foundation public extension MVMCoreActionDelegateProtocol { - // Handles any action errors. + /// Handles any action errors. func handleAction(error: MVMCoreErrorObject, action: ActionModelProtocol, additionalData: [AnyHashable: Any]?) { MVMCoreActionHandler.shared()?.defaultHandleActionError(error, additionalData: additionalData) } diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler+Extension.swift b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler+Extension.swift index 1df7687..5acdbca 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler+Extension.swift +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler+Extension.swift @@ -19,8 +19,9 @@ public extension MVMCoreActionHandler { } return json } catch { - let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: "")! - delegateObject?.actionDelegate?.handleAction(error: errorObject, action: model, additionalData: model.extraParameters) ?? MVMCoreActionHandler.shared()?.defaultHandleActionError(errorObject, additionalData: model.extraParameters) + if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: "") { + delegateObject?.actionDelegate?.handleAction(error: errorObject, action: model, additionalData: model.extraParameters) ?? MVMCoreActionHandler.shared()?.defaultHandleActionError(errorObject, additionalData: model.extraParameters) + } return nil } } diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h index 26103f4..a7c22dd 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.h @@ -19,92 +19,92 @@ extern NSString * _Nonnull const KeyActionTypeOpen; @interface MVMCoreActionHandler : NSObject -// Returns the shared action handler +/// Returns the shared action handler + (nullable instancetype)sharedActionHandler; -// Convenience function for handling actions. This will pull action and pageInfo out of the dictionary and call handleAction: actionInformation: with those values +/// Convenience function for handling actions. This will pull action and pageInfo out of the dictionary and call handleAction: actionInformation: with those values - (void)handleActionWithDictionary:(nullable NSDictionary *)dictionary additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; -// Asynchronously handles action (dispatches and calls below function). Used by server driven user actions.. +/// Asynchronously handles action (dispatches and calls below function). Used by server driven user actions.. - (void)handleAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; -// Synchronously handles action. Used by server driven user actions.. +/// Synchronously handles action. Used by server driven user actions.. - (void)synchronouslyHandleAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; #pragma mark - Actions -// by default, returns the original RequestParameter that passed in. Can be overriden for some generic updates to the RequestParameter before handle open page action gets called. +/// by default, returns the original RequestParameter that passed in. Can be overriden for some generic updates to the RequestParameter before handle open page action gets called. - (void)updateRequestParametersBeforeHandleOpenPageAction:(nonnull MVMCoreRequestParameters *)requestParameters callBack:(void (^_Nonnull)(MVMCoreRequestParameters * _Nonnull requestParameters))callback; -// Logs the action. Currently is not action information driven... depends on delegate. +/// Logs the action. Currently is not action information driven... depends on delegate. - (void)logAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; -// Tries to open a page +/// Tries to open a page - (void)openPageAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; -// restarts the app +/// restarts the app - (void)restartAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; -// Goes back +/// Goes back - (void)backAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; -// Makes a phone call +/// Makes a phone call - (void)callAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; -// Makes the previous request, needs the delegate for this +/// Makes the previous request, needs the delegate for this - (void)previousSubmitAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; -// Redirects to another experience +/// Redirects to another experience - (void)redirectAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; -// Cancels (like in a popup) +/// Cancels (like in a popup) - (void)cancelAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; -// Goes to settings app +/// Goes to settings app - (void)settingsAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; /// Performs multiple actions - (void)actions:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; -// Subclass this to handle other custom actions. Return YES if handled, and NO if not. +/// Subclass this to handle other custom actions. Return YES if handled, and NO if not. - (BOOL)handleOtherActions:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; -// Last chance to handle unknown actions before throwing an error +/// Last chance to handle unknown actions before throwing an error - (void)unknownAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; -// Handles action errors. +/// Handles action errors. - (void)handleActionError:(nullable MVMCoreErrorObject *)error actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; #pragma mark - Link away action -// Links away to app or browser +/// Links away to app or browser - (void)linkAwayAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; -// Can subclass to add to urls if needed at global level (delegate is also called) +/// Can subclass to add to urls if needed at global level (delegate is also called) - (void)prepareLinkAwayWithURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; -// Opens the url +/// Opens the url - (void)openURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; -// opens the url in a webview. +/// opens the url in a webview. - (void)openURLInWebView:(nullable NSURL *)url actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; #pragma mark - Default Action Protocol Functions -// Currently no default log action but this will eventually be server driven. +/// Currently no default log action but this will eventually be server driven. + (void)defaultLogAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; -// Sends the request to the load handler. +/// Sends the request to the load handler. + (void)defaultHandleOpenPageForRequestParameters:(nonnull MVMCoreRequestParameters *)requestParameters additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; -// By default, throws an error, calling defaultHandleActionError. +/// By default, throws an error, calling defaultHandleActionError. + (void)defaultHandleUnknownActionType:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject; -// Logs the error. +/// Logs the error. - (void)defaultHandleActionError:(nonnull MVMCoreErrorObject *)error additionalData:(nullable NSDictionary *)additionalData; #pragma mark - Deprecated -// Convenience function for handling actions. This will pull action and pageInfo out of the dictionary and call handleAction: actionInformation: with those values +/// Convenience function for handling actions. This will pull action and pageInfo out of the dictionary and call handleAction: actionInformation: with those values - (void)handleActionWithDictionary:(nullable NSDictionary *)dictionary additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject *)delegate __deprecated; @end From 6a57e6b90382c829b17d118a9b32d4c08c20e5de Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 25 Jan 2021 11:13:15 -0500 Subject: [PATCH 41/44] actions mapped --- MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m | 4 +++- MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h | 1 + MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m | 1 + MVMCore/MVMCore/Models/ModelMapping.swift | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index 7bb2a11..f4c389d 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -84,7 +84,9 @@ NSString * const KeyActionTypeOpen = @"openPage"; } else if ([actionType isEqualToString:KeyActionTypeSettings]) { [self settingsAction:actionInformation additionalData:additionalData delegateObject:delegateObject]; - } else if ([actionType isEqualToString:KeyActionTypeNoop]){ + } else if ([actionType isEqualToString:KeyActionTypeNoop]) { + } else if ([actionType isEqualToString:KeyActionTypeActions]) { + [self actions:actionInformation additionalData:additionalData delegateObject:delegateObject]; } else if (![self handleOtherActions:actionType actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]) { // not a known action type. [self unknownAction:actionType actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]; diff --git a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h index 220b180..c2d7f8e 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h +++ b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.h @@ -40,6 +40,7 @@ extern NSString * const KeyActionTypeCancel; extern NSString * const KeyActionTypeRedirect; extern NSString * const KeyActionTypeSettings; extern NSString * const KeyActionTypeNoop; +extern NSString * const KeyActionTypeActions; extern NSString * const KeyActionInformation; extern NSString * const KeyLinkAwayAppURL; extern NSString * const KeyLinkAwayURL; diff --git a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m index 2127e2e..80317ea 100644 --- a/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m +++ b/MVMCore/MVMCore/Constants/MVMCoreJSONConstants.m @@ -40,6 +40,7 @@ NSString * const KeyActionTypeCancel = @"cancel"; NSString * const KeyActionTypeRedirect = @"switchApp"; NSString * const KeyActionTypeSettings = @"openSettings"; NSString * const KeyActionTypeNoop = @"noop"; +NSString * const KeyActionTypeActions = @"actions"; NSString * const KeyActionInformation = @"actionInformation"; NSString * const KeyLinkAwayAppURL = @"appURL"; NSString * const KeyLinkAwayURL = @"browserUrl"; diff --git a/MVMCore/MVMCore/Models/ModelMapping.swift b/MVMCore/MVMCore/Models/ModelMapping.swift index 74acf80..6c3df04 100644 --- a/MVMCore/MVMCore/Models/ModelMapping.swift +++ b/MVMCore/MVMCore/Models/ModelMapping.swift @@ -21,5 +21,6 @@ import Foundation try? ModelRegistry.register(ActionCancelModel.self) try? ModelRegistry.register(ActionSettingModel.self) try? ModelRegistry.register(ActionNoopModel.self) + try? ModelRegistry.register(ActionActionsModel.self) } } From d7da39ce25ac53ee08a19b07346fa0b5429d7a37 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 28 Jan 2021 11:46:27 -0500 Subject: [PATCH 42/44] Adds url and base url for open page. --- .../MVMCore/LoadHandling/MVMCoreLoadHandler.m | 48 +++++++++---------- .../LoadHandling/MVMCoreRequestParameters.h | 11 +++-- .../LoadHandling/MVMCoreRequestParameters.m | 9 ++++ .../ActionType/ActionOpenPageModel.swift | 3 ++ 4 files changed, 42 insertions(+), 29 deletions(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m index db3673f..27043bf 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m @@ -110,34 +110,32 @@ - (nullable NSURLRequest *)requestWithParameters:(nonnull MVMCoreRequestParameters *)requestParameters error:(MVMCoreErrorObject *_Nonnull *_Nonnull)error { - NSURL *url = nil; - - if (requestParameters.alternateBaseURL) { - url = requestParameters.alternateBaseURL; - } else { - url = [MVMCoreSessionObject sharedGlobal].baseURL; - } - + NSURL *url = requestParameters.URL; if (!url) { - url = [NSURL URLWithString:URLProdPostpayBase]; + if (requestParameters.alternateBaseURL) { + url = requestParameters.alternateBaseURL; + } else { + url = [MVMCoreSessionObject sharedGlobal].baseURL ?: [NSURL URLWithString:URLProdPostpayBase]; + } + + // Appends the context root. + if (requestParameters.contextRoot) { + url = [url URLByAppendingPathComponent:requestParameters.contextRoot]; + } else if ([MVMCoreSessionObject sharedGlobal].contextRoot) { + url = [url URLByAppendingPathComponent:[MVMCoreSessionObject sharedGlobal].contextRoot]; + } + + // Appends the page type + if (requestParameters.pageType) { + url = [url URLByAppendingPathComponent:requestParameters.pageType]; + } + + // This has changed since the initial agreement. Seems server always needs page type now. + /* else if (requestParameters.modules) { + url = [url URLByAppendingPathComponent:KeyModuleMap]; + }*/ } - // Appends the context root. - if (requestParameters.contextRoot) { - url = [url URLByAppendingPathComponent:requestParameters.contextRoot]; - } else if ([MVMCoreSessionObject sharedGlobal].contextRoot) { - url = [url URLByAppendingPathComponent:[MVMCoreSessionObject sharedGlobal].contextRoot]; - } - - // Appends the page type - if (requestParameters.pageType) { - url = [url URLByAppendingPathComponent:requestParameters.pageType]; - } - // This has changed since the initial agreement. Seems server always needs page type now. - /* else if (requestParameters.modules) { - url = [url URLByAppendingPathComponent:KeyModuleMap]; - }*/ - // Adds modules needed to the request parameters. if (requestParameters.modules.count > 0) { [requestParameters addRequestParameters:@{KeyModuleList:requestParameters.modules}]; diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h index 15163a0..07768d8 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h @@ -36,9 +36,15 @@ typedef NS_ENUM(NSInteger, MFLoadStyle) { // adding parent pageType for freebee @property (nullable, strong, nonatomic) NSString *parentPageType; -// Context root for server +/// App context to use when building the url. For ex: https://baseURL/appContext/pageType @property (nullable, strong, nonatomic) NSString *contextRoot; +/// Host to use when building the url. For ex: https://baseURL/appContext/pageType +@property (nullable, strong, nonatomic) NSURL *alternateBaseURL; + +/// Entire URL to use instead of building the url +@property (nullable, strong, nonatomic) NSURL *URL; + // A flag for if you do not want to try loading any actual view controller. (Unless there is an error screen) @property (assign, nonatomic) BOOL noViewControllerToLoad; @@ -82,9 +88,6 @@ typedef NS_ENUM(NSInteger, MFLoadStyle) { // If the request was created with an action map. @property (nullable, strong, nonatomic) NSDictionary *actionMap; -// only used when the base url is not the same as mf -@property (nullable, strong, nonatomic) NSURL *alternateBaseURL; - @property (nullable, strong, nonatomic) NSNumber *customTimeoutTime; // Will open support panel at the end of the load. diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m index f2e689f..5279dcc 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m @@ -66,6 +66,14 @@ if (self = [self initWithPageType:[actionMap stringForKey:KeyPageType] additionalModules:[actionMap array:KeyModuleList] extraParameters:[actionMap dict:KeyExtraParameters]]) { self.contextRoot = [actionMap string:KeyContextRoot]; + NSString *alternateBase = [actionMap string:@"baseURL"]; + if (alternateBase) { + self.alternateBaseURL = [NSURL URLWithString:[alternateBase stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLHostAllowedCharacterSet]]; + } + NSString *url = [actionMap string:@"URL"]; + if (url) { + self.URL = [NSURL URLWithString:[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; + } self.actionMap = actionMap; self.customTimeoutTime = [actionMap optionalNumberForKey:@"customTimeoutTime"]; self.openSupportPanel = [actionMap boolForKey:KeyOpenSupport]; @@ -136,6 +144,7 @@ copyObject.imageData = self.imageData; copyObject.customTimeoutTime = self.customTimeoutTime; copyObject.backgroundRequest = self.backgroundRequest; + copyObject.URL = self.URL; return copyObject; } diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift index a20d343..69adbdc 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift @@ -15,6 +15,9 @@ public static var identifier: String = "openPage" public var actionType: String = ActionOpenPageModel.identifier public var pageType: String + public var baseURL: String? + public var appContext: String? + public var URL: String? public var extraParameters: JSONValueDictionary? public var analyticsData: JSONValueDictionary? public var presentationStyle: String? From 252d96e20cf0a30aef6a6987cb880a89a0c2bfb9 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 28 Jan 2021 11:59:09 -0500 Subject: [PATCH 43/44] comment update --- MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h index 07768d8..df2aa69 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h @@ -36,10 +36,10 @@ typedef NS_ENUM(NSInteger, MFLoadStyle) { // adding parent pageType for freebee @property (nullable, strong, nonatomic) NSString *parentPageType; -/// App context to use when building the url. For ex: https://baseURL/appContext/pageType +/// App context to use when building the url. For ex: baseURL/appContext/pageType @property (nullable, strong, nonatomic) NSString *contextRoot; -/// Host to use when building the url. For ex: https://baseURL/appContext/pageType +/// Base URL to use when building the url. For ex: baseURL/appContext/pageType @property (nullable, strong, nonatomic) NSURL *alternateBaseURL; /// Entire URL to use instead of building the url From 6f0735ed0265106d1cb01a875c8d3c3d3d8e0f21 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 29 Jan 2021 11:11:15 -0500 Subject: [PATCH 44/44] Warning fix --- MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m | 2 +- MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m index f4c389d..ddb1fab 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.m @@ -395,7 +395,7 @@ NSString * const KeyActionTypeOpen = @"openPage"; } else { [MVMCoreDispatchUtility performBlockInBackground:^{ // Cannot linkaway, show error. - MVMCoreErrorObject *error = error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeLinkawayFailed domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@_%@",NSStringFromClass([delegateObject.actionDelegate class]),KeyActionTypeLinkAway]]; + MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeLinkawayFailed domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@_%@",NSStringFromClass([delegateObject.actionDelegate class]),KeyActionTypeLinkAway]]; [self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject]; }]; } diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m index 5279dcc..d90af0a 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m @@ -68,11 +68,11 @@ self.contextRoot = [actionMap string:KeyContextRoot]; NSString *alternateBase = [actionMap string:@"baseURL"]; if (alternateBase) { - self.alternateBaseURL = [NSURL URLWithString:[alternateBase stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLHostAllowedCharacterSet]]; + self.alternateBaseURL = [NSURL URLWithString:alternateBase]; } NSString *url = [actionMap string:@"URL"]; if (url) { - self.URL = [NSURL URLWithString:[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; + self.URL = [NSURL URLWithString:url]; } self.actionMap = actionMap; self.customTimeoutTime = [actionMap optionalNumberForKey:@"customTimeoutTime"];