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:
Pfeil, Scott Robert 2024-02-22 14:07:57 +00:00
commit 03f81ca9fc
5 changed files with 38 additions and 3 deletions

View File

@ -34,12 +34,35 @@ open class ActionOpenPageHandler: MVMCoreJSONActionHandlerProtocol {
continuation.resume()
}
}
if operation.error != nil, let fallbackResponseJson = model.fallbackResponse?.toJSON() {
await runFallback(response: fallbackResponseJson, requestParameters: requestParameters, delegateObject: delegateObject, additionalData: additionalData)
}
}
} catch {
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 {
guard let model = model as? ActionOpenPageModel else { return }
do {

View File

@ -27,6 +27,7 @@ public struct ActionOpenPageModel: ActionModelProtocol, ActionOpenPageProtocol,
public var background: Bool?
public var clientParameters: ClientParameterModel?
public var customTimeoutTime: TimeInterval?
public var fallbackResponse: JSONValueDictionary?
public var requestParameters: MVMCoreRequestParameters
@ -67,6 +68,7 @@ public struct ActionOpenPageModel: ActionModelProtocol, ActionOpenPageProtocol,
case background
case clientParameters
case customTimeoutTime
case fallbackResponse
}
public init(from decoder: Decoder) throws {
@ -83,6 +85,7 @@ public struct ActionOpenPageModel: ActionModelProtocol, ActionOpenPageProtocol,
customTimeoutTime = try typeContainer.decodeIfPresent(TimeInterval.self, forKey: .customTimeoutTime)
extraParameters = try typeContainer.decodeIfPresent(JSONValueDictionary.self, forKey: .extraParameters)
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.contextRoot = appContext
@ -110,5 +113,6 @@ public struct ActionOpenPageModel: ActionModelProtocol, ActionOpenPageProtocol,
try container.encodeIfPresent(customTimeoutTime, forKey: .customTimeoutTime)
try container.encodeIfPresent(extraParameters, forKey: .extraParameters)
try container.encodeIfPresent(analyticsData, forKey: .analyticsData)
try container.encodeIfPresent(fallbackResponse, forKey: .fallbackResponse)
}
}

View File

@ -11,6 +11,7 @@
#import <MVMCore/MVMCoreLoadDelegateProtocol.h>
#import <MVMCore/MVMCorePresentationDelegateProtocol.h>
#import <MVMCore/MVMCoreActionDelegateProtocol.h>
#import <MVMCore/MVMCoreErrorObject.h>
@class MVMCoreLoadRequestOperation;
@class MVMCoreRequestParameters;
@ -58,9 +59,12 @@
// The full response json
@property (nullable, strong, nonatomic) NSDictionary *responseJSON;
//Unique Identifier for event tracking
// Unique Identifier for event tracking
@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)initWithRequestParameters:(nullable MVMCoreRequestParameters *)requestParameters dataForPage:(nullable NSDictionary *)dataForPage delegateObject:(nullable DelegateObject *)delegateObject;

View File

@ -19,6 +19,7 @@
@interface MVMCoreLoadRequestOperation : MVMCoreOperation
@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) NSDictionary *dataForPage;
@property (nullable, strong, nonatomic) DelegateObject *delegateObject;
@ -27,6 +28,8 @@
@property (nonatomic) BOOL backgroundLoad;
@property (nonatomic, getter=areDependenciesAdded) BOOL dependenciesAdded;
@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.
@property (nonatomic, readonly) BOOL alertToShow;

View File

@ -53,7 +53,7 @@
- (nullable instancetype)initWithLoadObject:(nullable MVMCoreLoadObject *)loadObject backgroundLoad:(BOOL)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;
}
return self;
@ -856,7 +856,8 @@
//make post load calls function
[MVMCoreLoadRequestOperation loadPostCallActions:loadObject];
[MVMCoreLoadRequestOperation loadPostAction:loadObject delegateObject:delegateObject];
loadObject.error = errorObject;
loadObject.operation.error = errorObject;
[loadObject.operation markAsFinished];
}