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