Search in sources :

Example 1 with DatasetDTO

use of org.talend.dataprep.api.dataset.DatasetDTO in project data-prep by Talend.

the class DatasetBeanConversionTest method datasetToDatasetDTOConversion.

@Test
public void datasetToDatasetDTOConversion() {
    // when
    DatasetDTO datasetDTO = beanConversionService.convert(dataset, DatasetDTO.class);
    // then
    assertEquals(dataset.getId(), datasetDTO.getId());
    assertEquals(dataset.getCreated(), datasetDTO.getCreationDate());
    assertEquals(dataset.getUpdated(), datasetDTO.getLastModificationDate());
    assertEquals(dataset.getLabel(), datasetDTO.getName());
    assertEquals(dataset.getOwner(), datasetDTO.getAuthor());
    assertEquals(CSVFormatFamily.MEDIA_TYPE, datasetDTO.getType());
    assertEquals(dataset.getCertification(), datasetDTO.getCertification());
}
Also used : DatasetDTO(org.talend.dataprep.api.dataset.DatasetDTO) Test(org.junit.Test)

Example 2 with DatasetDTO

use of org.talend.dataprep.api.dataset.DatasetDTO in project data-prep by Talend.

the class DataSetAPI method list.

@RequestMapping(value = "/api/datasets", method = GET, produces = APPLICATION_JSON_VALUE)
@ApiOperation(value = "List data sets.", produces = APPLICATION_JSON_VALUE, notes = "Returns a list of data sets the user can use.")
@Timed
public Stream<DatasetDTO> list(@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) {
    try {
        CertificationState certification = certified ? CERTIFIED : null;
        Boolean filterOnFavorite = favorite ? Boolean.TRUE : null;
        Stream<DatasetDTO> datasetStream = datasetClient.listDataSetMetadata(certification, filterOnFavorite);
        if (isNotBlank(name)) {
            datasetStream = datasetStream.filter(ds -> containsIgnoreCase(ds.getName(), name));
        }
        if (certified) {
            datasetStream = datasetStream.filter(dataset -> dataset.getCertification() == CERTIFIED);
        }
        if (limit) {
            datasetStream = datasetStream.limit(datasetListLimit);
        }
        return // 
        datasetStream.sorted(SortAndOrderHelper.getDatasetDTOComparator(sort, order));
    } finally {
        LOG.info("listing datasets done [favorite: {}, certified: {}, name: {}, limit: {}]", favorite, certified, name, limit);
    }
}
Also used : DatasetDTO(org.talend.dataprep.api.dataset.DatasetDTO) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) UpdateDataSet(org.talend.dataprep.api.service.command.dataset.UpdateDataSet) StringUtils.containsIgnoreCase(org.apache.commons.lang3.StringUtils.containsIgnoreCase) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) Autowired(org.springframework.beans.factory.annotation.Autowired) ApiParam(io.swagger.annotations.ApiParam) SetFavorite(org.talend.dataprep.api.service.command.dataset.SetFavorite) DatasetDetailsDTO(org.talend.dataprep.api.dataset.DatasetDetailsDTO) CommandHelper.toStream(org.talend.dataprep.command.CommandHelper.toStream) DatasetDTO(org.talend.dataprep.api.dataset.DatasetDTO) TEXT_PLAIN_VALUE(org.springframework.http.MediaType.TEXT_PLAIN_VALUE) CommandHelper.toStreaming(org.talend.dataprep.command.CommandHelper.toStreaming) SemanticDomain(org.talend.dataprep.api.dataset.statistics.SemanticDomain) ApiOperation(io.swagger.annotations.ApiOperation) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) DataSet(org.talend.dataprep.api.dataset.DataSet) CertificationState(org.talend.dataprep.dataset.adapter.Dataset.CertificationState) 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) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) Stream(java.util.stream.Stream) GetDataSetColumnTypes(org.talend.dataprep.api.service.command.dataset.GetDataSetColumnTypes) 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) 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) DatasetClient(org.talend.dataprep.dataset.adapter.DatasetClient) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) CONTENT_TYPE(org.springframework.http.HttpHeaders.CONTENT_TYPE) Charset(java.nio.charset.Charset) CompatibleDataSetList(org.talend.dataprep.api.service.command.dataset.CompatibleDataSetList) POST(org.springframework.web.bind.annotation.RequestMethod.POST) DataSetGetImportParameters(org.talend.dataprep.api.service.command.dataset.DataSetGetImportParameters) DELETE(org.springframework.web.bind.annotation.RequestMethod.DELETE) CreateDataSet(org.talend.dataprep.api.service.command.dataset.CreateDataSet) Sort(org.talend.dataprep.util.SortAndOrderHelper.Sort) APPLICATION_JSON_VALUE(org.springframework.http.MediaType.APPLICATION_JSON_VALUE) StringsHelper(org.talend.dataprep.util.StringsHelper) ActionForm(org.talend.dataprep.api.action.ActionForm) PreparationDTO(org.talend.dataprep.api.preparation.PreparationDTO) DataSetDelete(org.talend.dataprep.api.service.command.dataset.DataSetDelete) CERTIFIED(org.talend.dataprep.dataset.adapter.Dataset.CertificationState.CERTIFIED) ResponseEntity(org.springframework.http.ResponseEntity) CommandHelper(org.talend.dataprep.command.CommandHelper) EncodingSupport(org.talend.dataprep.configuration.EncodingSupport) Timed(org.talend.dataprep.metrics.Timed) InputStream(java.io.InputStream) CertificationState(org.talend.dataprep.dataset.adapter.Dataset.CertificationState) Timed(org.talend.dataprep.metrics.Timed) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with DatasetDTO

use of org.talend.dataprep.api.dataset.DatasetDTO in project data-prep by Talend.

the class DataSetService method list.

@RequestMapping(value = "/datasets", method = RequestMethod.GET)
@ApiOperation(value = "List all data sets and filters on certified, or favorite or a limited number when asked", notes = "Returns the list of data sets (and filters) the current user is allowed to see. Creation date is a Epoch time value (in UTC time zone).")
@Timed
public Stream<DatasetDTO> list(@ApiParam(value = "Sort key (by name, creation or modification date)") @RequestParam(defaultValue = "creationDate") Sort sort, @ApiParam(value = "Order for sort key (desc or asc or modif)") @RequestParam(defaultValue = "desc") Order order, @ApiParam(value = "Filter on name containing the specified name") @RequestParam(required = false) String name, @ApiParam(value = "Filter on name containing the specified name strictness") @RequestParam(defaultValue = "false") boolean nameStrict, @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 = "Only return a limited number of data sets") @RequestParam(defaultValue = "false") boolean limit) {
    String userId = security.getUserId();
    final UserData userData = userDataRepository.get(userId);
    Set<String> favorites = new HashSet<>();
    if (userData != null) {
        favorites = userData.getFavoritesDatasets();
    }
    Stream<DataSetMetadata> datasetList = findDataset(sort, order, name, nameStrict, certified, favorite, limit, favorites);
    Set<String> finalFavorites = favorites;
    return datasetList.map(p -> beanConversionService.convert(p, DatasetDTO.class, injectFavorite(finalFavorites)));
}
Also used : DatasetDTO(org.talend.dataprep.api.dataset.DatasetDTO) UserData(org.talend.dataprep.api.user.UserData) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) HashSet(java.util.HashSet) Timed(org.talend.dataprep.metrics.Timed) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DatasetDTO (org.talend.dataprep.api.dataset.DatasetDTO)3 ApiOperation (io.swagger.annotations.ApiOperation)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)2 Timed (org.talend.dataprep.metrics.Timed)2 HystrixCommand (com.netflix.hystrix.HystrixCommand)1 ApiParam (io.swagger.annotations.ApiParam)1 InputStream (java.io.InputStream)1 Charset (java.nio.charset.Charset)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)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.containsIgnoreCase (org.apache.commons.lang3.StringUtils.containsIgnoreCase)1 StringUtils.isNotBlank (org.apache.commons.lang3.StringUtils.isNotBlank)1 Test (org.junit.Test)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Value (org.springframework.beans.factory.annotation.Value)1