Java Code Examples for org.springframework.hateoas.Resources#add()

The following examples show how to use org.springframework.hateoas.Resources#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecentTacosController.java    From spring-in-action-5-samples with Apache License 2.0 6 votes vote down vote up
@GetMapping(path="/tacos/recent", produces="application/hal+json")
public ResponseEntity<Resources<TacoResource>> recentTacos() {
  PageRequest page = PageRequest.of(
                        0, 12, Sort.by("createdAt").descending());
  List<Taco> tacos = tacoRepo.findAll(page).getContent();

  List<TacoResource> tacoResources = 
      new TacoResourceAssembler().toResources(tacos);
  Resources<TacoResource> recentResources = 
          new Resources<TacoResource>(tacoResources);
  
  recentResources.add(
      linkTo(methodOn(RecentTacosController.class).recentTacos())
          .withRel("recents"));
  return new ResponseEntity<>(recentResources, HttpStatus.OK);
}
 
Example 2
Source File: RecentTacosController.java    From spring-in-action-5-samples with Apache License 2.0 6 votes vote down vote up
@GetMapping(path="/tacos/recent", produces="application/hal+json")
public ResponseEntity<Resources<TacoResource>> recentTacos() {
  PageRequest page = PageRequest.of(
                        0, 12, Sort.by("createdAt").descending());
  List<Taco> tacos = tacoRepo.findAll(page).getContent();

  List<TacoResource> tacoResources = 
      new TacoResourceAssembler().toResources(tacos);
  Resources<TacoResource> recentResources = 
          new Resources<TacoResource>(tacoResources);
  
  recentResources.add(
      linkTo(methodOn(RecentTacosController.class).recentTacos())
          .withRel("recents"));
  return new ResponseEntity<>(recentResources, HttpStatus.OK);
}
 
Example 3
Source File: RecentTacosController.java    From spring-in-action-5-samples with Apache License 2.0 6 votes vote down vote up
@GetMapping(path="/tacos/recent", produces="application/hal+json")
public ResponseEntity<Resources<TacoResource>> recentTacos() {
  PageRequest page = PageRequest.of(
                        0, 12, Sort.by("createdAt").descending());
  List<Taco> tacos = tacoRepo.findAll(page).getContent();

  List<TacoResource> tacoResources = 
      new TacoResourceAssembler().toResources(tacos);
  Resources<TacoResource> recentResources = 
          new Resources<TacoResource>(tacoResources);
  
  recentResources.add(
      linkTo(methodOn(RecentTacosController.class).recentTacos())
          .withRel("recents"));
  return new ResponseEntity<>(recentResources, HttpStatus.OK);
}
 
Example 4
Source File: RecentTacosController.java    From spring-in-action-5-samples with Apache License 2.0 6 votes vote down vote up
@GetMapping(path="/tacos/recent", produces="application/hal+json")
public ResponseEntity<Resources<TacoResource>> recentTacos() {
  PageRequest page = PageRequest.of(
                        0, 12, Sort.by("createdAt").descending());
  List<Taco> tacos = tacoRepo.findAll(page).getContent();

  List<TacoResource> tacoResources = 
      new TacoResourceAssembler().toResources(tacos);
  Resources<TacoResource> recentResources = 
          new Resources<TacoResource>(tacoResources);
  
  recentResources.add(
      linkTo(methodOn(RecentTacosController.class).recentTacos())
          .withRel("recents"));
  return new ResponseEntity<>(recentResources, HttpStatus.OK);
}
 
Example 5
Source File: BookmarksController.java    From Microservices-with-Spring-Cloud with MIT License 5 votes vote down vote up
@GetMapping
public Resources<Resource<Bookmark>> findAllBookmarks(HttpServletRequest request){
    Resources<Resource<Bookmark>> bookmarks = new Resources<>(
            resourceAssembler.toResourceList(bookmarkService.findAll()),
            BasicLinkBuilder.linkToCurrentMapping()
                    .slash("bookmarks").withSelfRel()
    );
    if(request.isUserInRole("ADMIN")){
        bookmarks.add(
                linkTo(methodOn(BookmarksController.class).addBookmark(null)).withRel("add"),
                linkTo(methodOn(BookmarkController.class).getBookmarkTemplate()).withRel("template")
        );
    }
    return bookmarks;
}
 
Example 6
Source File: EngineController.java    From micro-ecommerce with Apache License 2.0 5 votes vote down vote up
/**
 * Exposes all {@link Order}s currently in preparation.
 * 
 * @return
 */
@RequestMapping("/engine")
HttpEntity<Resources<Resource<Order>>> showOrdersInProgress() {

	Resources<Resource<Order>> orderResources = Resources.wrap(processor.getOrders());
	orderResources.add(linkTo(methodOn(EngineController.class).showOrdersInProgress()).withSelfRel());

	return new ResponseEntity<>(orderResources, HttpStatus.OK);
}
 
Example 7
Source File: WebsiteRestController.java    From JiwhizBlogWeb with Apache License 2.0 5 votes vote down vote up
@RequestMapping(method = RequestMethod.GET, value = ApiUrls.URL_SITE_RECENT_BLOGS)
public HttpEntity<Resources<PublicBlogResource>> getRecentPublicBlogPosts() {
    PageRequest request = new PageRequest(0, MOST_RECENT_NUMBER);
    Collection<PublicBlogResource> blogPostResourceCollection = new ArrayList<PublicBlogResource>();
    Page<BlogPost> blogPosts = this.blogPostRepository.findByPublishedIsTrueOrderByPublishedTimeDesc(request);
    for (BlogPost blogPost : blogPosts) {
        PublicBlogResource resource = publicBlogResourceAssembler.toResource(blogPost);
        blogPostResourceCollection.add(resource);
    }
    
    Resources<PublicBlogResource> resources = new Resources<>(blogPostResourceCollection);
    resources.add(linkTo(methodOn(WebsiteRestController.class).getRecentPublicBlogPosts())
            .withSelfRel());
    return new ResponseEntity<>(resources, HttpStatus.OK);
}
 
Example 8
Source File: WebsiteRestController.java    From JiwhizBlogWeb with Apache License 2.0 5 votes vote down vote up
@RequestMapping(method = RequestMethod.GET, value = ApiUrls.URL_SITE_RECENT_COMMENTS)
public HttpEntity<Resources<Resource<CommentPost>>> getRecentPublicCommentPosts() {
    PageRequest request = new PageRequest(0, MOST_RECENT_NUMBER);
    Collection<Resource<CommentPost>> resourceCollection = new ArrayList<Resource<CommentPost>>();
    Page<CommentPost> commentPosts = this.commentPostRepository.findByStatusOrderByCreatedTimeDesc(CommentStatusType.APPROVED, request);
    for (CommentPost comment : commentPosts) {
        Resource<CommentPost> resource = publicCommentResourceAssembler.toResource(comment);
        resourceCollection.add(resource);
    }
    
    Resources<Resource<CommentPost>> resources = new Resources<Resource<CommentPost>>(resourceCollection);
    resources.add(linkTo(methodOn(WebsiteRestController.class).getRecentPublicCommentPosts())
            .withSelfRel());
    return new ResponseEntity<>(resources, HttpStatus.OK);
}