Search in sources :

Example 71 with DataSetMetadata

use of org.talend.dataprep.api.dataset.DataSetMetadata in project data-prep by Talend.

the class DataSetServiceTest method updateRawContent_should_preserve_non_content_related_metadata_except_last_modification_date.

@Test
public void updateRawContent_should_preserve_non_content_related_metadata_except_last_modification_date() throws Exception {
    // given
    String dataSetId = UUID.randomUUID().toString();
    DataSetMetadata dataSetMetadata = metadataBuilder.metadata().id(dataSetId).build();
    dataSetMetadataRepository.save(dataSetMetadata);
    given().body(IOUtils.toString(this.getClass().getResourceAsStream(TAGADA_CSV), UTF_8)).when().put("/datasets/{id}/raw", dataSetId).then().statusCode(OK.value());
    String datasets = when().get("/datasets").asString();
    List<DataSetMetadata> datasetsMetadata = mapper.readValue(datasets, new TypeReference<ArrayList<DataSetMetadata>>() {
    });
    final DataSetMetadata original = datasetsMetadata.get(0);
    // when
    given().body(IOUtils.toString(this.getClass().getResourceAsStream(TAGADA2_CSV), UTF_8)).when().put("/datasets/{id}/raw", dataSetId).then().statusCode(OK.value());
    // then
    datasets = when().get("/datasets").asString();
    datasetsMetadata = mapper.readValue(datasets, new TypeReference<ArrayList<DataSetMetadata>>() {
    });
    final DataSetMetadata copy = datasetsMetadata.get(0);
    assertThat(copy.getId(), equalTo(original.getId()));
    assertThat(copy.getAppVersion(), equalTo(original.getAppVersion()));
    assertThat(copy.getAuthor(), equalTo(original.getAuthor()));
    assertThat(copy.getCreationDate(), equalTo(original.getCreationDate()));
    assertThat(copy.getLocation(), equalTo(original.getLocation()));
}
Also used : ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) TypeReference(com.fasterxml.jackson.core.type.TypeReference) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) DataSetBaseTest(org.talend.dataprep.dataset.DataSetBaseTest) Test(org.junit.Test)

Example 72 with DataSetMetadata

use of org.talend.dataprep.api.dataset.DataSetMetadata in project data-prep by Talend.

the class XlsSerializerTest method getDataSetMetadataFromExcelFile.

/**
 * Return the dataset metadata out of the given file name.
 *
 * @param fileName the excel file to open.
 * @param sheetName name of the excel sheet.
 * @return the dataset metadata.
 * @throws IOException s**y happens.
 */
private DataSetMetadata getDataSetMetadataFromExcelFile(String fileName, String sheetName) throws IOException {
    DataSetMetadata dataSetMetadata = metadataBuilder.metadata().id("ff").sheetName(sheetName).build();
    try (InputStream inputStream = this.getClass().getResourceAsStream(fileName)) {
        List<Schema.SheetContent> sheetContents = xlsSchemaParser.parseAllSheets(getRequest(inputStream, "#8"));
        List<ColumnMetadata> columnsMetadata = sheetContents.get(0).getColumnMetadatas();
        logger.debug("columnsMetadata: {}", columnsMetadata);
        Assertions.assertThat(columnsMetadata).isNotNull().isNotEmpty();
        dataSetMetadata.getRowMetadata().setColumns(columnsMetadata);
    }
    return dataSetMetadata;
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) InputStream(java.io.InputStream) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata)

Example 73 with DataSetMetadata

use of org.talend.dataprep.api.dataset.DataSetMetadata in project data-prep by Talend.

the class XlsSerializerTest method test_second_sheet_parsing.

@Test
public void test_second_sheet_parsing() throws Exception {
    String fileName = "Talend_Desk-Tableau-Bord-011214.xls";
    assertFormat(fileName);
    DataSetMetadata dataSetMetadata = metadataBuilder.metadata().id("beer").sheetName("Leads").build();
    try (InputStream inputStream = this.getClass().getResourceAsStream(fileName)) {
        List<Schema.SheetContent> sheetContents = xlsSchemaParser.parseAllSheets(getRequest(inputStream, "#8"));
        List<ColumnMetadata> columnsMetadata = sheetContents.stream().filter(sheetContent -> "Leads".equals(sheetContent.getName())).findFirst().get().getColumnMetadatas();
        logger.debug("columnsMetadata: {}", columnsMetadata);
        Assertions.assertThat(columnsMetadata).isNotNull().isNotEmpty().hasSize(6);
        ColumnMetadata columnMetadata = columnsMetadata.get(4);
        Assertions.assertThat(columnMetadata.getHeaderSize()).isEqualTo(1);
        Assertions.assertThat(columnMetadata.getName()).isEqualTo("age");
        Assertions.assertThat(columnMetadata.getType()).isEqualTo(Type.STRING.getName());
        dataSetMetadata.getRowMetadata().setColumns(columnsMetadata);
    }
    List<Map<String, String>> values = getValuesFromFile(fileName, dataSetMetadata);
    logger.trace("values: {}", values);
    Assertions.assertThat(values).isNotEmpty().hasSize(3);
    // 
    Assertions.assertThat(values.get(0)).contains(// 
    entry("0000", "301638"), // 
    entry("0001", "foo@foo.com"), entry("0004", "23"));
    // 
    Assertions.assertThat(values.get(1)).contains(// 
    entry("0000", "12349383"), // 
    entry("0001", "beer@gof.org"), entry("0004", "23"));
    // 
    Assertions.assertThat(values.get(2)).contains(// 
    entry("0000", "73801093"), // 
    entry("0001", "wine@go.com"), entry("0003", "Jean"));
}
Also used : LocalizationRule(org.talend.dataprep.test.LocalizationRule) java.util(java.util) StringUtils(org.apache.commons.lang.StringUtils) DataSetMetadataBuilder(org.talend.dataprep.dataset.DataSetMetadataBuilder) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Schema(org.talend.dataprep.schema.Schema) Assert.assertThat(org.junit.Assert.assertThat) AbstractSchemaTestUtils(org.talend.dataprep.schema.AbstractSchemaTestUtils) CompositeFormatDetector(org.talend.dataprep.schema.CompositeFormatDetector) Cell(org.apache.poi.ss.usermodel.Cell) Assertions(org.assertj.core.api.Assertions) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Path(java.nio.file.Path) Logger(org.slf4j.Logger) Files(java.nio.file.Files) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Format(org.talend.dataprep.schema.Format) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Test(org.junit.Test) CollectionType(com.fasterxml.jackson.databind.type.CollectionType) IOUtils(org.apache.commons.io.IOUtils) Type(org.talend.dataprep.api.type.Type) Rule(org.junit.Rule) Builder.column(org.talend.dataprep.api.dataset.ColumnMetadata.Builder.column) Paths(java.nio.file.Paths) SameJSONAs.sameJSONAs(uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs) Assert(org.junit.Assert) MapEntry.entry(org.assertj.core.data.MapEntry.entry) InputStream(java.io.InputStream) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) InputStream(java.io.InputStream) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test)

Example 74 with DataSetMetadata

use of org.talend.dataprep.api.dataset.DataSetMetadata in project data-prep by Talend.

the class XlsSerializerTest method more_than_52_columns.

/**
 * test for TDP-1660 and TDP-1648
 */
@Test
public void more_than_52_columns() throws Exception {
    String fileName = "TDP_Epics.xlsx";
    DataSetMetadata dataSetMetadata = metadataBuilder.metadata().id("epics").build();
    try (InputStream inputStream = this.getClass().getResourceAsStream(fileName)) {
        // 
        dataSetMetadata.getRowMetadata().setColumns(// 
        xlsSchemaParser.parse(getRequest(inputStream, "#456")).getSheetContents().get(// 
        0).getColumnMetadatas());
    }
    // 
    Assertions.assertThat(dataSetMetadata.getRowMetadata().getColumns()).isNotNull().isNotEmpty().hasSize(98);
    List<Map<String, String>> values = getValuesFromFile(fileName, dataSetMetadata);
    logger.debug("values: {}", values);
    Assertions.assertThat(values.get(3).get("0090")).isEqualTo("Small");
}
Also used : InputStream(java.io.InputStream) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test)

Example 75 with DataSetMetadata

use of org.talend.dataprep.api.dataset.DataSetMetadata in project data-prep by Talend.

the class SortAndOrderHelperTest method getDatasetComparison.

private // 
int getDatasetComparison(// 
String firstName, // 
String secondName, // 
String firstOwnerFirstName, // 
String secondOwnerFirstName, // 
String firstOwnerLastName, // 
String secondOwnerLastName, // 
long firstCreation, // 
long secondCreation, // 
long firstModification, // 
long secondModification, // 
long firstSize, // 
long secondSize, Sort sort, Order order) {
    DataSetMetadata firstUserDatasetMetadata = createUserDatasetMetadata("firstDsId", firstName, "1", firstCreation, firstModification, null, null, firstOwnerFirstName, firstOwnerLastName);
    firstUserDatasetMetadata.getContent().setNbRecords(firstSize);
    DataSetMetadata secondUserDatasetMetadata = createUserDatasetMetadata("secondDsId", secondName, "2", secondCreation, secondModification, null, null, secondOwnerFirstName, secondOwnerLastName);
    secondUserDatasetMetadata.getContent().setNbRecords(secondSize);
    // Used to make sure that when using DatasetMetadata instead of UserDatasetMetada the behaviour of the comparison remains
    // the same
    DataSetMetadata firstDatasetMetadata = createDatasetMetadata("firstDsId", firstName, firstCreation, firstModification, null, null, firstOwnerFirstName, firstOwnerLastName);
    firstDatasetMetadata.getContent().setNbRecords(firstSize);
    DataSetMetadata secondDatasetMetadata = createDatasetMetadata("secondDsId", secondName, secondCreation, secondModification, null, null, secondOwnerFirstName, secondOwnerLastName);
    secondDatasetMetadata.getContent().setNbRecords(secondSize);
    // when
    Comparator<DataSetMetadata> preparationComparator = SortAndOrderHelper.getDataSetMetadataComparator(sort, order);
    // then
    assertNotNull(preparationComparator);
    final int userDatasetMetadataOrder = preparationComparator.compare(firstUserDatasetMetadata, secondUserDatasetMetadata);
    final int datasetMetadataOrder = preparationComparator.compare(firstDatasetMetadata, secondDatasetMetadata);
    // Make sure that when using DatasetMetadata instead of UserDatasetMetada the behaviour of the comparison remains the same
    assertEquals(userDatasetMetadataOrder, datasetMetadataOrder);
    return userDatasetMetadataOrder;
}
Also used : DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) UserDataSetMetadata(org.talend.dataprep.dataset.service.UserDataSetMetadata)

Aggregations

DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)192 Test (org.junit.Test)126 DataSetBaseTest (org.talend.dataprep.dataset.DataSetBaseTest)63 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)48 InputStream (java.io.InputStream)45 Matchers.containsString (org.hamcrest.Matchers.containsString)28 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)28 TDPException (org.talend.dataprep.exception.TDPException)26 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)20 DataSetServiceTest (org.talend.dataprep.dataset.service.DataSetServiceTest)20 ApiOperation (io.swagger.annotations.ApiOperation)18 DataSet (org.talend.dataprep.api.dataset.DataSet)18 Type (org.talend.dataprep.api.type.Type)17 Timed (org.talend.dataprep.metrics.Timed)17 DistributedLock (org.talend.dataprep.lock.DistributedLock)16 Autowired (org.springframework.beans.factory.annotation.Autowired)14 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)14 IOException (java.io.IOException)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 ArrayList (java.util.ArrayList)12