Skip to content

Commit

Permalink
#1434 experimenting with ways to register view port type ahead on Vie…
Browse files Browse the repository at this point in the history
…w Port specific rcp handler
  • Loading branch information
naleeha authored and keikeicheung committed Sep 5, 2024
1 parent d38ba3f commit d6d3dde
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.finos.vuu.person;

import org.finos.vuu.core.module.typeahead.MyTypeAheadHandler;
import org.finos.vuu.core.table.DataTable;
import org.finos.vuu.core.table.TableContainer;
import org.finos.vuu.net.rpc.*;
import scala.Some;

import java.util.Arrays;

Expand All @@ -15,6 +15,9 @@ public class PersonRpcHandler extends DefaultRpcHandler {
public PersonRpcHandler(DataTable table, TableContainer tableContainer) {
this.table = table;

var typeAheadHandler = new MyTypeAheadHandler(this, tableContainer);
typeAheadHandler.register();

registerRpc("UpdateName", (params) -> processUpdateNameRpcRequest(params));
registerRpc("GetPeopleWithName", (params) -> processGetPeopleNameRpcRequest(params));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.finos.vuu.core.module.typeahead

import org.finos.vuu.core.table.{DataTable, TableContainer}
import org.finos.vuu.net.{RequestContext, RpcNames}
import org.finos.vuu.net.rpc.{DefaultRpcHandler, RpcMethodCallResult, RpcMethodSuccess, RpcParams}
import org.finos.vuu.viewport.ViewPortColumns

class MyTypeAheadHandler(rpcRegistry: DefaultRpcHandler, tableContainer: TableContainer) {

def register(): Unit = {
rpcRegistry.registerRpc(RpcNames.UniqueFieldValuesRpc, params => processGetUniqueFieldValuesRequest(params))
rpcRegistry.registerRpc(RpcNames.UniqueFieldValuesStartWithRpc, params => processGetUniqueFieldValuesStartWithRequest(params))
}

def processGetUniqueFieldValuesRequest(params: RpcParams): RpcMethodCallResult = {
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 RpcMethodSuccess(values)
}

def processGetUniqueFieldValuesStartWithRequest(params: RpcParams): RpcMethodCallResult = {
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,
params.viewPortColumns.get,
null //todo what to do about request context
)
new RpcMethodSuccess(values) //how to control what viewport action to trigger?
}


def getUniqueFieldValues(tableName: String, moduleName: String, column: String, viewPortColumns: ViewPortColumns, ctx: RequestContext): Array[String] = {
tableContainer.getTable(tableName) match {
case dataTable: DataTable =>
val columValueProvider = dataTable.getColumnValueProvider
columValueProvider.getUniqueValuesVPColumn(column, viewPortColumns)
case null =>
throw new Exception("Could not find table by name:" + tableName)
}
}

def getUniqueFieldValuesStartingWith(tableName: String, moduleName: String, column: String, starts: String, viewPortColumns: ViewPortColumns, ctx: RequestContext): Array[String] = {
tableContainer.getTable(tableName) match {
case dataTable: DataTable =>
val columValueProvider = dataTable.getColumnValueProvider
columValueProvider.getUniqueValuesStartingWithVPColumn(column, starts, viewPortColumns)
case null =>
throw new Exception("Could not find table by name:" + tableName)
}
}
}

0 comments on commit d6d3dde

Please sign in to comment.