Search in sources :

Example 1 with PreparationService

use of org.talend.dataprep.preparation.service.PreparationService 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)

Aggregations

ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 ApplicationContext (org.springframework.context.ApplicationContext)1 LocaleContextHolder.getLocale (org.springframework.context.i18n.LocaleContextHolder.getLocale)1 Component (org.springframework.stereotype.Component)1 ActionDefinition (org.talend.dataprep.api.action.ActionDefinition)1 ActionForm (org.talend.dataprep.api.action.ActionForm)1 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)1 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)1 FilterTranslator (org.talend.dataprep.api.filter.FilterTranslator)1 TQLFilterService (org.talend.dataprep.api.filter.TQLFilterService)1 Action (org.talend.dataprep.api.preparation.Action)1 Preparation (org.talend.dataprep.api.preparation.Preparation)1