use of org.springframework.web.bind.annotation.PathVariable 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);
}
use of org.springframework.web.bind.annotation.PathVariable in project runelite by runelite.
the class CacheController method listIndexes.
@RequestMapping("{cacheId}")
public List<CacheIndex> listIndexes(@PathVariable int cacheId) {
CacheEntry cache = cacheService.findCache(cacheId);
if (cache == null) {
throw new NotFoundException();
}
List<IndexEntry> indexes = cacheService.findIndexesForCache(cache);
return indexes.stream().map(entry -> new CacheIndex(entry.getIndexId(), entry.getRevision())).collect(Collectors.toList());
}
use of org.springframework.web.bind.annotation.PathVariable in project metasfresh-webui-api by metasfresh.
the class ProcessRestController method getParameterDropdown.
@RequestMapping(value = "/{processId}/{pinstanceId}/field/{parameterName}/dropdown", method = RequestMethod.GET)
public JSONLookupValuesList getParameterDropdown(//
@PathVariable("processId") final String processIdStr, //
@PathVariable("pinstanceId") final String pinstanceIdStr, //
@PathVariable("parameterName") final String parameterName) {
userSession.assertLoggedIn();
final ProcessId processId = ProcessId.fromJson(processIdStr);
final DocumentId pinstanceId = DocumentId.of(pinstanceIdStr);
final IProcessInstancesRepository instancesRepository = getRepository(processId);
return instancesRepository.forProcessInstanceReadonly(pinstanceId, processInstance -> processInstance.getParameterLookupValues(parameterName)).transform(JSONLookupValuesList::ofLookupValuesList);
}
use of org.springframework.web.bind.annotation.PathVariable in project metasfresh-webui-api by metasfresh.
the class ASIRestController method getAttributeTypeahead.
@GetMapping("/{asiDocId}/field/{attributeName}/typeahead")
public JSONLookupValuesList getAttributeTypeahead(//
@PathVariable("asiDocId") final String asiDocIdStr, //
@PathVariable("attributeName") final String attributeName, //
@RequestParam(name = "query", required = true) final String query) {
userSession.assertLoggedIn();
final DocumentId asiDocId = DocumentId.of(asiDocIdStr);
return asiRepo.forASIDocumentReadonly(asiDocId, asiDoc -> asiDoc.getFieldLookupValuesForQuery(attributeName, query)).transform(JSONLookupValuesList::ofLookupValuesList);
}
use of org.springframework.web.bind.annotation.PathVariable in project metasfresh-webui-api by metasfresh.
the class ASIRestController method getAttributeDropdown.
@GetMapping("/{asiDocId}/field/{attributeName}/dropdown")
public JSONLookupValuesList getAttributeDropdown(//
@PathVariable("asiDocId") final String asiDocIdStr, //
@PathVariable("attributeName") final String attributeName) {
userSession.assertLoggedIn();
final DocumentId asiDocId = DocumentId.of(asiDocIdStr);
return asiRepo.forASIDocumentReadonly(asiDocId, asiDoc -> asiDoc.getFieldLookupValues(attributeName)).transform(JSONLookupValuesList::ofLookupValuesList);
}
Aggregations