Search in sources :

Example 1 with CommandHelper.toPublisher

use of org.talend.dataprep.command.CommandHelper.toPublisher 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)

Aggregations

HystrixCommand (com.netflix.hystrix.HystrixCommand)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiParam (io.swagger.annotations.ApiParam)1 InputStream (java.io.InputStream)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 StringUtils (org.apache.commons.lang.StringUtils)1 CONTENT_TYPE (org.springframework.http.HttpHeaders.CONTENT_TYPE)1 MediaType (org.springframework.http.MediaType)1 APPLICATION_JSON_VALUE (org.springframework.http.MediaType.APPLICATION_JSON_VALUE)1 TEXT_PLAIN_VALUE (org.springframework.http.MediaType.TEXT_PLAIN_VALUE)1 ResponseEntity (org.springframework.http.ResponseEntity)1 PathVariable (org.springframework.web.bind.annotation.PathVariable)1 RequestHeader (org.springframework.web.bind.annotation.RequestHeader)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 DELETE (org.springframework.web.bind.annotation.RequestMethod.DELETE)1 GET (org.springframework.web.bind.annotation.RequestMethod.GET)1 POST (org.springframework.web.bind.annotation.RequestMethod.POST)1