Java Code Examples for org.springframework.hateoas.EntityModel#of()

The following examples show how to use org.springframework.hateoas.EntityModel#of() . 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: UserResource.java    From spring-web-services with MIT License 5 votes vote down vote up
@GetMapping("/users/{id}")
public EntityModel<User> retrieveUser(@PathVariable int id) {
	User user = service.findOne(id);
	
	if(user==null)
		throw new UserNotFoundException("id-"+ id);
	
	
	//"all-users", SERVER_PATH + "/users"
	//retrieveAllUsers
	EntityModel<User> resource = EntityModel.of(user);
	
	WebMvcLinkBuilder linkTo = 
			linkTo(methodOn(this.getClass()).retrieveAllUsers());
	
	resource.add(linkTo.withRel("all-users"));
	
	//HATEOAS
	
	return resource;
}
 
Example 2
Source File: UserJPAResource.java    From spring-web-services with MIT License 4 votes vote down vote up
@GetMapping("/jpa/users/{id}")
public EntityModel<User> retrieveUser(@PathVariable int id) {
	Optional<User> user = userRepository.findById(id);

	if (!user.isPresent())
		throw new UserNotFoundException("id-" + id);

	// "all-users", SERVER_PATH + "/users"
	// retrieveAllUsers
	EntityModel<User> resource = EntityModel.of(user.get());//new EntityModel<User>(user.get());

	WebMvcLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveAllUsers());

	resource.add(linkTo.withRel("all-users"));

	// HATEOAS

	return resource;
}
 
Example 3
Source File: UserResource.java    From spring-microservices with MIT License 4 votes vote down vote up
@GetMapping("/users/{id}")
public EntityModel<User> retrieveUser(@PathVariable int id) {
	User user = service.findOne(id);
	
	if(user==null)
		throw new UserNotFoundException("id-"+ id);
	
	
	//"all-users", SERVER_PATH + "/users"
	//retrieveAllUsers
	EntityModel<User> resource = EntityModel.of(user);
	
	WebMvcLinkBuilder linkTo = 
			linkTo(methodOn(this.getClass()).retrieveAllUsers());
	
	resource.add(linkTo.withRel("all-users"));
	
	//HATEOAS
	
	return resource;
}
 
Example 4
Source File: UserJPAResource.java    From spring-microservices with MIT License 3 votes vote down vote up
@GetMapping("/jpa/users/{id}")
public EntityModel<User> retrieveUser(@PathVariable int id) {
	Optional<User> user = userRepository.findById(id);

	if (!user.isPresent())
		throw new UserNotFoundException("id-" + id);

	// "all-users", SERVER_PATH + "/users"
	// retrieveAllUsers
	EntityModel<User> resource = EntityModel.of(user.get());//new EntityModel<User>(user.get());

	WebMvcLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveAllUsers());

	resource.add(linkTo.withRel("all-users"));

	// HATEOAS

	return resource;
}