Search in sources :

Example 51 with Preparation

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

the class PreparationTest method initialStepWithAppend.

@Test
public void initialStepWithAppend() {
    final String version = versionService.version().getVersionId();
    final List<Action> actions = getSimpleAction("uppercase", "column_name", "lastname");
    final PreparationActions newContent = PreparationActions.ROOT_ACTIONS.append(actions);
    repository.add(newContent);
    final Step s = new Step(Step.ROOT_STEP.id(), newContent.id(), version);
    repository.add(s);
    final Preparation preparation = new Preparation("#5438743", "1234", s.id(), version);
    preparation.setCreationDate(0L);
    repository.add(preparation);
    assertThat(preparation.id(), Is.is("#5438743"));
}
Also used : Action(org.talend.dataprep.api.preparation.Action) Preparation(org.talend.dataprep.api.preparation.Preparation) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) Step(org.talend.dataprep.api.preparation.Step) Test(org.junit.Test) ServiceBaseTest(org.talend.ServiceBaseTest)

Example 52 with Preparation

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

the class DataSetAPI method listSummary.

@RequestMapping(value = "/api/datasets/summary", method = GET, produces = APPLICATION_JSON_VALUE)
@ApiOperation(value = "List data sets summary.", produces = APPLICATION_JSON_VALUE, notes = "Returns a list of data sets summary the user can use.")
@Timed
public Callable<Stream<EnrichedDataSetMetadata>> listSummary(@ApiParam(value = "Sort key (by name or date), defaults to 'date'.") @RequestParam(defaultValue = "creationDate") Sort sort, @ApiParam(value = "Order for sort key (desc or asc), defaults to 'desc'.") @RequestParam(defaultValue = "desc") Order order, @ApiParam(value = "Filter on name containing the specified name") @RequestParam(defaultValue = "") String name, @ApiParam(value = "Filter on certified data sets") @RequestParam(defaultValue = "false") boolean certified, @ApiParam(value = "Filter on favorite data sets") @RequestParam(defaultValue = "false") boolean favorite, @ApiParam(value = "Filter on recent data sets") @RequestParam(defaultValue = "false") boolean limit) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Listing datasets summary (pool: {})...", getConnectionStats());
    }
    return () -> {
        GenericCommand<InputStream> listDataSets = getCommand(DataSetList.class, sort, order, name, certified, favorite, limit);
        return // 
        Flux.from(CommandHelper.toPublisher(UserDataSetMetadata.class, mapper, listDataSets)).map(m -> {
            LOG.debug("found dataset {} in the summary list" + m.getName());
            // Add the related preparations list to the given dataset metadata.
            final PreparationSearchByDataSetId getPreparations = getCommand(PreparationSearchByDataSetId.class, m.getId());
            return // 
            Flux.from(CommandHelper.toPublisher(Preparation.class, mapper, getPreparations)).collectList().map(preparations -> {
                final List<Preparation> list = // 
                preparations.stream().filter(// 
                p -> p.getSteps() != null).collect(Collectors.toList());
                return new EnrichedDataSetMetadata(m, list);
            }).block();
        }).toStream(1);
    };
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) StringUtils(org.apache.commons.lang.StringUtils) RequestParam(org.springframework.web.bind.annotation.RequestParam) DataSetGet(org.talend.dataprep.command.dataset.DataSetGet) UpdateDataSet(org.talend.dataprep.api.service.command.dataset.UpdateDataSet) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) ApiParam(io.swagger.annotations.ApiParam) DataSetGetEncodings(org.talend.dataprep.api.service.command.dataset.DataSetGetEncodings) SetFavorite(org.talend.dataprep.api.service.command.dataset.SetFavorite) CommandHelper.toStream(org.talend.dataprep.command.CommandHelper.toStream) TEXT_PLAIN_VALUE(org.springframework.http.MediaType.TEXT_PLAIN_VALUE) CommandHelper.toStreaming(org.talend.dataprep.command.CommandHelper.toStreaming) DataSetGetImports(org.talend.dataprep.api.service.command.dataset.DataSetGetImports) SemanticDomain(org.talend.dataprep.api.dataset.statistics.SemanticDomain) ApiOperation(io.swagger.annotations.ApiOperation) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) UserDataSetMetadata(org.talend.dataprep.dataset.service.UserDataSetMetadata) Order(org.talend.dataprep.util.SortAndOrderHelper.Order) MediaType(org.springframework.http.MediaType) UpdateColumn(org.talend.dataprep.api.service.command.dataset.UpdateColumn) PublicAPI(org.talend.dataprep.security.PublicAPI) StreamingResponseBody(org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) DataSetPreview(org.talend.dataprep.api.service.command.dataset.DataSetPreview) List(java.util.List) HystrixCommand(com.netflix.hystrix.HystrixCommand) Stream(java.util.stream.Stream) GetDataSetColumnTypes(org.talend.dataprep.api.service.command.dataset.GetDataSetColumnTypes) CommandHelper.toPublisher(org.talend.dataprep.command.CommandHelper.toPublisher) RequestHeader(org.springframework.web.bind.annotation.RequestHeader) PreparationList(org.talend.dataprep.api.service.command.preparation.PreparationList) CopyDataSet(org.talend.dataprep.api.service.command.dataset.CopyDataSet) GenericCommand(org.talend.dataprep.command.GenericCommand) EnrichedDataSetMetadata(org.talend.dataprep.api.service.api.EnrichedDataSetMetadata) SuggestLookupActions(org.talend.dataprep.api.service.command.transformation.SuggestLookupActions) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Callable(java.util.concurrent.Callable) CreateOrUpdateDataSet(org.talend.dataprep.api.service.command.dataset.CreateOrUpdateDataSet) SortAndOrderHelper(org.talend.dataprep.util.SortAndOrderHelper) GET(org.springframework.web.bind.annotation.RequestMethod.GET) PreparationSearchByDataSetId(org.talend.dataprep.api.service.command.preparation.PreparationSearchByDataSetId) DataSetList(org.talend.dataprep.api.service.command.dataset.DataSetList) Import(org.talend.dataprep.api.dataset.Import) CONTENT_TYPE(org.springframework.http.HttpHeaders.CONTENT_TYPE) CompatibleDataSetList(org.talend.dataprep.api.service.command.dataset.CompatibleDataSetList) POST(org.springframework.web.bind.annotation.RequestMethod.POST) Preparation(org.talend.dataprep.api.preparation.Preparation) DataSetGetImportParameters(org.talend.dataprep.api.service.command.dataset.DataSetGetImportParameters) DELETE(org.springframework.web.bind.annotation.RequestMethod.DELETE) HttpResponseContext(org.talend.dataprep.http.HttpResponseContext) CreateDataSet(org.talend.dataprep.api.service.command.dataset.CreateDataSet) Sort(org.talend.dataprep.util.SortAndOrderHelper.Sort) Mono(reactor.core.publisher.Mono) APPLICATION_JSON_VALUE(org.springframework.http.MediaType.APPLICATION_JSON_VALUE) Flux(reactor.core.publisher.Flux) DataSetDelete(org.talend.dataprep.api.service.command.dataset.DataSetDelete) DataSetGetMetadata(org.talend.dataprep.command.dataset.DataSetGetMetadata) ResponseEntity(org.springframework.http.ResponseEntity) CommandHelper(org.talend.dataprep.command.CommandHelper) SuggestDataSetActions(org.talend.dataprep.api.service.command.transformation.SuggestDataSetActions) Timed(org.talend.dataprep.metrics.Timed) InputStream(java.io.InputStream) EnrichedDataSetMetadata(org.talend.dataprep.api.service.api.EnrichedDataSetMetadata) GenericCommand(org.talend.dataprep.command.GenericCommand) PreparationSearchByDataSetId(org.talend.dataprep.api.service.command.preparation.PreparationSearchByDataSetId) List(java.util.List) PreparationList(org.talend.dataprep.api.service.command.preparation.PreparationList) DataSetList(org.talend.dataprep.api.service.command.dataset.DataSetList) CompatibleDataSetList(org.talend.dataprep.api.service.command.dataset.CompatibleDataSetList) DataSetList(org.talend.dataprep.api.service.command.dataset.DataSetList) CompatibleDataSetList(org.talend.dataprep.api.service.command.dataset.CompatibleDataSetList) Timed(org.talend.dataprep.metrics.Timed) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 53 with Preparation

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

the class SearchAPITest method shouldNotReturnNonMatchingPreparationsWhenPerformingInventory.

@Test
public void shouldNotReturnNonMatchingPreparationsWhenPerformingInventory() throws IOException {
    // given
    testClient.createPreparationFromFile("t-shirt_100.csv", "nonMatchingPreparation", home.getId());
    // when
    final Response response = // 
    given().queryParam("name", // 
    "Inventory").when().expect().statusCode(200).log().ifError().get("/api/search");
    // then
    assertEquals(200, response.getStatusCode());
    JsonNode rootNode = mapper.readTree(response.asInputStream());
    JsonNode preparations = rootNode.get("preparations");
    List<Preparation> preparationList = mapper.readValue(preparations.toString(), new TypeReference<List<Preparation>>() {
    });
    assertThat(preparationList.size(), is(0));
}
Also used : Response(com.jayway.restassured.response.Response) Preparation(org.talend.dataprep.api.preparation.Preparation) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 54 with Preparation

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

the class PreparationCleanerTest method shouldNotRemovePreparationActions_sharedByMultiplePreparation.

@Test
public void shouldNotRemovePreparationActions_sharedByMultiplePreparation() 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.exist(eq(PersistentStep.class), eq(TqlBuilder.eq("contentId", content.id())))).thenReturn(true);
    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));
    // add the preparations to the repository
    when(repository.list(Preparation.class)).thenReturn(Stream.of(firstPreparation, secondPreparation));
    // when
    cleaner.removeOrphanSteps();
    // then
    verify(repository, never()).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 55 with Preparation

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

the class PreparationCleanerTest method shouldNotRemovePreparationActions_ownedByOnePreparation.

@Test
public void shouldNotRemovePreparationActions_ownedByOnePreparation() 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));
    // add the preparations to the repository
    when(repository.exist(eq(PersistentStep.class), any())).thenReturn(true);
    // Remove first preparation
    when(repository.list(Preparation.class)).thenReturn(Stream.of(secondPreparation));
    // when
    cleaner.removeOrphanSteps();
    // then
    // when the first preparation is removed, the shared action is not deleted
    verify(repository, never()).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)

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