use of org.springframework.web.bind.annotation.RequestMethod.GET in project data-prep by Talend.
the class FolderService method list.
/**
* Get folders. If parentId is supplied, it will be used as filter.
*
* @param parentId the parent folder id parameter
* @return direct sub folders for the given id.
*/
// @formatter:off
@RequestMapping(value = "/folders", method = GET)
@ApiOperation(value = "List children folders of the parameter if null list root children.", notes = "List all child folders of the one as parameter")
@Timed
public Stream<Folder> list(@RequestParam(required = false) @ApiParam(value = "Parent id filter.") String parentId, @RequestParam(defaultValue = "lastModificationDate") @ApiParam(value = "Sort key (by name or date).") Sort sort, @RequestParam(defaultValue = "desc") @ApiParam(value = "Order for sort key (desc or asc).") Order order) {
// @formatter:on
Stream<Folder> children;
if (parentId != null) {
if (!folderRepository.exists(parentId)) {
throw new TDPException(FOLDER_NOT_FOUND, build().put("id", parentId));
}
children = folderRepository.children(parentId);
} else {
// This will list all folders
children = folderRepository.searchFolders("", false);
}
final AtomicInteger folderCount = new AtomicInteger();
// update the number of preparations in each children
children = children.peek(f -> {
final long count = folderRepository.count(f.getId(), PREPARATION);
f.setNbPreparations(count);
folderCount.addAndGet(1);
});
LOGGER.info("Found {} children for parentId: {}", folderCount.get(), parentId);
// sort the folders
return children.sorted(getFolderComparator(sort, order));
}
use of org.springframework.web.bind.annotation.RequestMethod.GET in project data-prep by Talend.
the class DataSetService method preview.
/**
* Returns preview of the the data set content for given id (first 100 rows). Service might return
* {@link org.apache.http.HttpStatus#SC_ACCEPTED} if the data set exists but analysis is not yet fully
* completed so content is not yet ready to be served.
*
* @param metadata If <code>true</code>, includes data set metadata information.
* @param sheetName the sheet name to preview
* @param dataSetId A data set id.
*/
@RequestMapping(value = "/datasets/{id}/preview", method = RequestMethod.GET)
@ApiOperation(value = "Get a data preview set by id", notes = "Get a data set preview content based on provided id. Not valid or non existing data set id returns empty content. Data set not in drat status will return a redirect 301")
@Timed
@ResponseBody
public DataSet preview(@RequestParam(defaultValue = "true") @ApiParam(name = "metadata", value = "Include metadata information in the response") boolean metadata, @RequestParam(defaultValue = "") @ApiParam(name = "sheetName", value = "Sheet name to preview") String sheetName, @PathVariable(value = "id") @ApiParam(name = "id", value = "Id of the requested data set") String dataSetId) {
DataSetMetadata dataSetMetadata = dataSetMetadataRepository.get(dataSetId);
if (dataSetMetadata == null) {
HttpResponseContext.status(HttpStatus.NO_CONTENT);
// No data set, returns empty content.
return DataSet.empty();
}
if (!dataSetMetadata.isDraft()) {
// Moved to get data set content operation
HttpResponseContext.status(HttpStatus.MOVED_PERMANENTLY);
HttpResponseContext.header("Location", "/datasets/" + dataSetId + "/content");
// dataset not anymore a draft so preview doesn't make sense.
return DataSet.empty();
}
if (StringUtils.isNotEmpty(sheetName)) {
dataSetMetadata.setSheetName(sheetName);
}
// take care of previous data without schema parser result
if (dataSetMetadata.getSchemaParserResult() != null) {
// sheet not yet set correctly so use the first one
if (StringUtils.isEmpty(dataSetMetadata.getSheetName())) {
String theSheetName = dataSetMetadata.getSchemaParserResult().getSheetContents().get(0).getName();
LOG.debug("preview for dataSetMetadata: {} with sheetName: {}", dataSetId, theSheetName);
dataSetMetadata.setSheetName(theSheetName);
}
String theSheetName = dataSetMetadata.getSheetName();
Optional<Schema.SheetContent> sheetContentFound = dataSetMetadata.getSchemaParserResult().getSheetContents().stream().filter(sheetContent -> theSheetName.equals(sheetContent.getName())).findFirst();
if (!sheetContentFound.isPresent()) {
HttpResponseContext.status(HttpStatus.NO_CONTENT);
// No sheet found, returns empty content.
return DataSet.empty();
}
List<ColumnMetadata> columnMetadatas = sheetContentFound.get().getColumnMetadatas();
if (dataSetMetadata.getRowMetadata() == null) {
dataSetMetadata.setRowMetadata(new RowMetadata(emptyList()));
}
dataSetMetadata.getRowMetadata().setColumns(columnMetadatas);
} else {
LOG.warn("dataset#{} has draft status but any SchemaParserResult");
}
// Build the result
DataSet dataSet = new DataSet();
if (metadata) {
dataSet.setMetadata(conversionService.convert(dataSetMetadata, UserDataSetMetadata.class));
}
dataSet.setRecords(contentStore.stream(dataSetMetadata).limit(100));
return dataSet;
}
use of org.springframework.web.bind.annotation.RequestMethod.GET in project collect by openforis.
the class AbstractPersistedObjectEditFormController method load.
@RequestMapping(value = "/{id}", method = GET)
@ResponseBody
public F load(@PathVariable int id) {
T item = loadItem(id);
F form = createFormInstance(item);
return form;
}
use of org.springframework.web.bind.annotation.RequestMethod.GET in project spring-framework by spring-projects.
the class RequestMappingInfoTests method compareToWithImpicitVsExplicitHttpMethodDeclaration.
@Test
void compareToWithImpicitVsExplicitHttpMethodDeclaration() {
RequestMappingInfo noMethods = RequestMappingInfo.paths().build();
RequestMappingInfo oneMethod = RequestMappingInfo.paths().methods(GET).build();
RequestMappingInfo oneMethodOneParam = RequestMappingInfo.paths().methods(GET).params("foo").build();
MockHttpServletRequest request = PathPatternsTestUtils.initRequest("GET", "/", false);
Comparator<RequestMappingInfo> comparator = (info, otherInfo) -> info.compareTo(otherInfo, request);
List<RequestMappingInfo> list = asList(noMethods, oneMethod, oneMethodOneParam);
Collections.shuffle(list);
list.sort(comparator);
assertThat(list.get(0)).isEqualTo(oneMethodOneParam);
assertThat(list.get(1)).isEqualTo(oneMethod);
assertThat(list.get(2)).isEqualTo(noMethods);
}
use of org.springframework.web.bind.annotation.RequestMethod.GET in project spring-framework by spring-projects.
the class RequestMappingInfoTests method compareToWithHttpHeadMapping.
@Test
// SPR-14383
void compareToWithHttpHeadMapping() {
MockHttpServletRequest request = PathPatternsTestUtils.initRequest("GET", "/", false);
request.setMethod("HEAD");
request.addHeader("Accept", "application/json");
RequestMappingInfo noMethods = RequestMappingInfo.paths().build();
RequestMappingInfo getMethod = RequestMappingInfo.paths().methods(GET).produces("application/json").build();
RequestMappingInfo headMethod = RequestMappingInfo.paths().methods(HEAD).build();
Comparator<RequestMappingInfo> comparator = (info, otherInfo) -> info.compareTo(otherInfo, request);
List<RequestMappingInfo> list = asList(noMethods, getMethod, headMethod);
Collections.shuffle(list);
list.sort(comparator);
assertThat(list.get(0)).isEqualTo(headMethod);
assertThat(list.get(1)).isEqualTo(getMethod);
assertThat(list.get(2)).isEqualTo(noMethods);
}
Aggregations