From f2c67cf93c6b8bebf32e335813c059441961a7d7 Mon Sep 17 00:00:00 2001 From: barnamensch056 Date: Mon, 25 Nov 2024 21:05:46 +0530 Subject: [PATCH] task 2 of creating entities --- .../wellsfargo/counselor/entity/Advisor.java | 18 ++- .../wellsfargo/counselor/entity/ClientR.java | 116 ++++++++++++++++++ .../counselor/entity/Portfolio.java | 66 ++++++++++ .../wellsfargo/counselor/entity/Security.java | 102 +++++++++++++++ 4 files changed, 300 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/wellsfargo/counselor/entity/ClientR.java create mode 100644 src/main/java/com/wellsfargo/counselor/entity/Portfolio.java create mode 100644 src/main/java/com/wellsfargo/counselor/entity/Security.java diff --git a/src/main/java/com/wellsfargo/counselor/entity/Advisor.java b/src/main/java/com/wellsfargo/counselor/entity/Advisor.java index 1a6861ec..33c2a9ab 100644 --- a/src/main/java/com/wellsfargo/counselor/entity/Advisor.java +++ b/src/main/java/com/wellsfargo/counselor/entity/Advisor.java @@ -1,10 +1,12 @@ package com.wellsfargo.counselor.entity; - import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import jakarta.persistence.CascadeType; +import java.util.*; @Entity public class Advisor { @@ -28,11 +30,15 @@ public class Advisor { @Column(nullable = false) private String email; + @OneToMany(mappedBy = "advisor") + private List clients; + protected Advisor() { } - public Advisor(String firstName, String lastName, String address, String phone, String email) { + public Advisor(String firstName, String lastName, String address, String phone, String email, + List clients) { this.firstName = firstName; this.lastName = lastName; this.address = address; @@ -83,4 +89,12 @@ public String getEmail() { public void setEmail(String email) { this.email = email; } + + public List getClients() { + return clients; + } + + public void setClients(List clients) { + this.clients = clients; + } } diff --git a/src/main/java/com/wellsfargo/counselor/entity/ClientR.java b/src/main/java/com/wellsfargo/counselor/entity/ClientR.java new file mode 100644 index 00000000..0d8cbad7 --- /dev/null +++ b/src/main/java/com/wellsfargo/counselor/entity/ClientR.java @@ -0,0 +1,116 @@ +package com.wellsfargo.counselor.entity; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OneToOne; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Column; +import java.util.*; + +@Entity +public class ClientR { + + @Id + @GeneratedValue() + private long clientId; + + @Column(nullable = false) + private String firstName; + + @Column(nullable = false) + private String lastName; + + @Column(nullable = false) + private String address; + + @Column(nullable = false) + private String phone; + + @Column(nullable = false) + private String email; + + @ManyToOne + @JoinColumn(name = "advisorId") + private Advisor advisor; + + @OneToMany + private List portfolios; + + protected ClientR() { + + } + + public ClientR(String firstName, String lastName, String address, String phone, String email, Advisor advisor, + List portfolios) { + this.firstName = firstName; + this.lastName = lastName; + this.address = address; + this.phone = phone; + this.email = email; + this.advisor = advisor; + this.portfolios = portfolios; + } + + public Long getClientId() { + return clientId; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public Advisor getAdvisor() { + return advisor; + } + + public void setAdvisor(Advisor advisor) { + this.advisor = advisor; + } + + public List getPortfolios() { + return portfolios; + } + + public void setPortfolios(List portfolios) { + this.portfolios = portfolios; + } +} diff --git a/src/main/java/com/wellsfargo/counselor/entity/Portfolio.java b/src/main/java/com/wellsfargo/counselor/entity/Portfolio.java new file mode 100644 index 00000000..cf431322 --- /dev/null +++ b/src/main/java/com/wellsfargo/counselor/entity/Portfolio.java @@ -0,0 +1,66 @@ +package com.wellsfargo.counselor.entity; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToOne; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Column; +import jakarta.persistence.OneToMany; +import java.time.LocalDateTime; +import java.util.*; + +@Entity +public class Portfolio { + + @Id + @GeneratedValue() + private long portfolioId; + + @Column(nullable = false) + private LocalDateTime creationDate; + + @ManyToOne + @JoinColumn(name = "clientId") + private ClientR client; + + @OneToMany + private List securities; + + public Portfolio(long portfolioId, LocalDateTime creationDate, ClientR client, List securities) { + this.portfolioId = portfolioId; + this.creationDate = creationDate; + this.client = client; + this.securities = securities; + } + + public Long getPortfolioId() { + return portfolioId; + } + + public LocalDateTime getCreationDate() { + return creationDate; + } + + public void setCreationDate(LocalDateTime creationDate) { + this.creationDate = creationDate; + } + + public ClientR getClient() { + return client; + } + + public void setClient(ClientR client) { + this.client = client; + } + + public List getSecurities() { + return securities; + } + + public void setSecurites(List securities) { + this.securities = securities; + } + +} diff --git a/src/main/java/com/wellsfargo/counselor/entity/Security.java b/src/main/java/com/wellsfargo/counselor/entity/Security.java new file mode 100644 index 00000000..203639a2 --- /dev/null +++ b/src/main/java/com/wellsfargo/counselor/entity/Security.java @@ -0,0 +1,102 @@ +package com.wellsfargo.counselor.entity; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToOne; +import jakarta.persistence.GeneratedValue; + +import java.time.LocalDateTime; + +import jakarta.persistence.Column; + +@Entity +public class Security { + + @Id + @GeneratedValue() + private long securityId; + @Column(nullable = false) + private String name; + @Column + private String category; + @Column + private String purchasePrice; + @Column + private LocalDateTime purchaseDate; + @Column + private long quantity; + @ManyToOne + @JoinColumn(name = "portfolioId") + private Portfolio portfolio; + + protected Security() { + } + + // Constructor with parameters + public Security(String name, String category, String purchasePrice, LocalDateTime purchaseDate, long quantity, + Portfolio portfolio) { + this.name = name; + this.category = category; + this.purchasePrice = purchasePrice; + this.purchaseDate = purchaseDate; + this.quantity = quantity; + this.portfolio = portfolio; + } + + // Getters and Setters + + public Long getId() { + return securityId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + + public String getPurchasePrice() { + return purchasePrice; + } + + public void setPurchasePrice(String purchasePrice) { + this.purchasePrice = purchasePrice; + } + + public LocalDateTime getPurchaseDate() { + return purchaseDate; + } + + public void setPurchaseDate(LocalDateTime purchaseDate) { + this.purchaseDate = purchaseDate; + } + + public long getQuantity() { + return quantity; + } + + public void setQuantity(long quantity) { + this.quantity = quantity; + } + + public Portfolio getPortfolio() { + return portfolio; + } + + public void setPortfolio(Portfolio portfolio) { + this.portfolio = portfolio; + } + +}