Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Coding-Challenge

A webservice which performs CRUD operations.

###################################### README

Author : Shalima Sidhik Date : 11/12/2015 Updated : 11/16/2015, 11/17/2015 #####################################

CONTENTS

  • Introduction
  • Resources
  • Modus Operandi
  • Deployment
  • Testing
  • FAQ
  • Issues
  • Improvements to be made

INTRODUCTION

This module upon deployment will publish a webservice which will perform CRUD operations along with some other operations.

The operations include :

  1. Create a claim and persisting to the backing store And xml input is given to the webservice and a claim is created and persisted in the backing store. A SUCCESS or Error message will appear on the page.

  2. Read a claim from backing store A claim number is given as input and a claim is read from the backing store and displayed.

  3. Read a list of claims by date range of loss date A date range is given as input and a list of claims are read from backing store with loss date in the given range.

  4. Update a claim in the backing store A claim given as input xml is updated on the backing store.

  5. Read a specific vehicle A vehicle is read from the backing store with vin and claim number given as input.

  6. Delete claim from backing store A claim is deleted from the backing store.

RESOURCES

Database : Embedded HSQLDB Frameworks : Spring (Dependency injection), Hibernate (ORM mapping), JAXB(Xml binding), JAX-RS with Jersey(REST Webservice), Log4j, Jersey (Client) Logging : Log4j Server : JBoss Testing : JUnit, Postman

Modus Operandi

Data model :

HSQLDB embedded database is used in the project.

The model has 3 tables : CLAIM, LOSSINFOTYPE, VEHICLEINFOTYPE.
CLAIM has OneToOne relationship with LOSSINFOTYPE where claimnumber of CLAIM is the primary key in the LOSSINFOTYPE table.
CLAIM has OneToMany relationship with VEHICLEINFOTYPE where claimnumber of CLAIM is the foreign key in the VEHICLEINFOTYPE. The primary key of Vehicleinfotype is vin.

The DB is initialized with createDB.SQL and insertDB.SQL scripts.

AutoGeneration of model classes with hibernate :

1. Created tables in DB.
2. Autogenerated model classes with reverse engineering utility of the hibernate.

AutoGeneration of JAXB classes with JAXB :

1. JAXB classes are autogenerated with the help of JAXB.

Flow :

WebServiceClient -> MitchellApplication -> MitchellRestResource -> MitchellService -> BaseDAO -> DB

MitchellApplication 
	Starts from here.

MitchellRestResource
	Has the POST, GET, PUT and DELETE methods.
	Converts the JAXB classes to model classes wherever necessary and sends them to corresponding service methods.

MitchellService
	Has corresponding service methods.
	MitchellServiceImpl implements the respective methods.
	Uses the DAOFactory to get respective DAO objects and inputs are sent to the DAOs.
	
BaseDAO
	Interface implemented by all DAOs 
	All DAO interfaces have corresponding DAOImpl classes where the methods are implemented.
	Database transactions are performed here and the response is sent back.

Files included

dbInit.xml
	Used to initialize the DB using Spring
	
spring.xml
	Used to inject dependency and also register datasource.
	
springTest.xml
	Used for testing
	
log4j.properties
	Has properties for log4j loggin
	
hibernate.cfg.xml (Used for auto code generation of model classes)
	Configuring the hibernate with the datasource
	
hibernate.reveng.xml (Used for auto code generation of model classes)
	Used for reverse engineering

createDB.sql (/db)
	SQL script for creatisng the tables

insertDB.sql (/db)
	SQL script for inserting data into the table

DEPLOYMENT

Deploy the code in any of the following ways.

  1. Deploy the war file in a server
  2. Open the code in eclipse and run as server.

TESTING

Test the program in any of the following ways

  1. Use Postman (an extension in google chrome) or any other extension for that matter.
  2. Use testWebServiceClient to test the code.

WebService URLs

  1. Reading all the claims (@GET) http://localhost:8080/org.mitchell.claim/resources/claims

  2. Create a claim (@POST) http://localhost:8080/org.mitchell.claim/resources/claims/create/{xmlInput}

  3. Update a claim(@PUT) http://localhost:8080/org.mitchell.claim/resources/claims/update/{xmlInput}

  4. Delete a claim(@DELETE) http://localhost:8080/org.mitchell.claim/resource/deleteClaim/{claimNumber:String}

  5. Read a claim(@GET) http://localhost:8080/org.mitchell.claim/resources/claims/getClaim/{claimNumber:String}

  6. Read claims in given loss date range http://localhost:8080/org.mitchell.claim/resources/claims/getInDateRange/{fromDate:.*}/{toDate:.*}?fromDate={String}&toDate={String}

  7. Read a vehicle from the table http://localhost:8080/org.mitchell.claim/resources/claims/getVehicle/{claimNumber:.*}/{vin:.*}?claimNumber={String}&vin={String}

FAQ ?

What if I want to change the Datasource ? Change the datasource properties in spring.xml and alter the dbInit, if using, or delete it and you are good to go.

What if I want to change the webservice ? Change or delete the mitchellRestResource file and everything else stays the same.

What if I want to add more tables in DB ? Add the table and reverse engineer the model classes using hibernate.

What if I want to change the XML Schema ? Autogenerate the jaxb classes from the new schema using JAXB and use it.

ISSUES

A few issues and bugs are yet to be fixed : 

	An illegal mismatch while testing client 
		Potential root cause : A mismatch in the version in jsr311-api and jersey bundle.
		
	Constraint violation in update and delete method
		Potential root cause : The DB is not initialized properly everytime program is deployed.
		
	If 'Session.close()' not commented, upon deployment, throws exception during database transactions but works fine with Unit test
		Potential root cause : A version mismatch between hibernate and spring.
		
	The unit test cases except client test case are working.

IMPROVEMENTS TO BE MADE

Fix the issues.

Improve the test cases.
	Check the boundary conditions. If using another DB, use mock objects for testing.
	
Improve logging.

About

A webservice which performs CRUD operations.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages