Пример #1
0
  public static void parseOneWorkSheet(
      SpreadsheetService service,
      Project project,
      ProjectMetadata metadata,
      final ImportingJob job,
      URL docURL,
      URL worksheetURL,
      int limit,
      JSONObject options,
      List<Exception> exceptions) {

    try {
      WorksheetEntry worksheetEntry = service.getEntry(worksheetURL, WorksheetEntry.class);
      String spreadsheetName = docURL.toExternalForm();
      try {
        SpreadsheetEntry spreadsheetEntry = service.getEntry(docURL, SpreadsheetEntry.class);
        spreadsheetName = spreadsheetEntry.getTitle().getPlainText();
      } catch (ServiceException e) { // RedirectRequiredException among others
        // fall back to just using the URL (better for traceability anyway?)
      }

      String fileSource = spreadsheetName + " # " + worksheetEntry.getTitle().getPlainText();

      setProgress(job, fileSource, 0);
      TabularImportingParserBase.readTable(
          project,
          metadata,
          job,
          new WorksheetBatchRowReader(job, fileSource, service, worksheetEntry, 20),
          fileSource,
          limit,
          options,
          exceptions);
      setProgress(job, fileSource, 100);
    } catch (IOException e) {
      e.printStackTrace();
      exceptions.add(e);
    } catch (ServiceException e) {
      e.printStackTrace();
      exceptions.add(e);
    }
  }
Пример #2
0
  public static void parse(
      GoogleService service,
      Project project,
      ProjectMetadata metadata,
      final ImportingJob job,
      int limit,
      JSONObject options,
      List<Exception> exceptions) {

    String docUrlString = JSONUtilities.getString(options, "docUrl", null);
    String id = getFTid(docUrlString); // Use GDataExtension.getFusionTableKey(url) ?
    // TODO: Allow arbitrary Fusion Tables URL instead of (in addition to?) constructing our own?

    try {
      List<FTColumnData> columns = new ArrayList<GDataImporter.FTColumnData>();
      List<List<String>> rows = GDataExtension.runFusionTablesSelect(service, "DESCRIBE " + id);
      if (rows.size() > 1) {
        for (int i = 1; i < rows.size(); i++) {
          List<String> row = rows.get(i);
          if (row.size() >= 2) {
            FTColumnData cd = new FTColumnData();
            cd.name = row.get(1);
            cd.type = FTColumnType.STRING;

            if (row.size() > 2) {
              String type = row.get(2).toLowerCase();
              if (type.equals("number")) {
                cd.type = FTColumnType.NUMBER;
              } else if (type.equals("datetime")) {
                cd.type = FTColumnType.DATETIME;
              } else if (type.equals("location")) {
                cd.type = FTColumnType.LOCATION;
              }
            }
            columns.add(cd);
          }
        }

        setProgress(job, docUrlString, -1);

        // Force these options for the next call because each fusion table
        // is strictly structured with a single line of headers.
        JSONUtilities.safePut(
            options, "ignoreLines", 0); // number of blank lines at the beginning to ignore
        JSONUtilities.safePut(options, "headerLines", 1); // number of header lines

        TabularImportingParserBase.readTable(
            project,
            metadata,
            job,
            new FusionTableBatchRowReader(job, docUrlString, service, id, columns, 100),
            docUrlString,
            limit,
            options,
            exceptions);
        setProgress(job, docUrlString, 100);
      }
    } catch (IOException e) {
      e.printStackTrace();
      exceptions.add(e);
    } catch (ServiceException e) {
      e.printStackTrace();
      exceptions.add(e);
    }
  }