Search in sources :

Example 16 with Action

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());
}
Also used : PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Action(org.talend.dataprep.api.preparation.Action) ArrayList(java.util.ArrayList) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) Test(org.junit.Test)

Example 17 with Action

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"));
}
Also used : PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Action(org.talend.dataprep.api.preparation.Action) ArrayList(java.util.ArrayList) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) Test(org.junit.Test)

Example 18 with Action

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);
}
Also used : VERSION(org.talend.dataprep.upgrade.model.UpgradeTask.target.VERSION) Logger(org.slf4j.Logger) MixedContentMapModule(org.talend.dataprep.api.preparation.json.MixedContentMapModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) UpgradeTask(org.talend.dataprep.upgrade.model.UpgradeTask) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) Map(java.util.Map) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) PostConstruct(javax.annotation.PostConstruct) JsonNode(com.fasterxml.jackson.databind.JsonNode) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) Action(org.talend.dataprep.api.preparation.Action) AtomicLong(java.util.concurrent.atomic.AtomicLong) Action(org.talend.dataprep.api.preparation.Action) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions)

Example 19 with Action

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);
}
Also used : Action(org.talend.dataprep.api.preparation.Action) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) Test(org.junit.Test)

Example 20 with Action

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;
}
Also used : Action(org.talend.dataprep.api.preparation.Action)

Aggregations

Action (org.talend.dataprep.api.preparation.Action)27 Test (org.junit.Test)14 PreparationActions (org.talend.dataprep.api.preparation.PreparationActions)12 ArrayList (java.util.ArrayList)9 List (java.util.List)7 PreparationRepository (org.talend.dataprep.preparation.store.PreparationRepository)7 Preparation (org.talend.dataprep.api.preparation.Preparation)6 Step (org.talend.dataprep.api.preparation.Step)6 PersistentStep (org.talend.dataprep.preparation.store.PersistentStep)6 IOException (java.io.IOException)4 Collections (java.util.Collections)4 Stream (java.util.stream.Stream)4 ActionDefinition (org.talend.dataprep.api.action.ActionDefinition)4 RunnableAction (org.talend.dataprep.transformation.actions.common.RunnableAction)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3 StringUtils (org.apache.commons.lang.StringUtils)3 InjectMocks (org.mockito.InjectMocks)3 Mock (org.mockito.Mock)3