Search in sources :

Example 1 with PersistentStep

use of org.talend.dataprep.preparation.store.PersistentStep in project data-prep by Talend.

the class PreparationCleanerTest method removeOrphanSteps_should_not_remove_root_step.

@Test
public void removeOrphanSteps_should_not_remove_root_step() {
    // given
    when(repository.list(eq(Preparation.class))).thenReturn(Stream.empty());
    final PersistentStep rootStep = new PersistentStep();
    rootStep.setId(Step.ROOT_STEP.id());
    when(repository.list(eq(PersistentStep.class))).thenReturn(Stream.of(rootStep));
    // when
    cleaner.removeOrphanSteps();
    // then
    verify(repository, never()).remove(eq(Step.ROOT_STEP));
}
Also used : PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Preparation(org.talend.dataprep.api.preparation.Preparation) BaseMaintenanceTest(org.talend.dataprep.maintenance.BaseMaintenanceTest) Test(org.junit.Test)

Example 2 with PersistentStep

use of org.talend.dataprep.preparation.store.PersistentStep in project data-prep by Talend.

the class PreparationCleanerTest method removeOrphanSteps_should_remove_orphan_step_content.

@Test
public void removeOrphanSteps_should_remove_orphan_step_content() {
    // given
    final String version = "1.2.3";
    final PreparationActions content = new PreparationActions();
    content.setAppVersion(version);
    when(repository.list(PreparationActions.class)).thenReturn(Stream.of(content));
    when(repository.get(content.id(), PreparationActions.class)).thenReturn(content);
    final Step step = new Step(Step.ROOT_STEP.id(), content.id(), version);
    when(repository.list(eq(Step.class))).thenReturn(Stream.of(step));
    when(repository.list(eq(PersistentStep.class))).thenReturn(Stream.of(step).map(s -> {
        final PersistentStep persistentStep = new PersistentStep();
        persistentStep.setId(s.id());
        persistentStep.setContent(s.getContent());
        return persistentStep;
    }));
    when(repository.list(eq(Preparation.class))).thenReturn(Stream.empty());
    // when
    cleaner.removeOrphanSteps();
    // then
    verify(repository, times(1)).remove(eq(content));
}
Also used : InjectMocks(org.mockito.InjectMocks) Preparation(org.talend.dataprep.api.preparation.Preparation) Arrays(java.util.Arrays) TqlBuilder(org.talend.tql.api.TqlBuilder) Mock(org.mockito.Mock) BaseMaintenanceTest(org.talend.dataprep.maintenance.BaseMaintenanceTest) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Test(org.junit.Test) Step(org.talend.dataprep.api.preparation.Step) PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) ArrayList(java.util.ArrayList) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) Action(org.talend.dataprep.api.preparation.Action) Collections(java.util.Collections) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Preparation(org.talend.dataprep.api.preparation.Preparation) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Step(org.talend.dataprep.api.preparation.Step) BaseMaintenanceTest(org.talend.dataprep.maintenance.BaseMaintenanceTest) Test(org.junit.Test)

Example 3 with PersistentStep

use of org.talend.dataprep.preparation.store.PersistentStep in project data-prep by Talend.

the class PreparationCleanerTest method removeOrphanSteps_should_not_remove_step_that_still_belongs_to_a_preparation.

@Test
public void removeOrphanSteps_should_not_remove_step_that_still_belongs_to_a_preparation() {
    // given
    final String version = "1.2.3";
    final Step firstStep = new Step(Step.ROOT_STEP.id(), "first", version);
    final Step secondStep = new Step(firstStep.id(), "second", version);
    final Step thirdStep = new Step(secondStep.id(), "third", version);
    when(repository.list(eq(Step.class))).thenReturn(Stream.of(firstStep, secondStep, thirdStep));
    when(repository.list(eq(PersistentStep.class))).thenReturn(Stream.of(firstStep, secondStep, thirdStep).map(s -> {
        final PersistentStep persistentStep = new PersistentStep();
        persistentStep.setId(s.id());
        persistentStep.setContent(s.getContent());
        return persistentStep;
    }));
    final Preparation firstPreparation = new Preparation("#458", "1", firstStep.id(), version);
    firstPreparation.setSteps(Collections.singletonList(firstStep));
    final Preparation secondPreparation = new Preparation("#5428", "2", thirdStep.id(), version);
    secondPreparation.setSteps(Arrays.asList(thirdStep, secondStep, firstStep));
    when(repository.list(eq(Preparation.class))).thenReturn(Stream.of(firstPreparation, secondPreparation));
    // when
    cleaner.removeOrphanSteps();
    // then
    verify(repository, never()).remove(eq(firstStep));
    verify(repository, never()).remove(eq(secondStep));
    verify(repository, never()).remove(eq(thirdStep));
}
Also used : InjectMocks(org.mockito.InjectMocks) Preparation(org.talend.dataprep.api.preparation.Preparation) Arrays(java.util.Arrays) TqlBuilder(org.talend.tql.api.TqlBuilder) Mock(org.mockito.Mock) BaseMaintenanceTest(org.talend.dataprep.maintenance.BaseMaintenanceTest) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Test(org.junit.Test) Step(org.talend.dataprep.api.preparation.Step) PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) ArrayList(java.util.ArrayList) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) Action(org.talend.dataprep.api.preparation.Action) Collections(java.util.Collections) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Preparation(org.talend.dataprep.api.preparation.Preparation) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Step(org.talend.dataprep.api.preparation.Step) BaseMaintenanceTest(org.talend.dataprep.maintenance.BaseMaintenanceTest) Test(org.junit.Test)

Example 4 with PersistentStep

use of org.talend.dataprep.preparation.store.PersistentStep in project data-prep by Talend.

the class StepRowMetadataMigration method run.

@Override
public void run() {
    // Allow non numeric value like NaN
    objectMapper.configure(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS, true);
    LOGGER.info("Migration of step row metadata in preparations...");
    preparationRepository.list(PersistentStep.class).forEach(persistentStep -> {
        String id = persistentStep.getId();
        LOGGER.info("Migration of step #{}", id);
        String rowMetadata = persistentStep.getRowMetadata();
        try {
            // the rootstep has no metadata => avoid conversion
            if (rowMetadata != null) {
                // Dirty patch to convert all histogram (2.0) to new one (2.1)
                rowMetadata = rowMetadata.replace("_class", "type").replace("org.talend.dataprep.api.dataset.statistics.number.NumberHistogram", "number").replace("org.talend.dataprep.api.dataset.statistics.date.DateHistogram", "date");
                final DataSetMetadata dataSetMetadata = objectMapper.readerFor(DataSetMetadata.class).readValue(rowMetadata);
                final StepRowMetadata stepRowMetadata = new StepRowMetadata(dataSetMetadata.getRowMetadata());
                persistentStep.setRowMetadata(stepRowMetadata.getId());
                preparationRepository.add(persistentStep);
                preparationRepository.add(stepRowMetadata);
            }
        } catch (Exception e) {
            LOGGER.info("Ignore migration of step #{} (enable debug for full log).", id);
            LOGGER.debug("Unable to migrate step", e);
        }
    });
    LOGGER.info("Migration of step metadata in preparations done.");
}
Also used : StepRowMetadata(org.talend.dataprep.api.preparation.StepRowMetadata) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata)

Example 5 with PersistentStep

use of org.talend.dataprep.preparation.store.PersistentStep in project data-prep by Talend.

the class ToPEPersistentIdentifiable method turnToPersistentStep.

private PersistentStep turnToPersistentStep(Step step) {
    PersistentStep result = new PersistentStep();
    result.setId(step.getId());
    result.setAppVersion(step.getAppVersion());
    result.setContent(step.getContent());
    result.setDiff(step.getDiff());
    result.setParentId(step.getParent());
    result.setRowMetadata(step.getRowMetadata());
    return result;
}
Also used : PersistentStep(org.talend.dataprep.preparation.store.PersistentStep)

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