Search in sources :

Example 71 with RequestParam

use of org.springframework.web.bind.annotation.RequestParam in project data-prep by Talend.

the class FolderService method search.

/**
 * Search for folders.
 *
 * @param name the folder name to search.
 * @param strict strict mode means the name is the full name.
 * @return the folders whose part of their name match the given path.
 */
@RequestMapping(value = "/folders/search", method = GET)
@ApiOperation(value = "Search Folders with parameter as part of the name")
@Timed
public Stream<Folder> search(@RequestParam(required = false, defaultValue = "") final String name, @RequestParam(required = false, defaultValue = "false") final Boolean strict, @RequestParam(required = false) final String path) {
    Stream<Folder> folders;
    if (path == null) {
        folders = folderRepository.searchFolders(name, strict);
    } else {
        folders = folderRepository.searchFolders(name, strict).filter(f -> f.getPath().equals(path));
    }
    AtomicInteger foldersFound = new AtomicInteger(0);
    folders = folders.peek(folder -> {
        folder.setNbPreparations(folderRepository.count(folder.getId(), PREPARATION));
        foldersFound.incrementAndGet();
    });
    LOGGER.info("Found {} folder(s) searching for {}", foldersFound, name);
    return folders;
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) TDPException(org.talend.dataprep.exception.TDPException) PREPARATION(org.talend.dataprep.api.folder.FolderContentType.PREPARATION) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ApiParam(io.swagger.annotations.ApiParam) FOLDER_NOT_FOUND(org.talend.dataprep.exception.error.FolderErrorCodes.FOLDER_NOT_FOUND) GET(org.springframework.web.bind.annotation.RequestMethod.GET) RequestBody(org.springframework.web.bind.annotation.RequestBody) ApiOperation(io.swagger.annotations.ApiOperation) ExceptionContext.build(org.talend.daikon.exception.ExceptionContext.build) ExceptionContext(org.talend.daikon.exception.ExceptionContext) Folder(org.talend.dataprep.api.folder.Folder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StreamSupport(java.util.stream.StreamSupport) Api(io.swagger.annotations.Api) FolderRepository(org.talend.dataprep.folder.store.FolderRepository) SortAndOrderHelper.getFolderComparator(org.talend.dataprep.util.SortAndOrderHelper.getFolderComparator) Logger(org.slf4j.Logger) DELETE(org.springframework.web.bind.annotation.RequestMethod.DELETE) Order(org.talend.dataprep.util.SortAndOrderHelper.Order) HttpResponseContext(org.talend.dataprep.http.HttpResponseContext) Sort(org.talend.dataprep.util.SortAndOrderHelper.Sort) FolderTreeNode(org.talend.dataprep.api.folder.FolderTreeNode) RestController(org.springframework.web.bind.annotation.RestController) HttpStatus(org.springframework.http.HttpStatus) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) BaseDataprepAuditService(org.talend.dataprep.audit.BaseDataprepAuditService) Stream(java.util.stream.Stream) Security(org.talend.dataprep.security.Security) Timed(org.talend.dataprep.metrics.Timed) FolderInfo(org.talend.dataprep.api.folder.FolderInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Folder(org.talend.dataprep.api.folder.Folder) Timed(org.talend.dataprep.metrics.Timed) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 72 with RequestParam

use of org.springframework.web.bind.annotation.RequestParam in project data-prep by Talend.

the class DataSetService method get.

/**
 * Returns the <b>full</b> data set content for given id.
 *
 * @param metadata If <code>true</code>, includes data set metadata information.
 * @param dataSetId A data set id.
 * @return The full data set.
 */
@RequestMapping(value = "/datasets/{id}/content", method = RequestMethod.GET)
@ApiOperation(value = "Get a data set by id", notes = "Get a data set content based on provided id. Id should be a UUID returned by the list operation. Not valid or non existing data set id returns empty content.")
@Timed
@ResponseBody
public Callable<DataSet> get(@RequestParam(defaultValue = "true") @ApiParam(name = "metadata", value = "Include metadata information in the response") boolean metadata, @RequestParam(defaultValue = "false") @ApiParam(name = "includeInternalContent", value = "Include internal content in the response") boolean includeInternalContent, // 
@RequestParam(defaultValue = "-1") @ApiParam(name = STORAGE_LIMIT, value = STORAGE_LIMIT) long limit, @ApiParam(value = "Filter for retrieved content.") @RequestParam(value = "filter", defaultValue = "") String filter, @PathVariable(value = "id") @ApiParam(name = "id", value = "Id of the requested data set") String dataSetId) {
    return () -> {
        final Marker marker = Markers.dataset(dataSetId);
        LOG.debug(marker, "Get data set #{}", dataSetId);
        Stream<DataSetRow> stream = null;
        try {
            DataSetMetadata dataSetMetadata = dataSetMetadataRepository.get(dataSetId);
            assertDataSetMetadata(dataSetMetadata, dataSetId);
            // Build the result
            DataSet dataSet = new DataSet();
            if (metadata) {
                dataSet.setMetadata(conversionService.convert(dataSetMetadata, UserDataSetMetadata.class));
            }
            // Disable line limit
            stream = contentStore.stream(dataSetMetadata, limit);
            // on-demand analyzer for dataset (See TDP-4404, migration problems)
            if (dataSetMetadata.getRowMetadata().getColumns().stream().anyMatch(c -> c.getStatistics().getWordPatternFrequencyTable().isEmpty())) {
                stream = insertWordPatternAnalysis(dataSetMetadata, stream);
            }
            if (!includeInternalContent) {
                LOG.debug("Skip internal content when serving data set #{} content.", dataSetId);
                stream = stream.map(r -> {
                    final Map<String, Object> values = r.values();
                    final Map<String, Object> filteredValues = new HashMap<>(values);
                    // Remove technical properties from returned values.
                    values.forEach((k, v) -> {
                        if (k != null && k.startsWith(FlagNames.INTERNAL_PROPERTY_PREFIX)) {
                            filteredValues.remove(k);
                        }
                    });
                    // Include TDP_ID anyway
                    filteredValues.put(FlagNames.TDP_ID, r.getTdpId());
                    return new DataSetRow(r.getRowMetadata(), filteredValues);
                });
            }
            // Filter content
            stream = stream.filter(filterService.build(filter, dataSetMetadata.getRowMetadata()));
            dataSet.setRecords(stream);
            return dataSet;
        } catch (Exception e) {
            if (stream != null) {
                stream.close();
            }
            throw e;
        } finally {
            LOG.debug(marker, "Get done.");
        }
    };
}
Also used : VolumeMetered(org.talend.dataprep.metrics.VolumeMetered) RequestParam(org.springframework.web.bind.annotation.RequestParam) ImportBuilder(org.talend.dataprep.api.dataset.Import.ImportBuilder) FormatFamilyFactory(org.talend.dataprep.schema.FormatFamilyFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ApiParam(io.swagger.annotations.ApiParam) StringUtils(org.apache.commons.lang3.StringUtils) TEXT_PLAIN_VALUE(org.springframework.http.MediaType.TEXT_PLAIN_VALUE) SortAndOrderHelper.getDataSetMetadataComparator(org.talend.dataprep.util.SortAndOrderHelper.getDataSetMetadataComparator) Collections.singletonList(java.util.Collections.singletonList) SemanticDomain(org.talend.dataprep.api.dataset.statistics.SemanticDomain) BeanConversionService(org.talend.dataprep.conversions.BeanConversionService) PipedInputStream(java.io.PipedInputStream) DistributedLock(org.talend.dataprep.lock.DistributedLock) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) DataprepBundle.message(org.talend.dataprep.i18n.DataprepBundle.message) UserData(org.talend.dataprep.api.user.UserData) TaskExecutor(org.springframework.core.task.TaskExecutor) MAX_STORAGE_MAY_BE_EXCEEDED(org.talend.dataprep.exception.error.DataSetErrorCodes.MAX_STORAGE_MAY_BE_EXCEEDED) DataSet(org.talend.dataprep.api.dataset.DataSet) LocalStoreLocation(org.talend.dataprep.api.dataset.location.LocalStoreLocation) FormatFamily(org.talend.dataprep.schema.FormatFamily) Resource(javax.annotation.Resource) Set(java.util.Set) DatasetUpdatedEvent(org.talend.dataprep.dataset.event.DatasetUpdatedEvent) RestController(org.springframework.web.bind.annotation.RestController) IOUtils(org.apache.commons.io.IOUtils) QuotaService(org.talend.dataprep.dataset.store.QuotaService) SecurityProxy(org.talend.dataprep.security.SecurityProxy) Stream(java.util.stream.Stream) StreamSupport.stream(java.util.stream.StreamSupport.stream) FlagNames(org.talend.dataprep.api.dataset.row.FlagNames) UNEXPECTED_CONTENT(org.talend.dataprep.exception.error.CommonErrorCodes.UNEXPECTED_CONTENT) Analyzers(org.talend.dataquality.common.inference.Analyzers) DatasetImportedEvent(org.talend.dataprep.dataset.event.DatasetImportedEvent) DataSetLocatorService(org.talend.dataprep.api.dataset.location.locator.DataSetLocatorService) Callable(java.util.concurrent.Callable) Schema(org.talend.dataprep.schema.Schema) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) RequestBody(org.springframework.web.bind.annotation.RequestBody) DataSetLocationService(org.talend.dataprep.api.dataset.location.DataSetLocationService) AnalyzerService(org.talend.dataprep.quality.AnalyzerService) UserDataRepository(org.talend.dataprep.user.store.UserDataRepository) Markers(org.talend.dataprep.log.Markers) Api(io.swagger.annotations.Api) DraftValidator(org.talend.dataprep.schema.DraftValidator) HttpResponseContext(org.talend.dataprep.http.HttpResponseContext) Sort(org.talend.dataprep.util.SortAndOrderHelper.Sort) IOException(java.io.IOException) PipedOutputStream(java.io.PipedOutputStream) FormatAnalysis(org.talend.dataprep.dataset.service.analysis.synchronous.FormatAnalysis) ContentAnalysis(org.talend.dataprep.dataset.service.analysis.synchronous.ContentAnalysis) SchemaAnalysis(org.talend.dataprep.dataset.service.analysis.synchronous.SchemaAnalysis) HttpStatus(org.springframework.http.HttpStatus) FilterService(org.talend.dataprep.api.filter.FilterService) Marker(org.slf4j.Marker) NullOutputStream(org.apache.commons.io.output.NullOutputStream) StatisticsAdapter(org.talend.dataprep.dataset.StatisticsAdapter) Timed(org.talend.dataprep.metrics.Timed) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) PathVariable(org.springframework.web.bind.annotation.PathVariable) DataSetMetadataBuilder(org.talend.dataprep.dataset.DataSetMetadataBuilder) DataSetErrorCodes(org.talend.dataprep.exception.error.DataSetErrorCodes) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) DatasetDTO(org.talend.dataprep.api.dataset.DatasetDTO) SEMANTIC(org.talend.dataprep.quality.AnalyzerService.Analysis.SEMANTIC) ApiOperation(io.swagger.annotations.ApiOperation) UNABLE_TO_CREATE_OR_UPDATE_DATASET(org.talend.dataprep.exception.error.DataSetErrorCodes.UNABLE_TO_CREATE_OR_UPDATE_DATASET) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) StrictlyBoundedInputStream(org.talend.dataprep.dataset.store.content.StrictlyBoundedInputStream) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) UNSUPPORTED_CONTENT(org.talend.dataprep.exception.error.DataSetErrorCodes.UNSUPPORTED_CONTENT) TimeToLive(org.talend.dataprep.cache.ContentCache.TimeToLive) Order(org.talend.dataprep.util.SortAndOrderHelper.Order) Collections.emptyList(java.util.Collections.emptyList) Predicate(java.util.function.Predicate) PublicAPI(org.talend.dataprep.security.PublicAPI) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ContentCache(org.talend.dataprep.cache.ContentCache) INVALID_DATASET_NAME(org.talend.dataprep.exception.error.DataSetErrorCodes.INVALID_DATASET_NAME) List(java.util.List) Optional(java.util.Optional) Analyzer(org.talend.dataquality.common.inference.Analyzer) RequestHeader(org.springframework.web.bind.annotation.RequestHeader) Pattern(java.util.regex.Pattern) Security(org.talend.dataprep.security.Security) Spliterator(java.util.Spliterator) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) ComponentProperties(org.talend.dataprep.parameters.jsonschema.ComponentProperties) TDPException(org.talend.dataprep.exception.TDPException) JsonErrorCodeDescription(org.talend.dataprep.exception.json.JsonErrorCodeDescription) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) UNABLE_CREATE_DATASET(org.talend.dataprep.exception.error.DataSetErrorCodes.UNABLE_CREATE_DATASET) HashMap(java.util.HashMap) GET(org.springframework.web.bind.annotation.RequestMethod.GET) HashSet(java.util.HashSet) Import(org.talend.dataprep.api.dataset.Import) ExceptionContext.build(org.talend.daikon.exception.ExceptionContext.build) ExceptionContext(org.talend.daikon.exception.ExceptionContext) UpdateColumnParameters(org.talend.dataprep.dataset.service.api.UpdateColumnParameters) VersionService(org.talend.dataprep.api.service.info.VersionService) POST(org.springframework.web.bind.annotation.RequestMethod.POST) OutputStream(java.io.OutputStream) DataSetLocation(org.talend.dataprep.api.dataset.DataSetLocation) Logger(org.slf4j.Logger) LocaleContextHolder.getLocale(org.springframework.context.i18n.LocaleContextHolder.getLocale) UpdateDataSetCacheKey(org.talend.dataprep.dataset.service.cache.UpdateDataSetCacheKey) DataSetContentLimit(org.talend.dataprep.dataset.store.content.DataSetContentLimit) APPLICATION_JSON_VALUE(org.springframework.http.MediaType.APPLICATION_JSON_VALUE) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Certification(org.talend.dataprep.api.dataset.DataSetGovernance.Certification) Comparator(java.util.Comparator) InputStream(java.io.InputStream) DataSet(org.talend.dataprep.api.dataset.DataSet) HashMap(java.util.HashMap) PipedInputStream(java.io.PipedInputStream) Stream(java.util.stream.Stream) PipedOutputStream(java.io.PipedOutputStream) NullOutputStream(org.apache.commons.io.output.NullOutputStream) StrictlyBoundedInputStream(org.talend.dataprep.dataset.store.content.StrictlyBoundedInputStream) OutputStream(java.io.OutputStream) InputStream(java.io.InputStream) Marker(org.slf4j.Marker) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) IOException(java.io.IOException) TDPException(org.talend.dataprep.exception.TDPException) Timed(org.talend.dataprep.metrics.Timed) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

RequestParam (org.springframework.web.bind.annotation.RequestParam)72 List (java.util.List)56 PathVariable (org.springframework.web.bind.annotation.PathVariable)52 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)49 Collectors (java.util.stream.Collectors)47 IOException (java.io.IOException)37 HttpServletRequest (javax.servlet.http.HttpServletRequest)35 HttpServletResponse (javax.servlet.http.HttpServletResponse)35 Autowired (org.springframework.beans.factory.annotation.Autowired)34 HttpStatus (org.springframework.http.HttpStatus)31 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)31 Map (java.util.Map)30 GetMapping (org.springframework.web.bind.annotation.GetMapping)30 MediaType (org.springframework.http.MediaType)28 Controller (org.springframework.stereotype.Controller)28 RestController (org.springframework.web.bind.annotation.RestController)28 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)27 Set (java.util.Set)21 RequestBody (org.springframework.web.bind.annotation.RequestBody)21 ArrayList (java.util.ArrayList)20