use of org.springframework.web.bind.annotation.PathVariable in project resilience4j by resilience4j.
the class RateLimiterEventsEndpoint method getEventsStreamFilteredByRateLimiterNameAndEventType.
@RequestMapping(value = "stream/events/{rateLimiterName}/{eventType}", produces = MEDIA_TYPE_TEXT_EVENT_STREAM)
public SseEmitter getEventsStreamFilteredByRateLimiterNameAndEventType(@PathVariable("rateLimiterName") String rateLimiterName, @PathVariable("eventType") String eventType) {
RateLimiterEvent.Type targetType = RateLimiterEvent.Type.valueOf(eventType.toUpperCase());
RateLimiter rateLimiter = rateLimiterRegistry.getAllRateLimiters().find(rL -> rL.getName().equals(rateLimiterName)).getOrElseThrow(() -> new IllegalArgumentException(String.format("rate limiter with name %s not found", rateLimiterName)));
Flux<RateLimiterEvent> eventStream = toFlux(rateLimiter.getEventPublisher()).filter(event -> event.getEventType() == targetType);
return RateLimiterEventsEmitter.createSseEmitter(eventStream);
}
use of org.springframework.web.bind.annotation.PathVariable in project scoold by Erudika.
the class ApiController method getPost.
@GetMapping("/posts/{id}")
public Map<String, Object> getPost(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) {
Model model = new ExtendedModelMap();
questionController.get(id, "", req.getParameter("sortby"), req, res, model);
Post showPost = (Post) model.getAttribute("showPost");
List<Post> answers = (List<Post>) model.getAttribute("answerslist");
List<Post> similar = (List<Post>) model.getAttribute("similarquestions");
if (showPost == null) {
res.setStatus(HttpStatus.NOT_FOUND.value());
return null;
}
Map<String, Object> result = new LinkedHashMap<>(ParaObjectUtils.getAnnotatedFields(showPost, false));
List<Map<String, Object>> answerz = answers.stream().map(p -> {
Map<String, Object> post = new LinkedHashMap<>(ParaObjectUtils.getAnnotatedFields(p, false));
post.put("author", p.getAuthor());
return post;
}).collect(Collectors.toList());
result.put("comments", showPost.getComments());
result.put("author", showPost.getAuthor());
showPost.setItemcount(null);
if (!showPost.isReply()) {
result.put("children", answerz);
result.put("similar", similar);
}
return result;
}
use of org.springframework.web.bind.annotation.PathVariable in project scoold by Erudika.
the class ApiController method listTaggedQuestions.
@GetMapping("/tags/{id}/questions")
public List<Map<String, Object>> listTaggedQuestions(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) {
Model model = new ExtendedModelMap();
questionsController.getTagged(new Tag(id).getTag(), req, model);
return ((List<Post>) model.getAttribute("questionslist")).stream().map(p -> {
Map<String, Object> post = new LinkedHashMap<>(ParaObjectUtils.getAnnotatedFields(p, false));
post.put("author", p.getAuthor());
return post;
}).collect(Collectors.toList());
}
use of org.springframework.web.bind.annotation.PathVariable in project spring-framework by spring-projects.
the class PathVariableMethodArgumentResolver method createNamedValueInfo.
@Override
protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
PathVariable ann = parameter.getParameterAnnotation(PathVariable.class);
Assert.state(ann != null, "No PathVariable annotation");
return new PathVariableNamedValueInfo(ann);
}
use of org.springframework.web.bind.annotation.PathVariable in project dhis2-core by dhis2.
the class AbstractFullReadOnlyController method getCollectionItem.
@GetMapping("/{uid}/{property}/{itemId}")
@ResponseBody
public RootNode getCollectionItem(@PathVariable("uid") String pvUid, @PathVariable("property") String pvProperty, @PathVariable("itemId") String pvItemId, @RequestParam Map<String, String> parameters, TranslateParams translateParams, HttpServletResponse response, @CurrentUser User currentUser) throws Exception {
setUserContext(currentUser, translateParams);
try {
if (!aclService.canRead(currentUser, getEntityClass())) {
throw new ReadAccessDeniedException("You don't have the proper permissions to read objects of this type.");
}
RootNode rootNode = getObjectInternal(pvUid, parameters, Lists.newArrayList(), Lists.newArrayList(pvProperty + "[:all]"), currentUser);
// TODO optimize this using field filter (collection filtering)
if (!rootNode.getChildren().isEmpty() && rootNode.getChildren().get(0).isCollection()) {
rootNode.getChildren().get(0).getChildren().stream().filter(Node::isComplex).forEach(node -> {
node.getChildren().stream().filter(child -> child.isSimple() && child.getName().equals("id") && !((SimpleNode) child).getValue().equals(pvItemId)).forEach(child -> rootNode.getChildren().get(0).removeChild(node));
});
}
if (rootNode.getChildren().isEmpty() || rootNode.getChildren().get(0).getChildren().isEmpty()) {
throw new WebMessageException(notFound(pvProperty + " with ID " + pvItemId + " could not be found."));
}
cachePrivate(response);
return rootNode;
} finally {
UserContext.reset();
}
}
Aggregations