use of org.talend.dataprep.api.preparation.PreparationListItemDTO in project data-prep by Talend.
the class PreparationAPITest method testPreparationsList.
@Test
public void testPreparationsList() throws Exception {
// given
String tagadaId = testClient.createDataset("dataset/dataset.csv", "tagada");
String preparationId = testClient.createPreparationFromDataset(tagadaId, "testPreparation", home.getId());
// when : short format
final JsonPath shortFormat = when().get("/api/preparations/?format=short").jsonPath();
// then
final List<String> values = shortFormat.getList("id");
assertThat(values.get(0), is(preparationId));
// when : long format
Response response1 = when().get("/api/preparations/?format=long");
// then
List<PreparationListItemDTO> preparations = mapper.readerFor(PreparationListItemDTO.class).<PreparationListItemDTO>readValues(response1.asInputStream()).readAll();
assertEquals(1, preparations.size());
PreparationListItemDTO userPreparation = preparations.iterator().next();
assertThat(userPreparation.getDataSet().getDataSetName(), is("tagada"));
assertThat(userPreparation.getId(), is(preparationId));
// when : summary format
Response response = when().get("/api/preparations/?format=summary");
// then
List<PreparationListItemDTO> preparationSummaries = mapper.readerFor(PreparationListItemDTO.class).<PreparationListItemDTO>readValues(response.asInputStream()).readAll();
assertEquals(1, preparationSummaries.size());
PreparationListItemDTO preparationSummary = preparationSummaries.iterator().next();
assertThat(preparationSummary.getId(), is(preparationId));
assertThat(preparationSummary.getName(), is("testPreparation"));
assertThat(preparationSummary.getLastModificationDate(), is(notNullValue()));
}
use of org.talend.dataprep.api.preparation.PreparationListItemDTO in project data-prep by Talend.
the class FolderAPI method listPreparationsByFolder.
/**
* List all the folders and preparations out of the given id.
*
* @param id Where to list folders and preparations.
*/
// @formatter:off
@RequestMapping(value = "/api/folders/{id}/preparations", method = RequestMethod.GET, produces = APPLICATION_JSON_VALUE)
@ApiOperation(value = "Get all preparations for a given id.", notes = "Returns the list of preparations for the given id the current user is allowed to see.")
@Timed
public PreparationsByFolder listPreparationsByFolder(//
@PathVariable @ApiParam(name = "id", value = "The destination to search preparations from.") final String id, //
@ApiParam(value = "Sort key (by name or date), defaults to 'date'.") @RequestParam(defaultValue = "creationDate") final Sort sort, @ApiParam(value = "Order for sort key (desc or asc), defaults to 'desc'.") @RequestParam(defaultValue = "desc") final Order order) {
if (LOG.isDebugEnabled()) {
LOG.debug("Listing preparations in destination {} (pool: {} )...", id, getConnectionStats());
}
LOG.info("Listing preparations in folder {}", id);
final FolderChildrenList commandListFolders = getCommand(FolderChildrenList.class, id, sort, order);
final Stream<Folder> folders = toStream(Folder.class, mapper, commandListFolders);
final PreparationListByFolder listPreparations = getCommand(PreparationListByFolder.class, id, sort, order);
final Stream<PreparationListItemDTO> preparations = //
toStream(PreparationDTO.class, mapper, listPreparations).map(dto -> beanConversionService.convert(dto, PreparationListItemDTO.class, APIService::injectDataSetName));
return new PreparationsByFolder(folders, preparations);
}
Aggregations