Search in sources :

Example 1 with Dataset

use of org.talend.dataprep.dataset.adapter.Dataset in project data-prep by Talend.

the class DataSetGetSchemaTest method testExecuteDataSetGetSchema_shouldReturnDataset.

@Test
public void testExecuteDataSetGetSchema_shouldReturnDataset() {
    when(security.getAuthenticationToken()).thenReturn(AUTHENTICATION_TOKEN);
    DataSetGetMetadata command = context.getBean(DataSetGetMetadata.class, "no-matter");
    Dataset dataset = command.execute();
    assertEquals(HttpStatus.OK, command.getStatus());
    assertNotNull(dataset);
    // check dataset does not contains null values
    assertNotNull(dataset.getId());
    assertNotNull(dataset.getLabel());
}
Also used : Dataset(org.talend.dataprep.dataset.adapter.Dataset) ServiceBaseTest(org.talend.ServiceBaseTest) Test(org.junit.Test)

Example 2 with Dataset

use of org.talend.dataprep.dataset.adapter.Dataset in project data-prep by Talend.

the class DatasetBeanConversionTest method datasetToDataSetMetadataConversionWithLegacy.

@Test
@Ignore
public void datasetToDataSetMetadataConversionWithLegacy() {
    // given
    // manage legacy DataSetMetadata fields that don't match the Dataset Catalog model
    Dataset.DataSetMetadataLegacy dataSetMetadataLegacy = new Dataset.DataSetMetadataLegacy();
    dataSetMetadataLegacy.setDraft(true);
    dataSetMetadataLegacy.setSheetName("xls-sheet-name");
    dataSetMetadataLegacy.setEncoding(StandardCharsets.UTF_8.name());
    dataSetMetadataLegacy.setTag("tag-from-studio");
    Schema.Builder builder = new Schema.Builder();
    dataSetMetadataLegacy.setSchemaParserResult(builder.build());
    dataset.setDataSetMetadataLegacy(dataSetMetadataLegacy);
    // when
    DataSetMetadata dataSetMetadata = beanConversionService.convert(dataset, DataSetMetadata.class);
    // then
    assertEquals(dataset.getId(), dataSetMetadata.getId());
    assertEquals(dataset.getCreated(), (Long) dataSetMetadata.getCreationDate());
    assertEquals(dataset.getUpdated(), (Long) dataSetMetadata.getLastModificationDate());
    assertEquals(dataset.getLabel(), dataSetMetadata.getName());
    assertEquals(dataset.getOwner(), dataSetMetadata.getAuthor());
    assertEquals(dataSetMetadataLegacy.getSheetName(), dataSetMetadata.getSheetName());
    assertNotNull(dataSetMetadata.getSchemaParserResult());
    assertEquals(dataSetMetadataLegacy.isDraft(), dataSetMetadata.isDraft());
    assertEquals(dataSetMetadataLegacy.getEncoding(), dataSetMetadata.getEncoding());
    assertEquals(dataSetMetadataLegacy.getTag(), dataSetMetadata.getTag());
}
Also used : Dataset(org.talend.dataprep.dataset.adapter.Dataset) Schema(org.talend.dataprep.schema.Schema) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with Dataset

use of org.talend.dataprep.dataset.adapter.Dataset in project data-prep by Talend.

the class DataSetNameInjectionTest method injectDatasetNameBasedOnId_datasetClientError.

@Test
public void injectDatasetNameBasedOnId_datasetClientError() {
    // given
    PersistentPreparation input = new PersistentPreparation();
    String dataSetId = "1234";
    input.setDataSetId(dataSetId);
    when(security.getTenantId()).thenReturn("tenant id");
    Dataset datasetMetadata = new Dataset();
    String datasetLabel = "dataset label";
    datasetMetadata.setLabel(datasetLabel);
    when(dataCatalogClient.getMetadata(dataSetId)).thenThrow(new TDPException());
    // when
    PersistentPreparation result = dataSetNameInjection.injectDatasetNameBasedOnId(input);
    // then
    // dataset name has not changed in DTO
    assertNull(result.getDataSetName());
    verify(security).getTenantId();
    verifyNoMoreInteractions(security);
    verify(securityProxy).asTechnicalUserForDataSet();
    verify(securityProxy).releaseIdentity();
    verifyNoMoreInteractions(securityProxy);
    verify(dataCatalogClient).getMetadata(dataSetId);
    verifyNoMoreInteractions(dataCatalogClient);
    verifyZeroInteractions(preparationRepository);
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) Dataset(org.talend.dataprep.dataset.adapter.Dataset) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation) Test(org.junit.Test)

Example 4 with Dataset

use of org.talend.dataprep.dataset.adapter.Dataset in project data-prep by Talend.

the class DataSetNameInjectionTest method injectDatasetNameBasedOnId.

@Test
public void injectDatasetNameBasedOnId() {
    // given
    PersistentPreparation input = new PersistentPreparation();
    String dataSetId = "1234";
    input.setDataSetId(dataSetId);
    when(security.getTenantId()).thenReturn("tenant id");
    Dataset datasetMetadata = new Dataset();
    String datasetLabel = "dataset label";
    datasetMetadata.setLabel(datasetLabel);
    when(dataCatalogClient.getMetadata(dataSetId)).thenReturn(datasetMetadata);
    // when
    PersistentPreparation result = dataSetNameInjection.injectDatasetNameBasedOnId(input);
    // then
    assertEquals(datasetLabel, result.getDataSetName());
    verify(security).getTenantId();
    verifyNoMoreInteractions(security);
    verify(securityProxy).asTechnicalUserForDataSet();
    verify(securityProxy).releaseIdentity();
    verifyNoMoreInteractions(securityProxy);
    verify(dataCatalogClient).getMetadata(dataSetId);
    verifyNoMoreInteractions(dataCatalogClient);
    verify(preparationRepository).add(input);
    verifyNoMoreInteractions(preparationRepository);
}
Also used : Dataset(org.talend.dataprep.dataset.adapter.Dataset) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation) Test(org.junit.Test)

Example 5 with Dataset

use of org.talend.dataprep.dataset.adapter.Dataset in project data-prep by Talend.

the class DataSetMetadataBeanConversion method doWith.

@Override
public BeanConversionService doWith(BeanConversionService instance, String beanName, ApplicationContext applicationContext) {
    instance.register(// 
    fromBean(DataSetMetadata.class).toBeans(// 
    Dataset.class).using(Dataset.class, (dataSetMetadata, dataset) -> {
        dataset.setId(dataSetMetadata.getId());
        dataset.setEnabled(true);
        dataset.setCreated(dataSetMetadata.getCreationDate());
        dataset.setUpdated(dataSetMetadata.getLastModificationDate());
        dataset.setOwner(dataSetMetadata.getAuthor());
        dataset.setLabel(dataSetMetadata.getName());
        DataSetGovernance governance = dataSetMetadata.getGovernance();
        if (governance != null) {
            Certification certificationStep = governance.getCertificationStep();
            dataset.setCertification(CertificationState.valueOf(certificationStep.name()));
        }
        DataSetLocation location = dataSetMetadata.getLocation();
        if (location instanceof LocalStoreLocation) {
            // FIXME by-pass for DataSet based on Local file (because Catalog doesn't provide Local file DataStore)
            dataset.setType(location.getLocationType());
            ObjectNode jsonNode = objectMapper.createObjectNode();
            jsonNode.set("location", objectMapper.valueToTree(location));
            jsonNode.set("content", objectMapper.valueToTree(dataSetMetadata.getContent()));
            dataset.setProperties(jsonNode);
        }
        // Manage legacy fields that doesn't match data catalog concept
        Dataset.DataSetMetadataLegacy metadataLegacy = new Dataset.DataSetMetadataLegacy();
        metadataLegacy.setSheetName(dataSetMetadata.getSheetName());
        metadataLegacy.setDraft(dataSetMetadata.isDraft());
        metadataLegacy.setSchemaParserResult(dataSetMetadata.getSchemaParserResult());
        metadataLegacy.setEncoding(dataSetMetadata.getEncoding());
        metadataLegacy.setTag(dataSetMetadata.getTag());
        metadataLegacy.setNbRecords(dataSetMetadata.getContent().getNbRecords());
        dataset.setDataSetMetadataLegacy(metadataLegacy);
        return dataset;
    }).build());
    return instance;
}
Also used : DataSetGovernance(org.talend.dataprep.api.dataset.DataSetGovernance) DataSetLocation(org.talend.dataprep.api.dataset.DataSetLocation) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Dataset(org.talend.dataprep.dataset.adapter.Dataset) Certification(org.talend.dataprep.api.dataset.DataSetGovernance.Certification) LocalStoreLocation(org.talend.dataprep.api.dataset.location.LocalStoreLocation)

Aggregations

Dataset (org.talend.dataprep.dataset.adapter.Dataset)5 Test (org.junit.Test)4 PersistentPreparation (org.talend.dataprep.preparation.store.PersistentPreparation)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Ignore (org.junit.Ignore)1 ServiceBaseTest (org.talend.ServiceBaseTest)1 DataSetGovernance (org.talend.dataprep.api.dataset.DataSetGovernance)1 Certification (org.talend.dataprep.api.dataset.DataSetGovernance.Certification)1 DataSetLocation (org.talend.dataprep.api.dataset.DataSetLocation)1 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)1 LocalStoreLocation (org.talend.dataprep.api.dataset.location.LocalStoreLocation)1 TDPException (org.talend.dataprep.exception.TDPException)1 Schema (org.talend.dataprep.schema.Schema)1