Search in sources :

Example 21 with PersistentPreparation

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();
}
Also used : StepRowMetadata(org.talend.dataprep.api.preparation.StepRowMetadata) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation) Preparation(org.talend.dataprep.api.preparation.Preparation) ContentCacheKey(org.talend.dataprep.cache.ContentCacheKey) Step(org.talend.dataprep.api.preparation.Step) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test)

Example 22 with PersistentPreparation

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;
}
Also used : ImplicitParameters(org.talend.dataprep.transformation.actions.common.ImplicitParameters) CREATE_NEW_COLUMN(org.talend.dataprep.transformation.actions.common.ActionsUtils.CREATE_NEW_COLUMN) BeanConversionService.fromBean(org.talend.dataprep.conversions.BeanConversionService.fromBean) LoggerFactory(org.slf4j.LoggerFactory) PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) PreparationSummary(org.talend.dataprep.api.preparation.PreparationSummary) PreparationMessage(org.talend.dataprep.api.preparation.PreparationMessage) StringUtils(org.apache.commons.lang3.StringUtils) StepRowMetadata(org.talend.dataprep.api.preparation.StepRowMetadata) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation) ArrayList(java.util.ArrayList) ScopeCategory(org.talend.dataprep.transformation.actions.category.ScopeCategory) BeanConversionService(org.talend.dataprep.conversions.BeanConversionService) FilterTranslator(org.talend.dataprep.api.filter.FilterTranslator) Map(java.util.Map) TQLFilterService(org.talend.dataprep.api.filter.TQLFilterService) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) Action(org.talend.dataprep.api.preparation.Action) StepDiff(org.talend.dataprep.api.preparation.StepDiff) Preparation(org.talend.dataprep.api.preparation.Preparation) PreparationDetailsDTO(org.talend.dataprep.api.preparation.PreparationDetailsDTO) Logger(org.slf4j.Logger) LocaleContextHolder.getLocale(org.springframework.context.i18n.LocaleContextHolder.getLocale) ActionRegistry(org.talend.dataprep.transformation.pipeline.ActionRegistry) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Step(org.talend.dataprep.api.preparation.Step) Collectors(java.util.stream.Collectors) ApplicationContext(org.springframework.context.ApplicationContext) ActionForm(org.talend.dataprep.api.action.ActionForm) PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) TqlBuilder.in(org.talend.tql.api.TqlBuilder.in) PreparationService(org.talend.dataprep.preparation.service.PreparationService) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Component(org.springframework.stereotype.Component) ActionDefinition(org.talend.dataprep.api.action.ActionDefinition) UserPreparation(org.talend.dataprep.preparation.service.UserPreparation) Collections(java.util.Collections) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) BeanConversionServiceWrapper(org.talend.dataprep.processor.BeanConversionServiceWrapper) PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) StepDiff(org.talend.dataprep.api.preparation.StepDiff) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation) PreparationService(org.talend.dataprep.preparation.service.PreparationService)

Example 23 with PersistentPreparation

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);
}
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 24 with PersistentPreparation

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);
}
Also used : Dataset(org.talend.dataprep.dataset.adapter.Dataset) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation) Test(org.junit.Test)

Example 25 with PersistentPreparation

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);
}
Also used : PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation) Test(org.junit.Test)

Aggregations

PersistentPreparation (org.talend.dataprep.preparation.store.PersistentPreparation)25 Test (org.junit.Test)8 TDPException (org.talend.dataprep.exception.TDPException)7 PersistentStep (org.talend.dataprep.preparation.store.PersistentStep)7 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)5 FolderEntry (org.talend.dataprep.api.folder.FolderEntry)5 Action (org.talend.dataprep.api.preparation.Action)5 Preparation (org.talend.dataprep.api.preparation.Preparation)5 PreparationDTO (org.talend.dataprep.api.preparation.PreparationDTO)5 Step (org.talend.dataprep.api.preparation.Step)5 ArrayList (java.util.ArrayList)4 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)4 PreparationActions (org.talend.dataprep.api.preparation.PreparationActions)4 StepDiff (org.talend.dataprep.api.preparation.StepDiff)4 StepRowMetadata (org.talend.dataprep.api.preparation.StepRowMetadata)4 Collections (java.util.Collections)3 List (java.util.List)3 Map (java.util.Map)3 Collectors.toList (java.util.stream.Collectors.toList)3 StringUtils (org.apache.commons.lang3.StringUtils)3