/** * @param target The target whose result is required * @param resultModel The model containing the results * @param resultTimestamp The timestamp of the results * @return {@code {"rowId": rowId, "0": col0Val, "1": col1Val, ...}} cell values: {@code {"v": * value, "h": [historyVal1, historyVal2, ...]}} */ public Map<String, Object> getTargetResult( ComputationTargetSpecification target, ViewTargetResultModel resultModel, Long resultTimestamp) { Integer rowId = getGridStructure().getRowId(target); if (rowId == null) { // Result not in the grid return Collections.emptyMap(); } Map<String, Object> valuesToSend = createTargetResult(rowId); // insert nulls into the results for cells which are unsatisfied in the dependency graph for (Integer unsatisfiedColId : getGridStructure().getUnsatisfiedCells(rowId)) { valuesToSend.put(Integer.toString(unsatisfiedColId), null); } // Whether or not the row is in the viewport, we may have to store history if (resultModel != null) { for (String calcConfigName : resultModel.getCalculationConfigurationNames()) { for (ComputedValue value : resultModel.getAllValues(calcConfigName)) { ValueSpecification specification = value.getSpecification(); Collection<WebViewGridColumn> columns = getGridStructure().getColumns(calcConfigName, specification); if (columns == null) { // Expect a column for every value s_logger.warn( "Could not find column for calculation configuration {} with value specification {}", calcConfigName, specification); continue; } Object originalValue = value.getValue(); for (WebViewGridColumn column : columns) { int colId = column.getId(); WebGridCell cell = WebGridCell.of(rowId, colId); ResultConverter<Object> converter; if (originalValue == null) { converter = null; } else { converter = getConverter( column, value.getSpecification().getValueName(), originalValue.getClass()); } Map<String, Object> cellData = getCellValue(cell, specification, originalValue, resultTimestamp, converter); if (cellData != null) { valuesToSend.put(Integer.toString(colId), cellData); } } } } } return valuesToSend; }
@Override protected String[][] getRawDataRows(ViewComputationResultModel result) { String[][] rows = new String[getGridStructure().getTargets().size()][]; int columnCount = getGridStructure().getColumns().size() + getAdditionalCsvColumnCount(); int offset = getCsvDataColumnOffset(); for (ComputationTargetSpecification target : result.getAllTargets()) { Integer rowId = getGridStructure().getRowId(target); if (rowId == null) { continue; } ViewTargetResultModel resultModel = result.getTargetResult(target); String[] values = new String[columnCount]; supplementCsvRowData(rowId, target, values); rows[rowId] = values; for (String calcConfigName : resultModel.getCalculationConfigurationNames()) { for (ComputedValue value : resultModel.getAllValues(calcConfigName)) { Object originalValue = value.getValue(); if (originalValue == null) { continue; } ValueSpecification specification = value.getSpecification(); Collection<WebViewGridColumn> columns = getGridStructure().getColumns(calcConfigName, specification); if (columns == null) { // Expect a column for every value s_logger.warn( "Could not find column for calculation configuration {} with value specification {}", calcConfigName, specification); continue; } for (WebViewGridColumn column : columns) { int colId = column.getId(); ResultConverter<Object> converter = getConverter( column, value.getSpecification().getValueName(), originalValue.getClass()); values[offset + colId] = converter.convertToText( getConverterCache(), value.getSpecification(), originalValue); } } } } return rows; }