Search in sources :

Example 6 with PreparationActions

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);
}
Also used : StepNode(org.talend.dataprep.transformation.pipeline.node.StepNode) StepNode(org.talend.dataprep.transformation.pipeline.node.StepNode) ActionNode(org.talend.dataprep.transformation.pipeline.node.ActionNode) Node(org.talend.dataprep.transformation.pipeline.Node) BasicNode(org.talend.dataprep.transformation.pipeline.node.BasicNode) BasicNode(org.talend.dataprep.transformation.pipeline.node.BasicNode) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) Step(org.talend.dataprep.api.preparation.Step) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Example 7 with PreparationActions

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());
}
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 8 with PreparationActions

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());
}
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 9 with PreparationActions

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"));
}
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 10 with PreparationActions

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);
}
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)

Aggregations

PreparationActions (org.talend.dataprep.api.preparation.PreparationActions)17 Test (org.junit.Test)14 Action (org.talend.dataprep.api.preparation.Action)13 Step (org.talend.dataprep.api.preparation.Step)11 ArrayList (java.util.ArrayList)8 PersistentStep (org.talend.dataprep.preparation.store.PersistentStep)8 PreparationRepository (org.talend.dataprep.preparation.store.PreparationRepository)8 Preparation (org.talend.dataprep.api.preparation.Preparation)7 List (java.util.List)5 Stream (java.util.stream.Stream)5 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 InjectMocks (org.mockito.InjectMocks)4 Mock (org.mockito.Mock)4 Mockito (org.mockito.Mockito)4 BaseMaintenanceTest (org.talend.dataprep.maintenance.BaseMaintenanceTest)4 TqlBuilder (org.talend.tql.api.TqlBuilder)4 ServiceBaseTest (org.talend.ServiceBaseTest)3 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)2 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)2