use of org.talend.dataprep.preparation.store.PersistentStep in project data-prep by Talend.
the class PreparationCleanerTest method removeOrphanSteps_should_not_remove_root_step.
@Test
public void removeOrphanSteps_should_not_remove_root_step() {
// given
when(repository.list(eq(Preparation.class))).thenReturn(Stream.empty());
final PersistentStep rootStep = new PersistentStep();
rootStep.setId(Step.ROOT_STEP.id());
when(repository.list(eq(PersistentStep.class))).thenReturn(Stream.of(rootStep));
// when
cleaner.removeOrphanSteps();
// then
verify(repository, never()).remove(eq(Step.ROOT_STEP));
}
use of org.talend.dataprep.preparation.store.PersistentStep in project data-prep by Talend.
the class PreparationCleanerTest method removeOrphanSteps_should_remove_orphan_step_content.
@Test
public void removeOrphanSteps_should_remove_orphan_step_content() {
// given
final String version = "1.2.3";
final PreparationActions content = new PreparationActions();
content.setAppVersion(version);
when(repository.list(PreparationActions.class)).thenReturn(Stream.of(content));
when(repository.get(content.id(), PreparationActions.class)).thenReturn(content);
final Step step = new Step(Step.ROOT_STEP.id(), content.id(), version);
when(repository.list(eq(Step.class))).thenReturn(Stream.of(step));
when(repository.list(eq(PersistentStep.class))).thenReturn(Stream.of(step).map(s -> {
final PersistentStep persistentStep = new PersistentStep();
persistentStep.setId(s.id());
persistentStep.setContent(s.getContent());
return persistentStep;
}));
when(repository.list(eq(Preparation.class))).thenReturn(Stream.empty());
// when
cleaner.removeOrphanSteps();
// then
verify(repository, times(1)).remove(eq(content));
}
use of org.talend.dataprep.preparation.store.PersistentStep in project data-prep by Talend.
the class PreparationCleanerTest method removeOrphanSteps_should_not_remove_step_that_still_belongs_to_a_preparation.
@Test
public void removeOrphanSteps_should_not_remove_step_that_still_belongs_to_a_preparation() {
// given
final String version = "1.2.3";
final Step firstStep = new Step(Step.ROOT_STEP.id(), "first", version);
final Step secondStep = new Step(firstStep.id(), "second", version);
final Step thirdStep = new Step(secondStep.id(), "third", version);
when(repository.list(eq(Step.class))).thenReturn(Stream.of(firstStep, secondStep, thirdStep));
when(repository.list(eq(PersistentStep.class))).thenReturn(Stream.of(firstStep, secondStep, thirdStep).map(s -> {
final PersistentStep persistentStep = new PersistentStep();
persistentStep.setId(s.id());
persistentStep.setContent(s.getContent());
return persistentStep;
}));
final Preparation firstPreparation = new Preparation("#458", "1", firstStep.id(), version);
firstPreparation.setSteps(Collections.singletonList(firstStep));
final Preparation secondPreparation = new Preparation("#5428", "2", thirdStep.id(), version);
secondPreparation.setSteps(Arrays.asList(thirdStep, secondStep, firstStep));
when(repository.list(eq(Preparation.class))).thenReturn(Stream.of(firstPreparation, secondPreparation));
// when
cleaner.removeOrphanSteps();
// then
verify(repository, never()).remove(eq(firstStep));
verify(repository, never()).remove(eq(secondStep));
verify(repository, never()).remove(eq(thirdStep));
}
use of org.talend.dataprep.preparation.store.PersistentStep in project data-prep by Talend.
the class StepRowMetadataMigration method run.
@Override
public void run() {
// Allow non numeric value like NaN
objectMapper.configure(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS, true);
LOGGER.info("Migration of step row metadata in preparations...");
preparationRepository.list(PersistentStep.class).forEach(persistentStep -> {
String id = persistentStep.getId();
LOGGER.info("Migration of step #{}", id);
String rowMetadata = persistentStep.getRowMetadata();
try {
// the rootstep has no metadata => avoid conversion
if (rowMetadata != null) {
// Dirty patch to convert all histogram (2.0) to new one (2.1)
rowMetadata = rowMetadata.replace("_class", "type").replace("org.talend.dataprep.api.dataset.statistics.number.NumberHistogram", "number").replace("org.talend.dataprep.api.dataset.statistics.date.DateHistogram", "date");
final DataSetMetadata dataSetMetadata = objectMapper.readerFor(DataSetMetadata.class).readValue(rowMetadata);
final StepRowMetadata stepRowMetadata = new StepRowMetadata(dataSetMetadata.getRowMetadata());
persistentStep.setRowMetadata(stepRowMetadata.getId());
preparationRepository.add(persistentStep);
preparationRepository.add(stepRowMetadata);
}
} catch (Exception e) {
LOGGER.info("Ignore migration of step #{} (enable debug for full log).", id);
LOGGER.debug("Unable to migrate step", e);
}
});
LOGGER.info("Migration of step metadata in preparations done.");
}
use of org.talend.dataprep.preparation.store.PersistentStep in project data-prep by Talend.
the class ToPEPersistentIdentifiable method turnToPersistentStep.
private PersistentStep turnToPersistentStep(Step step) {
PersistentStep result = new PersistentStep();
result.setId(step.getId());
result.setAppVersion(step.getAppVersion());
result.setContent(step.getContent());
result.setDiff(step.getDiff());
result.setParentId(step.getParent());
result.setRowMetadata(step.getRowMetadata());
return result;
}
Aggregations