diff --git a/vuu/src/main/scala/org/finos/vuu/core/sort/FilterAndSort.scala b/vuu/src/main/scala/org/finos/vuu/core/sort/FilterAndSort.scala index 504607315..9b1ba6d82 100644 --- a/vuu/src/main/scala/org/finos/vuu/core/sort/FilterAndSort.scala +++ b/vuu/src/main/scala/org/finos/vuu/core/sort/FilterAndSort.scala @@ -16,7 +16,7 @@ case class VisualLinkedFilter(viewPortVisualLink: ViewPortVisualLink) extends Fi childColumn: Column, source: RowSource, primaryKeys: TablePrimaryKeys): TablePrimaryKeys = { if (parentSelectionKeys.isEmpty) { - InMemTablePrimaryKeys(ImmutableArray.empty[String]) + primaryKeys } else { source.asTable.indexForColumn(childColumn) match { case Some(index: StringIndexedField) if childColumn.dataType == DataType.StringDataType => @@ -64,9 +64,11 @@ case class VisualLinkedFilter(viewPortVisualLink: ViewPortVisualLink) extends Fi val parentColumn = viewPortVisualLink.parentColumn val childColumn = viewPortVisualLink.childColumn - val filtered = doFilterByIndexIfPossible(parentSelectionKeys, parentColumn, childColumn, source, primaryKeys) + val filtered = doFilterByIndexIfPossible(parentSelectionKeys, parentColumn, childColumn, source, primaryKeys) filtered + + } } @@ -108,18 +110,20 @@ case class AntlrBasedFilter(clause: FilterClause) extends Filter with StrictLogg trait FilterAndSort { - def filterAndSort(source: RowSource, primaryKeys: TablePrimaryKeys, vpColumns:ViewPortColumns, permission: Option[RowPermissionChecker]): TablePrimaryKeys + def filterAndSort(source: RowSource, primaryKeys: TablePrimaryKeys, vpColumns: ViewPortColumns, permission: Option[RowPermissionChecker]): TablePrimaryKeys + def filter: Filter + def sort: Sort } case class UserDefinedFilterAndSort(filter: Filter, sort: Sort) extends FilterAndSort with StrictLogging { - override def filterAndSort(source: RowSource, primaryKeys: TablePrimaryKeys, vpColumns:ViewPortColumns, checkerOption: Option[RowPermissionChecker]): TablePrimaryKeys = { - try { + override def filterAndSort(source: RowSource, primaryKeys: TablePrimaryKeys, vpColumns: ViewPortColumns, checkerOption: Option[RowPermissionChecker]): TablePrimaryKeys = { + try { val realizedFilter = checkerOption match { case Some(checker) => TwoStepCompoundFilter(RowPermissionFilter(checker), filter) - case None=> filter + case None => filter } val filteredKeys = realizedFilter.dofilter(source, primaryKeys, vpColumns) @@ -142,7 +146,9 @@ class NoFilterNoSort() extends FilterAndSort { override def filterAndSort(source: RowSource, primaryKeys: TablePrimaryKeys, viewPortColumns: ViewPortColumns, checkerOption: Option[RowPermissionChecker]): TablePrimaryKeys = { primaryKeys } + override def filter: Filter = NoFilter + override def sort: Sort = NoSort } diff --git a/vuu/src/test/scala/org/finos/vuu/viewport/VisualLinkedTreeViewPortTest.scala b/vuu/src/test/scala/org/finos/vuu/viewport/VisualLinkedTreeViewPortTest.scala index 3aa087c96..8e4875ac8 100644 --- a/vuu/src/test/scala/org/finos/vuu/viewport/VisualLinkedTreeViewPortTest.scala +++ b/vuu/src/test/scala/org/finos/vuu/viewport/VisualLinkedTreeViewPortTest.scala @@ -83,8 +83,8 @@ class VisualLinkedTreeViewPortTest extends AbstractViewPortTestCase with Matcher And("we run the container once through") viewPortContainer.runOnce() - Then("we should have nothing available in the viewport") - viewPortOrders.getKeys.length shouldEqual 0 + Then("we should show all by default in the viewport") + viewPortOrders.getKeys.length shouldEqual 12 When("we select some rows in the grid") viewPortContainer.changeSelection(session, outQueue, viewPortPricesGroupBy.id, ViewPortSelectedIndices(Array(5))) @@ -146,8 +146,8 @@ class VisualLinkedTreeViewPortTest extends AbstractViewPortTestCase with Matcher viewPortContainer.changeSelection(session, outQueue, viewPortPricesGroupBy.id, ViewPortSelectedIndices(Array())) viewPortContainer.runOnce() - Then("we should have nothing available in the viewport") - viewPortOrders.getKeys.length shouldEqual 0 + Then("we should show all by default in the viewport") + viewPortOrders.getKeys.length shouldEqual 12 } } } diff --git a/vuu/src/test/scala/org/finos/vuu/viewport/VisualLinkedViewPortTest.scala b/vuu/src/test/scala/org/finos/vuu/viewport/VisualLinkedViewPortTest.scala index 2e0ca0b9b..c77816e7f 100644 --- a/vuu/src/test/scala/org/finos/vuu/viewport/VisualLinkedViewPortTest.scala +++ b/vuu/src/test/scala/org/finos/vuu/viewport/VisualLinkedViewPortTest.scala @@ -3,7 +3,7 @@ package org.finos.vuu.viewport import org.finos.toolbox.jmx.{MetricsProvider, MetricsProviderImpl} import org.finos.toolbox.lifecycle.LifecycleContainer import org.finos.toolbox.time.{Clock, TestFriendlyClock} -import org.finos.vuu.api.{Index, Indices, Link, TableDef, VisualLinks} +import org.finos.vuu.api._ import org.finos.vuu.client.messages.RequestId import org.finos.vuu.core.table.TableTestHelper.combineQs import org.finos.vuu.core.table.{Columns, TableContainer, ViewPortColumnCreator} @@ -86,8 +86,8 @@ class VisualLinkedViewPortTest extends AbstractViewPortTestCase with Matchers wi And("we run the container once through") viewPortContainer.runOnce() - Then("we should have nothing available in the viewport") - viewPortOrders.getKeys.length shouldEqual 0 + Then("we should show all by default in the viewport") + viewPortOrders.getKeys.length shouldEqual 12 When("we select some rows in the grid") viewPortContainer.changeSelection(session, outQueue, viewPortPrices.id, ViewPortSelectedIndices(Array(1))) @@ -103,6 +103,8 @@ class VisualLinkedViewPortTest extends AbstractViewPortTestCase with Matchers wi And("we run the container once through to pick up ") viewPortContainer.runOnce() + Then("check we now have 4 keys in the viewport") + viewPortOrders.getKeys.length shouldEqual 4 assertVpEqWithMeta(combineQs(viewPortOrders)) { Table( ("sel" ,"orderId" ,"trader" ,"ric" ,"tradeTime","quantity"), @@ -118,6 +120,8 @@ class VisualLinkedViewPortTest extends AbstractViewPortTestCase with Matchers wi viewPortContainer.runOnce() + Then("check we now have 9 keys in the viewport") + viewPortOrders.getKeys.length shouldEqual 9 Then("Check we still maintain the selection") assertVpEqWithMeta(combineQs(viewPortOrders).filter(vpu => vpu.vp.id == viewPortOrders.id)) { Table( @@ -130,15 +134,28 @@ class VisualLinkedViewPortTest extends AbstractViewPortTestCase with Matchers wi ) } - Then("check we now have 9 keys in the viewport") - viewPortOrders.getKeys.length shouldEqual 9 - And("if we set selection to none") viewPortContainer.changeSelection(session, outQueue, viewPortPrices.id, ViewPortSelectedIndices(Array())) viewPortContainer.runOnce() - Then("we should have nothing available in the viewport") - viewPortOrders.getKeys.length shouldEqual 0 + Then("we should show all by default in the viewport") + viewPortOrders.getKeys.length shouldEqual 12 + + assertVpEqWithMeta(combineQs(viewPortOrders).filter(vpu => vpu.vp.id == viewPortOrders.id)) { + Table( + ("sel", "orderId", "trader", "ric", "tradeTime", "quantity"), + (0, "NYC-0000", "chris", "VOD.L", 1311544800000L, 100), + (0, "NYC-0001", "chris", "VOD.L", 1311544800010L, 101), + (0, "NYC-0002", "chris", "VOD.L", 1311544800020L, 102), + (0, "NYC-0003", "chris", "BT.L", 1311544800030L, 100), + (0, "NYC-0004", "chris", "BT.L", 1311544800040L, 101), + (0, "NYC-0005", "chris", "BT.L", 1311544800050L, 102), + (0, "NYC-0006", "chris", "BT.L", 1311544800060L, 103), + (0, "NYC-0007", "chris", "BP.L", 1311544800070L, 100), + (0, "NYC-0008", "chris", "BP.L", 1311544800080L, 101), + (0, "NYC-0009", "chris", "BP.L", 1311544800090L, 102) + ) + } Then("Change the viewport to sort by quantity") viewPortContainer.change(RequestId.oneNew(), session, viewPortOrders.id, ViewPortRange(0, 10), vpcolumnsOrders, SortSpec(List(SortDef("quantity", 'D')))) @@ -146,16 +163,8 @@ class VisualLinkedViewPortTest extends AbstractViewPortTestCase with Matchers wi viewPortContainer.runOnce() - Then("Check we still maintain the selection even with a new sort or filter") - assertVpEqWithMeta(combineQs(viewPortOrders).filter(vpu => vpu.vp.id == viewPortOrders.id)) { - Table( - ("sel" ,"orderId" ,"trader" ,"ric" ,"tradeTime","quantity"), - (0 ,"NYC-0003","chris" ,"BT.L" ,1311544800030L,100 ), - (0 ,"NYC-0004","chris" ,"BT.L" ,1311544800040L,101 ), - (0 ,"NYC-0005","chris" ,"BT.L" ,1311544800050L,102 ), - (0 ,"NYC-0006","chris" ,"BT.L" ,1311544800060L,103 ) - ) - } + Then("check we now have 4 keys in the viewport") + viewPortOrders.getKeys.length shouldEqual 4 Then("Check we can remove the visual linking") @@ -292,8 +301,8 @@ class VisualLinkedViewPortTest extends AbstractViewPortTestCase with Matchers wi And("we run the container once through") viewPortContainer.runOnce() - Then("we should have nothing available in the viewport") - viewPortOrders1.getKeys.length shouldEqual 0 + Then("we should show all by default in the viewport") + viewPortOrders1.getKeys.length shouldEqual 12 When("we select second row in the grid") viewPortContainer.changeSelection(session, outQueue, viewPortOrders2.id, ViewPortSelectedIndices(Array(1))) @@ -316,5 +325,74 @@ class VisualLinkedViewPortTest extends AbstractViewPortTestCase with Matchers wi ) } } + + Scenario("should show all when no parent is selected") { + + implicit val clock: Clock = new TestFriendlyClock(TestTimeStamp.EPOCH_DEFAULT) + implicit val metrics: MetricsProvider = new MetricsProviderImpl + + Given("we've created a viewport with orders in") + val (viewPortContainer, orders, ordersProvider, prices, pricesProvider, session, outQueue) = createDefaultOrderPricesViewPortInfra() + + val vpcolumnsOrders = ViewPortColumnCreator.create(orders, List("orderId", "trader", "tradeTime", "quantity", "ric")) + val vpcolumnsPrices = ViewPortColumnCreator.create(prices, List("ric", "bid", "ask", "last", "open")) + + createPricesRow(pricesProvider, "VOD.L", 100, 101, 100.5, 99.5) + createPricesRow(pricesProvider, "BT.L", 200, 201, 200.5, 199.5) + createPricesRow(pricesProvider, "BP.L", 300, 301, 300.5, 299.5) + + createNOrderRows(ordersProvider, 3)(clock) + createNOrderRows(ordersProvider, 4, ric = "BT.L", idOffset = 3)(clock) + createNOrderRows(ordersProvider, 5, ric = "BP.L", idOffset = 7)(clock) + + val viewPortOrders = viewPortContainer.create(RequestId.oneNew(), session, outQueue, orders, ViewPortRange(0, 10), vpcolumnsOrders) + val viewPortPrices = viewPortContainer.create(RequestId.oneNew(), session, outQueue, prices, ViewPortRange(0, 10), vpcolumnsPrices) + + viewPortContainer.runOnce() + + val combinedUpdates = combineQs(viewPortOrders) + + val priceUpdates = combinedUpdates.filter(_.vp.id == viewPortPrices.id) + val orderUpdates = combinedUpdates.filter(_.vp.id == viewPortOrders.id) + + assertVpEqWithMeta(orderUpdates) { + Table( + ("sel", "orderId", "trader", "ric", "tradeTime", "quantity"), + (0, "NYC-0000", "chris", "VOD.L", 1311544800000L, 100), + (0, "NYC-0001", "chris", "VOD.L", 1311544800010L, 101), + (0, "NYC-0002", "chris", "VOD.L", 1311544800020L, 102), + (0, "NYC-0003", "chris", "BT.L", 1311544800030L, 100), + (0, "NYC-0004", "chris", "BT.L", 1311544800040L, 101), + (0, "NYC-0005", "chris", "BT.L", 1311544800050L, 102), + (0, "NYC-0006", "chris", "BT.L", 1311544800060L, 103), + (0, "NYC-0007", "chris", "BP.L", 1311544800070L, 100), + (0, "NYC-0008", "chris", "BP.L", 1311544800080L, 101), + (0, "NYC-0009", "chris", "BP.L", 1311544800090L, 102) + ) + } + + assertVpEqWithMeta(priceUpdates) { + Table( + ("sel", "ric", "bid", "ask", "last", "open"), + (0, "BP.L", 300.0, 301.0, 300.5, null), + (0, "BT.L", 200.0, 201.0, 200.5, null), + (0, "VOD.L", 100.0, 101.0, 100.5, null) + ) + } + + val results = viewPortContainer.getViewPortVisualLinks(session, viewPortOrders.id) + results.size shouldEqual 1 + results.head._2.table.name shouldEqual "prices" + + Then("we link the viewports, with nothing selected in the parent grid yet") + viewPortContainer.linkViewPorts(session, outQueue, childVpId = viewPortOrders.id, parentVpId = viewPortPrices.id, "ric", "ric") + + And("we run the container once through") + viewPortContainer.runOnce() + + Then("we should show all by default in the viewport") + viewPortOrders.getKeys.length shouldEqual 12 + } + } }