Merge branch 'feature/open_page_fallback' into 'develop'
Fallback response JSON handling. ### Summary Adds a fallback response and handling to the openPage action. Co-authored-by: Hedden, Kyle Matthew <kyle.hedden@verizonwireless.com> See merge request https://gitlab.verizon.com/BPHV_MIPS/mvm_core/-/merge_requests/313
This commit is contained in:
commit
03f81ca9fc
@ -34,12 +34,35 @@ open class ActionOpenPageHandler: MVMCoreJSONActionHandlerProtocol {
|
|||||||
continuation.resume()
|
continuation.resume()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if operation.error != nil, let fallbackResponseJson = model.fallbackResponse?.toJSON() {
|
||||||
|
await runFallback(response: fallbackResponseJson, requestParameters: requestParameters, delegateObject: delegateObject, additionalData: additionalData)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
try handle(error: error, model: model, delegateObject: delegateObject)
|
try handle(error: error, model: model, delegateObject: delegateObject)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Given backup JSON data, run it through the load handler.
|
||||||
|
fileprivate func runFallback(response: JSONDictionary, requestParameters: MVMCoreRequestParameters, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async {
|
||||||
|
guard let loadHandler = MVMCoreLoadHandler.sharedGlobal(), let fallbackLoadObject = MVMCoreLoadObject(requestParameters: requestParameters, dataForPage: additionalData, delegateObject: delegateObject)
|
||||||
|
else { return }
|
||||||
|
|
||||||
|
let (loadObject, errorObject) = await MVMCoreLoadRequestOperation.processJSON(fromServer: response, loadObject: fallbackLoadObject)
|
||||||
|
|
||||||
|
if let errorObject {
|
||||||
|
MVMCoreLoggingHandler.shared()?.addError(toLog: errorObject)
|
||||||
|
} else {
|
||||||
|
let operation = loadHandler.loadObject(loadObject)
|
||||||
|
await withCheckedContinuation { continuation in
|
||||||
|
operation.completionBlock = {
|
||||||
|
continuation.resume()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
open func execute(with model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws {
|
open func execute(with model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws {
|
||||||
guard let model = model as? ActionOpenPageModel else { return }
|
guard let model = model as? ActionOpenPageModel else { return }
|
||||||
do {
|
do {
|
||||||
|
|||||||
@ -27,6 +27,7 @@ public struct ActionOpenPageModel: ActionModelProtocol, ActionOpenPageProtocol,
|
|||||||
public var background: Bool?
|
public var background: Bool?
|
||||||
public var clientParameters: ClientParameterModel?
|
public var clientParameters: ClientParameterModel?
|
||||||
public var customTimeoutTime: TimeInterval?
|
public var customTimeoutTime: TimeInterval?
|
||||||
|
public var fallbackResponse: JSONValueDictionary?
|
||||||
|
|
||||||
public var requestParameters: MVMCoreRequestParameters
|
public var requestParameters: MVMCoreRequestParameters
|
||||||
|
|
||||||
@ -67,6 +68,7 @@ public struct ActionOpenPageModel: ActionModelProtocol, ActionOpenPageProtocol,
|
|||||||
case background
|
case background
|
||||||
case clientParameters
|
case clientParameters
|
||||||
case customTimeoutTime
|
case customTimeoutTime
|
||||||
|
case fallbackResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(from decoder: Decoder) throws {
|
public init(from decoder: Decoder) throws {
|
||||||
@ -83,6 +85,7 @@ public struct ActionOpenPageModel: ActionModelProtocol, ActionOpenPageProtocol,
|
|||||||
customTimeoutTime = try typeContainer.decodeIfPresent(TimeInterval.self, forKey: .customTimeoutTime)
|
customTimeoutTime = try typeContainer.decodeIfPresent(TimeInterval.self, forKey: .customTimeoutTime)
|
||||||
extraParameters = try typeContainer.decodeIfPresent(JSONValueDictionary.self, forKey: .extraParameters)
|
extraParameters = try typeContainer.decodeIfPresent(JSONValueDictionary.self, forKey: .extraParameters)
|
||||||
analyticsData = try typeContainer.decodeIfPresent(JSONValueDictionary.self, forKey: .analyticsData)
|
analyticsData = try typeContainer.decodeIfPresent(JSONValueDictionary.self, forKey: .analyticsData)
|
||||||
|
fallbackResponse = try typeContainer.decodeIfPresent(JSONValueDictionary.self, forKey: .fallbackResponse)
|
||||||
|
|
||||||
requestParameters = MVMCoreRequestParameters(pageType: pageType, additionalModules: modules ?? [], extraParameters: extraParameters.toJSON())!
|
requestParameters = MVMCoreRequestParameters(pageType: pageType, additionalModules: modules ?? [], extraParameters: extraParameters.toJSON())!
|
||||||
requestParameters.contextRoot = appContext
|
requestParameters.contextRoot = appContext
|
||||||
@ -110,5 +113,6 @@ public struct ActionOpenPageModel: ActionModelProtocol, ActionOpenPageProtocol,
|
|||||||
try container.encodeIfPresent(customTimeoutTime, forKey: .customTimeoutTime)
|
try container.encodeIfPresent(customTimeoutTime, forKey: .customTimeoutTime)
|
||||||
try container.encodeIfPresent(extraParameters, forKey: .extraParameters)
|
try container.encodeIfPresent(extraParameters, forKey: .extraParameters)
|
||||||
try container.encodeIfPresent(analyticsData, forKey: .analyticsData)
|
try container.encodeIfPresent(analyticsData, forKey: .analyticsData)
|
||||||
|
try container.encodeIfPresent(fallbackResponse, forKey: .fallbackResponse)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
#import <MVMCore/MVMCoreLoadDelegateProtocol.h>
|
#import <MVMCore/MVMCoreLoadDelegateProtocol.h>
|
||||||
#import <MVMCore/MVMCorePresentationDelegateProtocol.h>
|
#import <MVMCore/MVMCorePresentationDelegateProtocol.h>
|
||||||
#import <MVMCore/MVMCoreActionDelegateProtocol.h>
|
#import <MVMCore/MVMCoreActionDelegateProtocol.h>
|
||||||
|
#import <MVMCore/MVMCoreErrorObject.h>
|
||||||
|
|
||||||
@class MVMCoreLoadRequestOperation;
|
@class MVMCoreLoadRequestOperation;
|
||||||
@class MVMCoreRequestParameters;
|
@class MVMCoreRequestParameters;
|
||||||
@ -58,9 +59,12 @@
|
|||||||
// The full response json
|
// The full response json
|
||||||
@property (nullable, strong, nonatomic) NSDictionary *responseJSON;
|
@property (nullable, strong, nonatomic) NSDictionary *responseJSON;
|
||||||
|
|
||||||
//Unique Identifier for event tracking
|
// Unique Identifier for event tracking
|
||||||
@property (nullable, strong, nonatomic) NSString *identifier;
|
@property (nullable, strong, nonatomic) NSString *identifier;
|
||||||
|
|
||||||
|
// If any error happened during the load.
|
||||||
|
@property (nullable, strong, nonatomic) MVMCoreErrorObject *error;
|
||||||
|
|
||||||
- (nullable instancetype)initWithPageJSON:(nullable NSDictionary *)pageJSON modulesJSON:(nullable NSDictionary *)modulesJSON requestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegateObject:(nullable DelegateObject *)delegateObject;
|
- (nullable instancetype)initWithPageJSON:(nullable NSDictionary *)pageJSON modulesJSON:(nullable NSDictionary *)modulesJSON requestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegateObject:(nullable DelegateObject *)delegateObject;
|
||||||
|
|
||||||
- (nullable instancetype)initWithRequestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegateObject:(nullable DelegateObject *)delegateObject;
|
- (nullable instancetype)initWithRequestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegateObject:(nullable DelegateObject *)delegateObject;
|
||||||
|
|||||||
@ -19,6 +19,7 @@
|
|||||||
@interface MVMCoreLoadRequestOperation : MVMCoreOperation
|
@interface MVMCoreLoadRequestOperation : MVMCoreOperation
|
||||||
|
|
||||||
@property (nullable, strong, nonatomic) MVMCoreRequestParameters *requestParameters;
|
@property (nullable, strong, nonatomic) MVMCoreRequestParameters *requestParameters;
|
||||||
|
/// For load objects as in input parameter. Does not attach self generated load objects.
|
||||||
@property (nullable, strong, nonatomic) MVMCoreLoadObject *loadObject;
|
@property (nullable, strong, nonatomic) MVMCoreLoadObject *loadObject;
|
||||||
@property (nullable, strong, nonatomic) NSDictionary *dataForPage;
|
@property (nullable, strong, nonatomic) NSDictionary *dataForPage;
|
||||||
@property (nullable, strong, nonatomic) DelegateObject *delegateObject;
|
@property (nullable, strong, nonatomic) DelegateObject *delegateObject;
|
||||||
@ -27,6 +28,8 @@
|
|||||||
@property (nonatomic) BOOL backgroundLoad;
|
@property (nonatomic) BOOL backgroundLoad;
|
||||||
@property (nonatomic, getter=areDependenciesAdded) BOOL dependenciesAdded;
|
@property (nonatomic, getter=areDependenciesAdded) BOOL dependenciesAdded;
|
||||||
@property (nonnull, nonatomic, strong) NSString *identifier;
|
@property (nonnull, nonatomic, strong) NSString *identifier;
|
||||||
|
/// If any error happened during the operation.
|
||||||
|
@property (nullable, strong, nonatomic) MVMCoreErrorObject *error;
|
||||||
|
|
||||||
/// Legacy flag for if this operation will have an alert to show when finished.
|
/// Legacy flag for if this operation will have an alert to show when finished.
|
||||||
@property (nonatomic, readonly) BOOL alertToShow;
|
@property (nonatomic, readonly) BOOL alertToShow;
|
||||||
|
|||||||
@ -53,7 +53,7 @@
|
|||||||
- (nullable instancetype)initWithLoadObject:(nullable MVMCoreLoadObject *)loadObject backgroundLoad:(BOOL)backgroundLoad {
|
- (nullable instancetype)initWithLoadObject:(nullable MVMCoreLoadObject *)loadObject backgroundLoad:(BOOL)backgroundLoad {
|
||||||
|
|
||||||
if (self = [self initWithRequestParameters:loadObject.requestParameters dataForPage:loadObject.dataForPage delegateObject:loadObject.delegateObject backgroundLoad:backgroundLoad]) {
|
if (self = [self initWithRequestParameters:loadObject.requestParameters dataForPage:loadObject.dataForPage delegateObject:loadObject.delegateObject backgroundLoad:backgroundLoad]) {
|
||||||
loadObject.identifier = self.identifier;
|
self.identifier = loadObject.identifier;
|
||||||
self.loadObject = loadObject;
|
self.loadObject = loadObject;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
@ -856,7 +856,8 @@
|
|||||||
//make post load calls function
|
//make post load calls function
|
||||||
[MVMCoreLoadRequestOperation loadPostCallActions:loadObject];
|
[MVMCoreLoadRequestOperation loadPostCallActions:loadObject];
|
||||||
[MVMCoreLoadRequestOperation loadPostAction:loadObject delegateObject:delegateObject];
|
[MVMCoreLoadRequestOperation loadPostAction:loadObject delegateObject:delegateObject];
|
||||||
|
loadObject.error = errorObject;
|
||||||
|
loadObject.operation.error = errorObject;
|
||||||
[loadObject.operation markAsFinished];
|
[loadObject.operation markAsFinished];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user