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