Search in sources :

Example 56 with Preparation

use of org.talend.dataprep.api.preparation.Preparation in project data-prep by Talend.

the class PreparationCleanerTest method removeOrphanSteps_should_remove_orphan_step_after_at_least_X_hours.

@Test
public void removeOrphanSteps_should_remove_orphan_step_after_at_least_X_hours() {
    // 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 orphanStep = new Step(secondStep.id(), "orphan", version);
    when(repository.list(eq(Step.class))).thenReturn(Stream.of(firstStep, secondStep, orphanStep));
    when(repository.list(eq(PersistentStep.class))).thenReturn(Stream.of(firstStep, secondStep, orphanStep).map(s -> {
        final PersistentStep persistentStep = new PersistentStep();
        persistentStep.setId(s.id());
        persistentStep.setContent(s.getContent());
        return persistentStep;
    }));
    final Preparation preparation = new Preparation("#123", "1", secondStep.id(), version);
    preparation.setSteps(Arrays.asList(secondStep, firstStep));
    when(repository.list(eq(Preparation.class))).thenReturn(Stream.of(preparation));
    // when
    cleaner.removeOrphanSteps();
    // then
    verify(repository, never()).remove(eq(firstStep));
    verify(repository, never()).remove(eq(secondStep));
    verify(repository, times(1)).remove(eq(orphanStep));
}
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 57 with Preparation

use of org.talend.dataprep.api.preparation.Preparation in project data-prep by Talend.

the class PreparationCleanerTest method shouldRemovePreparationActions_noPreparation.

@Test
public void shouldRemovePreparationActions_noPreparation() throws Exception {
    // given
    final String version = "1.2.3";
    final PreparationActions content = new PreparationActions();
    List<Action> actions = new ArrayList<>();
    content.append(actions);
    content.setAppVersion(version);
    when(repository.list(PreparationActions.class)).thenReturn(Stream.of(content));
    when(repository.get(content.id(), PreparationActions.class)).thenReturn(content);
    // 2 preparations, with each, one step that shares the same action
    final Step stepFirstPreparation = new Step(Step.ROOT_STEP.getId(), content.getId(), version);
    final Step stepSecondPreparation = new Step(Step.ROOT_STEP.getId(), content.getId(), version);
    // add the steps to the repository
    when(repository.list(Step.class)).thenReturn(Stream.of(stepFirstPreparation, stepSecondPreparation));
    when(repository.list(eq(PersistentStep.class))).thenReturn(Stream.of(stepFirstPreparation, stepSecondPreparation).map(s -> {
        final PersistentStep persistentStep = new PersistentStep();
        persistentStep.setId(s.id());
        persistentStep.setContent(s.getContent());
        return persistentStep;
    }));
    Preparation firstPreparation = new Preparation("1", null, stepFirstPreparation.getId(), version);
    firstPreparation.setSteps(Collections.singletonList(stepFirstPreparation));
    Preparation secondPreparation = new Preparation("2", null, stepSecondPreparation.getId(), version);
    secondPreparation.setSteps(Collections.singletonList(stepSecondPreparation));
    // when
    when(repository.exist(eq(PersistentStep.class), eq(TqlBuilder.eq("contentId", content.id())))).thenReturn(false);
    // Remove first and second preparations
    when(repository.list(Preparation.class)).thenReturn(Stream.empty());
    cleaner.removeOrphanSteps();
    // then
    // 2 steps content
    verify(repository, times(2)).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) Action(org.talend.dataprep.api.preparation.Action) Preparation(org.talend.dataprep.api.preparation.Preparation) ArrayList(java.util.ArrayList) 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 58 with Preparation

use of org.talend.dataprep.api.preparation.Preparation in project data-prep by Talend.

the class PreparationOrphanStepsFinderTest method shouldListOrphanSteps.

@Test
public void shouldListOrphanSteps() {
    // given
    final Step firstStep = new Step(Step.ROOT_STEP.id(), "first", "2.1");
    final Step secondStep = new Step(firstStep.id(), "second", "2.1");
    final Step orphanStep = new Step(Step.ROOT_STEP.id(), "orphan", "2.1");
    when(repository.list(eq(Step.class))).thenReturn(Stream.of(firstStep, secondStep, orphanStep));
    when(repository.get(eq(firstStep.id()), eq(Step.class))).thenReturn(firstStep);
    when(repository.get(eq(secondStep.id()), eq(Step.class))).thenReturn(secondStep);
    when(repository.get(eq(orphanStep.id()), eq(Step.class))).thenReturn(orphanStep);
    final Preparation preparation = new Preparation("#123", "1", secondStep.id(), "2.1");
    when(repository.list(eq(Preparation.class))).thenReturn(Stream.of(preparation));
    // when
    final Set<Step> orphanSteps = finder.getOrphanSteps();
    // then
    assertNotNull(orphanSteps);
    assertEquals(1, orphanSteps.size());
    assertEquals(orphanStep, orphanSteps.iterator().next());
}
Also used : Preparation(org.talend.dataprep.api.preparation.Preparation) Step(org.talend.dataprep.api.preparation.Step) BaseMaintenanceTest(org.talend.dataprep.maintenance.BaseMaintenanceTest) Test(org.junit.Test)

Example 59 with Preparation

use of org.talend.dataprep.api.preparation.Preparation in project data-prep by Talend.

the class SortAndOrderHelperTest method getPreparationComparison.

private // 
int getPreparationComparison(// 
String firstName, // 
String secondName, // 
String firstAuthor, // 
String secondAuthor, // 
long firstCreation, // 
long secondCreation, // 
long firstModification, // 
long secondModification, // 
long firstSize, // 
long secondSize, // 
String firstDsName, // 
String secondDsName, Sort sort, Order order) {
    String firstDsId = "firstDsId";
    Preparation firstUserPrep = createUserPreparation(firstName, firstAuthor, firstCreation, firstModification, firstSize, firstDsId);
    DataSetMetadata firstDs = new DataSetMetadata(firstDsId, firstDsName, null, 0, 0, null, null);
    String secondDsId = "secondDsId";
    Preparation secondUserPrep = createUserPreparation(secondName, secondAuthor, secondCreation, secondModification, secondSize, secondDsId);
    DataSetMetadata secondDs = new DataSetMetadata(secondDsId, secondDsName, null, 0, 0, null, null);
    Preparation firstPrep = createPreparation(firstName, firstAuthor, firstCreation, firstModification, firstSize, firstDsId);
    Preparation secondPrep = createPreparation(secondName, secondAuthor, secondCreation, secondModification, secondSize, secondDsId);
    // when
    Comparator<Preparation> preparationComparator = SortAndOrderHelper.getPreparationComparator(sort, order, p -> Objects.equals(p.getDataSetId(), firstDsId) ? firstDs : (Objects.equals(p.getDataSetId(), secondDsId) ? secondDs : null));
    // then
    assertNotNull(preparationComparator);
    final int userPreparationOrder = preparationComparator.compare(firstUserPrep, secondUserPrep);
    final int preparationOrder = preparationComparator.compare(firstPrep, secondPrep);
    assertEquals(userPreparationOrder, preparationOrder);
    return userPreparationOrder;
}
Also used : Preparation(org.talend.dataprep.api.preparation.Preparation) UserPreparation(org.talend.dataprep.preparation.service.UserPreparation) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) UserDataSetMetadata(org.talend.dataprep.dataset.service.UserDataSetMetadata)

Example 60 with Preparation

use of org.talend.dataprep.api.preparation.Preparation in project data-prep by Talend.

the class TransformationService method getPreparationExportTypesForPreparation.

/**
 * Get the available export formats for preparation
 */
@RequestMapping(value = "/export/formats/preparations/{preparationId}", method = GET)
@ApiOperation(value = "Get the available format types for the preparation")
@Timed
public Stream<ExportFormatMessage> getPreparationExportTypesForPreparation(@PathVariable String preparationId) {
    final Preparation preparation = getPreparation(preparationId);
    final DataSetMetadata metadata = context.getBean(DataSetGetMetadata.class, preparation.getDataSetId()).execute();
    return getPreparationExportTypesForDataSet(metadata.getId());
}
Also used : Preparation(org.talend.dataprep.api.preparation.Preparation) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) DataSetGetMetadata(org.talend.dataprep.command.dataset.DataSetGetMetadata) Timed(org.talend.dataprep.metrics.Timed) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

Preparation (org.talend.dataprep.api.preparation.Preparation)65 Test (org.junit.Test)44 Step (org.talend.dataprep.api.preparation.Step)18 List (java.util.List)14 ServiceBaseTest (org.talend.ServiceBaseTest)11 ArrayList (java.util.ArrayList)10 Action (org.talend.dataprep.api.preparation.Action)10 PreparationActions (org.talend.dataprep.api.preparation.PreparationActions)10 Response (com.jayway.restassured.response.Response)9 Arrays (java.util.Arrays)8 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)8 ExportParameters (org.talend.dataprep.api.export.ExportParameters)8 UserPreparation (org.talend.dataprep.preparation.service.UserPreparation)8 TransformationCacheKey (org.talend.dataprep.cache.TransformationCacheKey)7 PreparationRepository (org.talend.dataprep.preparation.store.PreparationRepository)7 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)6 Folder (org.talend.dataprep.api.folder.Folder)6 TDPException (org.talend.dataprep.exception.TDPException)6 PersistentStep (org.talend.dataprep.preparation.store.PersistentStep)6 PreparationRepositoryTest (org.talend.dataprep.preparation.store.PreparationRepositoryTest)6