- Problem
- Tools and Resources
- Models/Entities
- Entities RelationShip
- Sample code For Relation
- DTO and Validation Code Sample
- File Structure of Project
- Access the Functionalities
- Features of Project
- How to Run Local Server
- Use Postman(API testing)
- My Details
Assignment:- Create an Insurance Management Platform with Spring Boot and Java .
Objective:- Build an insurance management platform that allows users to manage insurance policies, clients, and claims using Spring Boot and Java.
- Java 8, Spring Web, Spring Data JPA, Rest API, Spring Boot version 2.7.10 .
- Spring Initializr (https://start.spring.io/), STS(Spring Tool Suite), MySQL Server(SQLyog), Postman and Windows .
- Spring-boot Maven Dependencies:-
- spring-boot-starter-data-jpa
- spring-boot-starter-validation
- spring-boot-starter-web
- mysql-connector-j
- spring-boot-starter-test
As par Project requirement we take three Entities which are given below---
- Client Entity
- Name (Property)
- Date Of Birth (Property)
- Address (Property)
- contact information (Property)
- Insurance Policy Entity
- policy number (Property)
- type (Property)
- coverage amount (Property)
- premium (Property)
- start date (Property)
- end date (Property)
- Claim Entity
- claim number (Property)
- description (Property)
- claim date (Property)
- claim status (Property)
In project i created two relationship----
- I build the relationship Many To Many relationship between Claim Entity and Insurance Policy Entity because A Client have many Insurance Policy and Insurance Policy have many Client.
- And another relationship which is build between Insurance Policy Entity and Claim Entity.The relationship is Many to One relationship because of a policy can have many claim in different stages.
I showing the image of relationship of entities:--
//==================InsurancePolicy==========
@Entity
public class InsurancePolicy {
@Id
@GeneratedValue
private Integer policy_No;
private String policy_Type;
private Double Coverage_Amount;
private Double premium;
private String start_Time;
private String end_Time;
@OneToMany(targetEntity = Claim.class,cascade = CascadeType.REMOVE)
@JoinColumn(name = "policy_No" )
private List<Claim> claims;
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(
name = "policy_addTo_Client",
joinColumns = {@JoinColumn(name="policy_No")},
inverseJoinColumns = {@JoinColumn(name="client_No")}
)
private List<Client> clients;
}//================== Client =================
@Entity
@Table(name = "client")
public class Client {
@Id
@GeneratedValue
private Long client_No;
private String name;
private String dob;
private String phoneNo;
@Embedded
private Address address;
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(
name = "policy_addTo_Client",
joinColumns = {@JoinColumn(name="client_No")},
inverseJoinColumns = {@JoinColumn(name="policy_No")}
)
private List<InsurancePolicy> policy;
}//=================== Address ===============
@Embeddable
public class Address {
private String city;
private String state;
private String country;
}//==================== Claim ================
@Entity
public class Claim {
@Id
private Integer claim_No;
private String description;
private String claim_Date;
private String claim_Status;
}//==================== Claim dto ================
public class Claim_dto {
@NotNull(message = "claim_No your claim it not be null")
private Integer claim_No;
@NotNull(message = "Plese describe your claim it not be null")
private String description;
@NotNull
@Pattern(regexp = "^(3[01]|[12][0-9]|00|0[1-9])/(1[0-2]|00|0[1-9])/([0-9]{4})$",message = "date formate dd/mm/yy")
private String claim_Date;
@NotNull(message = "status can not be null")
private String claim_Status;
}//================== Client ================
public class Client_dto {
private Long client_Id;
@NotNull(message = "name can not be null")
@Pattern(regexp = "^[A-Z][a-z]+\\W[A-Z][a-z]+$",
message ="First letter of String Must be capital.Take a space between two string")
private String name;
@NotNull(message = "date of birth can not be null")
@Pattern(regexp = "^(3[01]|[12][0-9]|00|0[1-9])/(1[0-2]|00|0[1-9])/([0-9]{4})$",
message = "date formate dd/mm/yy")
private String dob;
@NotNull(message = "Phone number can not be null")
@Pattern(regexp = "^(0|91)?[7-9][0-9]{9}$",
message ="Enter the valid phone number.first 0 or 91 optional but actual number must be 10 digits" )
private String phoneNo;
@NotNull(message = "Address can not be null")
@Valid
private Address address;
private List<Integer> policy_No;
}//==================InsurancePolicy==========
public class InsurancePolicy_dto {
private Integer policy_No;
@NotEmpty(message ="policy_Type can not be null")
private String policy_Type;
@NotNull(message = "Coverage_Amount can not be null")
private Double Coverage_Amount;
@NotNull(message = "premium can not be null")
private Double premium;
@NotNull
@Pattern(regexp = "^(3[01]|[12][0-9]|00|0[1-9])/(1[0-2]|00|0[1-9])/([0-9]{4})$",message = "valid date in valid formate dd/mm/yy")
private String start_Time;
@NotNull
@Pattern(regexp = "^(3[01]|[12][0-9]|00|0[1-9])/(1[0-2]|00|0[1-9])/([0-9]{4})$",message = "valid date in valid formate dd/mm/yy")
private String end_Time;
private List<Integer> claimsN;
}Project Folder Structure is given below-----
- For Client :-
- For Insurance Policy :-
- For Claim :-
The main Features of that project Data
Integrity Exception Handling and Data validation
- Goto my GitHub link--" https://github.com/susanta09/Insurance_Policy_Management.git"
- Then goto code Option then click.
- then click Download ZIP for download ZIP file for Project.
- Create a folder with any name Extract the downloaded ZIP file.
- Open STS tool and import the file insurance_policy
- Open Mysql server (SQLyog or MySQL Workbench) And create "apolicy" database.
spring.datasource.url=jdbc:mysql://localhost:3306/apolicy - Then goto the project and open resources file .
- open the application.properties file and chang the username and password as par your mysql server
- also provide unique port number
spring.datasource.username=root spring.datasource.password=admin server.port=9090
Note:-
Problem:
If get error like-----
Solution:
Then you must be add tomcat-embed-jasper dependency
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>Here i provide structure of entities in Json formate for working in Postman tool.
- Json Client :-
{
"client_Id": 3,
"name": "Susanta Barman",
"dob": "23/07/2009",
"phoneNo": "8768316572",
"address": {
"city": "herosima",
"state": "cocoham",
"country": "japan"
},
"policy_No": []
}- json for Insurance policy :-
{
"policy_No": 1,
"policy_Type": "type1",
"premium": 3000,
"start_Time": "23/09/2000",
"end_Time": "21/03/2014",
"claimsN": [],
"coverage_Amount": 15000
}- json for claim
{
"claim_No": 1005,
"description": "hghghj",
"claim_Date": "10/08/2005",
"claim_Status": "not clear"
}I provide few sample Postman Screenshot images---

Name:- Susanta Barman
Email:- ssbarmant107@gmail.com Phone No:- 8768316572


