use of org.talend.dataprep.api.preparation.PreparationActions in project data-prep by Talend.
the class UpdatedStepVisitorTest method testUpdatedStepsWithOk.
@Test
public void testUpdatedStepsWithOk() throws Exception {
// Given
final Step step = new Step(ROOT_STEP.id(), new PreparationActions().id(), "0.0");
final RowMetadata stepRowMetadata = new RowMetadata();
final Node stepNode = NodeBuilder.from(new StepNode(step, stepRowMetadata, entryNode, new BasicNode())).to(new BasicNode()).build();
final UpdatedStepVisitor visitor = new UpdatedStepVisitor(stepMetadataRepository);
// OK action!
actionContext.setActionStatus(ActionContext.ActionStatus.OK);
// When
stepNode.exec().receive(new DataSetRow(metadata), metadata);
// Then
stepNode.accept(visitor);
verify(stepMetadataRepository).update(step.id(), stepRowMetadata);
}
use of org.talend.dataprep.api.preparation.PreparationActions 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.api.preparation.PreparationActions 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.api.preparation.PreparationActions 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"));
}
use of org.talend.dataprep.api.preparation.PreparationActions in project data-prep by Talend.
the class SplitReplaceOnValueAction method run.
@Override
public void run() {
final Stream<PreparationActions> preparationActionsStream = preparationRepository.list(PreparationActions.class).filter(p -> p.getActions().stream().anyMatch(a -> REPLACE_ON_VALUE.equals(a.getName()) && CELL.equals(a.getParameters().get("scope"))));
AtomicLong actionsUpdated = new AtomicLong(0);
preparationActionsStream.forEach(currentPrepActions -> {
final List<Action> actions = currentPrepActions.getActions();
boolean updatePrepActions = false;
for (Action action : actions) {
final Map<String, String> parameters = action.getParameters();
// only deal with replace_on_value with scope cell
if (REPLACE_ON_VALUE.equals(action.getName()) && CELL.equals(parameters.get("scope"))) {
// rename action
action.setName(REPLACE_CELL_VALUE);
// update parameters
updateActionParameters(parameters);
updatePrepActions = true;
}
}
// only save updated preparation actions
if (updatePrepActions) {
preparationRepository.add(currentPrepActions);
actionsUpdated.getAndIncrement();
}
});
LOGGER.info("'Replace On Value' implementations were successfully split, {} action(s) updated", actionsUpdated);
}
Aggregations