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());
}
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());
}
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);
}
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);
}
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;
}
Aggregations