Skip to content

Commit

Permalink
#1019 converting weighting and limit price field to a double as json …
Browse files Browse the repository at this point in the history
…serialisation parse it as BigDecimal or Integer
  • Loading branch information
naleeha committed Nov 27, 2023
1 parent 99cefd4 commit 82931ad
Showing 1 changed file with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import org.finos.vuu.net.rpc.{EditRpcHandler, RpcHandler}
import org.finos.vuu.net.{ClientSessionId, RequestContext}
import org.finos.vuu.viewport._

import scala.util.control.NonFatal


trait BasketTradingConstituentJoinServiceIF extends EditRpcHandler {
def setSell(selection: ViewPortSelection, session: ClientSessionId): ViewPortAction
Expand Down Expand Up @@ -77,12 +79,30 @@ class BasketTradingConstituentJoinService(val table: DataTable, val tableContain
}

private def onEditCell(key: String, columnName: String, data: Any, vp: ViewPort, session: ClientSessionId): ViewPortEditAction = {
getBaseTable() match {
case Some(baseTable: DataTable) =>
baseTable.processUpdate(key, RowWithData(key, Map(ColumnName.InstanceIdRic -> key, columnName -> data)), clock.now())
ViewPortEditSuccess()
case None =>
ViewPortEditFailure("Could not find base table")
try {
getBaseTable() match {
case Some(baseTable: DataTable) =>
columnName match {
case ColumnName.Weighting | ColumnName.LimitPrice =>
val doubleValue = convertToDouble(data)
baseTable.processUpdate(key, RowWithData(key, Map(ColumnName.InstanceIdRic -> key, columnName -> doubleValue)), clock.now())
case _ => baseTable.processUpdate(key, RowWithData(key, Map(ColumnName.InstanceIdRic -> key, columnName -> data)), clock.now())
}
ViewPortEditSuccess()
case None =>
ViewPortEditFailure("Could not find base table for basket trading constituent join ")
}
} catch {
case NonFatal(t) => ViewPortEditFailure(s"Could not update $columnName. $t")
}
}
private def convertToDouble(data:Any): Double = {
data match {
case decimalValue: java.math.BigDecimal =>
decimalValue.doubleValue
case integer: java.lang.Integer => integer.toDouble
case int: Int => int.toDouble
case _ => data.asInstanceOf[Double]
}
}

Expand Down

0 comments on commit 82931ad

Please sign in to comment.