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());
}
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);
}
}
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)));
}
Aggregations