Search in sources :

Example 6 with PreparationDetailsDTO

use of org.talend.dataprep.api.preparation.PreparationDetailsDTO in project data-prep by Talend.

the class PreparationControllerTest method getDetailsWithSpecificStepId.

@Test
public void getDetailsWithSpecificStepId() throws Exception {
    // given
    final String preparationContent = IOUtils.toString(this.getClass().getResourceAsStream("base_preparation.json"), "UTF-8");
    final String preparationId = clientTest.createPreparationWithAPI(preparationContent);
    final String step = IOUtils.toString(this.getClass().getResourceAsStream("actions/append_copy_firstname.json"), "UTF-8");
    clientTest.addStep(preparationId, step);
    final String wantedStepId = clientTest.addStep(preparationId, step);
    clientTest.addStep(preparationId, step);
    // when
    final PreparationDetailsDTO details = clientTest.getDetails(preparationId, wantedStepId);
    // then
    assertNotNull(details);
    assertEquals(wantedStepId, details.getSteps().get(details.getSteps().size() - 1));
    assertEquals(3, details.getSteps().size());
}
Also used : PreparationDetailsDTO(org.talend.dataprep.api.preparation.PreparationDetailsDTO) BasePreparationTest(org.talend.dataprep.preparation.BasePreparationTest) Test(org.junit.Test)

Example 7 with PreparationDetailsDTO

use of org.talend.dataprep.api.preparation.PreparationDetailsDTO in project data-prep by Talend.

the class StandardExportStrategiesIntegrationTest method idOfPrepWith2StepsOrMore.

private String idOfPrepWith2StepsOrMore() throws IOException {
    reset(preparationDetailsGet);
    final PreparationDetailsDTO preparationDetailsDTO = mapper.readerFor(// 
    PreparationDetailsDTO.class).readValue(this.getClass().getResourceAsStream("two_steps_preparation_details.json"));
    // 
    when(preparationDetailsGet.execute()).thenReturn(// 
    preparationDetailsDTO).thenReturn(preparationDetailsDTO);
    final PreparationDTO preparationDTO = mapper.readerFor(// 
    PreparationDTO.class).readValue(this.getClass().getResourceAsStream("two_steps_preparation_details_summary.json"));
    // 
    when(preparationSummaryGet.execute()).thenReturn(// 
    preparationDTO).thenReturn(preparationDTO);
    return "prepId-1234";
}
Also used : PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) PreparationDetailsDTO(org.talend.dataprep.api.preparation.PreparationDetailsDTO)

Example 8 with PreparationDetailsDTO

use of org.talend.dataprep.api.preparation.PreparationDetailsDTO in project data-prep by Talend.

the class PreparationConversions method injectColumnNamesIntoActions.

/**
 * Inject column names into actions to display correctly every action label and filter label.
 *
 * @param headId the id of the head step of the version
 * @param target the already converted object to enrich
 * @param preparationService the service to find actions to enrich and inject into the converted object
 */
private void injectColumnNamesIntoActions(String headId, PreparationDetailsDTO target, PreparationService preparationService) {
    final List<Action> actions = preparationService.getVersionedAction(target.getId(), headId);
    target.setActions(actions);
    for (Action action : actions) {
        Map<String, String> parameters = action.getParameters();
        List<ColumnMetadata> filterColumns = new ArrayList<>();
        // Fetch column metadata relative to the filtered action
        // Ask for (n-1) metadata (necessary if some columns are deleted during last step)
        RowMetadata rowMetadata = preparationService.getPreparationStep(target.getSteps().get(actions.indexOf(action)));
        if (rowMetadata == null) {
            rowMetadata = target.getRowMetadata();
        }
        if (StringUtils.isNotBlank(parameters.get(ImplicitParameters.FILTER.getKey()))) {
            // Translate filter from JSON to TQL
            parameters.put(ImplicitParameters.FILTER.getKey(), translator.toTQL(parameters.get(ImplicitParameters.FILTER.getKey())));
            filterColumns = tqlFilterService.getFilterColumnsMetadata(parameters.get(ImplicitParameters.FILTER.getKey()), rowMetadata);
        }
        // example)
        if (filterColumns.stream().filter(column -> column.getId().equals(parameters.get(ImplicitParameters.COLUMN_ID.getKey()))).findFirst().orElse(null) == null) {
            filterColumns.addAll(rowMetadata.getColumns().stream().filter(column -> column.getId().equals(parameters.get(ImplicitParameters.COLUMN_ID.getKey()))).collect(Collectors.toList()));
        }
        action.setFilterColumns(filterColumns);
    }
}
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) Action(org.talend.dataprep.api.preparation.Action) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) ArrayList(java.util.ArrayList) StepRowMetadata(org.talend.dataprep.api.preparation.StepRowMetadata) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata)

Example 9 with PreparationDetailsDTO

use of org.talend.dataprep.api.preparation.PreparationDetailsDTO 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 10 with PreparationDetailsDTO

use of org.talend.dataprep.api.preparation.PreparationDetailsDTO in project data-prep by Talend.

the class InjectorUtilTest method testInjectPreparationDetailsDTO.

@Test
public void testInjectPreparationDetailsDTO() throws IllegalAccessException, InstantiationException {
    PreparationDetailsDTO prep = new PreparationDetailsDTO();
    List<Action> actions = new ArrayList<>();
    actions.add(getSimpleAction("uppercase", "column_name", "lastname"));
    actions.add(getSimpleAction("lowercase", "column_name", "lastname"));
    when(actionRegistry.get("uppercase")).thenReturn(UpperCase.class.newInstance());
    when(actionRegistry.get("lowercase")).thenReturn(LowerCase.class.newInstance());
    PreparationDetailsDTO detailsPrep = injectorUtil.injectPreparationDetails(actions, prep);
    detailsPrep.getMetadata().forEach(af -> {
        af.getParameters().forEach(p -> {
            // we check if action create new column then it is on readonly mode
            if (p.getName().equals(CREATE_NEW_COLUMN)) {
                assertTrue(p.isReadonly());
            }
        });
    });
    assertEquals("Number of action should be the same", actions.size(), detailsPrep.getActions().size());
    assertEquals("Number of ActionForm should be the same", actions.size(), detailsPrep.getMetadata().size());
}
Also used : Action(org.talend.dataprep.api.preparation.Action) UpperCase(org.talend.dataprep.transformation.actions.text.UpperCase) PreparationDetailsDTO(org.talend.dataprep.api.preparation.PreparationDetailsDTO) ArrayList(java.util.ArrayList) LowerCase(org.talend.dataprep.transformation.actions.text.LowerCase) Test(org.junit.Test)

Aggregations

PreparationDetailsDTO (org.talend.dataprep.api.preparation.PreparationDetailsDTO)10 PreparationDTO (org.talend.dataprep.api.preparation.PreparationDTO)6 Action (org.talend.dataprep.api.preparation.Action)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ActionDefinition (org.talend.dataprep.api.action.ActionDefinition)4 ActionForm (org.talend.dataprep.api.action.ActionForm)4 CREATE_NEW_COLUMN (org.talend.dataprep.transformation.actions.common.ActionsUtils.CREATE_NEW_COLUMN)4 ActionRegistry (org.talend.dataprep.transformation.pipeline.ActionRegistry)4 Collections (java.util.Collections)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 Collectors.toList (java.util.stream.Collectors.toList)3 Locale (java.util.Locale)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 ApplicationContext (org.springframework.context.ApplicationContext)2