forked from finos/vuu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finos#850 Added first cut of rpc services for basket trading
- Loading branch information
1 parent
110a91b
commit d38d600
Showing
6 changed files
with
98 additions
and
14 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
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
68 changes: 68 additions & 0 deletions
68
vuu/src/main/scala/org/finos/vuu/core/module/basket/service/BasketService.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,68 @@ | ||
package org.finos.vuu.core.module.basket.service | ||
|
||
import com.typesafe.scalalogging.StrictLogging | ||
import org.finos.toolbox.time.Clock | ||
import org.finos.vuu.core.module.basket.BasketModule | ||
import org.finos.vuu.core.module.basket.BasketModule.BasketConstituentTable | ||
import org.finos.vuu.core.table.{DataTable, RowData, RowWithData, TableContainer} | ||
import org.finos.vuu.net.ClientSessionId | ||
import org.finos.vuu.net.rpc.RpcHandler | ||
import org.finos.vuu.viewport.{NoAction, SelectionViewPortMenuItem, ViewPortAction, ViewPortMenu, ViewPortSelection} | ||
|
||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
class BasketService(val table: DataTable, val tableContainer: TableContainer)(implicit clock: Clock) extends RpcHandler with StrictLogging { | ||
|
||
private val counter = new AtomicInteger(0) | ||
|
||
import org.finos.vuu.core.module.basket.BasketModule.{BasketTradingColumnNames => BT} | ||
import org.finos.vuu.core.module.basket.BasketModule.{BasketConstituentColumnNames => BC} | ||
import org.finos.vuu.core.module.basket.BasketModule.{BasketTradingConstituentColumnNames => BTC} | ||
|
||
private def getAndPadCounter(session: ClientSessionId): String = { | ||
val counterValue = counter.incrementAndGet() | ||
session.user + "-" + "".padTo(5 - counterValue.toString.length, "0").mkString + counterValue | ||
} | ||
|
||
private def getConstituentsForBasketKey(key: String): List[RowData] = { | ||
val table = tableContainer.getTable(BasketConstituentTable) | ||
val keys = table.primaryKeys.toList | ||
keys.map( key => table.pullRow(key) ).filter(_.get(BC.BasketId).toString == key) | ||
} | ||
|
||
def createBasket(selection: ViewPortSelection, session: ClientSessionId): ViewPortAction = { | ||
|
||
//logger.info("createBasket()") | ||
|
||
val basketKey = selection.rowKeyIndex.map({ case (key, _) => key }).toList.head | ||
|
||
val instanceKey = getAndPadCounter(session) | ||
|
||
val constituents = getConstituentsForBasketKey(basketKey) | ||
|
||
tableContainer.getTable(BasketModule.BasketTradingTable) match { | ||
case table: DataTable => | ||
table.processUpdate(instanceKey, RowWithData(instanceKey, Map(BT.InstanceId -> instanceKey, BT.Status -> "OFF-MARKET", BT.BasketId -> basketKey)), clock.now()) | ||
case null => | ||
} | ||
|
||
tableContainer.getTable(BasketModule.BasketTradingConstituent) match { | ||
case table: DataTable => | ||
constituents.foreach( rowData => { | ||
val constituentKey = instanceKey + "." + rowData.get(BTC.Ric) | ||
table.processUpdate(constituentKey, RowWithData(constituentKey, Map(BTC.BasketId -> basketKey, BTC.Ric -> rowData.get(BC.Ric) , BTC.InstanceId -> instanceKey, | ||
//BTC.Quantity -> rowData.get(BC.Quantity), | ||
BTC.InstanceIdRic -> constituentKey, | ||
BTC.Description -> rowData.get(BC.Description) | ||
)), clock.now()) | ||
}) | ||
case null => | ||
} | ||
|
||
NoAction() | ||
} | ||
|
||
override def menuItems(): ViewPortMenu = ViewPortMenu( | ||
new SelectionViewPortMenuItem("Create New", "", (sel, sess) => this.createBasket(sel, sess), "CREATE_NEW_BASKET"), | ||
) | ||
} |