Package com.google.visualization.datasource.datatable

Examples of com.google.visualization.datasource.datatable.DataTable


      // Split the query.
      QueryPair query = DataSourceHelper.splitQuery(dsRequest.getQuery(), Capabilities.SELECT);

      // Generate the data table.
      DataTable data = generateMyDataTable(query.getDataSourceQuery(), req);

      // Apply the completion query to the data table.
      DataTable newData = DataSourceHelper.applyQuery(query.getCompletionQuery(), data,
          dsRequest.getUserLocale());

      DataSourceHelper.setServletResponse(newData, dsRequest, resp);
    } catch (RuntimeException rte) {
      log.error("A runtime exception has occured", rte);
View Full Code Here


   * @param query The selection query.
   *
   * @return A data table of animals.
   */
  private DataTable generateAnimalsTable(Query query) throws TypeMismatchException {
    DataTable data = new DataTable();
    List<ColumnDescription> requiredColumns = getRequiredColumns(query,
        ANIMAL_TABLE_COLUMNS);
    data.addColumns(requiredColumns);

    // Populate the data table
    for (String key : animalLinksByName.keySet()) {
      TableRow row = new TableRow();
      for (ColumnDescription selectionColumn : requiredColumns) {
        String columnName = selectionColumn.getId();
        if (columnName.equals(ANIMAL_COLUMN)) {
          row.addCell(key);
        } else if (columnName.equals(ARTICLE_COLUMN)) {
          row.addCell(animalLinksByName.get(key));
        }
      }
      data.addRow(row);
    }
    return data;
  }
View Full Code Here

   * @param query The selection query.
   *
   * @return planets data table.
   */
  private DataTable generatePlanetsTable(Query query) throws TypeMismatchException {
    DataTable data = new DataTable();
    List<ColumnDescription> requiredColumns = getRequiredColumns(
        query, planetTableColumns);
    data.addColumns(requiredColumns);

    // Populate data table
    for (Planet planet : Planet.values()) {
      TableRow row = new TableRow();
      for (ColumnDescription selectionColumn : requiredColumns) {
        String columnName = selectionColumn.getId();
        if (columnName.equals(PLANET_COLUMN)) {
          row.addCell(planet.name());
        } else if (columnName.equals(MASS_COLUMN)) {
          row.addCell(planet.getMass());
        } else if (columnName.equals(GRAVITY_COLUMN)) {
          row.addCell(planet.getSurfaceGravity());
        } else if (columnName.equals(MOONS_COLUMN)) {
          row.addCell(planet.getNumberOfMoons());
        }
      }
      data.addRow(row);
    }
    return data;
  }
View Full Code Here

      throw new DataSourceException(ReasonType.INVALID_REQUEST, "url is malformed: " + url);
    } catch (IOException e) {
      log.error("Couldn't read from url: " + url, e);
      throw new DataSourceException(ReasonType.INVALID_REQUEST, "Couldn't read from url: " + url);
    }
    DataTable dataTable = null;
    ULocale requestLocale = DataSourceHelper.getLocaleFromRequest(request);
    try {
      // Note: We assume that all the columns in the CSV file are text columns. In cases where the
      // column types are known in advance, this behavior can be overridden by passing a list of
      // ColumnDescription objects specifying the column types. See CsvDataSourceHelper.read() for
View Full Code Here

public class SimpleExampleServlet extends DataSourceServlet {

  @Override
  public DataTable generateDataTable(Query query, HttpServletRequest request) {
    // Create a data table.
    DataTable data = new DataTable();
    ArrayList<ColumnDescription> cd = new ArrayList<ColumnDescription>();
    cd.add(new ColumnDescription("name", ValueType.TEXT, "Animal name"));
    cd.add(new ColumnDescription("link", ValueType.TEXT, "Link to wikipedia"));
    cd.add(new ColumnDescription("population", ValueType.NUMBER, "Population size"));
    cd.add(new ColumnDescription("vegeterian", ValueType.BOOLEAN, "Vegetarian?"));

    data.addColumns(cd);

    // Fill the data table.
    try {
      data.addRowFromValues("Aye-aye", "http://en.wikipedia.org/wiki/Aye-aye", 100, true);
      data.addRowFromValues("Sloth", "http://en.wikipedia.org/wiki/Sloth", 300, true);
      data.addRowFromValues("Leopard", "http://en.wikipedia.org/wiki/Leopard", 50, false);
      data.addRowFromValues("Tiger", "http://en.wikipedia.org/wiki/Tiger", 80, false);
    } catch (TypeMismatchException e) {
      System.out.println("Invalid type!");
    }
    return data;
  }
View Full Code Here

  private static final Log log = LogFactory.getLog(SimpleExampleServlet2.class.getName());
 
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException {
    DataTable data = generateMyDataTable();
    DataSourceRequest dsRequest = null;

    try {
      // Extract the datasource request parameters.
      dsRequest = new DataSourceRequest(req);

      // NOTE: If you want to work in restricted mode, which means that only
      // requests from the same domain can access the data source, uncomment the following call.
      //
      // DataSourceHelper.verifyAccessApproved(dsRequest);

      // Apply the query to the data table.
      DataTable newData = DataSourceHelper.applyQuery(dsRequest.getQuery(), data,
          dsRequest.getUserLocale());

      // Set the response.
      DataSourceHelper.setServletResponse(newData, dsRequest, resp);
    } catch (RuntimeException rte) {
View Full Code Here

    }
  }

  private DataTable generateMyDataTable() {
    // Create a data table,
    DataTable data = new DataTable();
    ArrayList<ColumnDescription> cd = new ArrayList<ColumnDescription>();
    cd.add(new ColumnDescription("name", ValueType.TEXT, "Animal name"));
    cd.add(new ColumnDescription("link", ValueType.TEXT, "Link to wikipedia"));
    cd.add(new ColumnDescription("population", ValueType.NUMBER, "Population size"));
    cd.add(new ColumnDescription("vegeterian", ValueType.BOOLEAN, "Vegetarian?"));

    data.addColumns(cd);

    // Fill the data table.
    try {
      data.addRowFromValues("Aye-aye", "http://en.wikipedia.org/wiki/Aye-aye", 100, true);
      data.addRowFromValues("Sloth", "http://en.wikipedia.org/wiki/Sloth", 300, true);
      data.addRowFromValues("Leopard", "http://en.wikipedia.org/wiki/Leopard", 50, false);
      data.addRowFromValues("Tiger", "http://en.wikipedia.org/wiki/Tiger", 80, false);
    } catch (TypeMismatchException e) {
      System.out.println("Invalid type!");
    }
    return data;
View Full Code Here

   * @param query The selection query.
   *
   * @return A data table of animals.
   */
  private DataTable generateAnimalsTable(Query query) throws TypeMismatchException {
    DataTable data = new DataTable();
    List<ColumnDescription> requiredColumns = getRequiredColumns(query,
        ANIMAL_TABLE_COLUMNS);
    data.addColumns(requiredColumns);

    // Populate the data table
    for (String key : animalLinksByName.keySet()) {
      TableRow row = new TableRow();
      for (ColumnDescription selectionColumn : requiredColumns) {
        String columnName = selectionColumn.getId();
        if (columnName.equals(ANIMAL_COLUMN)) {
          row.addCell(key);
        } else if (columnName.equals(ARTICLE_COLUMN)) {
          row.addCell(animalLinksByName.get(key));
        }
      }
      data.addRow(row);
    }
    return data;
  }
View Full Code Here

   * @param query The selection query.
   *
   * @return planets data table.
   */
  private DataTable generatePlanetsTable(Query query) throws TypeMismatchException {
    DataTable data = new DataTable();
    List<ColumnDescription> requiredColumns = getRequiredColumns(
        query, planetTableColumns);
    data.addColumns(requiredColumns);

    // Populate the planets data table
    for (Planet planet : Planet.values()) {
      TableRow row = new TableRow();
      for (ColumnDescription selectionColumn : requiredColumns) {
        String columnName = selectionColumn.getId();
        if (columnName.equals(PLANET_COLUMN)) {
          row.addCell(planet.name());
        } else if (columnName.equals(MASS_COLUMN)) {
          row.addCell(planet.getMass());
        } else if (columnName.equals(GRAVITY_COLUMN)) {
          row.addCell(planet.getSurfaceGravity());
        } else if (columnName.equals(MOONS_COLUMN)) {
          row.addCell(planet.getNumberOfMoons());
        }
      }
      data.addRow(row);
    }
    return data;
  }
View Full Code Here

        MockDataSource.getData(tableNum));
  }

  public void testGetRowPath() {
    TableAggregator aggregator = newTableAggregator(1);
    DataTable table = MockDataSource.getData(1);
    TableRow row = table.getRow(0);
    List<Value> path = aggregator.getRowPath(row, table, 0).getValues();
    assertEquals(1, path.size());
    assertEquals("1994", path.get(0).toString());

    row = table.getRow(6);
    path = aggregator.getRowPath(row, table, 1).getValues();
    assertEquals(2, path.size());
    assertEquals("1994", path.get(0).toString());
    assertEquals(2.0, ((NumberValue) path.get(1)).getValue());
  }
View Full Code Here

TOP

Related Classes of com.google.visualization.datasource.datatable.DataTable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.