Search in sources :

Example 66 with PathVariable

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);
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RateLimiterEvent(io.github.resilience4j.ratelimiter.event.RateLimiterEvent) RateLimiterEventsEndpointResponse(io.github.resilience4j.ratelimiter.monitoring.model.RateLimiterEventsEndpointResponse) RateLimiter(io.github.resilience4j.ratelimiter.RateLimiter) MediaType(org.springframework.http.MediaType) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Controller(org.springframework.stereotype.Controller) RateLimiterEventDTO(io.github.resilience4j.ratelimiter.monitoring.model.RateLimiterEventDTO) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) ReactorAdapter.toFlux(io.github.resilience4j.adapter.ReactorAdapter.toFlux) Flux(reactor.core.publisher.Flux) List(java.util.List) CircularEventConsumer(io.github.resilience4j.consumer.CircularEventConsumer) Seq(io.vavr.collection.Seq) Comparator(java.util.Comparator) EventConsumerRegistry(io.github.resilience4j.consumer.EventConsumerRegistry) RateLimiterRegistry(io.github.resilience4j.ratelimiter.RateLimiterRegistry) SseEmitter(org.springframework.web.servlet.mvc.method.annotation.SseEmitter) RateLimiterEvent(io.github.resilience4j.ratelimiter.event.RateLimiterEvent) RateLimiter(io.github.resilience4j.ratelimiter.RateLimiter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 67 with PathVariable

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;
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) Question(com.erudika.scoold.core.Question) Arrays(java.util.Arrays) RequestParam(org.springframework.web.bind.annotation.RequestParam) Webhook(com.erudika.para.core.Webhook) PeopleController(com.erudika.scoold.controllers.PeopleController) WebRequest(org.springframework.web.context.request.WebRequest) LoggerFactory(org.slf4j.LoggerFactory) ParaClient(com.erudika.para.client.ParaClient) Revision(com.erudika.scoold.core.Revision) StringUtils(org.apache.commons.lang3.StringUtils) Model(org.springframework.ui.Model) CommentController(com.erudika.scoold.controllers.CommentController) PutMapping(org.springframework.web.bind.annotation.PutMapping) Map(java.util.Map) Config(com.erudika.para.core.utils.Config) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ValidationUtils(com.erudika.para.core.validation.ValidationUtils) ScooldUtils(com.erudika.scoold.utils.ScooldUtils) PostMapping(org.springframework.web.bind.annotation.PostMapping) BadRequestException(com.erudika.scoold.utils.BadRequestException) ParaObject(com.erudika.para.core.ParaObject) QuestionsController(com.erudika.scoold.controllers.QuestionsController) Collection(java.util.Collection) Set(java.util.Set) StreamingResponseBody(org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody) UnapprovedQuestion(com.erudika.scoold.core.UnapprovedQuestion) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) REST_ENTITY_ATTRIBUTE(com.erudika.scoold.ScooldServer.REST_ENTITY_ATTRIBUTE) Comment(com.erudika.scoold.core.Comment) List(java.util.List) Tag(com.erudika.para.core.Tag) ReportsController(com.erudika.scoold.controllers.ReportsController) Optional(java.util.Optional) AUTH_USER_ATTRIBUTE(com.erudika.scoold.ScooldServer.AUTH_USER_ATTRIBUTE) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Sysprop(com.erudika.para.core.Sysprop) TagsController(com.erudika.scoold.controllers.TagsController) ParaObjectUtils(com.erudika.para.core.utils.ParaObjectUtils) RevisionsController(com.erudika.scoold.controllers.RevisionsController) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) Pager(com.erudika.para.core.utils.Pager) PatchMapping(org.springframework.web.bind.annotation.PatchMapping) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) AdminController(com.erudika.scoold.controllers.AdminController) HttpServletRequest(javax.servlet.http.HttpServletRequest) Locked(com.erudika.para.core.annotations.Locked) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) GetMapping(org.springframework.web.bind.annotation.GetMapping) UnapprovedReply(com.erudika.scoold.core.UnapprovedReply) ProfileController(com.erudika.scoold.controllers.ProfileController) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Post(com.erudika.scoold.core.Post) VoteController(com.erudika.scoold.controllers.VoteController) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) User(com.erudika.para.core.User) CONTEXT_PATH(com.erudika.scoold.ScooldServer.CONTEXT_PATH) Utils(com.erudika.para.core.utils.Utils) Report(com.erudika.scoold.core.Report) TimeUnit(java.util.concurrent.TimeUnit) HttpStatus(org.springframework.http.HttpStatus) ScooldServer(com.erudika.scoold.ScooldServer) NumberUtils(org.apache.commons.lang3.math.NumberUtils) QuestionController(com.erudika.scoold.controllers.QuestionController) Reply(com.erudika.scoold.core.Reply) MultipartFile(org.springframework.web.multipart.MultipartFile) ResponseEntity(org.springframework.http.ResponseEntity) Collections(java.util.Collections) Profile(com.erudika.scoold.core.Profile) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Post(com.erudika.scoold.core.Post) LinkedHashMap(java.util.LinkedHashMap) Model(org.springframework.ui.Model) List(java.util.List) ParaObject(com.erudika.para.core.ParaObject) Map(java.util.Map) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 68 with PathVariable

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());
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) Question(com.erudika.scoold.core.Question) Arrays(java.util.Arrays) RequestParam(org.springframework.web.bind.annotation.RequestParam) Webhook(com.erudika.para.core.Webhook) PeopleController(com.erudika.scoold.controllers.PeopleController) WebRequest(org.springframework.web.context.request.WebRequest) LoggerFactory(org.slf4j.LoggerFactory) ParaClient(com.erudika.para.client.ParaClient) Revision(com.erudika.scoold.core.Revision) StringUtils(org.apache.commons.lang3.StringUtils) Model(org.springframework.ui.Model) CommentController(com.erudika.scoold.controllers.CommentController) PutMapping(org.springframework.web.bind.annotation.PutMapping) Map(java.util.Map) Config(com.erudika.para.core.utils.Config) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ValidationUtils(com.erudika.para.core.validation.ValidationUtils) ScooldUtils(com.erudika.scoold.utils.ScooldUtils) PostMapping(org.springframework.web.bind.annotation.PostMapping) BadRequestException(com.erudika.scoold.utils.BadRequestException) ParaObject(com.erudika.para.core.ParaObject) QuestionsController(com.erudika.scoold.controllers.QuestionsController) Collection(java.util.Collection) Set(java.util.Set) StreamingResponseBody(org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody) UnapprovedQuestion(com.erudika.scoold.core.UnapprovedQuestion) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) REST_ENTITY_ATTRIBUTE(com.erudika.scoold.ScooldServer.REST_ENTITY_ATTRIBUTE) Comment(com.erudika.scoold.core.Comment) List(java.util.List) Tag(com.erudika.para.core.Tag) ReportsController(com.erudika.scoold.controllers.ReportsController) Optional(java.util.Optional) AUTH_USER_ATTRIBUTE(com.erudika.scoold.ScooldServer.AUTH_USER_ATTRIBUTE) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Sysprop(com.erudika.para.core.Sysprop) TagsController(com.erudika.scoold.controllers.TagsController) ParaObjectUtils(com.erudika.para.core.utils.ParaObjectUtils) RevisionsController(com.erudika.scoold.controllers.RevisionsController) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) Pager(com.erudika.para.core.utils.Pager) PatchMapping(org.springframework.web.bind.annotation.PatchMapping) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) AdminController(com.erudika.scoold.controllers.AdminController) HttpServletRequest(javax.servlet.http.HttpServletRequest) Locked(com.erudika.para.core.annotations.Locked) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) GetMapping(org.springframework.web.bind.annotation.GetMapping) UnapprovedReply(com.erudika.scoold.core.UnapprovedReply) ProfileController(com.erudika.scoold.controllers.ProfileController) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Post(com.erudika.scoold.core.Post) VoteController(com.erudika.scoold.controllers.VoteController) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) User(com.erudika.para.core.User) CONTEXT_PATH(com.erudika.scoold.ScooldServer.CONTEXT_PATH) Utils(com.erudika.para.core.utils.Utils) Report(com.erudika.scoold.core.Report) TimeUnit(java.util.concurrent.TimeUnit) HttpStatus(org.springframework.http.HttpStatus) ScooldServer(com.erudika.scoold.ScooldServer) NumberUtils(org.apache.commons.lang3.math.NumberUtils) QuestionController(com.erudika.scoold.controllers.QuestionController) Reply(com.erudika.scoold.core.Reply) MultipartFile(org.springframework.web.multipart.MultipartFile) ResponseEntity(org.springframework.http.ResponseEntity) Collections(java.util.Collections) Profile(com.erudika.scoold.core.Profile) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Model(org.springframework.ui.Model) List(java.util.List) Tag(com.erudika.para.core.Tag) Map(java.util.Map) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 69 with PathVariable

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);
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable)

Example 70 with PathVariable

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();
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) Order(org.hisp.dhis.query.Order) RequestParam(org.springframework.web.bind.annotation.RequestParam) ReflectionUtils(org.hisp.dhis.system.util.ReflectionUtils) UserContext(org.hisp.dhis.common.UserContext) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) InclusionStrategy(org.hisp.dhis.node.config.InclusionStrategy) Pagination(org.hisp.dhis.query.Pagination) UserSettingKey(org.hisp.dhis.user.UserSettingKey) Autowired(org.springframework.beans.factory.annotation.Autowired) CurrentUser(org.hisp.dhis.user.CurrentUser) PaginationUtils(org.hisp.dhis.webapi.utils.PaginationUtils) NodeUtils(org.hisp.dhis.node.NodeUtils) UserSettingService(org.hisp.dhis.user.UserSettingService) Locale(java.util.Locale) Optional(com.google.common.base.Optional) Map(java.util.Map) Preset(org.hisp.dhis.node.Preset) Query(org.hisp.dhis.query.Query) ContextService(org.hisp.dhis.webapi.service.ContextService) LinkService(org.hisp.dhis.webapi.service.LinkService) FieldFilterService(org.hisp.dhis.fieldfilter.FieldFilterService) CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) CacheControl.noCache(org.springframework.http.CacheControl.noCache) QueryService(org.hisp.dhis.query.QueryService) Property(org.hisp.dhis.schema.Property) Defaults(org.hisp.dhis.fieldfilter.Defaults) SimpleNode(org.hisp.dhis.node.types.SimpleNode) List(java.util.List) Include(org.hisp.dhis.node.config.InclusionStrategy.Include) ComplexNode(org.hisp.dhis.node.types.ComplexNode) AttributeService(org.hisp.dhis.attribute.AttributeService) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) AclService(org.hisp.dhis.security.acl.AclService) Schema(org.hisp.dhis.schema.Schema) RootNode(org.hisp.dhis.node.types.RootNode) Joiner(com.google.common.base.Joiner) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) WebMessageUtils.notFound(org.hisp.dhis.dxf2.webmessage.WebMessageUtils.notFound) CollectionNode(org.hisp.dhis.node.types.CollectionNode) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) HashMap(java.util.HashMap) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) ArrayList(java.util.ArrayList) Enums(com.google.common.base.Enums) HttpServletRequest(javax.servlet.http.HttpServletRequest) Lists(com.google.common.collect.Lists) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) User(org.hisp.dhis.user.User) GetMapping(org.springframework.web.bind.annotation.GetMapping) QueryParserException(org.hisp.dhis.query.QueryParserException) ReadAccessDeniedException(org.hisp.dhis.hibernate.exception.ReadAccessDeniedException) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) ContextUtils(org.hisp.dhis.webapi.utils.ContextUtils) Node(org.hisp.dhis.node.Node) Pager(org.hisp.dhis.common.Pager) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) HttpStatus(org.springframework.http.HttpStatus) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) Collectors.toList(java.util.stream.Collectors.toList) OrderParams(org.hisp.dhis.dxf2.common.OrderParams) CurrentUserService(org.hisp.dhis.user.CurrentUserService) TranslateParams(org.hisp.dhis.dxf2.common.TranslateParams) RootNode(org.hisp.dhis.node.types.RootNode) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ReadAccessDeniedException(org.hisp.dhis.hibernate.exception.ReadAccessDeniedException) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

PathVariable (org.springframework.web.bind.annotation.PathVariable)83 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)65 List (java.util.List)61 RequestParam (org.springframework.web.bind.annotation.RequestParam)54 Collectors (java.util.stream.Collectors)50 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)48 RestController (org.springframework.web.bind.annotation.RestController)44 Autowired (org.springframework.beans.factory.annotation.Autowired)43 RequestBody (org.springframework.web.bind.annotation.RequestBody)42 MediaType (org.springframework.http.MediaType)40 ApiOperation (io.swagger.annotations.ApiOperation)37 HttpStatus (org.springframework.http.HttpStatus)33 IOException (java.io.IOException)32 Set (java.util.Set)29 ApiParam (io.swagger.annotations.ApiParam)27 HttpServletResponse (javax.servlet.http.HttpServletResponse)27 Map (java.util.Map)26 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)26 ResponseEntity (org.springframework.http.ResponseEntity)25 GetMapping (org.springframework.web.bind.annotation.GetMapping)24