Example usage for org.springframework.hateoas Link REL_SELF

List of usage examples for org.springframework.hateoas Link REL_SELF

Introduction

In this page you can find the example usage for org.springframework.hateoas Link REL_SELF.

Prototype

LinkRelation REL_SELF

To view the source code for org.springframework.hateoas Link REL_SELF.

Click Source Link

Usage

From source file:org.moserp.common.domain.RestLinkContainer.java

@JsonIgnore
public RestLink getSelf() {
    return getLink(Link.REL_SELF);
}

From source file:com.github.hateoas.forms.spring.uber.UberUtilsTest.java

@Test
public void linkGetToUberNode() throws Exception {
    UberNode linkNode = UberUtils.toUberLink("/foo",
            new SpringActionDescriptor("get", RequestMethod.GET.name()), Link.REL_SELF);
    assertEquals(Arrays.asList(Link.REL_SELF), linkNode.getRel());
    assertEquals("/foo", linkNode.getUrl());
    assertNull(linkNode.getModel());//from   www .j a v a  2  s.  com
    assertNull(linkNode.getAction());
}

From source file:edu.pitt.dbmi.ccd.anno.links.ResourceLinks.java

default Link getRequestLink(HttpServletRequest request) {
    final StringBuffer url = request.getRequestURL();
    final String query = request.getQueryString();
    if (query == null) {
        return new Link(url.toString(), Link.REL_SELF);
    } else {/*  ww  w.  java  2 s  .c o m*/
        return new Link(url.append("?").append(query).toString(), Link.REL_SELF);
    }
}

From source file:com.github.hateoas.forms.spring.uber.UberUtilsTest.java

@Test
public void linkPostToUberNode() throws Exception {
    // TODO create a Link with variables separate from URITemplate for POST
    UberNode linkNode = UberUtils.toUberLink("/foo{?foo,bar}",
            new SpringActionDescriptor("post", RequestMethod.POST.name()), Link.REL_SELF);
    assertEquals(Arrays.asList(Link.REL_SELF), linkNode.getRel());
    assertEquals("/foo", linkNode.getUrl());
    assertEquals("foo={foo}&bar={bar}", linkNode.getModel());
    assertEquals(UberAction.APPEND, linkNode.getAction());
}

From source file:com.eretailservice.security.BookingRestController.java

@RequestMapping(method = RequestMethod.POST)
ResponseEntity<?> add(Principal principal, @RequestBody Booking input) {
    this.validateUser(principal);

    return accountRepository.findByUsername(principal.getName()).map(account -> {
        Booking booking = bookingRepository.save(new Booking(account, input.uri, input.description));

        Link forOneBooking = new BookingResource(booking).getLink(Link.REL_SELF);

        return ResponseEntity.created(URI.create(forOneBooking.getHref())).build();
    }).orElse(ResponseEntity.noContent().build());
}

From source file:org.lareferencia.backend.rest.PageResource.java

public PageResource(Page<T> page, String pageParam, String sizeParam) {
    super();/* w w w .j a v a  2 s . c  o  m*/
    this.page = page;
    if (page.hasPrevious()) {
        String path = createBuilder().queryParam(pageParam, page.getNumber() - 1)
                .queryParam(sizeParam, page.getSize()).build().toUriString();
        Link link = new Link(path, Link.REL_PREVIOUS);
        add(link);
    }
    if (page.hasNext()) {
        String path = createBuilder().queryParam(pageParam, page.getNumber() + 1)
                .queryParam(sizeParam, page.getSize()).build().toUriString();
        Link link = new Link(path, Link.REL_NEXT);
        add(link);
    }

    Link link = buildPageLink(pageParam, 0, sizeParam, page.getSize(), Link.REL_FIRST);
    add(link);

    int indexOfLastPage = page.getTotalPages() - 1;
    link = buildPageLink(pageParam, indexOfLastPage, sizeParam, page.getSize(), Link.REL_LAST);
    add(link);

    link = buildPageLink(pageParam, page.getNumber(), sizeParam, page.getSize(), Link.REL_SELF);
    add(link);
}

From source file:com.jiwhiz.rest.user.PostCommentRestController.java

@RequestMapping(method = RequestMethod.POST, value = URL_USER_BLOGS_BLOG_COMMENTS, consumes = MediaType.APPLICATION_JSON_VALUE)
@Transactional//  w ww.  j  a  v a  2  s  .  co m
public ResponseEntity<Void> postComment(@PathVariable("blogId") String blogId,
        @RequestBody CommentForm newComment) throws ResourceNotFoundException {
    UserAccount currentUser = getCurrentAuthenticatedUser();
    BlogPost blogPost = this.blogPostRepository.findOne(blogId);
    if (blogPost == null || !blogPost.isPublished()) {
        throw new ResourceNotFoundException("No published blog post with the id: " + blogId);
    }

    CommentPost commentPost = commentPostService.postComment(currentUser, blogPost, newComment.getContent());

    //send email to author if someone else posted a comment to blog.
    if (this.commentNotificationSender != null && !blogPost.getAuthor().equals(currentUser)) {
        this.commentNotificationSender.send(blogPost.getAuthor(), currentUser, commentPost, blogPost);
    }

    UserCommentResource resource = userCommentResourceAssembler.toResource(commentPost);
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setLocation(URI.create(resource.getLink(Link.REL_SELF).getHref()));

    return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED);
}

From source file:com.sra.biotech.submittool.persistence.service.SubmissionServiceImpl.java

@Override
public List<Submission> findAllSubmission() {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Accept", MediaType.APPLICATION_JSON_VALUE);
    HttpEntity<String> request = new HttpEntity<String>(headers);
    ResponseEntity<String> response = restTemplate.exchange(getSubmissionUrlTemplate(), HttpMethod.GET, request,
            String.class);

    String responseBody = response.getBody();
    try {//from  w  w w  . j a  v  a2 s .  co  m
        if (RestUtil.isError(response.getStatusCode())) {
            ErrorResource error = objectMapper.readValue(responseBody, ErrorResource.class);
            throw new RestClientException("[" + error.getCode() + "] " + error.getMessage());
        } else {
            SubmissionResources resources = objectMapper.readValue(responseBody, SubmissionResources.class);
            //  SubmissionResources resources = restTemplate.getForObject(getSubmissionUrlTemplate(), SubmissionResources.class);
            if (resources == null || CollectionUtils.isEmpty(resources.getContent())) {
                return Collections.emptyList();
            }

            Link listSelfLink = resources.getLink(Link.REL_SELF);
            Collection<SubmissionResource> content = resources.getContent();

            if (!content.isEmpty()) {
                SubmissionResource firstSubmissionResource = content.iterator().next();
                Link linkToFirstResource = firstSubmissionResource.getLink(Link.REL_SELF);
                System.out.println("href = " + linkToFirstResource.getHref());
                System.out.println("rel = " + linkToFirstResource.getRel());
            }

            return resources.unwrap();
            // return resources;
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

}