private WebViewPortfolioGrid( ViewClient viewClient, CompiledViewDefinition compiledViewDefinition, List<PortfolioRow> rows, ResultConverterCache resultConverterCache, LocalSession local, ServerSession remote, ComputationTargetResolver computationTargetResolver) { super( "portfolio", viewClient, compiledViewDefinition, getTargets(rows), // [PLAT-2286] Hack to get PositionWeight results to show up ImmutableSet.of( ComputationTargetType.PORTFOLIO_NODE, ComputationTargetType.POSITION, ComputationTargetType.PORTFOLIO_NODE.containing(ComputationTargetType.POSITION)), resultConverterCache, local, remote, "Loading...", computationTargetResolver); _rowIdToRowMap = new HashMap<Integer, PortfolioRow>(); for (PortfolioRow row : rows) { final int[] rowIds = getGridStructure().getRowIds(row.getTarget()); for (int rowId : rowIds) { _rowIdToRowMap.put(rowId, row); } } }
private static List<ComputationTargetSpecification> getTargets(List<PortfolioRow> rows) { List<ComputationTargetSpecification> targets = new ArrayList<ComputationTargetSpecification>(rows.size()); for (PortfolioRow row : rows) { targets.add(row.getTarget()); } return targets; }
@Override protected void supplementCsvRowData( int rowId, ComputationTargetSpecification target, String[] row) { PortfolioRow portfolioRow = _rowIdToRowMap.get(rowId); PortfolioRow parentRow = portfolioRow.getParentRow(); String parentRowIdText = parentRow != null ? Integer.toString(getGridStructure().getRowIds(parentRow.getTarget())[0]) : null; String name; String quantity; if (target.getType() == ComputationTargetType.POSITION) { Position position = portfolioRow.getPosition(); name = position.getSecurity().getName(); quantity = position.getQuantity().toPlainString(); } else { name = portfolioRow.getAggregateName(); quantity = ""; } row[0] = Integer.toString(rowId); row[1] = parentRowIdText; row[2] = name; row[3] = quantity; }
@Override protected void addRowDetails(UniqueId target, int rowId, Map<String, Object> details) { PortfolioRow row = _rowIdToRowMap.get(rowId); details.put("indent", row.getDepth()); if (row.getParentRow() != null) { final int[] parentRowIds = getGridStructure().getRowIds(row.getParentRow().getTarget()); details.put("parentRowId", parentRowIds[0]); } ComputationTargetType targetType = row.getTarget().getType(); details.put("type", targetType.toString()); if (targetType == ComputationTargetType.POSITION) { Position position = row.getPosition(); details.put("posId", position.getUniqueId()); details.put("position", position.getSecurity().getName()); DoubleValueFormatter formatter = new DoubleValueOptionalDecimalPlaceFormatter(); details.put( "quantity", position.getQuantity().signum() == 0 ? "0" : formatter.format(position.getQuantity())); } else { details.put("position", row.getAggregateName()); } }