{"action":"created","comment":{"url":"https://api.github.com/repos/bhuwang/java_training/pulls/comments/39482276","id":39482276,"diff_hunk":"@@ -0,0 +1,182 @@\n+\n+package com.lftechnology.java.training.dipak.employeemanagement.service;\n+\n+import java.sql.ResultSet;\n+import java.sql.SQLException;\n+import java.util.logging.ConsoleHandler;\n+import java.util.logging.Level;\n+import java.util.logging.Logger;\n+\n+import com.lftechnology.java.training.dipak.employeemanagement.LoggerFormatter;\n+import com.lftechnology.java.training.dipak.employeemanagement.api.EmployeeApi;\n+import com.lftechnology.java.training.dipak.employeemanagement.dao.DaoFactory;\n+import com.lftechnology.java.training.dipak.employeemanagement.dao.EmployeeDao;\n+import com.lftechnology.java.training.dipak.employeemanagement.domain.Employee;\n+import com.lftechnology.java.training.dipak.employeemanagement.domain.UserType;\n+\n+/**\n+ * <p>This class implements the EmployeeApi interface and hence has all the\n+ * overwritten methods.</p>\n+ * \n+ * @author Dipak Thapa<dipakthapa@lftechnology.com>\n+ */\n+public class EmployeeService implements EmployeeApi {\n+\n+\tprivate static final Logger LOGGER =\n+\t\tLogger.getLogger(EmployeeService.class.getName());\n+\n+\t/**\n+\t * <p>This method checks whether the fields which are not supposed to be\n+\t * empty are empty or not. Returns if they empty with a message else calls\n+\t * the addEmployee in DAO layer.</p>\n+\t * \n+\t * @param e\n+\t * @return numberOfUserInserted\n+\t */\n+\t@Override\n+\tpublic int addEmployee(Employee e) {\n+\n+\t\tint numberOfUserInserted = 0;\n+\t\tEmployeeDao ed = DaoFactory.getEmployeeDao();\n+\n+\t\tif (e.getUserName().length() == 0) {\n+\t\t\tLOGGER.info(\n+\t\t\t\t\"The username field can't be empty. Please re-check and try again.\");\n+\t\t\treturn numberOfUserInserted;\n+\t\t}\n+\t\telse if (e.getPassword().length() == 0) {\n+\t\t\tLOGGER.info(\n+\t\t\t\t\"The password field can't be empty. Please re-check and try again.\");\n+\t\t\treturn numberOfUserInserted;\n+\t\t}\n+\t\telse if (e.getRole().equals(UserType.INVALID)) {\n+\t\t\tLOGGER.info(\n+\t\t\t\t\"The role field should either be ADMIN or USER. Please re-check and try again.\");\n+\t\t\treturn numberOfUserInserted;\n+\t\t}\n+\t\telse if (e.getFullName().length() == 0) {\n+\t\t\tLOGGER.info(\n+\t\t\t\t\"The fullname field can't be empty. Please re-check and try again.\");\n+\t\t\treturn numberOfUserInserted;\n+\t\t}\n+\n+\t\tnumberOfUserInserted = ed.addEmployee(e);\n+\n+\t\tif (numberOfUserInserted == 0) {\n+\t\t\tLOGGER.info(\n+\t\t\t\t\"Insertion failed. No users were added. Please check and enter the data again.\");\n+\t\t}\n+\t\telse {\n+\t\t\tLOGGER.log(\n+\t\t\t\tLevel.INFO, \"Number of users added={0}\", numberOfUserInserted);\n+\t\t}\n+\n+\t\treturn numberOfUserInserted;\n+\t}\n+\n+\t/**\n+\t * <p>This method calls the viewEmployee in DAO layer and displays the\n+\t * result set obtained.</p>\n+\t * \n+\t * @param e\n+\t * @return\n+\t */\n+\t@Override\n+\tpublic ResultSet viewEmployee(Employee e) {\n+\n+\t\tConsoleHandler ch = new ConsoleHandler();\n+\t\tch.setLevel(Level.FINEST);\n+\t\tLOGGER.addHandler(ch);\n+\t\tLOGGER.setUseParentHandlers(false);\n+\n+\t\tLoggerFormatter myFormat = new LoggerFormatter();\n+\n+\t\tch.setFormatter(myFormat);\n+\n+\t\tResultSet rs = null;\n+\n+\t\tEmployeeDao ed = DaoFactory.getEmployeeDao();\n+\n+\t\trs = ed.viewEmployee(e);\n+\t\ttry {\n+\t\t\tLOGGER.info(\n+\t\t\t\t\"eid\\t\\tusername\\t\\tfullname\\t\\tdepartment\\t\\taddress\\t\\t\\n\");\n+\t\t\twhile (rs.next()) {\n+\t\t\t\tLOGGER.log(\n+\t\t\t\t\tLevel.INFO, \"{0}\\t\\t{1}\\t\\t{2}\\t\\t{3}\\t\\t{4}\\t\\t\\n\",\n+\t\t\t\t\tnew Object[] {\n+\t\t\t\t\t\trs.getInt(1), rs.getString(2), rs.getString(5),\n+\t\t\t\t\t\trs.getString(6), rs.getString(7)\n+\t\t\t\t});\n+\t\t\t}\n+\t\t}\n+\t\tcatch (SQLException e1) {\n+\t\t\tLOGGER.log(Level.INFO, \"Exception::{0}\", e1);\n+\t\t}\n+\n+\t\treturn null;\n+\t}\n+\n+\t// @Override\n+\t// public int deleteEmployee(Employee e) {\n+\t// EmployeeDao ed = DaoFactory.getEmployeeDao();\n+\t//\n+\t// int numberOfDeletedUsers=0;\n+\t//\n+\t// ed.deleteEmployee(e);\n+\t//\n+\t// if(numberOfDeletedUsers==0) {\n+\t// LOGGER.info(\"No users were deleted. Please check the fullname again.\");\n+\t// }else {\n+\t// LOGGER.log(Level.INFO,\"Number of users\n+\t// deleted={0}\",numberOfDeletedUsers);\n+\t// }\n+\t// return numberOfDeletedUsers;\n+\t// }\n+\n+\t/**\n+\t * <p>This method calls the terminateEmployee method present in the DAO\n+\t * layer and prints the number of employees terminated.</p>\n+\t * \n+\t * @param e\n+\t * @return numberOfTerminatedUsers\n+\t */\n+\t@Override\n+\tpublic int terminateEmployee(Employee e) {\n+\n+\t\tEmployeeDao ed = DaoFactory.getEmployeeDao();\n+\t\tint numberOfTerminatedUsers = 0;\n+\n+\t\tnumberOfTerminatedUsers = ed.terminateEmployee(e);\n+\n+\t\tif (numberOfTerminatedUsers == 0) {\n+\t\t\tLOGGER.info(\n+\t\t\t\t\"No users were deleted. Please check the fullname again.\");\n+\t\t}\n+\t\telse {\n+\t\t\tLOGGER.log(\n+\t\t\t\tLevel.INFO, \"Number of users deleted={0}\",\n+\t\t\t\tnumberOfTerminatedUsers);\n+\t\t}\n+\n+\t\treturn numberOfTerminatedUsers;\n+\n+\t}\n+\n+\t/**\n+\t * <p>This method calls editEmployeeDetails method present in DAO layer.</p>\n+\t * \n+\t * @param e\n+\t * @return e\n+\t */\n+\t@Override\n+\tpublic Employee editEmployeeDetails(Employee e) {\n+\n+\t\tEmployeeDao ed = DaoFactory.getEmployeeDao();\n+\n+\t\te = ed.editEmployeeDetails(e);","path":"src/com/lftechnology/java/training/dipak/employeemanagement/service/EmployeeService.java","position":177,"original_position":177,"commit_id":"9adcc8e839d2c910108d92886facc60d180b73c7","original_commit_id":"9adcc8e839d2c910108d92886facc60d180b73c7","user":{"login":"bhuwang","id":3335673,"avatar_url":"https://avatars.githubusercontent.com/u/3335673?v=3","gravatar_id":"","url":"https://api.github.com/users/bhuwang","html_url":"https://github.com/bhuwang","followers_url":"https://api.github.com/users/bhuwang/followers","following_url":"https://api.github.com/users/bhuwang/following{/other_user}","gists_url":"https://api.github.com/users/bhuwang/gists{/gist_id}","starred_url":"https://api.github.com/users/bhuwang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bhuwang/subscriptions","organizations_url":"https://api.github.com/users/bhuwang/orgs","repos_url":"https://api.github.com/users/bhuwang/repos","events_url":"https://api.github.com/users/bhuwang/events{/privacy}","received_events_url":"https://api.github.com/users/bhuwang/received_events","type":"User","site_admin":false},"body":"![MAJOR](https://raw.githubusercontent.com/SonarCommunity/sonar-github/master/images/severity-major.png) Introduce a new variable instead of reusing the parameter \"e\". [![rule](https://raw.githubusercontent.com/SonarCommunity/sonar-github/master/images/rule.png)](http://nemo.sonarqube.org/coding_rules#rule_key=squid%3AS1226)\n","created_at":"2015-09-15T07:42:56Z","updated_at":"2015-09-15T07:42:56Z","html_url":"https://github.com/bhuwang/java_training/pull/119#discussion_r39482276","pull_request_url":"https://api.github.com/repos/bhuwang/java_training/pulls/119","_links":{"self":{"href":"https://api.github.com/repos/bhuwang/java_training/pulls/comments/39482276"},"html":{"href":"https://github.com/bhuwang/java_training/pull/119#discussion_r39482276"},"pull_request":{"href":"https://api.github.com/repos/bhuwang/java_training/pulls/119"}}},"pull_request":{"url":"https://api.github.com/repos/bhuwang/java_training/pulls/119","id":45005484,"html_url":"https://github.com/bhuwang/java_training/pull/119","diff_url":"https://github.com/bhuwang/java_training/pull/119.diff","patch_url":"https://github.com/bhuwang/java_training/pull/119.patch","issue_url":"https://api.github.com/repos/bhuwang/java_training/issues/119","number":119,"state":"open","locked":false,"title":"32 dipak","user":{"login":"dipakthapaofficial","id":13015291,"avatar_url":"https://avatars.githubusercontent.com/u/13015291?v=3","gravatar_id":"","url":"https://api.github.com/users/dipakthapaofficial","html_url":"https://github.com/dipakthapaofficial","followers_url":"https://api.github.com/users/dipakthapaofficial/followers","following_url":"https://api.github.com/users/dipakthapaofficial/following{/other_user}","gists_url":"https://api.github.com/users/dipakthapaofficial/gists{/gist_id}","starred_url":"https://api.github.com/users/dipakthapaofficial/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dipakthapaofficial/subscriptions","organizations_url":"https://api.github.com/users/dipakthapaofficial/orgs","repos_url":"https://api.github.com/users/dipakthapaofficial/repos","events_url":"https://api.github.com/users/dipakthapaofficial/events{/privacy}","received_events_url":"https://api.github.com/users/dipakthapaofficial/received_events","type":"User","site_admin":false},"body":" crude application.\r\n-Password invisibilty works only when executed on the console.","created_at":"2015-09-15T03:30:42Z","updated_at":"2015-09-15T07:42:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2b24389da1e8ae8ebf81c66332a0de04a6ed0983","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bhuwang/java_training/pulls/119/commits","review_comments_url":"https://api.github.com/repos/bhuwang/java_training/pulls/119/comments","review_comment_url":"https://api.github.com/repos/bhuwang/java_training/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bhuwang/java_training/issues/119/comments","statuses_url":"https://api.github.com/repos/bhuwang/java_training/statuses/9adcc8e839d2c910108d92886facc60d180b73c7","head":{"label":"bhuwang:32_dipak","ref":"32_dipak","sha":"9adcc8e839d2c910108d92886facc60d180b73c7","user":{"login":"bhuwang","id":3335673,"avatar_url":"https://avatars.githubusercontent.com/u/3335673?v=3","gravatar_id":"","url":"https://api.github.com/users/bhuwang","html_url":"https://github.com/bhuwang","followers_url":"https://api.github.com/users/bhuwang/followers","following_url":"https://api.github.com/users/bhuwang/following{/other_user}","gists_url":"https://api.github.com/users/bhuwang/gists{/gist_id}","starred_url":"https://api.github.com/users/bhuwang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bhuwang/subscriptions","organizations_url":"https://api.github.com/users/bhuwang/orgs","repos_url":"https://api.github.com/users/bhuwang/repos","events_url":"https://api.github.com/users/bhuwang/events{/privacy}","received_events_url":"https://api.github.com/users/bhuwang/received_events","type":"User","site_admin":false},"repo":{"id":40284843,"name":"java_training","full_name":"bhuwang/java_training","owner":{"login":"bhuwang","id":3335673,"avatar_url":"https://avatars.githubusercontent.com/u/3335673?v=3","gravatar_id":"","url":"https://api.github.com/users/bhuwang","html_url":"https://github.com/bhuwang","followers_url":"https://api.github.com/users/bhuwang/followers","following_url":"https://api.github.com/users/bhuwang/following{/other_user}","gists_url":"https://api.github.com/users/bhuwang/gists{/gist_id}","starred_url":"https://api.github.com/users/bhuwang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bhuwang/subscriptions","organizations_url":"https://api.github.com/users/bhuwang/orgs","repos_url":"https://api.github.com/users/bhuwang/repos","events_url":"https://api.github.com/users/bhuwang/events{/privacy}","received_events_url":"https://api.github.com/users/bhuwang/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bhuwang/java_training","description":"","fork":false,"url":"https://api.github.com/repos/bhuwang/java_training","forks_url":"https://api.github.com/repos/bhuwang/java_training/forks","keys_url":"https://api.github.com/repos/bhuwang/java_training/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bhuwang/java_training/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bhuwang/java_training/teams","hooks_url":"https://api.github.com/repos/bhuwang/java_training/hooks","issue_events_url":"https://api.github.com/repos/bhuwang/java_training/issues/events{/number}","events_url":"https://api.github.com/repos/bhuwang/java_training/events","assignees_url":"https://api.github.com/repos/bhuwang/java_training/assignees{/user}","branches_url":"https://api.github.com/repos/bhuwang/java_training/branches{/branch}","tags_url":"https://api.github.com/repos/bhuwang/java_training/tags","blobs_url":"https://api.github.com/repos/bhuwang/java_training/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bhuwang/java_training/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bhuwang/java_training/git/refs{/sha}","trees_url":"https://api.github.com/repos/bhuwang/java_training/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bhuwang/java_training/statuses/{sha}","languages_url":"https://api.github.com/repos/bhuwang/java_training/languages","stargazers_url":"https://api.github.com/repos/bhuwang/java_training/stargazers","contributors_url":"https://api.github.com/repos/bhuwang/java_training/contributors","subscribers_url":"https://api.github.com/repos/bhuwang/java_training/subscribers","subscription_url":"https://api.github.com/repos/bhuwang/java_training/subscription","commits_url":"https://api.github.com/repos/bhuwang/java_training/commits{/sha}","git_commits_url":"https://api.github.com/repos/bhuwang/java_training/git/commits{/sha}","comments_url":"https://api.github.com/repos/bhuwang/java_training/comments{/number}","issue_comment_url":"https://api.github.com/repos/bhuwang/java_training/issues/comments{/number}","contents_url":"https://api.github.com/repos/bhuwang/java_training/contents/{+path}","compare_url":"https://api.github.com/repos/bhuwang/java_training/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bhuwang/java_training/merges","archive_url":"https://api.github.com/repos/bhuwang/java_training/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bhuwang/java_training/downloads","issues_url":"https://api.github.com/repos/bhuwang/java_training/issues{/number}","pulls_url":"https://api.github.com/repos/bhuwang/java_training/pulls{/number}","milestones_url":"https://api.github.com/repos/bhuwang/java_training/milestones{/number}","notifications_url":"https://api.github.com/repos/bhuwang/java_training/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bhuwang/java_training/labels{/name}","releases_url":"https://api.github.com/repos/bhuwang/java_training/releases{/id}","created_at":"2015-08-06T04:45:13Z","updated_at":"2015-08-31T05:46:12Z","pushed_at":"2015-09-15T07:41:15Z","git_url":"git://github.com/bhuwang/java_training.git","ssh_url":"git@github.com:bhuwang/java_training.git","clone_url":"https://github.com/bhuwang/java_training.git","svn_url":"https://github.com/bhuwang/java_training","homepage":null,"size":4236,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":32,"forks":3,"open_issues":32,"watchers":0,"default_branch":"dev"}},"base":{"label":"bhuwang:dev","ref":"dev","sha":"6fb41a3dd7b652fb505f2a4aed4547ed368a9dab","user":{"login":"bhuwang","id":3335673,"avatar_url":"https://avatars.githubusercontent.com/u/3335673?v=3","gravatar_id":"","url":"https://api.github.com/users/bhuwang","html_url":"https://github.com/bhuwang","followers_url":"https://api.github.com/users/bhuwang/followers","following_url":"https://api.github.com/users/bhuwang/following{/other_user}","gists_url":"https://api.github.com/users/bhuwang/gists{/gist_id}","starred_url":"https://api.github.com/users/bhuwang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bhuwang/subscriptions","organizations_url":"https://api.github.com/users/bhuwang/orgs","repos_url":"https://api.github.com/users/bhuwang/repos","events_url":"https://api.github.com/users/bhuwang/events{/privacy}","received_events_url":"https://api.github.com/users/bhuwang/received_events","type":"User","site_admin":false},"repo":{"id":40284843,"name":"java_training","full_name":"bhuwang/java_training","owner":{"login":"bhuwang","id":3335673,"avatar_url":"https://avatars.githubusercontent.com/u/3335673?v=3","gravatar_id":"","url":"https://api.github.com/users/bhuwang","html_url":"https://github.com/bhuwang","followers_url":"https://api.github.com/users/bhuwang/followers","following_url":"https://api.github.com/users/bhuwang/following{/other_user}","gists_url":"https://api.github.com/users/bhuwang/gists{/gist_id}","starred_url":"https://api.github.com/users/bhuwang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bhuwang/subscriptions","organizations_url":"https://api.github.com/users/bhuwang/orgs","repos_url":"https://api.github.com/users/bhuwang/repos","events_url":"https://api.github.com/users/bhuwang/events{/privacy}","received_events_url":"https://api.github.com/users/bhuwang/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bhuwang/java_training","description":"","fork":false,"url":"https://api.github.com/repos/bhuwang/java_training","forks_url":"https://api.github.com/repos/bhuwang/java_training/forks","keys_url":"https://api.github.com/repos/bhuwang/java_training/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bhuwang/java_training/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bhuwang/java_training/teams","hooks_url":"https://api.github.com/repos/bhuwang/java_training/hooks","issue_events_url":"https://api.github.com/repos/bhuwang/java_training/issues/events{/number}","events_url":"https://api.github.com/repos/bhuwang/java_training/events","assignees_url":"https://api.github.com/repos/bhuwang/java_training/assignees{/user}","branches_url":"https://api.github.com/repos/bhuwang/java_training/branches{/branch}","tags_url":"https://api.github.com/repos/bhuwang/java_training/tags","blobs_url":"https://api.github.com/repos/bhuwang/java_training/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bhuwang/java_training/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bhuwang/java_training/git/refs{/sha}","trees_url":"https://api.github.com/repos/bhuwang/java_training/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bhuwang/java_training/statuses/{sha}","languages_url":"https://api.github.com/repos/bhuwang/java_training/languages","stargazers_url":"https://api.github.com/repos/bhuwang/java_training/stargazers","contributors_url":"https://api.github.com/repos/bhuwang/java_training/contributors","subscribers_url":"https://api.github.com/repos/bhuwang/java_training/subscribers","subscription_url":"https://api.github.com/repos/bhuwang/java_training/subscription","commits_url":"https://api.github.com/repos/bhuwang/java_training/commits{/sha}","git_commits_url":"https://api.github.com/repos/bhuwang/java_training/git/commits{/sha}","comments_url":"https://api.github.com/repos/bhuwang/java_training/comments{/number}","issue_comment_url":"https://api.github.com/repos/bhuwang/java_training/issues/comments{/number}","contents_url":"https://api.github.com/repos/bhuwang/java_training/contents/{+path}","compare_url":"https://api.github.com/repos/bhuwang/java_training/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bhuwang/java_training/merges","archive_url":"https://api.github.com/repos/bhuwang/java_training/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bhuwang/java_training/downloads","issues_url":"https://api.github.com/repos/bhuwang/java_training/issues{/number}","pulls_url":"https://api.github.com/repos/bhuwang/java_training/pulls{/number}","milestones_url":"https://api.github.com/repos/bhuwang/java_training/milestones{/number}","notifications_url":"https://api.github.com/repos/bhuwang/java_training/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bhuwang/java_training/labels{/name}","releases_url":"https://api.github.com/repos/bhuwang/java_training/releases{/id}","created_at":"2015-08-06T04:45:13Z","updated_at":"2015-08-31T05:46:12Z","pushed_at":"2015-09-15T07:41:15Z","git_url":"git://github.com/bhuwang/java_training.git","ssh_url":"git@github.com:bhuwang/java_training.git","clone_url":"https://github.com/bhuwang/java_training.git","svn_url":"https://github.com/bhuwang/java_training","homepage":null,"size":4236,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":32,"forks":3,"open_issues":32,"watchers":0,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/bhuwang/java_training/pulls/119"},"html":{"href":"https://github.com/bhuwang/java_training/pull/119"},"issue":{"href":"https://api.github.com/repos/bhuwang/java_training/issues/119"},"comments":{"href":"https://api.github.com/repos/bhuwang/java_training/issues/119/comments"},"review_comments":{"href":"https://api.github.com/repos/bhuwang/java_training/pulls/119/comments"},"review_comment":{"href":"https://api.github.com/repos/bhuwang/java_training/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bhuwang/java_training/pulls/119/commits"},"statuses":{"href":"https://api.github.com/repos/bhuwang/java_training/statuses/9adcc8e839d2c910108d92886facc60d180b73c7"}}}}