org.springframework.hateoas.UriTemplate Java Examples

The following examples show how to use org.springframework.hateoas.UriTemplate. 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: Application.java    From micro-ecommerce with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/")
public HttpEntity<RootResource> getRootResource() {
	RootResource resource = new RootResource();
	String baseUri = BasicLinkBuilder.linkToCurrentMapping().toString();

	Link catalogServiceLink = new Link(new UriTemplate(baseUri + "/catalog"), RootResource.LINK_NAME_CATALOG);
	resource.add(catalogServiceLink);

	Link reviewServiceLink = new Link(new UriTemplate(baseUri + "/reviews"), RootResource.LINK_NAME_REVIEW);
	resource.add(reviewServiceLink);

	Link recommendationServiceLink = new Link(new UriTemplate(baseUri + "/recommendations"),
			RootResource.LINK_NAME_RECOMMENDATIONS);
	resource.add(recommendationServiceLink);

	Link orderServiceLink = new Link(new UriTemplate(baseUri + "/orders"), RootResource.LINK_NAME_ORDERS);
	resource.add(orderServiceLink);

	Link productLink = new Link(new UriTemplate(baseUri + "/product/{id}"), RootResource.LINK_NAME_PRODUCT_DETAIL);
	resource.add(productLink);

	return new ResponseEntity<>(resource, HttpStatus.OK);
}
 
Example #2
Source File: AuthorAccountResourceAssembler.java    From JiwhizBlogWeb with Apache License 2.0 6 votes vote down vote up
@Override
public AuthorAccountResource toResource(UserAccount entity) {
    AuthorAccountResource resource = new AuthorAccountResource(entity);

    try {
        resource.add(linkTo(methodOn(AuthorAccountRestController.class).getCurrentAuthorAccount())
                .withSelfRel());
        
        String baseUri = BasicLinkBuilder.linkToCurrentMapping().toString();
        Link blogsLink = new Link(
                new UriTemplate(baseUri + ApiUrls.API_ROOT + ApiUrls.URL_AUTHOR_BLOGS), AuthorAccountResource.LINK_NAME_BLOGS);
        resource.add(assembler.appendPaginationParameterTemplates(blogsLink));
        
        Link blogLink = new Link(
                new UriTemplate(baseUri + ApiUrls.API_ROOT + ApiUrls.URL_AUTHOR_BLOGS_BLOG), AuthorAccountResource.LINK_NAME_BLOG);
        resource.add(blogLink);

    } catch (Exception ex) {
        //do nothing
    }
    
    return resource;

}
 
Example #3
Source File: InitializrMetadataV21JsonMapper.java    From initializr with Apache License 2.0 5 votes vote down vote up
private ObjectNode dependenciesLink(String appUrl) {
	String uri = (appUrl != null) ? appUrl + "/dependencies" : "/dependencies";
	UriTemplate uriTemplate = UriTemplate.of(uri, this.dependenciesVariables);
	ObjectNode result = nodeFactory().objectNode();
	result.put("href", uriTemplate.toString());
	result.put("templated", true);
	return result;
}
 
Example #4
Source File: AdminAccountResourceAssembler.java    From JiwhizBlogWeb with Apache License 2.0 5 votes vote down vote up
@Override
public AdminAccountResource toResource(UserAccount userAccount) {
    AdminAccountResource resource = new AdminAccountResource(userAccount);

    try {
        resource.add(linkTo(methodOn(AdminAccountRestController.class).getAdminAccount()).withSelfRel());
        
        String baseUri = BasicLinkBuilder.linkToCurrentMapping().toString();
        
        Link usersLink = new Link(
                new UriTemplate(baseUri + ApiUrls.API_ROOT + ApiUrls.URL_ADMIN_USERS), AdminAccountResource.LINK_NAME_USERS);
        resource.add(assembler.appendPaginationParameterTemplates(usersLink));
        
        Link blogsLink = new Link(
                new UriTemplate(baseUri + ApiUrls.API_ROOT + ApiUrls.URL_ADMIN_BLOGS), AdminAccountResource.LINK_NAME_BLOGS);
        resource.add(assembler.appendPaginationParameterTemplates(blogsLink));
        
        Link commentsLink = new Link(
                new UriTemplate(baseUri + ApiUrls.API_ROOT + ApiUrls.URL_ADMIN_COMMENTS), AdminAccountResource.LINK_NAME_COMMENTS);
        resource.add(assembler.appendPaginationParameterTemplates(commentsLink));

    } catch (Exception ex) {
        //do nothing
    }
    
    return resource;

}
 
Example #5
Source File: CompletionTemplate.java    From spring-cloud-dashboard with Apache License 2.0 4 votes vote down vote up
public CompletionTemplate(RestTemplate restTemplate, Link streamLink, Link taskLink) {
	this.restTemplate = restTemplate;
	this.streamCompletionUriTemplate = new UriTemplate(streamLink.getHref());
	this.taskCompletionUriTemplate = new UriTemplate(taskLink.getHref());
}
 
Example #6
Source File: CompletionTemplate.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
public CompletionTemplate(RestTemplate restTemplate, Link streamLink, Link taskLink) {
	this.restTemplate = restTemplate;
	this.streamCompletionUriTemplate = UriTemplate.of(streamLink.getHref());
	this.taskCompletionUriTemplate = UriTemplate.of(taskLink.getHref());
}
 
Example #7
Source File: ApplicationConfiguration.java    From spring-rest-black-market with MIT License 4 votes vote down vote up
@Bean
public CurieProvider curieProvider() {
    return new DefaultCurieProvider("black-market", new UriTemplate("http://localhost:8080/docs/api-guide.html#{rel}"));
}
 
Example #8
Source File: InitializrMetadataV2JsonMapper.java    From initializr with Apache License 2.0 4 votes vote down vote up
private String generateTemplatedUri(String appUrl, Type type) {
	String uri = (appUrl != null) ? appUrl + type.getAction() : type.getAction();
	uri = uri + "?type=" + type.getId();
	UriTemplate uriTemplate = UriTemplate.of(uri, this.templateVariables);
	return uriTemplate.toString();
}
 
Example #9
Source File: WebsiteResourceAssembler.java    From JiwhizBlogWeb with Apache License 2.0 4 votes vote down vote up
public WebsiteResource toResource() {
    UserAccount currentUser = this.userAccountService.getCurrentUser();
    WebsiteResource resource = new WebsiteResource();
    resource.setAuthenticated(currentUser != null);
    
    try{
        resource.add(linkTo(methodOn(WebsiteRestController.class).getPublicWebsiteResource())
                .withSelfRel());
        
        String baseUri = BasicLinkBuilder.linkToCurrentMapping().toString();
        
        Link blogsLink = new Link(
                new UriTemplate(baseUri + ApiUrls.API_ROOT + ApiUrls.URL_SITE_BLOGS), WebsiteResource.LINK_NAME_BLOGS);
        resource.add(assembler.appendPaginationParameterTemplates(blogsLink));
        
        Link blogLink = new Link(
                new UriTemplate(baseUri + ApiUrls.API_ROOT + ApiUrls.URL_SITE_BLOGS_BLOG), WebsiteResource.LINK_NAME_BLOG);
        resource.add(blogLink);
        
        resource.add(linkTo(methodOn(WebsiteRestController.class).getCurrentUserAccount())
                .withRel(WebsiteResource.LINK_NAME_CURRENT_USER));
        resource.add(linkTo(methodOn(WebsiteRestController.class).getLatestBlogPost())
                .withRel(WebsiteResource.LINK_NAME_LATEST_BLOG));
        resource.add(linkTo(methodOn(WebsiteRestController.class).getRecentPublicBlogPosts())
                .withRel(WebsiteResource.LINK_NAME_RECENT_BLOGS));
        resource.add(linkTo(methodOn(WebsiteRestController.class).getRecentPublicCommentPosts())
                .withRel(WebsiteResource.LINK_NAME_RECENT_COMMENTS));
        resource.add(linkTo(methodOn(WebsiteRestController.class).getTagCloud())
                .withRel(WebsiteResource.LINK_NAME_TAG_CLOUD));

        Link profileLink = new Link(
                new UriTemplate(baseUri + ApiUrls.API_ROOT + ApiUrls.URL_SITE_PROFILES_USER), WebsiteResource.LINK_NAME_PROFILE);
        resource.add(profileLink);

        Link postCommentLink = new Link(
                new UriTemplate(baseUri + ApiUrls.API_ROOT + ApiUrls.URL_USER_BLOGS_BLOG_COMMENTS), WebsiteResource.LINK_NAME_POST_COMMENT);
        resource.add(postCommentLink);
    
    } catch (ResourceNotFoundException ex) {
    }

    return resource;
}
 
Example #10
Source File: ProductLinkProcessor.java    From sos with Apache License 2.0 3 votes vote down vote up
@Override
public RepositoryLinksResource process(RepositoryLinksResource resource) {

	Link products = entityLinks.linkToCollectionResource(Product.class);

	UriTemplate template = new UriTemplate(products.getHref().concat("/{id}"));

	resource.add(new Link(template, relProvider.getItemResourceRelFor(Product.class)));

	return resource;
}
 
Example #11
Source File: AppRegistryTemplate.java    From spring-cloud-dashboard with Apache License 2.0 2 votes vote down vote up
/**
 * Construct a {@code AppRegistryTemplate} object.
 *
 * @param restTemplate template for HTTP/rest commands
 * @param resourceSupport HATEOAS link support
 */
public AppRegistryTemplate(RestTemplate restTemplate, ResourceSupport resourceSupport) {
	this.restTemplate = restTemplate;
	this.uriTemplate = new UriTemplate(resourceSupport.getLink("apps").getHref());
}