{"action":"created","comment":{"url":"https://api.github.com/repos/roma-turkin/javafiddle/pulls/comments/59989422","id":59989422,"diff_hunk":"@@ -32,86 +38,93 @@\n     @EJB\n     ProjectBean projectBean;\n \n+    @EJB\n+    UserBean userBean;\n+\n+    @EJB\n+    AccessBean accessBean;\n+\n     @POST\n     @Consumes(MediaType.APPLICATION_JSON)\n     public Response addNewGroupMember(GroupMember newGroupMember, @PathParam(\"projectHash\") String projectHash) {\n \n-        try{\n+        Project project = projectBean.getProjectByProjectHash(projectHash);\n+        if (project == null) {\n+            return Response.status(Response.Status.NOT_FOUND).build();\n+        }\n+\n+        Group group = project.getGroup();\n \n-            int groupId = projectBean.getGroupId(projectHash);\n-            //!TODO let's postpone it for later untill signature in GroupBean methods will be established\n-//            groupsBean.addMember(groupId,\n-//                    newGroupMember.getUserNickName(),\n-//                    newGroupMember.getAccessRights());\n+        User user = userBean.getUser(newGroupMember.getUserNickName());\n+        if (user == null) {\n+            return Response.status(Response.Status.NOT_FOUND).build();\n+        }\n \n-            return Response.ok().build();\n+        Access access = accessBean.getAccess(newGroupMember.getAccessRights());\n+        if (access == null) {\n+            return Response.status(Response.Status.NOT_FOUND).build();\n+        }\n \n-        } catch (NotFoundException e) {\n-            return Response.status(Response.Status.BAD_REQUEST).build();\n+        try {\n+            groupBean.addMember(group, user, access);","path":"JavaFiddle-Web/src/main/java/ru/javafiddle/web/services/GroupService.java","position":56,"original_position":56,"commit_id":"d9efe0c42b1ecf174a709400ed43661476b30e52","original_commit_id":"d9efe0c42b1ecf174a709400ed43661476b30e52","user":{"login":"alexander1leonov","id":15158069,"avatar_url":"https://avatars.githubusercontent.com/u/15158069?v=3","gravatar_id":"","url":"https://api.github.com/users/alexander1leonov","html_url":"https://github.com/alexander1leonov","followers_url":"https://api.github.com/users/alexander1leonov/followers","following_url":"https://api.github.com/users/alexander1leonov/following{/other_user}","gists_url":"https://api.github.com/users/alexander1leonov/gists{/gist_id}","starred_url":"https://api.github.com/users/alexander1leonov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexander1leonov/subscriptions","organizations_url":"https://api.github.com/users/alexander1leonov/orgs","repos_url":"https://api.github.com/users/alexander1leonov/repos","events_url":"https://api.github.com/users/alexander1leonov/events{/privacy}","received_events_url":"https://api.github.com/users/alexander1leonov/received_events","type":"User","site_admin":false},"body":"I may have missed that in previous code reviews, but there's a much more elegant way of handling exceptions in RS. \r\nThis way is not reusable and looks a bit dirty.\r\nPlease find a good guide here: http://www.codingpedia.org/ama/error-handling-in-rest-api-with-jersey/\r\n\r\nShort summary:\r\n1) Jersey (javax.ws.rs implementation in Glassfish) has an OOB mechanism of exception handling, more generic than writing try/catch for each particular service method.\r\n2) By default Jersey handles runtime exceptions by wrapping them into WebApplicationException.\r\n3) If you prefer more control, use the examples on the link I gave above.\r\n\r\n","created_at":"2016-04-17T18:07:12Z","updated_at":"2016-04-17T18:07:12Z","html_url":"https://github.com/roma-turkin/javafiddle/pull/34#discussion_r59989422","pull_request_url":"https://api.github.com/repos/roma-turkin/javafiddle/pulls/34","_links":{"self":{"href":"https://api.github.com/repos/roma-turkin/javafiddle/pulls/comments/59989422"},"html":{"href":"https://github.com/roma-turkin/javafiddle/pull/34#discussion_r59989422"},"pull_request":{"href":"https://api.github.com/repos/roma-turkin/javafiddle/pulls/34"}}},"pull_request":{"url":"https://api.github.com/repos/roma-turkin/javafiddle/pulls/34","id":66555277,"html_url":"https://github.com/roma-turkin/javafiddle/pull/34","diff_url":"https://github.com/roma-turkin/javafiddle/pull/34.diff","patch_url":"https://github.com/roma-turkin/javafiddle/pull/34.patch","issue_url":"https://api.github.com/repos/roma-turkin/javafiddle/issues/34","number":34,"state":"open","locked":false,"title":"Projectbean branch","user":{"login":"Atsanda","id":8836917,"avatar_url":"https://avatars.githubusercontent.com/u/8836917?v=3","gravatar_id":"","url":"https://api.github.com/users/Atsanda","html_url":"https://github.com/Atsanda","followers_url":"https://api.github.com/users/Atsanda/followers","following_url":"https://api.github.com/users/Atsanda/following{/other_user}","gists_url":"https://api.github.com/users/Atsanda/gists{/gist_id}","starred_url":"https://api.github.com/users/Atsanda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Atsanda/subscriptions","organizations_url":"https://api.github.com/users/Atsanda/orgs","repos_url":"https://api.github.com/users/Atsanda/repos","events_url":"https://api.github.com/users/Atsanda/events{/privacy}","received_events_url":"https://api.github.com/users/Atsanda/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-04-14T21:16:18Z","updated_at":"2016-04-17T18:07:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3135b560f01d670f033aea18aa450a84897cd21b","assignee":{"login":"alexander1leonov","id":15158069,"avatar_url":"https://avatars.githubusercontent.com/u/15158069?v=3","gravatar_id":"","url":"https://api.github.com/users/alexander1leonov","html_url":"https://github.com/alexander1leonov","followers_url":"https://api.github.com/users/alexander1leonov/followers","following_url":"https://api.github.com/users/alexander1leonov/following{/other_user}","gists_url":"https://api.github.com/users/alexander1leonov/gists{/gist_id}","starred_url":"https://api.github.com/users/alexander1leonov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexander1leonov/subscriptions","organizations_url":"https://api.github.com/users/alexander1leonov/orgs","repos_url":"https://api.github.com/users/alexander1leonov/repos","events_url":"https://api.github.com/users/alexander1leonov/events{/privacy}","received_events_url":"https://api.github.com/users/alexander1leonov/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/roma-turkin/javafiddle/pulls/34/commits","review_comments_url":"https://api.github.com/repos/roma-turkin/javafiddle/pulls/34/comments","review_comment_url":"https://api.github.com/repos/roma-turkin/javafiddle/pulls/comments{/number}","comments_url":"https://api.github.com/repos/roma-turkin/javafiddle/issues/34/comments","statuses_url":"https://api.github.com/repos/roma-turkin/javafiddle/statuses/d9efe0c42b1ecf174a709400ed43661476b30e52","head":{"label":"roma-turkin:projectbean_branch","ref":"projectbean_branch","sha":"d9efe0c42b1ecf174a709400ed43661476b30e52","user":{"login":"roma-turkin","id":3299157,"avatar_url":"https://avatars.githubusercontent.com/u/3299157?v=3","gravatar_id":"","url":"https://api.github.com/users/roma-turkin","html_url":"https://github.com/roma-turkin","followers_url":"https://api.github.com/users/roma-turkin/followers","following_url":"https://api.github.com/users/roma-turkin/following{/other_user}","gists_url":"https://api.github.com/users/roma-turkin/gists{/gist_id}","starred_url":"https://api.github.com/users/roma-turkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roma-turkin/subscriptions","organizations_url":"https://api.github.com/users/roma-turkin/orgs","repos_url":"https://api.github.com/users/roma-turkin/repos","events_url":"https://api.github.com/users/roma-turkin/events{/privacy}","received_events_url":"https://api.github.com/users/roma-turkin/received_events","type":"User","site_admin":false},"repo":{"id":44048656,"name":"javafiddle","full_name":"roma-turkin/javafiddle","owner":{"login":"roma-turkin","id":3299157,"avatar_url":"https://avatars.githubusercontent.com/u/3299157?v=3","gravatar_id":"","url":"https://api.github.com/users/roma-turkin","html_url":"https://github.com/roma-turkin","followers_url":"https://api.github.com/users/roma-turkin/followers","following_url":"https://api.github.com/users/roma-turkin/following{/other_user}","gists_url":"https://api.github.com/users/roma-turkin/gists{/gist_id}","starred_url":"https://api.github.com/users/roma-turkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roma-turkin/subscriptions","organizations_url":"https://api.github.com/users/roma-turkin/orgs","repos_url":"https://api.github.com/users/roma-turkin/repos","events_url":"https://api.github.com/users/roma-turkin/events{/privacy}","received_events_url":"https://api.github.com/users/roma-turkin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/roma-turkin/javafiddle","description":"SImple Web-based Java IDE.","fork":false,"url":"https://api.github.com/repos/roma-turkin/javafiddle","forks_url":"https://api.github.com/repos/roma-turkin/javafiddle/forks","keys_url":"https://api.github.com/repos/roma-turkin/javafiddle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/roma-turkin/javafiddle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/roma-turkin/javafiddle/teams","hooks_url":"https://api.github.com/repos/roma-turkin/javafiddle/hooks","issue_events_url":"https://api.github.com/repos/roma-turkin/javafiddle/issues/events{/number}","events_url":"https://api.github.com/repos/roma-turkin/javafiddle/events","assignees_url":"https://api.github.com/repos/roma-turkin/javafiddle/assignees{/user}","branches_url":"https://api.github.com/repos/roma-turkin/javafiddle/branches{/branch}","tags_url":"https://api.github.com/repos/roma-turkin/javafiddle/tags","blobs_url":"https://api.github.com/repos/roma-turkin/javafiddle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/roma-turkin/javafiddle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/roma-turkin/javafiddle/git/refs{/sha}","trees_url":"https://api.github.com/repos/roma-turkin/javafiddle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/roma-turkin/javafiddle/statuses/{sha}","languages_url":"https://api.github.com/repos/roma-turkin/javafiddle/languages","stargazers_url":"https://api.github.com/repos/roma-turkin/javafiddle/stargazers","contributors_url":"https://api.github.com/repos/roma-turkin/javafiddle/contributors","subscribers_url":"https://api.github.com/repos/roma-turkin/javafiddle/subscribers","subscription_url":"https://api.github.com/repos/roma-turkin/javafiddle/subscription","commits_url":"https://api.github.com/repos/roma-turkin/javafiddle/commits{/sha}","git_commits_url":"https://api.github.com/repos/roma-turkin/javafiddle/git/commits{/sha}","comments_url":"https://api.github.com/repos/roma-turkin/javafiddle/comments{/number}","issue_comment_url":"https://api.github.com/repos/roma-turkin/javafiddle/issues/comments{/number}","contents_url":"https://api.github.com/repos/roma-turkin/javafiddle/contents/{+path}","compare_url":"https://api.github.com/repos/roma-turkin/javafiddle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/roma-turkin/javafiddle/merges","archive_url":"https://api.github.com/repos/roma-turkin/javafiddle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/roma-turkin/javafiddle/downloads","issues_url":"https://api.github.com/repos/roma-turkin/javafiddle/issues{/number}","pulls_url":"https://api.github.com/repos/roma-turkin/javafiddle/pulls{/number}","milestones_url":"https://api.github.com/repos/roma-turkin/javafiddle/milestones{/number}","notifications_url":"https://api.github.com/repos/roma-turkin/javafiddle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/roma-turkin/javafiddle/labels{/name}","releases_url":"https://api.github.com/repos/roma-turkin/javafiddle/releases{/id}","deployments_url":"https://api.github.com/repos/roma-turkin/javafiddle/deployments","created_at":"2015-10-11T10:57:50Z","updated_at":"2016-02-04T11:25:09Z","pushed_at":"2016-04-17T10:50:48Z","git_url":"git://github.com/roma-turkin/javafiddle.git","ssh_url":"git@github.com:roma-turkin/javafiddle.git","clone_url":"https://github.com/roma-turkin/javafiddle.git","svn_url":"https://github.com/roma-turkin/javafiddle","homepage":null,"size":6425,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":15,"forks":2,"open_issues":15,"watchers":0,"default_branch":"master"}},"base":{"label":"roma-turkin:development","ref":"development","sha":"b929d08029a900465744cb4ec51cfde78b1ff237","user":{"login":"roma-turkin","id":3299157,"avatar_url":"https://avatars.githubusercontent.com/u/3299157?v=3","gravatar_id":"","url":"https://api.github.com/users/roma-turkin","html_url":"https://github.com/roma-turkin","followers_url":"https://api.github.com/users/roma-turkin/followers","following_url":"https://api.github.com/users/roma-turkin/following{/other_user}","gists_url":"https://api.github.com/users/roma-turkin/gists{/gist_id}","starred_url":"https://api.github.com/users/roma-turkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roma-turkin/subscriptions","organizations_url":"https://api.github.com/users/roma-turkin/orgs","repos_url":"https://api.github.com/users/roma-turkin/repos","events_url":"https://api.github.com/users/roma-turkin/events{/privacy}","received_events_url":"https://api.github.com/users/roma-turkin/received_events","type":"User","site_admin":false},"repo":{"id":44048656,"name":"javafiddle","full_name":"roma-turkin/javafiddle","owner":{"login":"roma-turkin","id":3299157,"avatar_url":"https://avatars.githubusercontent.com/u/3299157?v=3","gravatar_id":"","url":"https://api.github.com/users/roma-turkin","html_url":"https://github.com/roma-turkin","followers_url":"https://api.github.com/users/roma-turkin/followers","following_url":"https://api.github.com/users/roma-turkin/following{/other_user}","gists_url":"https://api.github.com/users/roma-turkin/gists{/gist_id}","starred_url":"https://api.github.com/users/roma-turkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roma-turkin/subscriptions","organizations_url":"https://api.github.com/users/roma-turkin/orgs","repos_url":"https://api.github.com/users/roma-turkin/repos","events_url":"https://api.github.com/users/roma-turkin/events{/privacy}","received_events_url":"https://api.github.com/users/roma-turkin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/roma-turkin/javafiddle","description":"SImple Web-based Java IDE.","fork":false,"url":"https://api.github.com/repos/roma-turkin/javafiddle","forks_url":"https://api.github.com/repos/roma-turkin/javafiddle/forks","keys_url":"https://api.github.com/repos/roma-turkin/javafiddle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/roma-turkin/javafiddle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/roma-turkin/javafiddle/teams","hooks_url":"https://api.github.com/repos/roma-turkin/javafiddle/hooks","issue_events_url":"https://api.github.com/repos/roma-turkin/javafiddle/issues/events{/number}","events_url":"https://api.github.com/repos/roma-turkin/javafiddle/events","assignees_url":"https://api.github.com/repos/roma-turkin/javafiddle/assignees{/user}","branches_url":"https://api.github.com/repos/roma-turkin/javafiddle/branches{/branch}","tags_url":"https://api.github.com/repos/roma-turkin/javafiddle/tags","blobs_url":"https://api.github.com/repos/roma-turkin/javafiddle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/roma-turkin/javafiddle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/roma-turkin/javafiddle/git/refs{/sha}","trees_url":"https://api.github.com/repos/roma-turkin/javafiddle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/roma-turkin/javafiddle/statuses/{sha}","languages_url":"https://api.github.com/repos/roma-turkin/javafiddle/languages","stargazers_url":"https://api.github.com/repos/roma-turkin/javafiddle/stargazers","contributors_url":"https://api.github.com/repos/roma-turkin/javafiddle/contributors","subscribers_url":"https://api.github.com/repos/roma-turkin/javafiddle/subscribers","subscription_url":"https://api.github.com/repos/roma-turkin/javafiddle/subscription","commits_url":"https://api.github.com/repos/roma-turkin/javafiddle/commits{/sha}","git_commits_url":"https://api.github.com/repos/roma-turkin/javafiddle/git/commits{/sha}","comments_url":"https://api.github.com/repos/roma-turkin/javafiddle/comments{/number}","issue_comment_url":"https://api.github.com/repos/roma-turkin/javafiddle/issues/comments{/number}","contents_url":"https://api.github.com/repos/roma-turkin/javafiddle/contents/{+path}","compare_url":"https://api.github.com/repos/roma-turkin/javafiddle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/roma-turkin/javafiddle/merges","archive_url":"https://api.github.com/repos/roma-turkin/javafiddle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/roma-turkin/javafiddle/downloads","issues_url":"https://api.github.com/repos/roma-turkin/javafiddle/issues{/number}","pulls_url":"https://api.github.com/repos/roma-turkin/javafiddle/pulls{/number}","milestones_url":"https://api.github.com/repos/roma-turkin/javafiddle/milestones{/number}","notifications_url":"https://api.github.com/repos/roma-turkin/javafiddle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/roma-turkin/javafiddle/labels{/name}","releases_url":"https://api.github.com/repos/roma-turkin/javafiddle/releases{/id}","deployments_url":"https://api.github.com/repos/roma-turkin/javafiddle/deployments","created_at":"2015-10-11T10:57:50Z","updated_at":"2016-02-04T11:25:09Z","pushed_at":"2016-04-17T10:50:48Z","git_url":"git://github.com/roma-turkin/javafiddle.git","ssh_url":"git@github.com:roma-turkin/javafiddle.git","clone_url":"https://github.com/roma-turkin/javafiddle.git","svn_url":"https://github.com/roma-turkin/javafiddle","homepage":null,"size":6425,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":15,"forks":2,"open_issues":15,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/roma-turkin/javafiddle/pulls/34"},"html":{"href":"https://github.com/roma-turkin/javafiddle/pull/34"},"issue":{"href":"https://api.github.com/repos/roma-turkin/javafiddle/issues/34"},"comments":{"href":"https://api.github.com/repos/roma-turkin/javafiddle/issues/34/comments"},"review_comments":{"href":"https://api.github.com/repos/roma-turkin/javafiddle/pulls/34/comments"},"review_comment":{"href":"https://api.github.com/repos/roma-turkin/javafiddle/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/roma-turkin/javafiddle/pulls/34/commits"},"statuses":{"href":"https://api.github.com/repos/roma-turkin/javafiddle/statuses/d9efe0c42b1ecf174a709400ed43661476b30e52"}}}}