Skip to content

Commit

Permalink
finos#1353 remove legacy/unused code and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
junaidzm13 committed May 23, 2024
1 parent b647a3b commit d2af9d9
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 80 deletions.
4 changes: 2 additions & 2 deletions docs/rpc/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ object TypeAheadModule extends DefaultModule {

def apply()(implicit clock: Clock, lifecycle: LifecycleContainer): ViewServerModule = {
ModuleFactory.withNamespace(NAME)
.addRpcHandler(server => new TypeAheadRpcHandlerImpl(server.tableContainer))
.addRpcHandler(server => new GenericTypeAheadRpcHandler(server.tableContainer))
.asModule()
}
}
```

You can see we've defined an RpcHandler called TypeAheadRpcHandlerImpl, which implements the interface:
You can see we've defined an RpcHandler called GenericTypeAheadRpcHandler, which implements the interface:

```scala
trait TypeAheadRpcHandler{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,70 +1,8 @@
package org.finos.vuu.core.module.typeahead

import com.typesafe.scalalogging.StrictLogging
import org.finos.vuu.core.table.{Column, DataTable, TableContainer}
import org.finos.vuu.net.RequestContext
import org.finos.vuu.net.rpc.RpcHandler

trait TypeAheadRpcHandler{
def getUniqueFieldValues(tableMap: Map[String, String], column: String, ctx: RequestContext): Array[String]
def getUniqueFieldValuesStartingWith(tableMap: Map[String, String], column: String, starts: String, ctx: RequestContext): Array[String]
}


class TypeAheadRpcHandlerImpl(val tableContainer: TableContainer) extends RpcHandler with StrictLogging with TypeAheadRpcHandler {

private def addUnique(dt: DataTable, c: Column, set: Set[String], key: String): Set[String] = {
val row = dt.pullRow(key)
row.get(c) match {
case null =>
Set()
case x: String =>
set.+(x)
case x: Long =>
set.+(x.toString)
case x: Double =>
set.+(x.toString)
case x: Int =>
set.+(x.toString)
case x =>
set.+(x.toString)
}
}


override def getUniqueFieldValuesStartingWith(tableMap: Map[String, String], column: String, starts: String, ctx: RequestContext): Array[String] = {
val tableName = tableMap("table")

tableContainer.getTable(tableName) match {
case dataTable: DataTable =>
dataTable.columnForName(column) match {
case c: Column =>
dataTable.primaryKeys.foldLeft(Set[String]())(addUnique(dataTable, c, _, _)).filter(_.startsWith(starts)).toArray.sorted.take(10)
case null =>
logger.error(s"Column ${column} not found in table ${tableName}")
Array()
}
case null =>
throw new Exception("Could not find table by name:" + tableName)
}
}

def getUniqueFieldValues(tableMap: Map[String, String], column: String, ctx: RequestContext): Array[String] = {

val tableName = tableMap("table")

tableContainer.getTable(tableName) match {
case dataTable: DataTable =>
dataTable.columnForName(column) match {
case c: Column =>
dataTable.primaryKeys.foldLeft(Set[String]())(addUnique(dataTable, c, _, _)).toArray.sorted.take(10)
case null =>
logger.error(s"Column ${column} not found in table ${tableName}")
Array()
}
case null =>
throw new Exception("Could not find table by name:" + tableName)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TypeAheadModuleTest extends AnyFeatureSpec with Matchers with GivenWhenThe

def callGetUniqueFieldValues(tables: TableContainer, column: String): Array[String] = {

val typeAheadRpc = new TypeAheadRpcHandlerImpl(tables)
val typeAheadRpc = new GenericTypeAheadRpcHandler(tables)

val ctx = RequestContext("", ClientSessionId("", ""), null, "")

Expand All @@ -33,7 +33,7 @@ class TypeAheadModuleTest extends AnyFeatureSpec with Matchers with GivenWhenThe

def callGetUniqueFieldValuesStarting(tables: TableContainer, column: String, starts: String): Array[String] = {

val typeAheadRpc = new TypeAheadRpcHandlerImpl(tables)
val typeAheadRpc = new GenericTypeAheadRpcHandler(tables)

val ctx = new RequestContext("", ClientSessionId("", ""), null, "")

Expand Down

0 comments on commit d2af9d9

Please sign in to comment.