Skip to content

Commit

Permalink
#1434 using new rpc message for view port typeahead request
Browse files Browse the repository at this point in the history
  • Loading branch information
naleeha authored and keikeicheung committed Sep 5, 2024
1 parent a8eb90a commit 3e2506f
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import java.util.Collections;

import static org.assertj.core.api.Assertions.assertThat;
import static test.helper.ViewPortTestUtils.createRandomViewServerMessage;

public class RpcMethodHandlerTest {
Expand Down
13 changes: 10 additions & 3 deletions vuu/src/main/scala/org/finos/vuu/core/CoreServerApiHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,21 @@ class CoreServerApiHandler(val viewPortContainer: ViewPortContainer,
logger.info(s"Processed VP RPC call ${ctx.requestId}" + msg)
functionResult match {
case RpcFunctionSuccess(data) =>
RpcResponseNew(rpcName = msg.rpcName, result = RpcResult(true, data, null), null)
RpcResponseNew(rpcName = msg.rpcName, result = RpcResult(isSuccess = true, data, null), null)
case RpcFunctionFailure(_, error, exception) =>
RpcResponseNew(rpcName = msg.rpcName, RpcResult(false, null, errorMessage = error), null)
createErrorRpcResponse(msg, error)
}
case Failure(e) =>
logger.info(s"Failed to process VP RPC call ${ctx.requestId}", e)
RpcResponseNew(rpcName = msg.rpcName, RpcResult(false, null, errorMessage = e.getMessage), null)
createErrorRpcResponse(msg, e.getMessage)
}
vsMsg(response)(ctx)
}

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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import org.finos.vuu.viewport.ViewPortColumns

class ViewPortTypeAheadRpcHandler(tableContainer: TableContainer) extends DefaultRpcHandler with StrictLogging {

this.registerRpc(RpcNames.UniqueFieldValuesRpc, params => processGetUniqueFieldValuesRequestNew(params))
this.registerRpc(RpcNames.UniqueFieldValuesRpc, params => processGetUniqueFieldValuesRequest(params))
this.registerRpc(RpcNames.UniqueFieldValuesStartWithRpc, params => processGetUniqueFieldValuesStartWithRequest(params))


def processGetUniqueFieldValuesRequestNew(params: RpcParams): RpcFunctionResult = {
def processGetUniqueFieldValuesRequest(params: RpcParams): RpcFunctionResult = {

val inputParam = params.data.get.asInstanceOf[Map[String, Any]]

Expand All @@ -26,23 +25,15 @@ class ViewPortTypeAheadRpcHandler(tableContainer: TableContainer) extends Defaul
new RpcFunctionSuccess(values)
}

def processGetUniqueFieldValuesRequest(params: RpcParams): RpcFunctionResult = {
val values = getUniqueFieldValues(
params.namedParams("table").toString, //how to report error when expected param missing or fail to cast to right type
params.namedParams("module").toString,
params.namedParams("column").toString,
params.viewPortColumns.get,
null //todo what to do about request context
)
new RpcFunctionSuccess(values)
}

def processGetUniqueFieldValuesStartWithRequest(params: RpcParams): RpcFunctionResult = {

val inputParam = params.data.get.asInstanceOf[Map[String, Any]]

val values = getUniqueFieldValuesStartingWith(
params.namedParams("table").toString, //how to report error when expected param missing or fail to cast to right type
params.namedParams("module").toString,
params.namedParams("column").toString,
params.namedParams("starts").toString,
inputParam("table").toString, //how to report error when expected param missing or fail to cast to right type
inputParam("module").toString,
inputParam("column").toString,
inputParam("starts").toString,
params.viewPortColumns.get,
null //todo what to do about request context
)
Expand Down
19 changes: 11 additions & 8 deletions vuu/src/main/scala/org/finos/vuu/net/Messages.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.finos.vuu.net

import com.fasterxml.jackson.annotation.JsonTypeInfo
import com.fasterxml.jackson.annotation.JsonSubTypes.Type
import com.fasterxml.jackson.annotation.{JsonSubTypes, JsonTypeInfo}
import com.fasterxml.jackson.databind.annotation.{JsonDeserialize, JsonSerialize, JsonTypeIdResolver}
import org.finos.vuu.api.AvailableViewPortVisualLink
import org.finos.vuu.net.json.{RowUpdateDeserializer, RowUpdateSerializer}
Expand Down Expand Up @@ -226,10 +227,12 @@ case class RpcResult(isSuccess: Boolean, data: Any, errorMessage: String)
// override val isSuccess: Boolean = false
//}

trait UIAction {
val actionType: String
}

case class ShowNotificationAction(notificationType: String, title: String, message: String) extends UIAction {
override val actionType: String = "SHOW_NOTIFICATION_ACTION"
}
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonSubTypes(Array(
new Type(value = classOf[NoAction], 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
10 changes: 5 additions & 5 deletions vuu/src/test/scala/org/finos/vuu/wsapi/TableWSApiTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class TableWSApiTest extends WebSocketApiTestBase {

private val moduleName = "TEST"

Feature("Server web socket api") {
Scenario("client requests to get table metadata for a table") {
Feature("[Web Socket API] Get table metadata") {
Scenario("For a table") {

val requestId = vuuClient.send(sessionId, tokenId, GetTableMetaRequest(ViewPortTable("TableMetaTest", moduleName)))

Expand All @@ -30,7 +30,7 @@ class TableWSApiTest extends WebSocketApiTestBase {
responseBody.columns shouldEqual Array("Id", "Account")
}

Scenario("client requests to get table metadata for a table with no view port def defined") {
Scenario("For a table with no view port def defined") {

val requestId = vuuClient.send(sessionId, tokenId, GetTableMetaRequest(ViewPortTable("TableMetaDefaultVPTest", moduleName)))

Expand All @@ -42,7 +42,7 @@ class TableWSApiTest extends WebSocketApiTestBase {
responseBody.columns shouldEqual Array("Id")
}

Scenario("client requests to get table metadata for a non existent") {
Scenario("For a non existent table") {

val requestId = vuuClient.send(sessionId, tokenId, GetTableMetaRequest(ViewPortTable("DoesNotExist", moduleName)))

Expand All @@ -53,7 +53,7 @@ class TableWSApiTest extends WebSocketApiTestBase {
responseBody.msg shouldEqual "No such table found with name DoesNotExist in module " + moduleName
}

Scenario("client requests to get table metadata for null table name") {
Scenario("For null table name") {

val requestId = vuuClient.send(sessionId, tokenId, GetTableMetaRequest(ViewPortTable(null, moduleName)))

Expand Down
Loading

0 comments on commit 3e2506f

Please sign in to comment.