use of org.talend.dataprep.api.preparation.Action 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.Action 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.Action 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);
}
use of org.talend.dataprep.api.preparation.Action in project data-prep by Talend.
the class SplitReplaceOnValueActionTest method shouldSplitActions.
@Test
public void shouldSplitActions() {
// when
task.run();
// then
final List<PreparationActions> prepActionsList = repository.list(PreparationActions.class).collect(Collectors.toList());
int actionUpdated = 0;
int actionNotUpdated = 0;
for (PreparationActions prepActions : prepActionsList) {
for (Action action : prepActions.getActions()) {
if (REPLACE_CELL_VALUE.equals(action.getName())) {
final Map<String, String> parameters = action.getParameters();
assertTrue(parameters.containsKey("new_value"));
assertTrue(parameters.containsKey("original_value"));
assertFalse(parameters.containsKey(CELL_VALUE));
assertFalse(parameters.containsKey(REPLACE_VALUE));
actionUpdated++;
} else {
actionNotUpdated++;
}
}
}
assertEquals(1, actionUpdated);
assertEquals(33, actionNotUpdated);
}
use of org.talend.dataprep.api.preparation.Action in project data-prep by Talend.
the class EntityBuilder method buildAction.
public static Action buildAction(String secondActionName, MixedContentMap secondActionParams) {
Action secondAction = new Action();
secondAction.setName(secondActionName);
secondAction.setParameters(secondActionParams);
return secondAction;
}
Aggregations