Exemple #1
0
 @Override
 public void compile(ActionContext context) {
   super.compile(context);
   if (context.getActionStatus() == ActionContext.ActionStatus.OK) {
     final RowMetadata rowMetadata = context.getRowMetadata();
     final String columnId = context.getColumnId();
     final ColumnMetadata column = rowMetadata.getById(columnId);
     context.column(
         column.getName() + APPENDIX,
         r -> {
           final ColumnMetadata c =
               ColumnMetadata.Builder //
                   .column() //
                   .name(column.getName() + APPENDIX) //
                   .type(Type.INTEGER) //
                   .empty(column.getQuality().getEmpty()) //
                   .invalid(column.getQuality().getInvalid()) //
                   .valid(column.getQuality().getValid()) //
                   .headerSize(column.getHeaderSize()) //
                   .build();
           rowMetadata.insertAfter(columnId, c);
           return c;
         });
   }
 }
Exemple #2
0
 /**
  * @param name name of the column metadata to create.
  * @return a new column metadata
  */
 private ColumnMetadata createMetadata(String id, String name) {
   return ColumnMetadata.Builder.column()
       .computedId(id)
       .name(name)
       .type(Type.STRING)
       .headerSize(12)
       .empty(0)
       .invalid(2)
       .valid(5)
       .build();
 }
 void performColumnFilter(DataSetRow row, RowMetadata metadata) {
   final boolean needRefresh = rowMetadata == null || !metadata.equals(rowMetadata);
   List<ColumnMetadata> columns = metadata.getColumns();
   if (!columns.isEmpty()) {
     if (filteredColumns == null || needRefresh) {
       filteredColumns = columns.stream().filter(filter).collect(Collectors.toList());
       filteredColumnNames =
           filteredColumns.stream().map(ColumnMetadata::getId).collect(Collectors.toSet());
     }
   } else {
     // No column in row metadata, guess all type, starting from string columns.
     ColumnMetadata.Builder builder = ColumnMetadata.Builder.column().type(Type.STRING);
     final int rowSize = row.toArray(DataSetRow.SKIP_TDP_ID).length;
     columns = new ArrayList<>(rowSize + 1);
     for (int i = 0; i < rowSize; i++) {
       final ColumnMetadata newColumn = builder.build();
       metadata.addColumn(newColumn);
       columns.add(newColumn);
     }
     filteredColumns = columns;
     filteredColumnNames = columns.stream().map(ColumnMetadata::getId).collect(Collectors.toSet());
   }
   rowMetadata = metadata;
 }
Exemple #4
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")));
  }
 @PostConstruct
 public void init() {
   action = (FillWithValue) action.adapt(ColumnMetadata.Builder.column().type(Type.DATE).build());
 }