コード例 #1
0
 private Map<String, Object> getJsonColumnStructures(Collection<WebViewGridColumn> columns) {
   Map<String, Object> columnStructures = new HashMap<String, Object>(columns.size());
   for (WebViewGridColumn columnDetails : columns) {
     columnStructures.put(
         Integer.toString(columnDetails.getId()), getJsonColumnStructure(columnDetails));
   }
   return columnStructures;
 }
コード例 #2
0
  /**
   * @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;
  }
コード例 #3
0
 @Override
 protected String[][] getRawDataColumnHeaders() {
   Collection<WebViewGridColumn> columns = getGridStructure().getColumns();
   int additionalColumns = getAdditionalCsvColumnCount();
   int columnCount = columns.size() + additionalColumns;
   String[] header1 = new String[columnCount];
   String[] header2 = new String[columnCount];
   supplementCsvColumnHeaders(header1);
   int offset = getCsvDataColumnOffset();
   for (WebViewGridColumn column : columns) {
     header1[offset + column.getId()] = column.getHeader();
     header2[offset + column.getId()] = column.getDescription();
   }
   return new String[][] {header1, header2};
 }
コード例 #4
0
 @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;
 }
コード例 #5
0
 // TODO this publishes to the client. not nice for a method named get*
 @SuppressWarnings("unchecked")
 private ResultConverter<Object> getConverter(
     WebViewGridColumn column, String valueName, Class<?> valueType) {
   // Ensure the converter is cached against the value name before sending the column details
   ResultConverter<Object> converter =
       (ResultConverter<Object>) getConverterCache().getAndCacheConverter(valueName, valueType);
   if (!column.isTypeKnown()) {
     // TODO what's this all about?
     // getRemoteClient().deliver(getLocalClient(), _columnStructureChannel,
     // getJsonColumnStructures(Collections.singleton(column)), null);
   }
   return converter;
 }
コード例 #6
0
  private Map<String, Object> getJsonColumnStructure(WebViewGridColumn column) {
    Map<String, Object> detailsToSend = new HashMap<String, Object>();
    long colId = column.getId();
    detailsToSend.put("colId", colId);
    detailsToSend.put("header", column.getHeader());
    detailsToSend.put("description", column.getValueName() + ":\n" + column.getDescription());
    detailsToSend.put("nullValue", _nullCellValue);

    String resultType = getConverterCache().getKnownResultTypeName(column.getValueName());
    if (resultType != null) {
      column.setTypeKnown(true);
      detailsToSend.put("dataType", resultType);

      // Hack - the client should decide which columns it requires history for, taking into account
      // the capabilities of
      // the renderer.
      if (resultType.equals("DOUBLE")) {
        addHistoryOutput(column.getId());
      }
    }
    return detailsToSend;
  }