use of org.springframework.web.bind.annotation.RequestParam in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisController method list.
@ApiOperation("List analyses.")
@RequestMapping(value = "/api/v1/analysis-management/analyses", method = GET)
public JsonResult<List<D>> list(Principal principal, @RequestParam("study-id") Long studyId) throws PermissionDeniedException, NotExistException {
JsonResult<List<D>> result;
IUser user = userService.getByUsername(principal.getName());
if (user == null) {
result = new JsonResult<>(PERMISSION_DENIED);
return result;
}
Iterable<T> analyses = analysisService.list(user, studyId);
result = new JsonResult<>(NO_ERROR);
List<D> analysisDTOs = StreamSupport.stream(analyses.spliterator(), false).map(analysis -> conversionService.convert(analysis, getAnalysisDTOClass())).collect(Collectors.toList());
result.setResult(analysisDTOs);
return result;
}
use of org.springframework.web.bind.annotation.RequestParam in project powerauth-restful-integration by lime-company.
the class PowerAuthAnnotationInterceptor method expandResourceId.
/**
* The method substitutes placeholders (marked via "${placeholder}") in resourceID attribute value by
* the actual parameters of the handler method. The implementation takes into account all method parameters
* that are annotated via @RequestParam or @PathVariable annotations and extracts values from the request
* parameter map.<br>
* <br>
* <b>
* Note: In case both @RequestParam and @PathVariable with the same name exist, the value of @RequestParam
* takes precedence. This is because @RequestParam usually maps to the HTTP GET query parameter that cannot
* be easily changed in existing API, while @PathVariable is just a URL placeholder that can be renamed in
* the code with no impact on functionality.
* </b>
*
* @param resourceId Resource ID with possible placeholders.
* @param request HttpServletRequest for the current execution.
* @param handlerMethod Handler method that is responsible for the request processing.
* @return Resource ID with substituted placeholders.
*/
@SuppressWarnings("unchecked")
private String expandResourceId(String resourceId, HttpServletRequest request, HandlerMethod handlerMethod) {
// Get method parameters that could be replaced in the context of resource ID
final Map<String, String> parameters = new TreeMap<>();
final MethodParameter[] methodParameters = handlerMethod.getMethodParameters();
for (MethodParameter mp : methodParameters) {
// Handle parameters annotated by @RequestParam annotation.
// These are stored in the servlet request parameter map.
// Note: @RequestParam must be processed before @PathVariable since
// in API, it cannot be renamed (the path variable is just
// a placeholder and can have arbitrary name).
final RequestParam requestParam = mp.getParameterAnnotation(RequestParam.class);
if (requestParam != null) {
final String name = requestParam.name();
final String value = request.getParameter(name);
if (value != null) {
// do not check "&& !parameters.containsKey(name)" because in the case of
// a name conflict, we want @RequestParam to overwrite @PathVariable value
parameters.put(name, value);
}
} else {
// Handle parameters annotated by @PathVariable annotation.
// These are stored by Spring in the servlet request attributes map, under a special
// URI_TEMPLATE_VARIABLES_ATTRIBUTE key that contains Map<String, String> with path
// variable mapping.
final PathVariable pathVariable = mp.getParameterAnnotation(PathVariable.class);
if (pathVariable != null) {
final String name = pathVariable.name();
final Map<String, String> pathVariableMap = (Map<String, String>) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
if (pathVariableMap != null && !parameters.containsKey(name)) {
// prevent overwriting value that is already assigned
final String value = pathVariableMap.get(name);
if (value != null) {
parameters.put(name, value);
}
}
}
}
}
// Substitute the placeholders
final StringSubstitutor sub = new StringSubstitutor(parameters);
return sub.replace(resourceId);
}
Aggregations