Search in sources :

Example 6 with PersistentStep

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.");
}
Also used : PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) AtomicLong(java.util.concurrent.atomic.AtomicLong) Preparation(org.talend.dataprep.api.preparation.Preparation) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Step(org.talend.dataprep.api.preparation.Step) PersistentPreparation(org.talend.dataprep.preparation.store.PersistentPreparation) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata)

Example 7 with PersistentStep

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);
}
Also used : PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) PostConstruct(javax.annotation.PostConstruct)

Example 8 with PersistentStep

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

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

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

Aggregations

PersistentStep (org.talend.dataprep.preparation.store.PersistentStep)14 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)9 Action (org.talend.dataprep.api.preparation.Action)9 PreparationActions (org.talend.dataprep.api.preparation.PreparationActions)9 PreparationRepository (org.talend.dataprep.preparation.store.PreparationRepository)9 Preparation (org.talend.dataprep.api.preparation.Preparation)8 Step (org.talend.dataprep.api.preparation.Step)7 BaseMaintenanceTest (org.talend.dataprep.maintenance.BaseMaintenanceTest)7 Arrays (java.util.Arrays)6 Collections (java.util.Collections)6 List (java.util.List)6 Stream (java.util.stream.Stream)6 InjectMocks (org.mockito.InjectMocks)6 Mock (org.mockito.Mock)6 Mockito (org.mockito.Mockito)6 TqlBuilder (org.talend.tql.api.TqlBuilder)6 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 PostConstruct (javax.annotation.PostConstruct)1