-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1434 adding test for type ahead request at a view port level. Data i…
…s loaded into table at initialisation
- Loading branch information
1 parent
58ac06a
commit 4e7c25e
Showing
7 changed files
with
167 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
vuu/src/main/scala/org/finos/vuu/core/module/typeahead/ViewPortTypeAheadRpcHandler.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.finos.vuu.core.module.typeahead | ||
|
||
import com.typesafe.scalalogging.StrictLogging | ||
import org.finos.vuu.core.table.{DataTable, TableContainer} | ||
import org.finos.vuu.net.RequestContext | ||
import org.finos.vuu.net.rpc.{DefaultRpcHandler, RpcMethodCallResult, RpcMethodSuccess, RpcParams} | ||
|
||
class ViewPortTypeAheadRpcHandler(tableContainer: TableContainer) extends DefaultRpcHandler with StrictLogging { | ||
|
||
this.registerRpc("getUniqueFieldValues", params => processGetUniqueFieldValuesRequest(params)) | ||
this.registerRpc("getUniqueFieldValuesStartingWith", 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, | ||
null //todo what to do about request context | ||
) | ||
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, | ||
null //todo what to do about request context | ||
) | ||
RpcMethodSuccess(values) //how to control what viewport action to trigger? | ||
} | ||
|
||
def getUniqueFieldValues(tableName: String, moduleName: String, column: String, ctx: RequestContext): Array[String] = { | ||
tableContainer.getTable(tableName) match { | ||
case dataTable: DataTable => | ||
val columValueProvider = dataTable.getColumnValueProvider | ||
columValueProvider.getUniqueValues(column) | ||
case null => | ||
throw new Exception("Could not find table by name:" + tableName) | ||
} | ||
} | ||
|
||
def getUniqueFieldValuesStartingWith(tableName: String, moduleName: String, column: String, starts: String, ctx: RequestContext): Array[String] = { | ||
tableContainer.getTable(tableName) match { | ||
case dataTable: DataTable => | ||
val columValueProvider = dataTable.getColumnValueProvider | ||
columValueProvider.getUniqueValuesStartingWith(column, starts) | ||
case null => | ||
throw new Exception("Could not find table by name:" + tableName) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.finos.vuu.net | ||
|
||
import com.typesafe.scalalogging.StrictLogging | ||
import org.finos.toolbox.time.Clock | ||
import org.finos.vuu.core.table.{DataTable, RowWithData} | ||
import org.finos.vuu.provider.Provider | ||
|
||
class TestProvider(table: DataTable, fakeDataSource: FakeDataSource)(implicit clock: Clock) extends Provider with StrictLogging { | ||
|
||
override def subscribe(key: String): Unit = {} | ||
|
||
override def doStart(): Unit = { | ||
logger.info(s"Test Provider for ${table.name}- Starting") | ||
} | ||
|
||
override def doStop(): Unit = { | ||
logger.info(s"Test Provider for ${table.name}- Stopping") | ||
} | ||
|
||
override def doInitialize(): Unit = { | ||
logger.info(s"Test Provider for ${table.name}- Initialising") | ||
fakeDataSource.get() | ||
.foreach(row => { | ||
table.processUpdate(row._1, RowWithData(row._1, row._2), clock.now()) | ||
}) | ||
} | ||
|
||
override def doDestroy(): Unit = {} | ||
|
||
override val lifecycleId: String = s"TestProvider ${table.name}" | ||
} | ||
class FakeDataSource(rows: Map[String, Map[String, Any]]) { | ||
type RowKey = String | ||
type ColumnName = String | ||
|
||
def get(): Map[RowKey, Map[ColumnName, Any]] = { | ||
rows | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters