Merge branch 'develop' of https://gitlab.verizon.com/BPHV_MIPS/mvm_core into feature/swift_subnav
This commit is contained in:
commit
80be78a401
@ -8,6 +8,11 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol MVMCoreActionHandlerProtocol: ModelHandlerProtocol {
|
||||
init()
|
||||
func handleAction(_ model: ActionModelProtocol, additionalData: [AnyHashable : Any]?, delegateObject: DelegateObject?)
|
||||
}
|
||||
|
||||
public extension MVMCoreActionHandler {
|
||||
|
||||
/// Converts the action to json for old action handler to handle.
|
||||
@ -26,6 +31,41 @@ public extension MVMCoreActionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@objc func hasActionHandler(actionType: String?, actionInformation: [String: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) -> Bool {
|
||||
|
||||
guard //ensure there is a actinType
|
||||
let actionType = actionType,
|
||||
//ensure there is a serialized version of the Action
|
||||
let actionInformation = actionInformation,
|
||||
//esnure the actionModelType
|
||||
let actionModelType = ModelRegistry.getType(for: actionType, with: ActionModelProtocol.self),
|
||||
//ensure there is handlerType for the action of MVMCoreActionHandlerProtocol
|
||||
let actionHandlerType = try? ModelRegistry.getHandlerType(for: actionModelType) as? MVMCoreActionHandlerProtocol.Type
|
||||
else { return false }
|
||||
|
||||
do {
|
||||
//ensure the decoded actionModel is of ActionModelProtocol
|
||||
guard let actionModel = try actionModelType.decode(jsonDict: actionInformation) as? ActionModelProtocol else {
|
||||
throw ModelRegistry.Error.decoderOther(message: "Could not decode to ActionModelProtocol")
|
||||
}
|
||||
|
||||
//create the handler since we know it can initialize
|
||||
let actionHandler = actionHandlerType.init()
|
||||
|
||||
//call the handleAction of the handler
|
||||
actionHandler.handleAction(actionModel, additionalData: additionalData, delegateObject: delegateObject)
|
||||
|
||||
} catch {
|
||||
//log the error
|
||||
if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: "") {
|
||||
MVMCoreActionHandler.shared()?.defaultHandleActionError(errorObject, additionalData: additionalData)
|
||||
}
|
||||
}
|
||||
|
||||
//found the handler, returning true no matter if there was a failure in the do...catch
|
||||
return true
|
||||
}
|
||||
|
||||
/// Start action on current thread.
|
||||
func syncHandleAction(with model: ActionModelProtocol, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) {
|
||||
guard let json = convertActionToJSON(model, delegateObject: delegateObject) else { return }
|
||||
|
||||
@ -387,7 +387,7 @@ NSString * const KeyActionTypeOpen = @"openPage";
|
||||
}
|
||||
|
||||
- (BOOL)handleOtherActions:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
return NO;
|
||||
return [self hasActionHandlerWithActionType:actionType actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
}
|
||||
|
||||
- (void)unknownAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
return parameterType.init(clientParameterModel)
|
||||
} catch {
|
||||
if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: #function) {
|
||||
MVMCoreLoggingHandler.shared()?.addError(toLog: errorObject)
|
||||
MVMCoreLoggingHandler.addError(toLog: errorObject)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ public enum JSONValue: Codable, Equatable {
|
||||
self = value ?? JSONValue.null
|
||||
}
|
||||
|
||||
func decode<T: Decodable>() throws -> T {
|
||||
public func decode<T: Decodable>() throws -> T {
|
||||
let encoded = try JSONEncoder().encode(self)
|
||||
return try JSONDecoder().decode(T.self, from: encoded)
|
||||
}
|
||||
|
||||
@ -164,9 +164,13 @@ public struct ModelRegistry {
|
||||
// MARK: - Functions
|
||||
//--------------------------------------------------
|
||||
|
||||
///This returns a handler type.
|
||||
public static func getHandler(_ model: ModelProtocol) throws -> ModelHandlerProtocol.Type {
|
||||
// Get the modelType
|
||||
let modelType = type(of: model)
|
||||
return try getHandlerType(for: type(of: model))
|
||||
}
|
||||
|
||||
//get handler for the specific Model
|
||||
public static func getHandlerType(for modelType: ModelProtocol.Type) throws -> ModelHandlerProtocol.Type{
|
||||
|
||||
// Get the category for the ModelProtocol
|
||||
guard let category = categories[modelType.categoryName] else {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user