use of org.talend.dataprep.preparation.store.PersistentStep in project data-prep by Talend.
the class ToPEPersistentIdentifiable method run.
@Override
public void run() {
LOGGER.debug("starting upgrade from {} to {}.", Step.class, PersistentStep.class);
final AtomicLong counter = new AtomicLong(0L);
fileSystemPreparationRepository.list(Step.class).forEach(s -> {
fileSystemPreparationRepository.remove(s);
PersistentStep persistentStep = turnToPersistentStep(s);
preparationRepository.add(persistentStep);
LOGGER.debug("step {} updated to {}", s, persistentStep);
counter.incrementAndGet();
});
LOGGER.info("Upgrade from {} to {} done, {} steps processed.", Step.class, PersistentStep.class, counter.get());
LOGGER.debug("starting upgrade from {} to {}.", Preparation.class, PersistentPreparation.class);
final Stream<Preparation> preparations = fileSystemPreparationRepository.list(Preparation.class);
preparations.forEach(p -> {
fileSystemPreparationRepository.remove(p);
PersistentPreparation persistentPreparation = turnToPersistentPreparation(p);
preparationRepository.add(persistentPreparation);
});
LOGGER.info("Upgrade from {} to {} done.", Preparation.class, PersistentPreparation.class);
LOGGER.info("Migration of step ids in preparation...");
final Stream<PersistentPreparation> persistentPreparations = preparationRepository.list(PersistentPreparation.class);
persistentPreparations.forEach(p -> {
LOGGER.info("Migration of preparation #{}", p.getId());
final List<String> stepsIds = preparationUtils.listStepsIds(p.getHeadId(), preparationRepository);
p.setSteps(stepsIds);
final DataSetMetadata metadata = dataSetMetadataRepository.get(p.getDataSetId());
if (metadata != null) {
LOGGER.info("Set metadata {} in preparation {}.", p.getDataSetId(), p.getId());
p.setRowMetadata(metadata.getRowMetadata());
} else {
LOGGER.info("Metadata {} not found for preparation {}.", p.getDataSetId(), p.getId());
p.setRowMetadata(new RowMetadata());
}
preparationRepository.add(p);
LOGGER.info("Migration of preparation #{} done ({} steps)", p.getId(), stepsIds.size());
});
LOGGER.info("Migration of step ids in preparation done.");
}
use of org.talend.dataprep.preparation.store.PersistentStep in project data-prep by Talend.
the class FileSystemPreparationRepository method init.
/**
* Make sure the root folder is there.
*/
@PostConstruct
private void init() {
getRootFolder().mkdirs();
remove(Step.ROOT_STEP);
final PersistentStep persistentStep = new PersistentStep();
persistentStep.setId(Step.ROOT_STEP.id());
remove(persistentStep);
remove(PreparationActions.ROOT_ACTIONS);
}
use of org.talend.dataprep.preparation.store.PersistentStep in project data-prep by Talend.
the class ActionNewColumnToggleCommonTest method shouldNotUpdateSteps.
@Test
public void shouldNotUpdateSteps() {
// given
final PreparationRepository repository = mock(PreparationRepository.class);
final PreparationActions actions = mock(PreparationActions.class);
final PersistentStep step = mock(PersistentStep.class);
final Action action = mock(Action.class);
List<Action> actionsList = new ArrayList<>();
actionsList.add(action);
when(step.id()).thenReturn("step-1");
when(actions.getActions()).thenReturn(actionsList);
when(action.getName()).thenReturn("action");
when(repository.list(eq(PreparationActions.class))).thenReturn(Stream.of(actions));
// Twice "action-1" to pass root preparation action filter.
// same id
when(actions.id()).thenReturn("actions-1", "actions-1", "actions-1");
when(repository.list(eq(PersistentStep.class), any())).thenReturn(Stream.of(step));
// when
ActionNewColumnToggleCommon.upgradeActions(repository);
// then
verify(repository, times(1)).add(eq(actions));
verify(repository, never()).add(eq(step));
verify(step, never()).setContent(any());
}
use of org.talend.dataprep.preparation.store.PersistentStep in project data-prep by Talend.
the class ActionNewColumnToggleCommonTest method shouldNotUpdateRootStep.
@Test
public void shouldNotUpdateRootStep() {
// given
final PreparationRepository repository = mock(PreparationRepository.class);
final PreparationActions actions = mock(PreparationActions.class);
final PersistentStep step = mock(PersistentStep.class);
final Action action = mock(Action.class);
List<Action> actionsList = new ArrayList<>();
actionsList.add(action);
// Listed step is root step
when(step.id()).thenReturn(Step.ROOT_STEP.id());
when(actions.getActions()).thenReturn(actionsList);
when(action.getName()).thenReturn("action");
when(repository.list(eq(PreparationActions.class))).thenReturn(Stream.of(actions));
when(actions.id()).thenReturn("actions-1", "actions-2");
when(repository.list(eq(PersistentStep.class), any())).thenReturn(Stream.of(step));
// when
ActionNewColumnToggleCommon.upgradeActions(repository);
// then
verify(repository, times(1)).add(eq(actions));
verify(repository, never()).add(eq(step));
verify(step, never()).setContent(any());
}
use of org.talend.dataprep.preparation.store.PersistentStep in project data-prep by Talend.
the class ActionNewColumnToggleCommonTest method shouldUpdateSteps.
@Test
public void shouldUpdateSteps() {
// given
final PreparationRepository repository = mock(PreparationRepository.class);
final PreparationActions actions = mock(PreparationActions.class);
final PersistentStep step = mock(PersistentStep.class);
final Action action = mock(Action.class);
List<Action> actionsList = new ArrayList<>();
actionsList.add(action);
when(step.id()).thenReturn("step-1");
when(actions.getActions()).thenReturn(actionsList);
when(action.getName()).thenReturn("action");
when(repository.list(eq(PreparationActions.class))).thenReturn(Stream.of(actions));
// Twice "action-1" to pass root preparation action filter.
when(actions.id()).thenReturn("actions-1", "actions-1", "actions-2");
when(repository.list(eq(PersistentStep.class), any())).thenReturn(Stream.of(step));
// when
ActionNewColumnToggleCommon.upgradeActions(repository);
// then
verify(repository, times(1)).add(eq(actions));
verify(repository, times(1)).add(eq(step));
verify(step, times(1)).setContent(eq("actions-2"));
}
Aggregations