-
Notifications
You must be signed in to change notification settings - Fork 0
Employee management system #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
6d567f2
61c4cee
a94fd28
9df3b74
6820438
0c399ce
7c31c8c
f0174ee
fab3d7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,23 @@ | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>com.lftechnology.phpjava</groupId> | ||
| <artifactId>phpjava</artifactId> | ||
| <version>1.0.0</version> | ||
| </parent> | ||
| <artifactId>naresh</artifactId> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| <groupId>com.lftechnology.phpjava</groupId> | ||
| <artifactId>phpjava</artifactId> | ||
| <version>1.0.0</version> | ||
| </parent> | ||
| <dependencies> | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| <dependency> | ||
| <groupId>mysql</groupId> | ||
| <artifactId>mysql-connector-java</artifactId> | ||
| <version>5.1.6</version> | ||
| </dependency> | ||
| <!-- https://mvnrepository.com/artifact/de.vandermeer/asciitable --> | ||
| <dependency> | ||
| <groupId>de.vandermeer</groupId> | ||
| <artifactId>asciitable</artifactId> | ||
| <version>0.2.5</version> | ||
| </dependency> | ||
| </dependencies> | ||
| <artifactId>naresh</artifactId> | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| </project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.lftechnology.phpjava.ems; | ||
|
|
||
| import com.lftechnology.phpjava.ems.utlis.Router; | ||
|
|
||
| /** | ||
| * EmployeeManagementSystem | ||
| * | ||
| * @author Naresh Maharjan <nareshmaharjan@lftechnology.com> | ||
| * @since August, 12 2016 | ||
| */ | ||
| public class EmployeeManagementSystem { | ||
|
|
||
| /** | ||
| * @author Naresh Maharjan <nareshmaharjan@lftechnology.com> | ||
| * @param args | ||
| */ | ||
| public static void main(String[] args) { | ||
| Router.showMenu(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| CREATE TABLE user (id INT PRIMARY KEY AUTO_INCREMENT,username VARCHAR(255),password VARCHAR(255),is_terminated BINARY DEFAULT FALSE); | ||
|
|
||
| CREATE TABLE employee (id INT PRIMARY KEY AUTO_INCREMENT, fullname VARCHAR(255), department VARCHAR(255), address VARCHAR(255), role VARCHAR(10), user_id INT NOT NULL,CONSTRAINT emp_user_id_fk FOREIGN KEY (user_id) REFERENCES user (id)); | ||
| ALTER TABLE employee DROP FOREIGN KEY emp_user_id_fk; | ||
| ALTER TABLE employee ADD CONSTRAINT emp_user_id_fk FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE ON UPDATE CASCADE; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| url=jdbc:mysql://localhost/ems | ||
| driver=com.mysql.jdbc.Driver | ||
| username=root | ||
| password=naresh |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| package com.lftechnology.phpjava.ems.constants; | ||
|
|
||
|
|
||
| /** | ||
| * Constant | ||
| * | ||
| * @author Naresh Maharjan <nareshmaharjan@lftechnology.com> | ||
| * @since August, 09 2016 | ||
| */ | ||
| public class Constant { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| public static final int ADD_NEW_USER = 1; | ||
| public static final int UPDATE_PROFILE = 1; | ||
| public static final int SEARCH_USER = 2; | ||
| public static final int TERMINATE_USER = 3; | ||
| public static final int DELETE_USER = 4; | ||
| public static final int EXIT = 0; | ||
| public static final String PROPERTY_URL = "url"; | ||
| public static final String PROPERTY_DRIVER = "driver"; | ||
| public static final String PROPERTY_USERNAME = "username"; | ||
| public static final String PROPERTY_PASSWORD = "password"; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| public static final String POST_LOGIN_ACTION = "postLogin"; | ||
| public static final String ADD_USER_ACTION = "addUser"; | ||
| public static final String SEARCH_USER_ACTION = "searchUser"; | ||
| public static final String TERMINATE_USER_ACTION = "terminateUser"; | ||
| public static final String DELETE_USER_ACTION = "deleteUser"; | ||
| public static final String EXIT_ACTION = "exit"; | ||
| public static final String UPDATE_PROFILE_ACTION = "updateProfile"; | ||
| public static final String TERMINATE_USER_MESSAGE = "3. Terminate User"; | ||
| public static final String ADD_NEW_USER_MESSAGE = "1. Add New User"; | ||
| public static final String SEARCH_USERS = "2. Search User(s)"; | ||
| public static final String DELETE_USER_MESSAGE = "4. Delete User"; | ||
| public static final String EXIT_MESSAGE = "0. Exit"; | ||
| public static final String UPDATE_PROFILE_MESSAGE = "1. Update Profile"; | ||
| public static final String CHOOSE_ONE_OF_THE_FOLLOWING_USER_TYPE = "Choose One Of The Following User Type"; | ||
| public static final String ADD_ADMIN_USER = "1. Add Admin User"; | ||
| public static final String ADD_NORMAL_USER = "2. Add Normal User"; | ||
| public static final String EMPLOYEE = "employee"; | ||
| public static final String COMMON_UTILITY = "commonUtility"; | ||
| public static final String ENTER_USER_DETAILS = "Enter User Details"; | ||
| public static final String ENTER_FULLNAME = "1. Enter Fullname"; | ||
| public static final String ENTER_DEPARTMENT = "2. Enter Department"; | ||
| public static final String ENTER_ADDRESS = "3. Enter Address"; | ||
| public static final String ENTER_USERNAME = "4. Enter Username"; | ||
| public static final String ENTER_PASSWORD = "5. Enter Password"; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| public static final String CHOOSE_ONE_OF_THE_FOLLOWING_SEARCH_CRITERIA = "Choose One Of The Following Search Criteria"; | ||
| public static final String SEARCH_BY_FULLNAME = "1. Search By Fullname"; | ||
| public static final String SEARCH_BY_DEPARTMENT = "2. Search By Department"; | ||
| public static final String SEARCH_BY_ADDRESS = "3. Search By Address"; | ||
| public static final String ENTER_SEARCH_VALUE = "Enter search value"; | ||
| public static final String UPDATE_PROFILE_MENU = "Update Profile"; | ||
| public static final String UPDATE_FULLNAME = "1. Update Fullname"; | ||
| public static final String UPDATE_DEPARTMENT = "2. Update Department"; | ||
| public static final String UPDATE_ADDRESS = "3. Update Address"; | ||
| public static final String UPDATE_USERNAME = "4. Update Username"; | ||
| public static final String UPDATE_PASSWORD = "5. Update Password"; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| public static final String ENTER_VALUE = "Enter value"; | ||
| public static final String DELETE_USER_MENU = "Delete User"; | ||
| public static final String ENTER_FULLNAME_OF_EMPLOYEE = "1. Enter Fullname of Employee"; | ||
| public static final String RETURN_TO_MAIN_MENU = "2. Return to main menu"; | ||
| public static final String TERMINATE_USER_MENU = "Terminate User"; | ||
| public static final String LOGIN = "login"; | ||
| public static final String ENTER_YOUR_USERNAME_TO_LOGIN = "Enter your username:"; | ||
| public static final String ENTER_YOUR_PASSWORD_TO_LOGIN = "Enter your password:"; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| public static final String USER = "user"; | ||
| public static final String WELCOME_TO_EMPLOYEE_MANAGEMENT_SYSTEM = "Welcome To Employee Management System !!!"; | ||
| public static final String ENTER_YOUR_CREDENTAILS_TO_LOG_INTO_THE_SYSTEM = "Enter your credentails to log into the system"; | ||
| public static final String BYE_MESSAGE = "Bye, Felicia"; | ||
| public static final String DO_YOU_WANT_TO_CONTINUE = "Do you want to continue?"; | ||
| public static final String YES = "1. Yes"; | ||
| public static final String NO = "2. No"; | ||
| public static final String PRESS_1_TO_CONTINUE_OR_ANY_OTHER_NUMBER_TO_EXIT = "Press 1 to continue or any other number to exit"; | ||
| public static final String INVALID_OPTION_PLEASE_ENTER_AGAIN = "Invalid option. Please enter again"; | ||
| public static final String INVALID_CREDENTAILS = "Invalid Credentails"; | ||
| public static final String USER_ID = "User ID"; | ||
| public static final String FULL_NAME = "Full Name"; | ||
| public static final String ADDRESS = "Address"; | ||
| public static final String ROLE_USER_TYPE = "Role(User Type)"; | ||
| public static final String DEPARTMENT = "Department"; | ||
| public static final String EMPLOYEE_ADDED_SUCCESSFULLY = "Employee added successfully"; | ||
| public static final String UNABLE_TO_ADD_EMPLOYEE = "Unable to add employee"; | ||
| public static final String DATA_UPDATED_SUCCESSFULLY = "Data updated successfully."; | ||
| public static final String UNABLE_TO_UPDATE_PROFILE = "Unable to update profile."; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.lftechnology.phpjava.ems.controllers; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * ControllerSignature | ||
| * | ||
| * @author Naresh Maharjan <nareshmaharjan@lftechnology.com> | ||
| * @since August, 16 2016 | ||
| */ | ||
| public interface ControllerSignature<T> { | ||
| /** | ||
| * @author Naresh Maharjan <nareshmaharjan@lftechnology.com> | ||
| * @return | ||
| */ | ||
| Map<String, T> getData(); | ||
|
|
||
| /** | ||
| * @author Naresh Maharjan <nareshmaharjan@lftechnology.com> | ||
| * @param data | ||
| */ | ||
| void setData(Map<String, T> data); | ||
|
|
||
| /** | ||
| * @author Naresh Maharjan <nareshmaharjan@lftechnology.com> | ||
| * @return | ||
| */ | ||
| boolean isPost(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| package com.lftechnology.phpjava.ems.controllers; | ||
|
|
||
| import com.lftechnology.phpjava.ems.constants.Constant; | ||
| import com.lftechnology.phpjava.ems.entities.Employee; | ||
| import com.lftechnology.phpjava.ems.services.EmployeeService; | ||
| import com.lftechnology.phpjava.ems.views.CommonViewUtility; | ||
| import com.lftechnology.phpjava.ems.views.EmployeeView; | ||
|
|
||
| import java.sql.SQLException; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * EmployeeController | ||
| * | ||
| * @author Naresh Maharjan <nareshmaharjan@lftechnology.com> | ||
| * @since August, 08 2016 | ||
| */ | ||
| public class EmployeeController implements ControllerSignature<Object> { | ||
| private static EmployeeService employeeService = new EmployeeService(); | ||
| private static EmployeeView employeeView = new EmployeeView(); | ||
| private static Map<String, Object> postData = new HashMap<>(); | ||
| private boolean isPost = false; | ||
|
|
||
| /** | ||
| * @author Naresh Maharjan <nareshmaharjan@lftechnology.com> | ||
| */ | ||
| public void postLoginScreen() { | ||
| employeeView.setAction(Constant.POST_LOGIN_ACTION); | ||
| employeeView.setData(postData); | ||
| employeeView.render(); | ||
| } | ||
|
|
||
| /** | ||
| * @author Naresh Maharjan <nareshmaharjan@lftechnology.com> | ||
| */ | ||
| public void addUser() { | ||
| if (this.isPost) { | ||
| Employee employee = (Employee) postData.get(Constant.EMPLOYEE); | ||
| int result = 0; | ||
| try { | ||
| result = employeeService.addEmployee(employee); | ||
| } catch (Exception e) { | ||
| e.printStackTrace(); | ||
| } | ||
| String message; | ||
| if (result > 0) { | ||
| message = Constant.EMPLOYEE_ADDED_SUCCESSFULLY; | ||
| } else { | ||
| message = Constant.UNABLE_TO_ADD_EMPLOYEE; | ||
| } | ||
| postData.clear(); | ||
| this.isPost = false; | ||
| CommonViewUtility.showMessageAndContinue(message); | ||
| } else { | ||
| employeeView.setAction(Constant.ADD_USER_ACTION); | ||
| employeeView.render(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * @author Naresh Maharjan <nareshmaharjan@lftechnology.com> | ||
| */ | ||
| public void searchUser() { | ||
| if (this.isPost) { | ||
| Employee employee = (Employee) postData.get(Constant.EMPLOYEE); | ||
| List<Employee> result = new ArrayList<>(); | ||
| try { | ||
| result = employeeService.searchEmployee(employee); | ||
| } catch (SQLException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| employeeView.renderEmployeeList(employeeService.getColumns(), result); | ||
| this.isPost = false; | ||
| postData.clear(); | ||
| CommonViewUtility.pressKeyToContinue(); | ||
| } else { | ||
| employeeView.setAction(Constant.SEARCH_USER_ACTION); | ||
| employeeView.render(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @author Naresh Maharjan <nareshmaharjan@lftechnology.com> | ||
| */ | ||
| public void terminateUser() { | ||
| if (this.isPost()) { | ||
| Employee employee = (Employee) postData.get(Constant.EMPLOYEE); | ||
| int result = 0; | ||
| try { | ||
| result = employeeService.terminateUser(employee); | ||
| } catch (SQLException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| String message = result + " users were terminated"; | ||
| postData.clear(); | ||
| this.isPost = false; | ||
| CommonViewUtility.showMessageAndContinue(message); | ||
| } else { | ||
| employeeView.setAction(Constant.TERMINATE_USER_ACTION); | ||
| employeeView.render(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * @author Naresh Maharjan <nareshmaharjan@lftechnology.com> | ||
| */ | ||
| public void deleteUser() { | ||
| if (this.isPost()) { | ||
| Employee employee = (Employee) postData.get(Constant.EMPLOYEE); | ||
| int result = 0; | ||
| try { | ||
| result = employeeService.deleteUser(employee); | ||
| } catch (Exception e) { | ||
| e.printStackTrace(); | ||
| } | ||
| String message = result + " users were deleted"; | ||
| postData.clear(); | ||
| this.isPost = false; | ||
| CommonViewUtility.showMessageAndContinue(message); | ||
| } else { | ||
| employeeView.setAction(Constant.DELETE_USER_ACTION); | ||
| employeeView.render(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @author Naresh Maharjan <nareshmaharjan@lftechnology.com> | ||
| */ | ||
| public void updateProfile() { | ||
| if (this.isPost) { | ||
| Employee employee = (Employee) postData.get(Constant.EMPLOYEE); | ||
| int result = 0; | ||
| try { | ||
| result = employeeService.updateEmployee(employee); | ||
| } catch (Exception e) { | ||
| e.printStackTrace(); | ||
| } | ||
| this.isPost = false; | ||
| postData.clear(); | ||
| String message; | ||
| if (result > 0) { | ||
| message = Constant.DATA_UPDATED_SUCCESSFULLY; | ||
| } else { | ||
| message = Constant.UNABLE_TO_UPDATE_PROFILE; | ||
| } | ||
| CommonViewUtility.showMessageAndContinue(message); | ||
| } else { | ||
| employeeView.setAction(Constant.UPDATE_PROFILE_ACTION); | ||
| employeeView.render(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @author Naresh Maharjan <nareshmaharjan@lftechnology.com> | ||
| * @return | ||
| */ | ||
| @Override | ||
| public Map<String, Object> getData() { | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * @author Naresh Maharjan <nareshmaharjan@lftechnology.com> | ||
| * @param data | ||
| */ | ||
| @Override | ||
| public void setData(Map<String, Object> data) { | ||
| postData = data; | ||
| } | ||
|
|
||
| /** | ||
| * @author Naresh Maharjan <nareshmaharjan@lftechnology.com> | ||
| * @return | ||
| */ | ||
| @Override | ||
| public boolean isPost() { | ||
| return this.isPost; | ||
| } | ||
|
|
||
| /** | ||
| * @author Naresh Maharjan <nareshmaharjan@lftechnology.com> | ||
| */ | ||
| public void makeCurrentRequestPost() { | ||
| this.isPost = true; | ||
| } | ||
| } |




There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.