From 06dbe2c1a08db569e50f3db5333d828052811c19 Mon Sep 17 00:00:00 2001 From: teegsh2 Date: Thu, 29 Aug 2024 15:36:20 +0530 Subject: [PATCH] Swift code for webPunchOut UAD pages --- ...VMCoreLoadRequestOperation+Extension.swift | 27 +++++++++++++++++++ .../MVMCoreLoadRequestOperation.m | 18 +------------ 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation+Extension.swift b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation+Extension.swift index 1917fbc..25eb5ca 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation+Extension.swift +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation+Extension.swift @@ -135,3 +135,30 @@ public extension NavigationHandler { try await NavigationHandler.shared().navigate(with: getOperationPopToViewController(with: pageType, navigationController: navigationController, delegateObject: delegateObject, animated: animated)) } } + +@objc +public extension MVMCoreLoadRequestOperation { + @objc static func fetchJsonForPageType(requestParameter: MVMCoreRequestParameters, completion: @escaping (([AnyHashable: Any]?, [AnyHashable: Any]?) -> Void)) { + MVMCoreCache.shared()?.fetchJSON(forPageType: requestParameter.pageType, completionHandler: { jsonDictionary in + if requestParameter.pageType == "webPunchOut_UAD" { + guard var jsonDictionary = jsonDictionary, + let actionMap = requestParameter.actionMap, + let extraParameters = actionMap["extraParameters"] as? [String: String], + let flowName = extraParameters["flowName"] else { + return + } + MVMCoreCache.shared()?.fetchJSON(forModule: flowName, completionHandler: { moduleDictionary in + guard let moduleDictionary = moduleDictionary, + let punchOut = moduleDictionary[flowName] as? [String: String], + let browserUrl = punchOut["browserUrl"] else { + return + } + jsonDictionary["browserUrl"] = browserUrl + completion(jsonDictionary, nil) + }) + } else { + completion(jsonDictionary, nil) + } + }) + } +} diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 6fb5c28..dfae483 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -236,24 +236,8 @@ }]; }]; } else if (requestParameters.pageType.length != 0) { - - // Check cache function if page json is already in the cache. - [[MVMCoreCache sharedCache] fetchJSONForPageType:requestParameters.pageType completionHandler:^(NSDictionary * _Nullable jsonDictionary) { - if ([requestParameters.pageType isEqualToString:@"webPunchOut_UAD"]) { - NSMutableDictionary *newJsonDictionary = [jsonDictionary mutableCopy]; - NSString *flowName = requestParameters.actionMap[@"extraParameters"][@"flowName"]; - [[MVMCoreCache sharedCache] fetchJSONForModule: flowName completionHandler:^(NSDictionary * _Nullable moduleJsonDictionary) { - if (moduleJsonDictionary[flowName] != NULL && moduleJsonDictionary[flowName][@"browserUrl"] != NULL) { - [newJsonDictionary setObject: moduleJsonDictionary[flowName][@"browserUrl"] forKey:@"browserUrl"]; - completionHandler(newJsonDictionary, nil); - } - }]; - //jsonDictionary[@"browserUrl"] = - } else { - completionHandler(jsonDictionary,nil); - } - }]; + [self fetchJsonForPageTypeWithRequestParameter: requestParameters completion: completionHandler]; } else if (modules > 0) {