Search in sources :

Example 1 with ControllerLinkBuilder

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;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ModelMap(org.springframework.ui.ModelMap) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ControllerLinkBuilder(org.springframework.hateoas.mvc.ControllerLinkBuilder) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ControllerLinkBuilder

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;
}
Also used : ControllerLinkBuilder(org.springframework.hateoas.mvc.ControllerLinkBuilder) UriTemplate(org.springframework.hateoas.UriTemplate) Link(org.springframework.hateoas.Link)

Aggregations

ControllerLinkBuilder (org.springframework.hateoas.mvc.ControllerLinkBuilder)2 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)1 Project (ca.corefacility.bioinformatics.irida.model.project.Project)1 User (ca.corefacility.bioinformatics.irida.model.user.User)1 ResourceCollection (ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection)1 Link (org.springframework.hateoas.Link)1 UriTemplate (org.springframework.hateoas.UriTemplate)1 ModelMap (org.springframework.ui.ModelMap)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1