Java Code Examples for org.springframework.hateoas.UriTemplate

The following examples show how to use org.springframework.hateoas.UriTemplate. These examples are extracted from open source projects. 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 Project: micro-ecommerce   Source File: Application.java    License: 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
@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
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
@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 Project: spring-cloud-dashboard   Source File: CompletionTemplate.java    License: 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 Project: spring-cloud-dataflow   Source File: CompletionTemplate.java    License: 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
@Bean
public CurieProvider curieProvider() {
    return new DefaultCurieProvider("black-market", new UriTemplate("http://localhost:8080/docs/api-guide.html#{rel}"));
}
 
Example 8
Source Project: initializr   Source File: InitializrMetadataV2JsonMapper.java    License: 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 Project: JiwhizBlogWeb   Source File: WebsiteResourceAssembler.java    License: 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 Project: sos   Source File: ProductLinkProcessor.java    License: 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
/**
 * 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());
}