Class RESTProjectUsersController


  • @Controller
    public class RESTProjectUsersController
    extends java.lang.Object
    Controller for managing relationships between Project and User.
    • Field Detail

      • USER_ID_KEY

        public static final java.lang.String USER_ID_KEY
        key used in map when adding user to project.
        See Also:
        Constant Field Values
      • USER_ROLE_KEY

        public static final java.lang.String USER_ROLE_KEY
        Key used in map for role when adding user to project
        See Also:
        Constant Field Values
      • METADATA_ROLE_KEY

        public static final java.lang.String METADATA_ROLE_KEY
        See Also:
        Constant Field Values
      • REL_PROJECT_USERS

        public static final java.lang.String REL_PROJECT_USERS
        Rel to get to the list of users associated with a project.
        See Also:
        Constant Field Values
    • Constructor Detail

      • RESTProjectUsersController

        protected RESTProjectUsersController()
      • RESTProjectUsersController

        @Autowired
        public RESTProjectUsersController​(UserService userService,
                                          ProjectService projectService)
    • Method Detail

      • getUsersForProject

        @RequestMapping(value="/api/projects/{projectId}/users",
                        method=GET)
        public ResponseResource<ResourceCollection<User>> getUsersForProject​(@PathVariable
                                                                             java.lang.Long projectId)
                                                                      throws ProjectWithoutOwnerException
        Get all users associated with a project.
        Parameters:
        projectId - the project id to get users for.
        Returns:
        a model with a collection of user resources.
        Throws:
        ProjectWithoutOwnerException - If removing a user will leave the project without an owner. Should NEVER be thrown in this method, but needs to be listed.
      • addUserToProject

        @RequestMapping(value="/api/projects/{projectId}/users",
                        method=POST)
        public ResponseResource<LabelledRelationshipResource<Project,​User>> addUserToProject​(@PathVariable
                                                                                                   java.lang.Long projectId,
                                                                                                   @RequestBody
                                                                                                   java.util.Map<java.lang.String,​java.lang.String> representation,
                                                                                                   javax.servlet.http.HttpServletResponse response)
                                                                                            throws ProjectWithoutOwnerException
        Add a relationship between a Project and a User.
        Parameters:
        projectId - the project ID to add the user to.
        representation - the JSON key-value pair that contains the identifier for the project and the identifier for the user.
        response - a reference to the servlet response.
        Returns:
        a response indicating that the collection was modified.
        Throws:
        ProjectWithoutOwnerException - this cannot actually be thrown, it's an artifact of using spring HATEOAS linkTo and methodOn.