This Project is a sample Project to Implement Clean Coding and Following Coding Ethics.This sample project is having a very simple logic of storing employee details and performing CRUD operation on the Employee.
1. Core JAVA programing
2. Serlvel Programming and structure of Web Project
3. Web Cointainer (ex: TOMCAT(Servlet cointainer) & JETTY)
4. MONGODB
5. MAVEN life cycles
6. Eclipse
7. Jersey Rest(JAX-RS)
8. Jackson(or GSON) to convert JSON to Object (vise versa)
9. Spring Core
I am a fresher in the field so to become a successfull JAVA developer i needed to work on sample project to understand good coding ethics and to apply new technology to my project.
The main aim of project is not to apply complex buisness logic but only to learn how to configure REST,JETTY,JACKSON,MAVEN,SPRING etc.
The installation of project is very Simple follow the below Steps:
-
clone the project to a new directory.
-
run mvn clean package (all the dependencies will get downloaded automatically)
-
run mvn eclipse:eclipse
-
import it as a maven project to eclipse
-
start mongodb using command in terminal
mongod --auth --port 5000 --dbpath ~/db/mongodb
-
configure your mongodb by creating a employee Db and employeeProfile and counters Collection by running following code
use employee db.createUser( { user: "admin_anmol", pwd: "admin", roles: [ "readWrite", "dbAdmin" ] } ) db.counters.insert({"_id":"userid","seq":0}) db.employeeProfile.insert({"name":"anmol"})
counters is used to sequential increment of _id (employee ID) close the mongodb and
-
now start mongodb using
mongod --auth --port 5000 --dbpath ~/db/mongodb
-
create a DB.properties file to configure DB in your Project example
MONGODB PROPERTIES DB_ID=admin_anmol DB_PASSWORD=admin DB_NAME=employee DB_PORT=5000 HOST_NAME=localhost
-
now set VM Arguments in eclipse(-Dport is the port on which your webapp is running)
-Dport=8080 -Ddb_properties_file_path="/home/anmol/Workspace/Employee/src/main/resource/DB.properties"
-
run the porject and use below REST endpoints to perform CRUD Actions:
REQUEST-TYPE Actions URI
GET listofEmployee localhost:8080/Employee/service/employee
GET singleEmployee localhost:8080/Employee/service/employee/{id}
POST addEmployee localhost:8080/Employee/service/addEmployee
DELETE deleteEmployee localhost:8080/Employee/service/deleteEmployee/{id}
PUT updateEmployee localhost:8080/Employee/service/updateEmployee
sample payload for PUT and POST("_id" is not needed as _id is auto incremented from program)
{ "empId":"1",
"firstName":"anmol",
"lastName":"Srivastava",
"designation":"JAVA Developer",
"gender":"male"
}
-
MAVEN:
-
MONGODB:
-
REST:
-
JETTY:
-
Jackson & Gson:
-
Spring core: