예제 #1
0
  /**
   * Update the header and footer information in the dataset metadata.
   *
   * @param metadata the dataset metadata to update.
   */
  private void updateHeaderAndFooter(DataSetMetadata metadata) {

    DataSetContent datasetContent = metadata.getContent();
    // parameters
    final Map<String, String> parameters = metadata.getContent().getParameters();
    int headerNBLines = 1;
    try {
      headerNBLines = Integer.parseInt(parameters.get(CSVFormatFamily.HEADER_NB_LINES_PARAMETER));
    } catch (NumberFormatException e) {
      LOG.info(
          "No header information for {}, let's use the first line as header.", metadata.getId());
    }

    datasetContent.setNbLinesInHeader(headerNBLines);
    datasetContent.setNbLinesInFooter(0);
  }
예제 #2
0
  @Test
  public void testWrite1() throws Exception {
    final ColumnMetadata.Builder columnBuilder =
        ColumnMetadata.Builder //
            .column() //
            .id(5) //
            .name("column1") //
            .type(Type.STRING) //
            .empty(0) //
            .invalid(10) //
            .valid(50);

    DataSetMetadata metadata =
        metadataBuilder
            .metadata()
            .id("1234")
            .name("name")
            .author("author")
            .created(0)
            .row(columnBuilder)
            .build();

    final DataSetContent content = metadata.getContent();
    content.addParameter(CSVFormatGuess.SEPARATOR_PARAMETER, ",");
    content.setFormatGuessId(new CSVFormatGuess().getBeanId());
    content.setMediaType("text/csv");
    metadata.getLifecycle().qualityAnalyzed(true);
    metadata.getLifecycle().schemaAnalyzed(true);
    HttpLocation location = new HttpLocation();
    location.setUrl("http://estcequecestbientotleweekend.fr");
    metadata.setLocation(location);
    StringWriter writer = new StringWriter();
    DataSet dataSet = new DataSet();
    dataSet.setMetadata(metadata);
    to(dataSet, writer);
    assertThat(
        writer.toString(), sameJSONAsFile(DataSetJSONTest.class.getResourceAsStream("test2.json")));
  }