use of org.springframework.hateoas.mvc.ControllerLinkBuilder in project irida by phac-nml.
the class RESTUsersController method getUserProjects.
/**
* Get the collection of projects for a specific user.
*
* @param username
* the username for the desired user.
* @return a model containing the collection of projects for that user.
*/
@RequestMapping(value = "/api/{username}/projects", method = RequestMethod.GET)
public ModelMap getUserProjects(@PathVariable String username) {
logger.debug("Loading projects for user [" + username + "]");
ModelMap mav = new ModelMap();
// get the appropriate user from the database
User u = userService.getUserByUsername(username);
// get all of the projects that this user belongs to
ResourceCollection<Project> resources = new ResourceCollection<>();
List<Join<Project, User>> projects = projectService.getProjectsForUser(u);
ControllerLinkBuilder linkBuilder = linkTo(RESTProjectsController.class);
// add the project and a self-rel link to the project representation
for (Join<Project, User> join : projects) {
Project project = join.getSubject();
project.add(linkBuilder.slash(project.getId()).withSelfRel());
resources.add(project);
}
// add the resources to the response
mav.addAttribute("projectResources", resources);
// respond to the user
return mav;
}
use of org.springframework.hateoas.mvc.ControllerLinkBuilder in project sw360portal by sw360.
the class AttachmentController method process.
@Override
public RepositoryLinksResource process(RepositoryLinksResource resource) {
final ControllerLinkBuilder controllerLinkBuilder = linkTo(AttachmentController.class);
final Link attachments = new Link(new UriTemplate(controllerLinkBuilder.toUri().toString() + "/api/attachments{?sha1}"), "attachments");
resource.add(attachments);
return resource;
}
Aggregations