Skip to content

Commit

Permalink
#1434 rename to none action to avoid clash with no action viewport ac…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
naleeha authored and keikeicheung committed Sep 5, 2024
1 parent 3e2506f commit 0bc1175
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 21 deletions.
10 changes: 4 additions & 6 deletions vuu/src/main/scala/org/finos/vuu/core/CoreServerApiHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ class CoreServerApiHandler(val viewPortContainer: ViewPortContainer,
}
}


override def process(msg: RemoveVisualLinkRequest)(ctx: RequestContext): Option[ViewServerMessage] = {
Try(viewPortContainer.unlinkViewPorts(ctx.session, ctx.queue, msg.childVpId)) match {
case Success(_) =>
Expand All @@ -410,15 +409,14 @@ class CoreServerApiHandler(val viewPortContainer: ViewPortContainer,
vsMsg(CloseTreeNodeSuccess(msg.vpId, msg.treeKey))(ctx)
}


override def process(msg: RpcRequest)(ctx: RequestContext): Option[ViewServerMessage] = {
val response = Try(viewPortContainer.handleRpcRequest(msg.context.viewPortId, msg.rpcName, msg.params)(ctx)) match {
case Success(functionResult) =>
logger.info(s"Processed VP RPC call ${ctx.requestId}" + msg)
functionResult match {
case RpcFunctionSuccess(data) =>
RpcResponseNew(rpcName = msg.rpcName, result = RpcResult(isSuccess = true, data, null), null)
case RpcFunctionFailure(_, error, exception) =>
RpcResponseNew(rpcName = msg.rpcName, result = RpcResult.fromSuccess(data), NoneAction())
case RpcFunctionFailure(errorCode, error, exception) =>
createErrorRpcResponse(msg, error)
}
case Failure(e) =>
Expand All @@ -431,7 +429,7 @@ class CoreServerApiHandler(val viewPortContainer: ViewPortContainer,
private def createErrorRpcResponse(msg: RpcRequest, errorMessage: String) = {
RpcResponseNew(
rpcName = msg.rpcName,
result = RpcResult(isSuccess = false, null, errorMessage = errorMessage),
action = ShowNotificationAction("Error", s"Failed to process ${msg.rpcName} request", errorMessage))
result = RpcResult.fromError(errorMessage),
action = ShowNotificationAction(NotificationType.Error, s"Failed to process ${msg.rpcName} request", errorMessage))
}
}
60 changes: 45 additions & 15 deletions vuu/src/main/scala/org/finos/vuu/net/Messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ case class ChangeViewPortRangeSuccess(viewPortId: String, from: Int, to: Int) ex
case class OpenTreeNodeRequest(vpId: String, treeKey: String) extends MessageBody

case class ViewPortRpcCall(vpId: String, rpcName: String, params: Array[Any], namedParams: Map[String, Any]) extends MessageBody

case class ViewPortRpcResponse(vpId: String, method: String, action: ViewPortAction) extends MessageBody


Expand All @@ -131,12 +132,17 @@ case class ViewPortMenuRpcResponse(vpId: String, rpcName: String, action: ViewPo
case class ViewPortMenuRpcReject(vpId: String, rpcName: String, error: String) extends MessageBody

case class ViewPortEditRowRpcCall(vpId: String, rowKey: String, data: Map[String, Object]) extends MessageBody

case class ViewPortEditCellRpcCall(vpId: String, rowKey: String, field: String, value: Object) extends MessageBody

case class ViewPortEditSubmitFormRpcCall(vpId: String) extends MessageBody

case class ViewPortEditCloseFormRpcCall(vpId: String, field: String, value: Object) extends MessageBody

case class ViewPortAddRowRpcCall(vpId: String, rowKey: String, data: Map[String, Any]) extends MessageBody
case class ViewPortDeleteCellRpcCall(vpId: String, rowKey: String, field: String) extends MessageBody{}

case class ViewPortDeleteCellRpcCall(vpId: String, rowKey: String, field: String) extends MessageBody {}

case class ViewPortDeleteRowRpcCall(vpId: String, rowKey: String) extends MessageBody


Expand All @@ -145,7 +151,6 @@ case class ViewPortEditRpcResponse(vpId: String, rpcName: String, action: ViewPo
case class ViewPortEditRpcReject(vpId: String, rpcName: String, error: String) extends MessageBody



case class CloseTreeNodeRequest(vpId: String, treeKey: String) extends MessageBody

case class CloseTreeNodeSuccess(vpId: String, treeKey: String) extends MessageBody
Expand Down Expand Up @@ -212,27 +217,52 @@ case class RowUpdate(vpVersion: String, viewPortId: String, vpSize: Int, rowInde
case class RpcRequest(context: RpcContext, rpcName: String, params: Any) extends MessageBody
case class RpcContext(viewPortId: String)

//case class RpcContext(viewPortId: String, rowKey: String)
//object RpcContext {
// def forViewPort(viewPortId: String) = RpcContext(viewPortId)
// def forViewPortRow(viewPortId: String, rowKey: String) = RpcContext(viewPortId)
//}
//@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
//@JsonSubTypes(Array(
// new Type(value = classOf[GlobalContext], name = "GLOBAL_CONTEXT"),
// new Type(value = classOf[ViewPortContext], name = "VIEWPORT_CONTEXT"),
// new Type(value = classOf[ViewPortRowContext], name = "VIEWPORT_ROW_CONTEXT"),
//))
//trait RpcContext
//case class GlobalContext() extends RpcContext
//case class ViewPortContext(viewPortId: String) extends RpcContext
//case class ViewPortRowContext(viewPortId: String, rowKey: String) extends RpcContext

case class RpcResponseNew(rpcName: String, result: RpcResult, action: UIAction) extends MessageBody
case class RpcResult(isSuccess: Boolean, data: Any, errorMessage: String)

object RpcResult {
def fromError(errorMessage: String): RpcResult = RpcResult(isSuccess = false, data = null, errorMessage = errorMessage)
def fromSuccess(data: Any): RpcResult = RpcResult(isSuccess = true, data = data, errorMessage = null)
}

//trait RpcResult {
// val isSuccess: Boolean // todo use status enums? does that work with java
//}
//
//case class RpcSuccessResult(data: Any) extends RpcResult {
// override val isSuccess: Boolean = true
//}
//case class RpcErrorResult(errorMessage: String) extends RpcResult {
// override val isSuccess: Boolean = false
//}
//@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
//@JsonSubTypes(Array(
// new Type(value = classOf[RpcSuccessResult], name = "SUCCESS_RESULT"),
// new Type(value = classOf[RpcErrorResult], name = "ERROR_RESULT"),
//))
//trait RpcResult
//case class RpcSuccessResult(data: Any) extends RpcResult
//case class RpcErrorResult(errorMessage: String) extends RpcResult

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonSubTypes(Array(
new Type(value = classOf[NoAction], name = "NO_ACTION"),
new Type(value = classOf[NoneAction], name = "NO_ACTION"),
new Type(value = classOf[ShowNotificationAction], name = "SHOW_NOTIFICATION_ACTION"),
))
trait UIAction

case class NoAction() extends UIAction
case class ShowNotificationAction(notificationType: String, title: String, message: String) extends UIAction
case class NoneAction() extends UIAction

case class ShowNotificationAction(notificationType: String, title: String, message: String) extends UIAction

object NotificationType {
final val Error = "Error"
final val Warning = "Warning"
final val Info = "Info"
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class TypeAheadWSApiTest extends WebSocketApiTestBase {

responseBody.result.isSuccess shouldEqual true
responseBody.result.data shouldEqual List("12355", "45321", "89564", "42262", "65879", "88875", "45897", "23564", "33657", "99854")

And("return No Action")
responseBody.action shouldBe a[NoneAction]
}

Scenario("Start with a specified string for a column") {
Expand Down

0 comments on commit 0bc1175

Please sign in to comment.