use of org.talend.dataprep.preparation.store.PersistentPreparation in project data-prep by Talend.
the class PreparationEventUtilTest method shouldRemoveStepRowMetadata.
@Test
public void shouldRemoveStepRowMetadata() {
// given
final DataSetMetadata metadata = new DataSetMetadata();
metadata.setId("ds-1234");
final Step step1 = new Step();
step1.setId(UUID.randomUUID().toString());
step1.setRowMetadata("srmd-1");
final Step step2 = new Step();
step2.setId(UUID.randomUUID().toString());
step2.setRowMetadata("srmd-2");
step2.setParent(step1.id());
final Step step3 = new Step();
step3.setId(UUID.randomUUID().toString());
// Intentionally left to null
step3.setRowMetadata(null);
step3.setParent(step2.id());
final PersistentPreparation preparation = new PersistentPreparation();
preparation.setHeadId(step3.id());
when(preparationUtils.listSteps(eq(preparation.getHeadId()), eq(preparationRepository))).thenReturn(Arrays.asList(Step.ROOT_STEP, step1, step2, step3));
when(preparationRepository.list(eq(PersistentPreparation.class), eq(TqlBuilder.eq("dataSetId", "ds-1234")))).thenReturn(Stream.of(preparation), Stream.of(preparation));
when(preparationRepository.get(eq(step1.id()), eq(Step.class))).thenReturn(step1);
when(preparationRepository.get(eq(step2.id()), eq(Step.class))).thenReturn(step2);
when(datasetClient.getDataSetMetadata(any())).thenReturn(metadata);
// when
preparationEventUtil.performUpdateEvent(metadata.getId());
// then
verify(cacheEventProcessingUtil, times(2)).processCleanCacheEvent(any(ContentCacheKey.class), any());
verify(preparationRepository, times(1)).add(any(Preparation.class));
verify(preparationRepository, times(1)).remove(eq(StepRowMetadata.class), eq(TqlBuilder.in("id", "srmd-1", "srmd-2")));
verify(securityProxy, times(2)).asTechnicalUser();
verify(securityProxy, times(1)).asTechnicalUserForDataSet();
verify(securityProxy, times(3)).releaseIdentity();
}
use of org.talend.dataprep.preparation.store.PersistentPreparation in project data-prep by Talend.
the class PreparationConversions method toPreparationDetailsDTO.
private PreparationDetailsDTO toPreparationDetailsDTO(PreparationDTO source, PreparationDetailsDTO target, ApplicationContext applicationContext) {
final PreparationRepository preparationRepository = applicationContext.getBean(PreparationRepository.class);
List<String> idsStep = source.getSteps();
final List<StepDiff> diffs = preparationRepository.list(PersistentStep.class, in("id", idsStep.toArray(new String[] {}))).filter(//
step -> !Step.ROOT_STEP.id().equals(step.getId())).sorted((step1, step2) -> {
// we need to keep the order from the original list (source.getSteps())
int idPosStep1 = idsStep.indexOf(step1.getId());
int idPosStep2 = idsStep.indexOf(step2.getId());
return idPosStep1 - idPosStep2;
}).map(//
PersistentStep::getDiff).collect(toList());
target.setDiff(diffs);
// TDP-5888: It is important for Spark runs to have a row metadata to describe initial data schema.
// and also to display column names in filter labels of steps
final PersistentPreparation preparation = preparationRepository.get(source.getId(), PersistentPreparation.class);
target.setRowMetadata(preparation.getRowMetadata());
injectColumnNamesIntoActions(source.getHeadId(), target, applicationContext.getBean(PreparationService.class));
return target;
}
use of org.talend.dataprep.preparation.store.PersistentPreparation 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.preparation.store.PersistentPreparation 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.preparation.store.PersistentPreparation in project data-prep by Talend.
the class DataSetNameInjectionTest method injectDatasetNameBasedOnId_alreadyHasADatasetName.
@Test
public void injectDatasetNameBasedOnId_alreadyHasADatasetName() {
// given
PersistentPreparation input = new PersistentPreparation();
String dataSetId = "1234";
input.setDataSetId(dataSetId);
String datasetLabel = "dataset label";
input.setDataSetName(datasetLabel);
// when
PersistentPreparation result = dataSetNameInjection.injectDatasetNameBasedOnId(input);
// then
assertEquals(datasetLabel, result.getDataSetName());
verifyZeroInteractions(security);
verifyZeroInteractions(securityProxy);
verifyZeroInteractions(dataCatalogClient);
verifyZeroInteractions(preparationRepository);
}
Aggregations