├── .idea
├── .gitignore
├── vcs.xml
├── encodings.xml
├── misc.xml
├── compiler.xml
└── jarRepositories.xml
├── src
├── main
│ ├── java
│ │ └── com
│ │ │ └── stockman
│ │ │ ├── model
│ │ │ ├── AddressType.java
│ │ │ ├── TransactionType.java
│ │ │ ├── LoginDTO.java
│ │ │ ├── StockReport.java
│ │ │ ├── Address.java
│ │ │ ├── CurrentUserSession.java
│ │ │ ├── Wallet.java
│ │ │ ├── Stock.java
│ │ │ ├── MutualFund.java
│ │ │ ├── LoanAgainstShare.java
│ │ │ ├── Transaction.java
│ │ │ └── Customer.java
│ │ │ ├── repository
│ │ │ ├── WalletRepository.java
│ │ │ ├── SessionDao.java
│ │ │ ├── CustomerDao.java
│ │ │ ├── AdminRepository.java
│ │ │ └── TransactionRepository.java
│ │ │ ├── exception
│ │ │ ├── StockException.java
│ │ │ ├── LoginException.java
│ │ │ ├── CustomerException.java
│ │ │ ├── ResourceNotFoundException.java
│ │ │ ├── MyErrorDetails.java
│ │ │ └── GlobalExceptionHandler.java
│ │ │ ├── service
│ │ │ ├── WalletService.java
│ │ │ ├── AdminService.java
│ │ │ ├── LoginService.java
│ │ │ ├── WalletServiceImpl.java
│ │ │ ├── TransactionService.java
│ │ │ ├── CustomerService.java
│ │ │ ├── TransactionServiceImpl.java
│ │ │ ├── AdminServiceImpl.java
│ │ │ ├── LoginServiceImpl.java
│ │ │ └── CustomerServiceImpl.java
│ │ │ ├── StockManApplication.java
│ │ │ └── controller
│ │ │ ├── LoginController.java
│ │ │ ├── AdminController.java
│ │ │ └── CustomerController.java
│ └── resources
│ │ └── application.properties
└── test
│ └── java
│ └── com
│ └── stockman
│ └── StockManApplicationTests.java
├── target
├── classes
│ ├── com
│ │ └── stockman
│ │ │ ├── model
│ │ │ ├── Stock.class
│ │ │ ├── Address.class
│ │ │ ├── Customer.class
│ │ │ ├── LoginDTO.class
│ │ │ ├── Wallet.class
│ │ │ ├── MutualFund.class
│ │ │ ├── AddressType.class
│ │ │ ├── StockReport.class
│ │ │ ├── Transaction.class
│ │ │ ├── TransactionType.class
│ │ │ ├── CurrentUserSession.class
│ │ │ └── LoanAgainstShare.class
│ │ │ ├── StockManApplication.class
│ │ │ ├── repository
│ │ │ ├── SessionDao.class
│ │ │ ├── CustomerDao.class
│ │ │ ├── AdminRepository.class
│ │ │ ├── WalletRepository.class
│ │ │ └── TransactionRepository.class
│ │ │ ├── service
│ │ │ ├── AdminService.class
│ │ │ ├── LoginService.class
│ │ │ ├── WalletService.class
│ │ │ ├── AdminServiceImpl.class
│ │ │ ├── CustomerService.class
│ │ │ ├── LoginServiceImpl.class
│ │ │ ├── TransactionService.class
│ │ │ ├── WalletServiceImpl.class
│ │ │ ├── CustomerServiceImpl.class
│ │ │ └── TransactionServiceImpl.class
│ │ │ ├── exception
│ │ │ ├── LoginException.class
│ │ │ ├── MyErrorDetails.class
│ │ │ ├── StockException.class
│ │ │ ├── CustomerException.class
│ │ │ ├── GlobalExceptionHandler.class
│ │ │ └── ResourceNotFoundException.class
│ │ │ └── controller
│ │ │ ├── AdminController.class
│ │ │ ├── LoginController.class
│ │ │ └── CustomerController.class
│ └── application.properties
└── test-classes
│ └── com
│ └── stockman
│ ├── StockManApplicationTests.class
│ └── StockManApplicationTests$CustomerLoginControllerTest.class
├── .github
└── workflows
│ └── build.yml
├── HELP.md
├── pom.xml
├── README.md
├── mvnw.cmd
└── mvnw
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/model/AddressType.java:
--------------------------------------------------------------------------------
1 | package com.stockman.model;
2 |
3 | public enum AddressType {
4 | HOME,OFFICE;
5 | }
6 |
--------------------------------------------------------------------------------
/target/classes/com/stockman/model/Stock.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/model/Stock.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/model/Address.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/model/Address.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/model/Customer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/model/Customer.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/model/LoginDTO.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/model/LoginDTO.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/model/Wallet.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/model/Wallet.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/model/MutualFund.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/model/MutualFund.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/StockManApplication.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/StockManApplication.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/model/AddressType.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/model/AddressType.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/model/StockReport.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/model/StockReport.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/model/Transaction.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/model/Transaction.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/model/TransactionType.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/model/TransactionType.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/repository/SessionDao.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/repository/SessionDao.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/service/AdminService.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/service/AdminService.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/service/LoginService.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/service/LoginService.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/service/WalletService.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/service/WalletService.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/exception/LoginException.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/exception/LoginException.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/exception/MyErrorDetails.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/exception/MyErrorDetails.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/exception/StockException.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/exception/StockException.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/model/CurrentUserSession.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/model/CurrentUserSession.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/model/LoanAgainstShare.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/model/LoanAgainstShare.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/repository/CustomerDao.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/repository/CustomerDao.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/service/AdminServiceImpl.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/service/AdminServiceImpl.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/service/CustomerService.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/service/CustomerService.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/service/LoginServiceImpl.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/service/LoginServiceImpl.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/controller/AdminController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/controller/AdminController.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/controller/LoginController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/controller/LoginController.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/repository/AdminRepository.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/repository/AdminRepository.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/service/TransactionService.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/service/TransactionService.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/service/WalletServiceImpl.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/service/WalletServiceImpl.class
--------------------------------------------------------------------------------
/src/main/java/com/stockman/model/TransactionType.java:
--------------------------------------------------------------------------------
1 | package com.stockman.model;
2 |
3 | import java.lang.constant.Constable;
4 |
5 | public enum TransactionType{
6 | BUY,SOLD;
7 | }
8 |
--------------------------------------------------------------------------------
/target/classes/com/stockman/controller/CustomerController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/controller/CustomerController.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/exception/CustomerException.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/exception/CustomerException.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/repository/WalletRepository.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/repository/WalletRepository.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/service/CustomerServiceImpl.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/service/CustomerServiceImpl.class
--------------------------------------------------------------------------------
/target/test-classes/com/stockman/StockManApplicationTests.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/test-classes/com/stockman/StockManApplicationTests.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/service/TransactionServiceImpl.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/service/TransactionServiceImpl.class
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/target/classes/com/stockman/exception/GlobalExceptionHandler.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/exception/GlobalExceptionHandler.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/repository/TransactionRepository.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/repository/TransactionRepository.class
--------------------------------------------------------------------------------
/target/classes/com/stockman/exception/ResourceNotFoundException.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/classes/com/stockman/exception/ResourceNotFoundException.class
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/target/test-classes/com/stockman/StockManApplicationTests$CustomerLoginControllerTest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Manoj890880/stock-broker-system/HEAD/target/test-classes/com/stockman/StockManApplicationTests$CustomerLoginControllerTest.class
--------------------------------------------------------------------------------
/src/main/java/com/stockman/model/LoginDTO.java:
--------------------------------------------------------------------------------
1 | package com.stockman.model;
2 |
3 | import lombok.Data;
4 |
5 | @Data
6 | public class LoginDTO {
7 |
8 | private String mobileNo;
9 | private String password;
10 | //private String role;
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/repository/WalletRepository.java:
--------------------------------------------------------------------------------
1 | package com.stockman.repository;
2 |
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 |
5 | import com.stockman.model.Transaction;
6 |
7 | public interface WalletRepository extends JpaRepository{
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/exception/StockException.java:
--------------------------------------------------------------------------------
1 | package com.stockman.exception;
2 |
3 | public class StockException extends Exception {
4 | public StockException() {
5 | // TODO Auto-generated constructor stub
6 | }
7 |
8 | public StockException(String message) {
9 | super(message);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/service/WalletService.java:
--------------------------------------------------------------------------------
1 | package com.stockman.service;
2 |
3 | import com.stockman.exception.ResourceNotFoundException;
4 | import com.stockman.model.Wallet;
5 |
6 | public interface WalletService {
7 |
8 | public void delete(Wallet wallet)throws ResourceNotFoundException;
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/exception/LoginException.java:
--------------------------------------------------------------------------------
1 | package com.stockman.exception;
2 |
3 | public class LoginException extends Exception{
4 |
5 | public LoginException() {
6 | // TODO Auto-generated constructor stub
7 | }
8 |
9 | public LoginException(String message) {
10 | super(message);
11 | }
12 |
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/exception/CustomerException.java:
--------------------------------------------------------------------------------
1 | package com.stockman.exception;
2 |
3 | public class CustomerException extends Exception{
4 |
5 | public CustomerException() {
6 | // TODO Auto-generated constructor stub
7 | }
8 |
9 | public CustomerException(String message) {
10 | super(message);
11 | }
12 |
13 |
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/exception/ResourceNotFoundException.java:
--------------------------------------------------------------------------------
1 | package com.stockman.exception;
2 |
3 | public class ResourceNotFoundException extends Exception {
4 | public ResourceNotFoundException() {
5 | // TODO Auto-generated constructor stub
6 | }
7 |
8 | public ResourceNotFoundException(String message) {
9 | super(message);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/repository/SessionDao.java:
--------------------------------------------------------------------------------
1 | package com.stockman.repository;
2 |
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 |
5 | import com.stockman.model.CurrentUserSession;
6 |
7 |
8 |
9 | public interface SessionDao extends JpaRepository {
10 |
11 |
12 | public CurrentUserSession findByUuid(String uuid);
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/model/StockReport.java:
--------------------------------------------------------------------------------
1 | package com.stockman.model;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.NoArgsConstructor;
6 |
7 | @Data
8 | @AllArgsConstructor
9 | @NoArgsConstructor
10 | public class StockReport {
11 | private String name;
12 | private Integer totalQuantity;
13 | private Integer soldQuantity;
14 | private Integer remainingQuantity;
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/repository/CustomerDao.java:
--------------------------------------------------------------------------------
1 | package com.stockman.repository;
2 |
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 | import org.springframework.stereotype.Repository;
5 |
6 | import com.stockman.model.Customer;
7 |
8 | @Repository
9 | public interface CustomerDao extends JpaRepository{
10 |
11 | public Customer findByMobileNumber(String mobileNo);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/repository/AdminRepository.java:
--------------------------------------------------------------------------------
1 | package com.stockman.repository;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.data.jpa.repository.JpaRepository;
6 |
7 | import com.stockman.model.Stock;
8 |
9 | public interface AdminRepository extends JpaRepository{
10 |
11 | public Stock findByStockName(String stockName);
12 |
13 | public List findByCustomers_CustomerId(Integer id);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/StockManApplication.java:
--------------------------------------------------------------------------------
1 | package com.stockman;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | import springfox.documentation.swagger2.annotations.EnableSwagger2;
7 | @SpringBootApplication
8 | @EnableSwagger2
9 | public class StockManApplication {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(StockManApplication.class, args);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/service/AdminService.java:
--------------------------------------------------------------------------------
1 | package com.stockman.service;
2 |
3 | import java.util.List;
4 |
5 | import com.stockman.exception.StockException;
6 | import com.stockman.model.Stock;
7 |
8 | public interface AdminService {
9 | public Stock addStock(Stock stock)throws StockException;
10 |
11 | public List getAllStocks()throws StockException;
12 |
13 | public Stock findStockByName(String name)throws StockException;
14 |
15 | public List findByCustomers_Id(Integer id)throws StockException;
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/service/LoginService.java:
--------------------------------------------------------------------------------
1 | package com.stockman.service;
2 |
3 | import com.stockman.exception.LoginException;
4 | import com.stockman.model.LoginDTO;
5 |
6 | public interface LoginService {
7 |
8 | public String logIntoAccount(LoginDTO dto)throws LoginException;
9 |
10 | public String logOutFromAccount(String key)throws LoginException;
11 |
12 | public String logIntoAccountAdmin(LoginDTO dto)throws LoginException;
13 |
14 | public String logOutFromAccountAdmin(String key)throws LoginException;
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/model/Address.java:
--------------------------------------------------------------------------------
1 | package com.stockman.model;
2 |
3 | import javax.persistence.EnumType;
4 | import javax.persistence.Enumerated;
5 |
6 | import lombok.AllArgsConstructor;
7 | import lombok.Data;
8 | import lombok.EqualsAndHashCode;
9 | import lombok.NoArgsConstructor;
10 | import lombok.ToString;
11 |
12 | @Data
13 | @NoArgsConstructor
14 | @AllArgsConstructor
15 | @EqualsAndHashCode
16 | public class Address {
17 |
18 |
19 | private String state;
20 | private String city;
21 | private String pincode;
22 | // @Enumerated(EnumType.STRING)
23 | private AddressType type;
24 |
25 |
26 |
27 |
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/target/classes/application.properties:
--------------------------------------------------------------------------------
1 | #db specific properties
2 | spring.datasource.url=jdbc:mysql://localhost:3306/stockman
3 | spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
4 | spring.datasource.username=root
5 | spring.datasource.password=1999
6 |
7 | #ORM s/w specific properties
8 | spring.jpa.hibernate.ddl-auto=update
9 | spring.jpa.show-sql=true
10 | spring.mvc.throw-exception-if-no-handler-found=true
11 | spring.web.resources.add-mappings=false
12 |
13 | server.port=8088
14 |
15 | spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
16 |
17 |
18 | info:
19 | version: "1.0.0"
20 | title: My API title
21 | description: "Awesome description"
--------------------------------------------------------------------------------
/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | #db specific properties
2 | spring.datasource.url=jdbc:mysql://localhost:3306/stockman
3 | spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
4 | spring.datasource.username=root
5 | spring.datasource.password=1999
6 |
7 | #ORM s/w specific properties
8 | spring.jpa.hibernate.ddl-auto=update
9 | spring.jpa.show-sql=true
10 | spring.mvc.throw-exception-if-no-handler-found=true
11 | spring.web.resources.add-mappings=false
12 |
13 | server.port=8088
14 |
15 | spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
16 |
17 |
18 | info:
19 | version: "1.0.0"
20 | title: My API title
21 | description: "Awesome description"
--------------------------------------------------------------------------------
/src/main/java/com/stockman/service/WalletServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.stockman.service;
2 |
3 |
4 |
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.stereotype.Service;
7 |
8 | import com.stockman.exception.ResourceNotFoundException;
9 | import com.stockman.model.Wallet;
10 | import com.stockman.repository.WalletRepository;
11 |
12 |
13 | @Service
14 | public class WalletServiceImpl implements WalletService{
15 | @Autowired
16 | private WalletRepository walletRepository;
17 | @Override
18 | public void delete(Wallet wallet) throws ResourceNotFoundException {
19 | walletRepository.deleteById(wallet.getWalletId());
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/repository/TransactionRepository.java:
--------------------------------------------------------------------------------
1 | package com.stockman.repository;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.data.jpa.repository.JpaRepository;
6 | import org.springframework.data.jpa.repository.Query;
7 |
8 | import com.stockman.model.Customer;
9 | import com.stockman.model.Transaction;
10 |
11 | public interface TransactionRepository extends JpaRepository{
12 |
13 | @Query("SELECT SUM(t.quantity) FROM Transaction t WHERE t.stock.stockId = ?1 AND t.transactionType = 'SOLD'")
14 | public Integer getTotalSoldQuantityByStockId(int stockId);
15 |
16 |
17 | public List findByCustomer(Customer customer);
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/service/TransactionService.java:
--------------------------------------------------------------------------------
1 | package com.stockman.service;
2 |
3 | import java.util.List;
4 |
5 | import javax.transaction.TransactionalException;
6 |
7 | import com.stockman.exception.CustomerException;
8 | import com.stockman.exception.ResourceNotFoundException;
9 | import com.stockman.model.Customer;
10 | import com.stockman.model.Transaction;
11 |
12 | public interface TransactionService {
13 |
14 | public Integer getTotalSoldQuantityByStockId(Integer stockId)throws ResourceNotFoundException;
15 |
16 | public List findByCustomer(Customer customer)
17 | throws CustomerException,ResourceNotFoundException;
18 |
19 | public void deleteAll(List transactions)throws TransactionalException;
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/model/CurrentUserSession.java:
--------------------------------------------------------------------------------
1 | package com.stockman.model;
2 |
3 | import java.time.LocalDateTime;
4 |
5 | import javax.persistence.Column;
6 | import javax.persistence.Entity;
7 | import javax.persistence.GeneratedValue;
8 | import javax.persistence.GenerationType;
9 | import javax.persistence.Id;
10 |
11 | import lombok.AllArgsConstructor;
12 | import lombok.Data;
13 | import lombok.NoArgsConstructor;
14 | import lombok.ToString;
15 |
16 | @Entity
17 | @Data
18 | @NoArgsConstructor
19 | @AllArgsConstructor
20 | @ToString
21 | public class CurrentUserSession {
22 |
23 |
24 | @Id
25 | @Column(unique = true)
26 | private Integer userId;
27 |
28 |
29 | private String uuid;
30 |
31 | private LocalDateTime localDateTime;
32 |
33 |
34 |
35 |
36 |
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/model/Wallet.java:
--------------------------------------------------------------------------------
1 | package com.stockman.model;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.GenerationType;
7 | import javax.persistence.Id;
8 | import javax.persistence.JoinColumn;
9 | import javax.persistence.OneToOne;
10 | import javax.persistence.Table;
11 |
12 | import lombok.AllArgsConstructor;
13 | import lombok.Data;
14 | import lombok.NoArgsConstructor;
15 |
16 | @Entity
17 | @Table(name = "wallets")
18 | @Data
19 | @NoArgsConstructor
20 | @AllArgsConstructor
21 | public class Wallet {
22 | @Id
23 | @GeneratedValue(strategy = GenerationType.IDENTITY)
24 | @Column(name = "wallet_id")
25 | private Integer walletId;
26 |
27 | @OneToOne
28 | @JoinColumn(name = "customer_id")
29 | private Customer customer;
30 |
31 | @Column(name = "balance")
32 | private Double balance=0.0;
33 |
34 | // getters and setters
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/exception/MyErrorDetails.java:
--------------------------------------------------------------------------------
1 | package com.stockman.exception;
2 |
3 | import java.time.LocalDateTime;
4 |
5 | public class MyErrorDetails {
6 |
7 | private LocalDateTime timestamp;
8 | private String message;
9 | private String details;
10 |
11 |
12 | public MyErrorDetails() {
13 | // TODO Auto-generated constructor stub
14 | }
15 |
16 |
17 | public MyErrorDetails(LocalDateTime timestamp, String message, String details) {
18 | super();
19 | this.timestamp = timestamp;
20 | this.message = message;
21 | this.details = details;
22 | }
23 |
24 |
25 | public LocalDateTime getTimestamp() {
26 | return timestamp;
27 | }
28 |
29 |
30 | public void setTimestamp(LocalDateTime timestamp) {
31 | this.timestamp = timestamp;
32 | }
33 |
34 |
35 | public String getMessage() {
36 | return message;
37 | }
38 |
39 |
40 | public void setMessage(String message) {
41 | this.message = message;
42 | }
43 |
44 |
45 | public String getDetails() {
46 | return details;
47 | }
48 |
49 |
50 | public void setDetails(String details) {
51 | this.details = details;
52 | }
53 |
54 |
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/service/CustomerService.java:
--------------------------------------------------------------------------------
1 | package com.stockman.service;
2 |
3 | import java.util.List;
4 |
5 | import com.stockman.exception.CustomerException;
6 | import com.stockman.exception.ResourceNotFoundException;
7 | import com.stockman.exception.StockException;
8 | import com.stockman.model.Customer;
9 | import com.stockman.model.Stock;
10 | import com.stockman.model.Transaction;
11 |
12 | public interface CustomerService {
13 |
14 |
15 | public Customer createCustomer(Customer customer)throws CustomerException;
16 |
17 | public Customer updateCustomer(Customer customer,String key)throws CustomerException;
18 |
19 | public List getAllCustomers()throws CustomerException;
20 |
21 | public Customer findCustomerById(Integer id)throws CustomerException;
22 |
23 | public List getAllStocks(String key)throws CustomerException;
24 |
25 | public Transaction buyStockByName(Integer customerId, String stockName, Integer shares)
26 | throws CustomerException,StockException,ResourceNotFoundException;
27 |
28 | public Transaction sellStockByName(Integer customerId, String stockName, Integer shares)
29 | throws CustomerException,StockException,ResourceNotFoundException;
30 |
31 | public Customer save(Customer customer)throws CustomerException;
32 |
33 | public void delete(Customer customer)throws CustomerException;
34 |
35 |
36 | }
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: SonarCloud
2 | on:
3 | push:
4 | branches:
5 | - main
6 | pull_request:
7 | types: [opened, synchronize, reopened]
8 | jobs:
9 | build:
10 | name: Build and analyze
11 | runs-on: ubuntu-latest
12 | steps:
13 | - uses: actions/checkout@v3
14 | with:
15 | fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
16 | - name: Set up JDK 17
17 | uses: actions/setup-java@v3
18 | with:
19 | java-version: 17
20 | distribution: 'zulu' # Alternative distribution options are available.
21 | - name: Cache SonarCloud packages
22 | uses: actions/cache@v3
23 | with:
24 | path: ~/.sonar/cache
25 | key: ${{ runner.os }}-sonar
26 | restore-keys: ${{ runner.os }}-sonar
27 | - name: Cache Maven packages
28 | uses: actions/cache@v3
29 | with:
30 | path: ~/.m2
31 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
32 | restore-keys: ${{ runner.os }}-m2
33 | - name: Build and analyze
34 | env:
35 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
36 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
37 | run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=Manoj890880_stock-broker-system
38 |
--------------------------------------------------------------------------------
/HELP.md:
--------------------------------------------------------------------------------
1 | # Getting Started
2 |
3 | ### Reference Documentation
4 | For further reference, please consider the following sections:
5 |
6 | * [Official Apache Maven documentation](https://maven.apache.org/guides/index.html)
7 | * [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/3.0.6/maven-plugin/reference/html/)
8 | * [Create an OCI image](https://docs.spring.io/spring-boot/docs/3.0.6/maven-plugin/reference/html/#build-image)
9 | * [Spring Boot DevTools](https://docs.spring.io/spring-boot/docs/3.0.6/reference/htmlsingle/#using.devtools)
10 | * [Validation](https://docs.spring.io/spring-boot/docs/3.0.6/reference/htmlsingle/#io.validation)
11 | * [Spring Data JDBC](https://docs.spring.io/spring-boot/docs/3.0.6/reference/htmlsingle/#data.sql.jdbc)
12 | * [Spring Data JPA](https://docs.spring.io/spring-boot/docs/3.0.6/reference/htmlsingle/#data.sql.jpa-and-spring-data)
13 | * [Spring Web](https://docs.spring.io/spring-boot/docs/3.0.6/reference/htmlsingle/#web)
14 |
15 | ### Guides
16 | The following guides illustrate how to use some features concretely:
17 |
18 | * [Validation](https://spring.io/guides/gs/validating-form-input/)
19 | * [Using Spring Data JDBC](https://github.com/spring-projects/spring-data-examples/tree/master/jdbc/basics)
20 | * [Accessing Data with JPA](https://spring.io/guides/gs/accessing-data-jpa/)
21 | * [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/)
22 | * [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/)
23 | * [Building REST services with Spring](https://spring.io/guides/tutorials/rest/)
24 |
25 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/model/Stock.java:
--------------------------------------------------------------------------------
1 | package com.stockman.model;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import javax.persistence.CascadeType;
7 | import javax.persistence.Column;
8 | import javax.persistence.Entity;
9 | import javax.persistence.GeneratedValue;
10 | import javax.persistence.GenerationType;
11 | import javax.persistence.Id;
12 | import javax.persistence.ManyToMany;
13 | import javax.persistence.OneToMany;
14 | import javax.persistence.Table;
15 |
16 | import lombok.AllArgsConstructor;
17 | import lombok.Data;
18 | import lombok.NoArgsConstructor;
19 |
20 | @Entity
21 | @Table(name = "stocks")
22 | @Data
23 | @NoArgsConstructor
24 | @AllArgsConstructor
25 | public class Stock {
26 | @Id
27 | @GeneratedValue(strategy = GenerationType.IDENTITY)
28 | @Column(name = "stock_id")
29 | private Integer stockId;
30 |
31 | @Column(name = "stock_name")
32 | private String stockName;
33 |
34 | @Column(name = "current_price")
35 | private double currentPrice;
36 |
37 | @Column(name = "total_quantity")
38 | private Integer totalQuantity;
39 |
40 | @Column(name = "available_quantity")
41 | private Integer availableQuantity;
42 |
43 | @Column(name = "is_active")
44 | private boolean isActive = true;
45 |
46 | @OneToMany(mappedBy = "stock", cascade = CascadeType.ALL)
47 | private List transactions = new ArrayList<>();
48 |
49 | @ManyToMany(mappedBy = "stocks")
50 | private List customers = new ArrayList<>();
51 |
52 |
53 |
54 | // getters and setters
55 | }
56 |
57 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/model/MutualFund.java:
--------------------------------------------------------------------------------
1 | package com.stockman.model;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import javax.persistence.CascadeType;
7 | import javax.persistence.Column;
8 | import javax.persistence.Entity;
9 | import javax.persistence.GeneratedValue;
10 | import javax.persistence.GenerationType;
11 | import javax.persistence.Id;
12 | import javax.persistence.JoinColumn;
13 | import javax.persistence.ManyToOne;
14 | import javax.persistence.OneToMany;
15 | import javax.persistence.Table;
16 |
17 | import lombok.AllArgsConstructor;
18 | import lombok.Data;
19 | import lombok.NoArgsConstructor;
20 |
21 | @Entity
22 | @Table(name = "mutual_funds")
23 | @Data
24 | @NoArgsConstructor
25 | @AllArgsConstructor
26 | public class MutualFund {
27 | @Id
28 | @GeneratedValue(strategy = GenerationType.IDENTITY)
29 | @Column(name = "mutual_fund_id")
30 | private Integer mutualFundId;
31 |
32 | @Column(name = "mutual_fund_name")
33 | private String mutualFundName;
34 |
35 | @Column(name = "current_price")
36 | private double currentPrice;
37 |
38 | @Column(name = "total_quantity")
39 | private Integer totalQuantity;
40 |
41 | @Column(name = "available_quantity")
42 | private Integer availableQuantity;
43 |
44 | @Column(name = "is_active")
45 | private boolean isActive = true;
46 |
47 |
48 | @ManyToOne
49 | @JoinColumn(name = "customer_id")
50 | private Customer customer;
51 |
52 |
53 | @OneToMany(mappedBy = "mutualFund", cascade = CascadeType.ALL)
54 | private List transactions = new ArrayList<>();
55 |
56 | // getters and setters
57 | }
58 |
59 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/service/TransactionServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.stockman.service;
2 |
3 | import java.util.List;
4 | import java.util.Optional;
5 |
6 | import javax.transaction.TransactionalException;
7 |
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.stereotype.Service;
10 |
11 | import com.stockman.exception.CustomerException;
12 | import com.stockman.exception.ResourceNotFoundException;
13 | import com.stockman.model.Customer;
14 | import com.stockman.model.Transaction;
15 | import com.stockman.repository.TransactionRepository;
16 |
17 | @Service
18 | public class TransactionServiceImpl implements TransactionService{
19 | @Autowired
20 | private TransactionRepository transactionRepository;
21 |
22 |
23 | @Override
24 | public Integer getTotalSoldQuantityByStockId(Integer stockId) throws ResourceNotFoundException {
25 | Integer numInteger=transactionRepository.getTotalSoldQuantityByStockId(stockId);
26 | if (numInteger==null) {
27 | return 0;
28 | }
29 | return transactionRepository.getTotalSoldQuantityByStockId(stockId).intValue();
30 | }
31 |
32 |
33 | @Override
34 | public List findByCustomer(Customer customer) throws CustomerException, ResourceNotFoundException {
35 | List transactions=transactionRepository.findByCustomer(customer);
36 | if (transactions.size()==0) {
37 | throw new ResourceNotFoundException("No transactions found");
38 | }
39 | return transactions;
40 | }
41 |
42 |
43 | @Override
44 | public void deleteAll(List transactions) throws TransactionalException {
45 |
46 | transactionRepository.deleteAll(transactions);
47 |
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/controller/LoginController.java:
--------------------------------------------------------------------------------
1 | package com.stockman.controller;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.http.HttpStatus;
5 | import org.springframework.http.ResponseEntity;
6 | import org.springframework.web.bind.annotation.PostMapping;
7 | import org.springframework.web.bind.annotation.RequestBody;
8 | import org.springframework.web.bind.annotation.RequestParam;
9 | import org.springframework.web.bind.annotation.RestController;
10 |
11 | import com.stockman.exception.LoginException;
12 | import com.stockman.model.LoginDTO;
13 | import com.stockman.service.LoginService;
14 |
15 | @RestController
16 | public class LoginController {
17 |
18 | @Autowired
19 | private LoginService customerLogin;
20 |
21 | @PostMapping("/login")
22 | public ResponseEntity logInCustomer(@RequestBody LoginDTO dto) throws LoginException {
23 |
24 | String result = customerLogin.logIntoAccount(dto);
25 |
26 | return new ResponseEntity(result, HttpStatus.OK);
27 |
28 | }
29 |
30 | @PostMapping("/logout")
31 | public String logoutCustomer(@RequestParam String key) throws LoginException {
32 | return customerLogin.logOutFromAccount(key);
33 |
34 | }
35 |
36 | @PostMapping("/login/admin")
37 | public ResponseEntity logInAdmin(@RequestBody LoginDTO dto) throws LoginException {
38 |
39 | String result = customerLogin.logIntoAccountAdmin(dto);
40 |
41 | return new ResponseEntity(result, HttpStatus.OK);
42 |
43 | }
44 |
45 | @PostMapping("/logout/admin")
46 | public String logoutAdmin(@RequestParam String key) throws LoginException {
47 | return customerLogin.logOutFromAccountAdmin(key);
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/model/LoanAgainstShare.java:
--------------------------------------------------------------------------------
1 | package com.stockman.model;
2 |
3 | import java.time.LocalDate;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | import javax.persistence.CascadeType;
8 | import javax.persistence.Column;
9 | import javax.persistence.Entity;
10 | import javax.persistence.FetchType;
11 | import javax.persistence.GeneratedValue;
12 | import javax.persistence.GenerationType;
13 | import javax.persistence.Id;
14 | import javax.persistence.JoinColumn;
15 | import javax.persistence.ManyToOne;
16 | import javax.persistence.OneToMany;
17 | import javax.persistence.Table;
18 |
19 | import lombok.AllArgsConstructor;
20 | import lombok.NoArgsConstructor;
21 |
22 | @Entity
23 | @Table(name = "loan_against_share")
24 | @AllArgsConstructor
25 | @NoArgsConstructor
26 | public class LoanAgainstShare {
27 |
28 | @Id
29 | @GeneratedValue(strategy = GenerationType.IDENTITY)
30 | private Integer id;
31 |
32 | @Column(name = "amount")
33 | private double amount;
34 |
35 | @Column(name = "interest_rate")
36 | private double interestRate;
37 |
38 | @Column(name = "loan_date")
39 | private LocalDate loanDate;
40 |
41 | @Column(name = "duration_in_months")
42 | private int durationInMonths;
43 |
44 | @Column(name = "status")
45 | private String status;
46 |
47 |
48 | @ManyToOne(fetch = FetchType.LAZY)
49 | @JoinColumn(name = "customer_id")
50 | private Customer customer;
51 |
52 | @OneToMany(mappedBy = "loanAgainstShare", cascade = CascadeType.ALL, orphanRemoval = true)
53 | private List transactions = new ArrayList<>();
54 |
55 |
56 | // Constructors, getters and setters
57 |
58 | }
59 |
60 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/service/AdminServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.stockman.service;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.stereotype.Service;
7 |
8 | import com.stockman.exception.CustomerException;
9 | import com.stockman.exception.StockException;
10 | import com.stockman.model.Customer;
11 | import com.stockman.model.Stock;
12 | import com.stockman.repository.AdminRepository;
13 | import com.stockman.repository.SessionDao;
14 |
15 | @Service
16 | public class AdminServiceImpl implements AdminService{
17 |
18 | @Autowired
19 | private AdminRepository adminRepository;
20 |
21 | @Autowired
22 | private SessionDao sessionDao;
23 |
24 | @Override
25 | public Stock addStock(Stock stock) throws StockException {
26 | Stock existingStock = adminRepository.findByStockName(stock.getStockName());
27 |
28 | if (existingStock != null)
29 | throw new StockException("Stock Already Registered with this Name");
30 |
31 | return adminRepository.save(stock);
32 | }
33 |
34 | @Override
35 | public List getAllStocks() throws StockException {
36 | List stocks=adminRepository.findAll();
37 | if (stocks.size()==0) {
38 | throw new StockException("No Stock Found");
39 | }
40 | return stocks;
41 | }
42 |
43 | @Override
44 | public Stock findStockByName(String name) throws StockException {
45 | Stock existingStock = adminRepository.findByStockName(name);
46 |
47 | if (existingStock == null)
48 | throw new StockException("No Stock Found With this Name");
49 |
50 | return existingStock;
51 | }
52 |
53 | @Override
54 | public List findByCustomers_Id(Integer id) throws StockException {
55 | // TODO Auto-generated method stub
56 | return null;
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/model/Transaction.java:
--------------------------------------------------------------------------------
1 | package com.stockman.model;
2 |
3 | import java.time.LocalDate;
4 |
5 | import javax.persistence.CascadeType;
6 | import javax.persistence.Column;
7 | import javax.persistence.Entity;
8 | import javax.persistence.EnumType;
9 | import javax.persistence.Enumerated;
10 | import javax.persistence.GeneratedValue;
11 | import javax.persistence.GenerationType;
12 | import javax.persistence.Id;
13 | import javax.persistence.JoinColumn;
14 | import javax.persistence.ManyToOne;
15 | import javax.persistence.Table;
16 |
17 | import lombok.AllArgsConstructor;
18 | import lombok.Data;
19 | import lombok.NoArgsConstructor;
20 |
21 | @Entity
22 | @Table(name = "transactions")
23 | @Data
24 | @NoArgsConstructor
25 | @AllArgsConstructor
26 | public class Transaction {
27 | @Id
28 | @GeneratedValue(strategy = GenerationType.IDENTITY)
29 | @Column(name = "transaction_id")
30 | private Integer transactionId;
31 |
32 | @Column(name = "transaction_type")
33 | @Enumerated(EnumType.STRING)
34 | private TransactionType transactionType;
35 |
36 | @Column(name = "transaction_date")
37 | private LocalDate transactionDate;
38 |
39 | @Column(name = "transaction_price")
40 | private double transactionPrice;
41 |
42 | @Column(name = "quantity")
43 | private int quantity;
44 |
45 | @ManyToOne(cascade = CascadeType.ALL)
46 | @JoinColumn(name = "customer_id")
47 | private Customer customer;
48 |
49 | @ManyToOne
50 | @JoinColumn(name = "stock_id")
51 | private Stock stock;
52 |
53 |
54 | @ManyToOne
55 | @JoinColumn(name = "mutual_fund_id")
56 | private MutualFund mutualFund;
57 |
58 |
59 | @ManyToOne
60 | @JoinColumn(name = "loan_id")
61 | private LoanAgainstShare loanAgainstShare;
62 |
63 |
64 |
65 |
66 | // getters and setters
67 | }
68 |
--------------------------------------------------------------------------------
/src/test/java/com/stockman/StockManApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.stockman;
2 |
3 | import com.stockman.controller.LoginController;
4 | import com.stockman.exception.LoginException;
5 | import com.stockman.model.LoginDTO;
6 | import com.stockman.service.LoginService;
7 | import org.junit.jupiter.api.Test;
8 | import org.junit.runner.RunWith;
9 | import org.mockito.InjectMocks;
10 | import org.mockito.Mock;
11 | import org.mockito.junit.MockitoJUnitRunner;
12 | import org.springframework.boot.test.context.SpringBootTest;
13 | import org.springframework.http.HttpStatus;
14 | import org.springframework.http.ResponseEntity;
15 |
16 | import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
17 | import static org.mockito.Mockito.when;
18 |
19 | @SpringBootTest
20 | class StockManApplicationTests {
21 |
22 | @Test
23 | void contextLoads() {
24 | }
25 |
26 | // Add the CustomerLoginControllerTest class here
27 | @RunWith(MockitoJUnitRunner.class)
28 | public class CustomerLoginControllerTest {
29 |
30 | @InjectMocks
31 | private LoginController customerLoginController;
32 |
33 | @Mock
34 | private LoginService customerLoginService;
35 |
36 | @Test
37 | public void testLogInCustomer() throws LoginException {
38 | // Create a sample LoginDTO
39 | LoginDTO loginDTO = new LoginDTO();
40 | loginDTO.setMobileNo("john.doe");
41 | loginDTO.setPassword("password");
42 |
43 | // Mock the behavior of customerLoginService.logIntoAccount
44 | when(customerLoginService.logIntoAccount(loginDTO)).thenReturn("Login successful");
45 |
46 | // Perform the POST request
47 | ResponseEntity responseEntity = customerLoginController.logInCustomer(loginDTO);
48 |
49 | // Verify the response
50 | assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
51 | assertThat(responseEntity.getBody()).isEqualTo("Login successful");
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/model/Customer.java:
--------------------------------------------------------------------------------
1 | package com.stockman.model;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashSet;
5 | import java.util.List;
6 | import java.util.Set;
7 |
8 | import javax.persistence.CascadeType;
9 | import javax.persistence.Column;
10 | import javax.persistence.ElementCollection;
11 | import javax.persistence.Embedded;
12 | import javax.persistence.Entity;
13 | import javax.persistence.GeneratedValue;
14 | import javax.persistence.GenerationType;
15 | import javax.persistence.Id;
16 | import javax.persistence.JoinColumn;
17 | import javax.persistence.JoinTable;
18 | import javax.persistence.ManyToMany;
19 | import javax.persistence.OneToMany;
20 | import javax.persistence.OneToOne;
21 | import javax.persistence.Table;
22 |
23 | import com.fasterxml.jackson.annotation.JsonIgnore;
24 |
25 | import lombok.AllArgsConstructor;
26 | import lombok.Data;
27 | import lombok.NoArgsConstructor;
28 |
29 | @Entity
30 | @Table(name = "customers")
31 | @Data
32 | @NoArgsConstructor
33 | @AllArgsConstructor
34 | public class Customer {
35 | @Id
36 | @GeneratedValue(strategy = GenerationType.IDENTITY)
37 | @Column(name = "customer_id")
38 | private Integer customerId;
39 |
40 | @Column(name = "first_name")
41 | private String firstName;
42 |
43 | @Column(name = "last_name")
44 | private String lastName;
45 |
46 | @Column(name = "username")
47 | private String username;
48 |
49 | @Column(name = "password")
50 | private String password;
51 |
52 | @Column(name = "address")
53 | @ElementCollection
54 | @Embedded
55 | private Set addresses=new HashSet();
56 |
57 | @Column(name = "mobile_number")
58 | private String mobileNumber;
59 |
60 | @Column(name = "email")
61 | private String email;
62 |
63 | @Column(name = "is_active")
64 | private boolean isActive = true;
65 |
66 | @OneToOne(mappedBy = "customer")
67 | private Wallet wallet;
68 |
69 | @OneToMany(mappedBy = "customer", cascade = CascadeType.ALL)
70 | private List transactions = new ArrayList<>();
71 |
72 | @ManyToMany(cascade = CascadeType.ALL)
73 | @JsonIgnore
74 | @JoinTable(
75 | name = "customer_stock",
76 | joinColumns = @JoinColumn(name = "customer_id"),
77 | inverseJoinColumns = @JoinColumn(name = "stock_id")
78 | )
79 | private List stocks = new ArrayList<>();
80 |
81 | @OneToMany(mappedBy = "customer", cascade = CascadeType.ALL)
82 | private List loansAgainstShares = new ArrayList<>();
83 |
84 | @OneToMany(mappedBy = "customer", cascade = CascadeType.ALL, orphanRemoval = true)
85 | private List mutualFunds = new ArrayList<>();
86 |
87 | // getters and setters
88 |
89 | }
90 |
91 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/exception/GlobalExceptionHandler.java:
--------------------------------------------------------------------------------
1 | package com.stockman.exception;
2 |
3 | import java.time.LocalDateTime;
4 |
5 | import org.springframework.http.HttpStatus;
6 | import org.springframework.http.ResponseEntity;
7 | import org.springframework.web.bind.annotation.ControllerAdvice;
8 | import org.springframework.web.bind.annotation.ExceptionHandler;
9 | import org.springframework.web.context.request.WebRequest;
10 |
11 | @ControllerAdvice
12 | public class GlobalExceptionHandler {
13 |
14 | @ExceptionHandler(CustomerException.class)
15 | public ResponseEntity customerExceptionHandler(CustomerException se, WebRequest req){
16 |
17 |
18 | MyErrorDetails err= new MyErrorDetails();
19 | err.setTimestamp(LocalDateTime.now());
20 | err.setMessage(se.getMessage());
21 | err.setDetails(req.getDescription(false));
22 |
23 | return new ResponseEntity(err, HttpStatus.NOT_FOUND);
24 |
25 | }
26 |
27 | @ExceptionHandler(StockException.class)
28 | public ResponseEntity stockExceptionHandler(StockException se, WebRequest req){
29 |
30 |
31 | MyErrorDetails err= new MyErrorDetails();
32 | err.setTimestamp(LocalDateTime.now());
33 | err.setMessage(se.getMessage());
34 | err.setDetails(req.getDescription(false));
35 |
36 | return new ResponseEntity(err, HttpStatus.NOT_FOUND);
37 |
38 | }
39 |
40 | @ExceptionHandler(ResourceNotFoundException.class)
41 | public ResponseEntity resourceNotFoundExceptionHandler(ResourceNotFoundException se, WebRequest req){
42 |
43 |
44 | MyErrorDetails err= new MyErrorDetails();
45 | err.setTimestamp(LocalDateTime.now());
46 | err.setMessage(se.getMessage());
47 | err.setDetails(req.getDescription(false));
48 |
49 | return new ResponseEntity(err, HttpStatus.NOT_FOUND);
50 |
51 | }
52 |
53 |
54 | @ExceptionHandler(LoginException.class)
55 | public ResponseEntity loginExceptionHandler(LoginException se, WebRequest req){
56 |
57 |
58 | MyErrorDetails err= new MyErrorDetails();
59 | err.setTimestamp(LocalDateTime.now());
60 | err.setMessage(se.getMessage());
61 | err.setDetails(req.getDescription(false));
62 |
63 | return new ResponseEntity(err, HttpStatus.BAD_REQUEST);
64 |
65 | }
66 |
67 |
68 | @ExceptionHandler(Exception.class)
69 | public ResponseEntity otherExceptionHandler(Exception se, WebRequest req){
70 |
71 |
72 | MyErrorDetails err= new MyErrorDetails();
73 | err.setTimestamp(LocalDateTime.now());
74 | err.setMessage(se.getMessage());
75 | err.setDetails(req.getDescription(false));
76 |
77 | return new ResponseEntity(err, HttpStatus.INTERNAL_SERVER_ERROR);
78 |
79 | }
80 |
81 |
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.7.4
9 |
10 |
11 | com.stockman
12 | StockMan
13 | 0.0.1-SNAPSHOT
14 | StockMan
15 | A Stock Broker System Project
16 |
17 | 17
18 | manoj890880
19 | https://sonarcloud.io
20 |
21 |
22 |
23 |
24 | org.springframework.boot
25 | spring-boot-starter-data-jpa
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-web
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-devtools
34 | runtime
35 | true
36 |
37 |
38 | mysql
39 | mysql-connector-java
40 | runtime
41 |
42 |
43 |
44 | org.projectlombok
45 | lombok
46 | 1.18.24
47 | provided
48 |
49 |
50 |
51 | io.springfox
52 | springfox-boot-starter
53 | 3.0.0
54 |
55 |
56 | io.springfox
57 | springfox-swagger2
58 | 3.0.0
59 |
60 |
61 | io.springfox
62 | springfox-swagger-ui
63 | 3.0.0
64 |
65 |
66 | org.springframework.boot
67 | spring-boot-starter-test
68 | test
69 |
70 |
71 | junit
72 | junit
73 | test
74 |
75 |
76 |
77 |
78 |
79 | org.springframework.boot
80 | spring-boot-maven-plugin
81 |
82 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/service/LoginServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.stockman.service;
2 |
3 | import java.time.LocalDateTime;
4 | import java.util.Optional;
5 |
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Service;
8 |
9 | import com.stockman.exception.LoginException;
10 | import com.stockman.model.CurrentUserSession;
11 | import com.stockman.model.Customer;
12 | import com.stockman.model.LoginDTO;
13 | import com.stockman.repository.CustomerDao;
14 | import com.stockman.repository.SessionDao;
15 |
16 | import net.bytebuddy.utility.RandomString;
17 |
18 | @Service
19 | public class LoginServiceImpl implements LoginService {
20 |
21 | @Autowired
22 | private CustomerDao cDao;
23 |
24 | @Autowired
25 | private SessionDao sDao;
26 |
27 | @Override
28 | public String logIntoAccount(LoginDTO dto) throws LoginException {
29 |
30 | Customer existingCustomer = cDao.findByMobileNumber(dto.getMobileNo());
31 |
32 | if (existingCustomer == null) {
33 |
34 | throw new LoginException("Please Enter a valid mobile number");
35 |
36 | }
37 |
38 | Optional validCustomerSessionOpt = sDao.findById(existingCustomer.getCustomerId());
39 |
40 | if (validCustomerSessionOpt.isPresent()) {
41 |
42 | throw new LoginException("User already Logged In with this number");
43 |
44 | }
45 |
46 | if (existingCustomer.getPassword().equals(dto.getPassword())) {
47 |
48 | String key = RandomString.make(6);
49 |
50 | CurrentUserSession currentUserSession = new CurrentUserSession(existingCustomer.getCustomerId(), key,
51 | LocalDateTime.now());
52 |
53 | sDao.save(currentUserSession);
54 |
55 | return currentUserSession.toString();
56 | } else
57 | throw new LoginException("Please Enter a valid password");
58 |
59 | }
60 |
61 | @Override
62 | public String logOutFromAccount(String key) throws LoginException {
63 |
64 | CurrentUserSession validCustomerSession = sDao.findByUuid(key);
65 |
66 | if (validCustomerSession == null) {
67 | throw new LoginException("User Not Logged In with this number");
68 |
69 | }
70 |
71 | sDao.delete(validCustomerSession);
72 |
73 | return "Logged Out !";
74 |
75 | }
76 |
77 | @Override
78 | public String logIntoAccountAdmin(LoginDTO dto) throws LoginException {
79 | if (dto.getMobileNo().equals("admin")&&dto.getPassword().equals("admin")) {
80 |
81 | String key = RandomString.make(6);
82 |
83 | CurrentUserSession currentUserSession = new CurrentUserSession(1, key,
84 | LocalDateTime.now());
85 |
86 | sDao.save(currentUserSession);
87 |
88 | return currentUserSession.toString();
89 | } else
90 | throw new LoginException("Invalid username or password");
91 | }
92 |
93 | @Override
94 | public String logOutFromAccountAdmin(String key) throws LoginException {
95 | CurrentUserSession validCustomerSession = sDao.findByUuid(key);
96 |
97 | if (validCustomerSession == null) {
98 | throw new LoginException("Admin Not Logged in");
99 |
100 | }
101 |
102 | sDao.delete(validCustomerSession);
103 |
104 | return "Logged Out !";
105 | }
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/controller/AdminController.java:
--------------------------------------------------------------------------------
1 | package com.stockman.controller;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.http.HttpStatus;
7 | import org.springframework.http.ResponseEntity;
8 | import org.springframework.web.bind.annotation.DeleteMapping;
9 | import org.springframework.web.bind.annotation.GetMapping;
10 | import org.springframework.web.bind.annotation.PathVariable;
11 | import org.springframework.web.bind.annotation.PostMapping;
12 | import org.springframework.web.bind.annotation.RequestBody;
13 | import org.springframework.web.bind.annotation.RequestMapping;
14 | import org.springframework.web.bind.annotation.RestController;
15 |
16 | import com.stockman.exception.CustomerException;
17 | import com.stockman.exception.ResourceNotFoundException;
18 | import com.stockman.exception.StockException;
19 | import com.stockman.model.Customer;
20 | import com.stockman.model.Stock;
21 | import com.stockman.model.StockReport;
22 | import com.stockman.model.Transaction;
23 | import com.stockman.model.TransactionType;
24 | import com.stockman.service.AdminService;
25 | import com.stockman.service.CustomerService;
26 | import com.stockman.service.TransactionService;
27 |
28 | @RestController
29 | @RequestMapping("/stockman")
30 | public class AdminController {
31 | @Autowired
32 | private AdminService adminService;
33 | @Autowired
34 | private CustomerService customerService;
35 | @Autowired
36 | private TransactionService transactionService;
37 | @PostMapping("/stocks")
38 | public ResponseEntity saveStock(@RequestBody Stock stock) throws StockException {
39 | Stock savedStock = adminService.addStock(stock);
40 | return new ResponseEntity(savedStock, HttpStatus.CREATED);
41 | }
42 | @GetMapping("/customers")
43 | public ResponseEntity> getAllCustomers() throws CustomerException {
44 |
45 | List customers = customerService.getAllCustomers();
46 | return new ResponseEntity<>(customers, HttpStatus.ACCEPTED);
47 | }
48 | @GetMapping("/allStocks")
49 | public ResponseEntity> getAllStock() throws StockException {
50 | List stocks = adminService.getAllStocks();
51 | return new ResponseEntity<>(stocks, HttpStatus.ACCEPTED);
52 | }
53 |
54 | @GetMapping("/{name}/report")
55 | public ResponseEntity getStockReport(@PathVariable String name) throws ResourceNotFoundException, StockException {
56 | Stock stock = adminService.findStockByName(name);
57 | Integer stockId = stock.getStockId();
58 | Integer sold = transactionService.getTotalSoldQuantityByStockId(stockId);
59 | Integer remaining = stock.getTotalQuantity() - sold.intValue();
60 | return new ResponseEntity<>(new StockReport(stock.getStockName(), stock.getTotalQuantity(), sold, remaining), HttpStatus.ACCEPTED);
61 | }
62 |
63 |
64 | @DeleteMapping("/customers/{customerId}")
65 | public ResponseEntity deleteCustomerAccount(@PathVariable Integer customerId) throws CustomerException, ResourceNotFoundException {
66 | Customer customer = customerService.findCustomerById(customerId);
67 |
68 | // Credit the total amount of all stocks to the customer's wallet
69 |
70 | double totalValue = 0.0;
71 | List transactions = transactionService.findByCustomer(customer);
72 | for (Transaction transaction : transactions) {
73 | if (transaction.getTransactionType() == TransactionType.BUY) {
74 | totalValue += transaction.getTransactionPrice();
75 | } else if (transaction.getTransactionType() == TransactionType.SOLD) {
76 | totalValue -= transaction.getTransactionPrice();
77 | }
78 | }
79 | customer.getWallet().setBalance(customer.getWallet().getBalance() + totalValue);
80 |
81 | // Set account inactive
82 | customer.setActive(false);
83 |
84 | Customer customer2 = customerService.save(customer);
85 |
86 | return new ResponseEntity<>(customer2, HttpStatus.ACCEPTED);
87 | }
88 |
89 | }
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 | # StockMan
3 |
4 | The Stock Broker Application built using the Spring Boot framework is a powerful web-based tool that enables customers to invest in the stock market seamlessly. It provides customers with a secure and intuitive platform that facilitates buying and selling of shares of various companies.With the ability to create and manage their demat account, customers can easily add funds and store their investments in a virtual wallet. They can track their transaction history, view stock market analysis, and stay updated with real-time price updates to make informed decisions while investing.
5 |
6 | The application leverages the robustness and scalability of the Spring Boot framework to ensure the efficient handling of large volumes of transactions. It also implements robust security measures to protect the confidentiality of customer information and ensure the safety of transactions.Whether you're an experienced investor or a novice in the stock market, the Stock Trading Application using Spring Boot provides an intuitive and user-friendly interface that makes investing accessible to everyone. It's a reliable and efficient tool that enables customers to grow their wealth over time.
7 |
8 | # ER Diagram.
9 |
10 | 
11 | # Relationships
12 | The above ER Diagram has the following relationships :
13 | Customers and Wallet: One-to-One relationship, where each customer has only one wallet and each wallet is linked to only one customer.
14 |
15 | Customers and Transactions: One-to-Many relationship, where each customer can have multiple transactions, but each transaction belongs to only one customer.
16 |
17 | Stocks and Transactions: One-to-Many relationship, where each stock can be part of multiple transactions, but each transaction involves only one stock.
18 |
19 | Customers and Stocks: Many-to-Many relationship, where each customer can purchase multiple stocks, and each stock can be purchased by multiple customers. This relationship can be implemented through a junction table that will have foreign keys referencing both the Customers and Stocks tables.
20 |
21 | Mutual Funds and Transactions: One-to-Many relationship, where each mutual fund can be part of multiple transactions, but each transaction involves only one mutual fund.
22 |
23 | Customers and Loan Against Share: One-to-Many relationship, where each customer can have multiple loans against shares, but each loan belongs to only one customer.
24 |
25 | Loan Against Share and Transactions: One-to-Many relationship, where each mutual fund can be part of multiple transactions, but each transaction involves only one Loan Against Share.
26 |
27 | Customers and Mutual Funds: One-to-Many relationship, where each customer can have multiple Mutual Funds, but each Mutual Funds belongs to only one customer.
28 |
29 | # Flow Chart
30 |
31 | 
32 |
33 | 
34 |
35 | # Users:
36 |
37 | - Broker
38 | - Customer
39 |
40 | # Roles for the Broker:
41 |
42 | 1. Broker logs in with their username and password.
43 | 2. Broker can view all customers.
44 | 3. Broker can add new stocks.
45 | 4. Broker can view all stocks.
46 | 5. Broker can view a consolidated report of a stock, which shows how many pieces of a stock have been sold and how many are yet to be sold.
47 | 6. Broker can delete a customer, which credits the total amount of all stocks to the customer's wallet and marks the account inactive.
48 | 7. Broker can delete a stock, which credits the total amount for that stock to the customer's wallet and marks the stock as deleted from the database.
49 | 8. Broker logs out.
50 |
51 |
52 |
53 | 
54 | 
55 |
56 | # Roles of Customers:
57 |
58 | 1. Customer signs up with their first name, last name, username, password, address, mobile number, and email.
59 | 2. Customer logs in with their username and password.
60 | 3. Customer can view all stocks.
61 | 4. Customer can buy and sell stocks.
62 | 5. Customer can view their own transaction history.
63 | 6. Customer can add and withdraw funds to and from their wallet.
64 | 7. Customer logs out and can delete their account.
65 |
66 | 
67 | 
68 |
69 |
70 | # Technologies Used
71 | ## Spring Boot
72 | 1. Spring Core – Dependency Injection and Inversion of Control
73 | 2. Web MVC architectural pattern
74 | 3. Validation – Validator
75 | 4. Password using unquie key generating
76 | 5. JSON Binding
77 | 8. Rest Template
78 | 9. Apache Common Email
79 | 10. Java 17 Stream API
80 | 11. Server – Embedded Tomcat Server
81 | 12. Maven Plugin and dependencies
82 | 13. Session Management using Session Object
83 |
84 | ## Hibernate
85 | 1. Entity Manager
86 | 2. Relationship Mapping
87 | 3. Hibernate Validator
88 | 4. Criteria Query
89 |
90 | # Setup Required
91 | - Eclipse / Intellij IDE
92 | - JDK (jdk 10 and above)
93 | - JRE(any latest versions)
94 | - Tomcat Server
95 | - Web Browser(Google Crome, Mozilla Firefox, Microsoft Edge)
96 |
97 | # Running the Project
98 | - Clone the repository as a maven project.
99 | - Import all the dependencies.
100 | - Run Application.java to run the application.
101 | - You will see the processing and verification of the process during the Application run.
102 | - Open Browser and Type in [localhost:{server_port}](https://locallhost.com/).
(Server Port Depends on local System you can change it by going here [server.port](https://github.com/modhtanmay/Stock-Trading-Management/blob/master/Share-Data/src/main/resources/application.properties))
103 | - That's it You are Good to go!!!.
104 |
105 |
106 | ## Feedback
107 |
108 | If you have any feedback, please reach out to me at manojsahoo890880@gmail.com
109 |
110 |
111 |
112 |
113 |
114 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/controller/CustomerController.java:
--------------------------------------------------------------------------------
1 | package com.stockman.controller;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.http.HttpStatus;
7 | import org.springframework.http.ResponseEntity;
8 | import org.springframework.web.bind.annotation.GetMapping;
9 | import org.springframework.web.bind.annotation.PathVariable;
10 | import org.springframework.web.bind.annotation.PostMapping;
11 | import org.springframework.web.bind.annotation.PutMapping;
12 | import org.springframework.web.bind.annotation.RequestBody;
13 | import org.springframework.web.bind.annotation.RequestMapping;
14 | import org.springframework.web.bind.annotation.RequestMethod;
15 | import org.springframework.web.bind.annotation.RequestParam;
16 | import org.springframework.web.bind.annotation.RestController;
17 |
18 | import com.stockman.exception.CustomerException;
19 | import com.stockman.exception.ResourceNotFoundException;
20 | import com.stockman.exception.StockException;
21 | import com.stockman.model.Customer;
22 | import com.stockman.model.Stock;
23 | import com.stockman.model.Transaction;
24 | import com.stockman.model.Wallet;
25 | import com.stockman.service.AdminService;
26 | import com.stockman.service.CustomerService;
27 | import com.stockman.service.TransactionService;
28 | import com.stockman.service.WalletService;
29 |
30 | @RestController
31 | public class CustomerController {
32 |
33 | @Autowired
34 | private CustomerService cService;
35 |
36 | @Autowired
37 | private AdminService adminService;
38 |
39 | @Autowired
40 | private TransactionService transactionService;
41 |
42 | @Autowired
43 | private WalletService walletService;
44 |
45 |
46 | @PostMapping("/customers")
47 | public ResponseEntity saveCustomer(@RequestBody Customer customer) throws CustomerException {
48 |
49 |
50 | Wallet wallet=new Wallet();
51 | wallet.setBalance(0.0);
52 | wallet.setCustomer(customer);
53 | Customer savedCustomer= cService.createCustomer(customer);
54 |
55 | return new ResponseEntity(savedCustomer,HttpStatus.CREATED);
56 | }
57 |
58 | @PutMapping("/customers")
59 | public ResponseEntity updateCustomer(@RequestBody Customer customer,@RequestParam String key) throws CustomerException {
60 |
61 |
62 | Customer updatedCustomer= cService.updateCustomer(customer, key);
63 |
64 | return new ResponseEntity(updatedCustomer,HttpStatus.OK);
65 |
66 | }
67 |
68 | @GetMapping("/viewAllStocks")
69 |
70 | public ResponseEntity> viewAllStocks(@RequestParam String key) throws StockException, CustomerException {
71 |
72 |
73 |
74 |
75 | List stocks= cService.getAllStocks(key);
76 |
77 |
78 | return new ResponseEntity<>(stocks,HttpStatus.ACCEPTED);
79 | }
80 |
81 |
82 | @PostMapping("/customers/{customerId}/stocks/buy")
83 | public ResponseEntity buyStockByName(
84 | @PathVariable int customerId,
85 | @RequestParam String stockName,
86 | @RequestParam Integer shares) throws CustomerException, StockException, ResourceNotFoundException {
87 |
88 |
89 | Transaction transaction = cService.buyStockByName(customerId, stockName, shares);
90 |
91 | return new ResponseEntity<>(transaction,HttpStatus.ACCEPTED);
92 |
93 | }
94 |
95 |
96 | @PostMapping("/sellStockByName")
97 | public ResponseEntity sellStockByName(@RequestParam Integer customerId, @RequestParam String stockName, @RequestParam Integer shares) throws CustomerException, StockException, ResourceNotFoundException {
98 |
99 | Transaction transaction = cService.sellStockByName(customerId, stockName, shares);
100 |
101 |
102 | return new ResponseEntity<>(transaction,HttpStatus.ACCEPTED);
103 | }
104 |
105 |
106 | @GetMapping("/customers/{customerId}/transactions")
107 | public ResponseEntity> getCustomerTransactions(@PathVariable Integer customerId) throws CustomerException, ResourceNotFoundException {
108 | Customer customer = cService.findCustomerById(customerId);
109 |
110 | List transactions= transactionService.findByCustomer(customer);
111 |
112 |
113 | return new ResponseEntity<>(transactions,HttpStatus.ACCEPTED);
114 | }
115 |
116 | @RequestMapping(value = "/addFunds", method = RequestMethod.POST)
117 | public ResponseEntity addFunds(@RequestParam Integer customerId, @RequestParam double amount) throws CustomerException, ResourceNotFoundException {
118 | Customer customer = cService.findCustomerById(customerId);
119 | if (customer == null) {
120 | throw new ResourceNotFoundException("Customer not found with id: " + customerId);
121 | }
122 | if (amount <= 0) {
123 | throw new IllegalArgumentException("Amount must be greater than 0");
124 | }
125 | Double prevBal = customer.getWallet().getBalance();
126 | customer.getWallet().setBalance(prevBal + amount);
127 | Customer updatedCustomer = cService.save(customer);
128 | return new ResponseEntity<>(updatedCustomer, HttpStatus.OK);
129 | }
130 |
131 | @RequestMapping(value = "/withdrawFunds", method = RequestMethod.POST)
132 | public Customer withdrawFunds(@RequestParam Integer customerId, @RequestParam double amount) throws CustomerException, ResourceNotFoundException {
133 | Customer customer = cService.findCustomerById(customerId);
134 | if (customer.getWallet().getBalance() < amount) {
135 | throw new ResourceNotFoundException("Customer has insufficient balance to withdraw the given amount.");
136 | }
137 | customer.getWallet().setBalance(customer.getWallet().getBalance() - amount);
138 |
139 | return cService.save(customer);
140 | }
141 |
142 | @RequestMapping(value = "/deleteAccount", method = RequestMethod.DELETE)
143 | public void deleteAccount(@RequestParam Integer customerId) throws CustomerException, ResourceNotFoundException {
144 | Customer customer = cService.findCustomerById(customerId);
145 |
146 | if (customer.getWallet().getBalance()>0) {
147 | throw new ResourceNotFoundException("Before delete your account please withdraw money fast");
148 | }
149 |
150 | // Remove all transactions related to this customer
151 | List transactions = transactionService.findByCustomer(customer);
152 | transactionService.deleteAll(transactions);
153 |
154 | // Remove the customer's wallet
155 | Wallet wallet = customer.getWallet();
156 | customer.setWallet(null);
157 |
158 | walletService.delete(wallet);
159 |
160 | // Delete the customer
161 | cService.delete(customer);
162 | }
163 | }
164 |
--------------------------------------------------------------------------------
/src/main/java/com/stockman/service/CustomerServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.stockman.service;
2 |
3 | import java.time.LocalDate;
4 | import java.util.List;
5 | import java.util.Optional;
6 |
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Service;
9 |
10 | import com.stockman.exception.CustomerException;
11 | import com.stockman.exception.ResourceNotFoundException;
12 | import com.stockman.exception.StockException;
13 | import com.stockman.model.CurrentUserSession;
14 | import com.stockman.model.Customer;
15 | import com.stockman.model.Stock;
16 | import com.stockman.model.Transaction;
17 | import com.stockman.model.TransactionType;
18 | import com.stockman.repository.AdminRepository;
19 | import com.stockman.repository.CustomerDao;
20 | import com.stockman.repository.SessionDao;
21 | import com.stockman.repository.TransactionRepository;
22 |
23 |
24 |
25 | @Service
26 | public class CustomerServiceImpl implements CustomerService {
27 |
28 | @Autowired
29 | private CustomerDao cDao;
30 |
31 | @Autowired
32 | private AdminRepository adminRepository;
33 |
34 | @Autowired
35 | private SessionDao sDao;
36 |
37 | @Autowired
38 | private TransactionRepository transactionRepository;
39 |
40 | @Override
41 | public Customer createCustomer(Customer customer) throws CustomerException {
42 |
43 | Customer existingCustomer = cDao.findByMobileNumber(customer.getMobileNumber());
44 |
45 | if (existingCustomer != null)
46 | throw new CustomerException("Customer Already Registered with Mobile number");
47 |
48 | return cDao.save(customer);
49 |
50 | }
51 |
52 | @Override
53 | public Customer updateCustomer(Customer customer, String key) throws CustomerException {
54 |
55 | CurrentUserSession loggedInUser = sDao.findByUuid(key);
56 |
57 | if (loggedInUser == null) {
58 | throw new CustomerException("Please provide a valid key to update a customer");
59 | }
60 |
61 | if (customer.getCustomerId() == loggedInUser.getUserId()) {
62 | // If LoggedInUser id is same as the id of supplied Customer which we want to
63 | // update
64 | return cDao.save(customer);
65 | } else
66 | throw new CustomerException("Invalid Customer Details, please login first");
67 |
68 | }
69 |
70 | @Override
71 | public List getAllCustomers() throws CustomerException {
72 | List customers=cDao.findAll();
73 | if (customers.size()==0) {
74 | throw new CustomerException("No Customer Found");
75 | }
76 | return customers;
77 | }
78 |
79 | @Override
80 | public Customer findCustomerById(Integer id) throws CustomerException {
81 | Optional existingCustomer = cDao.findById(id);
82 |
83 | if (existingCustomer == null)
84 | throw new CustomerException("No Customer Found With this Id");
85 |
86 | return existingCustomer.get();
87 | }
88 |
89 | @Override
90 | public List getAllStocks(String key) throws CustomerException {
91 |
92 |
93 |
94 | CurrentUserSession loggedInUser = sDao.findByUuid(key);
95 |
96 | if (loggedInUser == null) {
97 | throw new CustomerException("Please provide a valid key to See all stocks");
98 | }
99 |
100 | return adminRepository.findAll();
101 | }
102 |
103 | @Override
104 | public Transaction buyStockByName(Integer customerId, String stockName, Integer shares)
105 | throws CustomerException, StockException, ResourceNotFoundException {
106 | Customer customer = cDao.findById(customerId)
107 | .orElseThrow(() -> new CustomerException("Invalid customer ID"));
108 |
109 | Stock stock = adminRepository.findByStockName(stockName);
110 |
111 | if (stock==null) {
112 | throw new StockException("Invalid stock name");
113 | }
114 |
115 | Integer availableShares = stock.getAvailableQuantity();
116 | if (shares > availableShares) {
117 | throw new ResourceNotFoundException("Not enough shares available to buy");
118 | }
119 |
120 | double totalPrice = shares * stock.getCurrentPrice();
121 |
122 | if (totalPrice > customer.getWallet().getBalance()) {
123 | throw new ResourceNotFoundException("Not enough funds in wallet to buy");
124 | }
125 |
126 | Transaction transaction = new Transaction();
127 | transaction.setCustomer(customer);
128 | transaction.setStock(stock);
129 | transaction.setTransactionType(TransactionType.BUY);
130 | transaction.setQuantity(shares);
131 | transaction.setTransactionPrice(totalPrice);
132 | transaction.setTransactionDate(LocalDate.now());
133 |
134 | customer.getWallet().setBalance(customer.getWallet().getBalance() - totalPrice);
135 | stock.setAvailableQuantity(stock.getAvailableQuantity() - shares);
136 |
137 |
138 | transactionRepository.save(transaction);
139 |
140 | return transaction;
141 |
142 | }
143 |
144 | @Override
145 | public Transaction sellStockByName(Integer customerId, String stockName, Integer shares)
146 | throws CustomerException, StockException, ResourceNotFoundException {
147 | Customer customer = cDao.findById(customerId).orElseThrow(() -> new CustomerException("Customer not found with id: " + customerId));
148 |
149 | Stock stock = adminRepository.findByStockName(stockName);
150 |
151 | if (stock==null) {
152 | throw new StockException("Invalid stock name");
153 | }
154 | double totalPrice = shares * stock.getCurrentPrice();
155 |
156 | List transactions=customer.getTransactions();
157 |
158 | Integer quantityAvailableToSell=0;
159 |
160 | for (Transaction transaction : transactions) {
161 | if (transaction.getStock().getStockName().equals(stockName)&&transaction.getTransactionType().equals("BUY")) {
162 | quantityAvailableToSell+=transaction.getStock().getTotalQuantity();
163 | }
164 | }
165 |
166 |
167 | if (quantityAvailableToSell < shares) {
168 | throw new ResourceNotFoundException("The given number of shares are not available to sell.");
169 | }
170 |
171 | Transaction transaction = new Transaction();
172 | transaction.setCustomer(customer);
173 | transaction.setStock(stock);
174 | transaction.setTransactionType(TransactionType.SOLD);
175 | transaction.setQuantity(shares);
176 | transaction.setTransactionPrice(totalPrice);
177 | transaction.setTransactionDate(LocalDate.now());
178 |
179 | customer.getWallet().setBalance(totalPrice);
180 |
181 | transactionRepository.save(transaction);
182 |
183 | return transaction;
184 | }
185 |
186 | @Override
187 | public Customer save(Customer customer) throws CustomerException {
188 | Customer cust=cDao.save(customer);
189 | if (cust==null) {
190 | throw new CustomerException("No customer saved");
191 | }
192 |
193 | return cust;
194 | }
195 |
196 | @Override
197 | public void delete(Customer customer) throws CustomerException {
198 | cDao.delete(customer);
199 | }
200 |
201 |
202 |
203 | }
204 |
205 |
206 |
--------------------------------------------------------------------------------
/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM https://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM set title of command window
39 | title %0
40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
42 |
43 | @REM set %HOME% to equivalent of $HOME
44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
45 |
46 | @REM Execute a user defined script before this one
47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
49 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %*
50 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %*
51 | :skipRcPre
52 |
53 | @setlocal
54 |
55 | set ERROR_CODE=0
56 |
57 | @REM To isolate internal variables from possible post scripts, we use another setlocal
58 | @setlocal
59 |
60 | @REM ==== START VALIDATION ====
61 | if not "%JAVA_HOME%" == "" goto OkJHome
62 |
63 | echo.
64 | echo Error: JAVA_HOME not found in your environment. >&2
65 | echo Please set the JAVA_HOME variable in your environment to match the >&2
66 | echo location of your Java installation. >&2
67 | echo.
68 | goto error
69 |
70 | :OkJHome
71 | if exist "%JAVA_HOME%\bin\java.exe" goto init
72 |
73 | echo.
74 | echo Error: JAVA_HOME is set to an invalid directory. >&2
75 | echo JAVA_HOME = "%JAVA_HOME%" >&2
76 | echo Please set the JAVA_HOME variable in your environment to match the >&2
77 | echo location of your Java installation. >&2
78 | echo.
79 | goto error
80 |
81 | @REM ==== END VALIDATION ====
82 |
83 | :init
84 |
85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
86 | @REM Fallback to current working directory if not found.
87 |
88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
90 |
91 | set EXEC_DIR=%CD%
92 | set WDIR=%EXEC_DIR%
93 | :findBaseDir
94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
95 | cd ..
96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
97 | set WDIR=%CD%
98 | goto findBaseDir
99 |
100 | :baseDirFound
101 | set MAVEN_PROJECTBASEDIR=%WDIR%
102 | cd "%EXEC_DIR%"
103 | goto endDetectBaseDir
104 |
105 | :baseDirNotFound
106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
107 | cd "%EXEC_DIR%"
108 |
109 | :endDetectBaseDir
110 |
111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
112 |
113 | @setlocal EnableExtensions EnableDelayedExpansion
114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
116 |
117 | :endReadAdditionalConfig
118 |
119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
122 |
123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
124 |
125 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
127 | )
128 |
129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data.
131 | if exist %WRAPPER_JAR% (
132 | if "%MVNW_VERBOSE%" == "true" (
133 | echo Found %WRAPPER_JAR%
134 | )
135 | ) else (
136 | if not "%MVNW_REPOURL%" == "" (
137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
138 | )
139 | if "%MVNW_VERBOSE%" == "true" (
140 | echo Couldn't find %WRAPPER_JAR%, downloading it ...
141 | echo Downloading from: %DOWNLOAD_URL%
142 | )
143 |
144 | powershell -Command "&{"^
145 | "$webclient = new-object System.Net.WebClient;"^
146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
148 | "}"^
149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
150 | "}"
151 | if "%MVNW_VERBOSE%" == "true" (
152 | echo Finished downloading %WRAPPER_JAR%
153 | )
154 | )
155 | @REM End of extension
156 |
157 | @REM Provide a "standardized" way to retrieve the CLI args that will
158 | @REM work with both Windows and non-Windows executions.
159 | set MAVEN_CMD_LINE_ARGS=%*
160 |
161 | %MAVEN_JAVA_EXE% ^
162 | %JVM_CONFIG_MAVEN_PROPS% ^
163 | %MAVEN_OPTS% ^
164 | %MAVEN_DEBUG_OPTS% ^
165 | -classpath %WRAPPER_JAR% ^
166 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
167 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
168 | if ERRORLEVEL 1 goto error
169 | goto end
170 |
171 | :error
172 | set ERROR_CODE=1
173 |
174 | :end
175 | @endlocal & set ERROR_CODE=%ERROR_CODE%
176 |
177 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost
178 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
179 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat"
180 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd"
181 | :skipRcPost
182 |
183 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
184 | if "%MAVEN_BATCH_PAUSE%"=="on" pause
185 |
186 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE%
187 |
188 | cmd /C exit /B %ERROR_CODE%
189 |
--------------------------------------------------------------------------------
/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # https://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /usr/local/etc/mavenrc ] ; then
40 | . /usr/local/etc/mavenrc
41 | fi
42 |
43 | if [ -f /etc/mavenrc ] ; then
44 | . /etc/mavenrc
45 | fi
46 |
47 | if [ -f "$HOME/.mavenrc" ] ; then
48 | . "$HOME/.mavenrc"
49 | fi
50 |
51 | fi
52 |
53 | # OS specific support. $var _must_ be set to either true or false.
54 | cygwin=false;
55 | darwin=false;
56 | mingw=false
57 | case "`uname`" in
58 | CYGWIN*) cygwin=true ;;
59 | MINGW*) mingw=true;;
60 | Darwin*) darwin=true
61 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
62 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
63 | if [ -z "$JAVA_HOME" ]; then
64 | if [ -x "/usr/libexec/java_home" ]; then
65 | export JAVA_HOME="`/usr/libexec/java_home`"
66 | else
67 | export JAVA_HOME="/Library/Java/Home"
68 | fi
69 | fi
70 | ;;
71 | esac
72 |
73 | if [ -z "$JAVA_HOME" ] ; then
74 | if [ -r /etc/gentoo-release ] ; then
75 | JAVA_HOME=`java-config --jre-home`
76 | fi
77 | fi
78 |
79 | if [ -z "$M2_HOME" ] ; then
80 | ## resolve links - $0 may be a link to maven's home
81 | PRG="$0"
82 |
83 | # need this for relative symlinks
84 | while [ -h "$PRG" ] ; do
85 | ls=`ls -ld "$PRG"`
86 | link=`expr "$ls" : '.*-> \(.*\)$'`
87 | if expr "$link" : '/.*' > /dev/null; then
88 | PRG="$link"
89 | else
90 | PRG="`dirname "$PRG"`/$link"
91 | fi
92 | done
93 |
94 | saveddir=`pwd`
95 |
96 | M2_HOME=`dirname "$PRG"`/..
97 |
98 | # make it fully qualified
99 | M2_HOME=`cd "$M2_HOME" && pwd`
100 |
101 | cd "$saveddir"
102 | # echo Using m2 at $M2_HOME
103 | fi
104 |
105 | # For Cygwin, ensure paths are in UNIX format before anything is touched
106 | if $cygwin ; then
107 | [ -n "$M2_HOME" ] &&
108 | M2_HOME=`cygpath --unix "$M2_HOME"`
109 | [ -n "$JAVA_HOME" ] &&
110 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
111 | [ -n "$CLASSPATH" ] &&
112 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
113 | fi
114 |
115 | # For Mingw, ensure paths are in UNIX format before anything is touched
116 | if $mingw ; then
117 | [ -n "$M2_HOME" ] &&
118 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
119 | [ -n "$JAVA_HOME" ] &&
120 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
121 | fi
122 |
123 | if [ -z "$JAVA_HOME" ]; then
124 | javaExecutable="`which javac`"
125 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
126 | # readlink(1) is not available as standard on Solaris 10.
127 | readLink=`which readlink`
128 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
129 | if $darwin ; then
130 | javaHome="`dirname \"$javaExecutable\"`"
131 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
132 | else
133 | javaExecutable="`readlink -f \"$javaExecutable\"`"
134 | fi
135 | javaHome="`dirname \"$javaExecutable\"`"
136 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
137 | JAVA_HOME="$javaHome"
138 | export JAVA_HOME
139 | fi
140 | fi
141 | fi
142 |
143 | if [ -z "$JAVACMD" ] ; then
144 | if [ -n "$JAVA_HOME" ] ; then
145 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
146 | # IBM's JDK on AIX uses strange locations for the executables
147 | JAVACMD="$JAVA_HOME/jre/sh/java"
148 | else
149 | JAVACMD="$JAVA_HOME/bin/java"
150 | fi
151 | else
152 | JAVACMD="`\\unset -f command; \\command -v java`"
153 | fi
154 | fi
155 |
156 | if [ ! -x "$JAVACMD" ] ; then
157 | echo "Error: JAVA_HOME is not defined correctly." >&2
158 | echo " We cannot execute $JAVACMD" >&2
159 | exit 1
160 | fi
161 |
162 | if [ -z "$JAVA_HOME" ] ; then
163 | echo "Warning: JAVA_HOME environment variable is not set."
164 | fi
165 |
166 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
167 |
168 | # traverses directory structure from process work directory to filesystem root
169 | # first directory with .mvn subdirectory is considered project base directory
170 | find_maven_basedir() {
171 |
172 | if [ -z "$1" ]
173 | then
174 | echo "Path not specified to find_maven_basedir"
175 | return 1
176 | fi
177 |
178 | basedir="$1"
179 | wdir="$1"
180 | while [ "$wdir" != '/' ] ; do
181 | if [ -d "$wdir"/.mvn ] ; then
182 | basedir=$wdir
183 | break
184 | fi
185 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
186 | if [ -d "${wdir}" ]; then
187 | wdir=`cd "$wdir/.."; pwd`
188 | fi
189 | # end of workaround
190 | done
191 | echo "${basedir}"
192 | }
193 |
194 | # concatenates all lines of a file
195 | concat_lines() {
196 | if [ -f "$1" ]; then
197 | echo "$(tr -s '\n' ' ' < "$1")"
198 | fi
199 | }
200 |
201 | BASE_DIR=`find_maven_basedir "$(pwd)"`
202 | if [ -z "$BASE_DIR" ]; then
203 | exit 1;
204 | fi
205 |
206 | ##########################################################################################
207 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
208 | # This allows using the maven wrapper in projects that prohibit checking in binary data.
209 | ##########################################################################################
210 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
211 | if [ "$MVNW_VERBOSE" = true ]; then
212 | echo "Found .mvn/wrapper/maven-wrapper.jar"
213 | fi
214 | else
215 | if [ "$MVNW_VERBOSE" = true ]; then
216 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
217 | fi
218 | if [ -n "$MVNW_REPOURL" ]; then
219 | jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
220 | else
221 | jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
222 | fi
223 | while IFS="=" read key value; do
224 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
225 | esac
226 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
227 | if [ "$MVNW_VERBOSE" = true ]; then
228 | echo "Downloading from: $jarUrl"
229 | fi
230 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
231 | if $cygwin; then
232 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
233 | fi
234 |
235 | if command -v wget > /dev/null; then
236 | if [ "$MVNW_VERBOSE" = true ]; then
237 | echo "Found wget ... using wget"
238 | fi
239 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
240 | wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
241 | else
242 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
243 | fi
244 | elif command -v curl > /dev/null; then
245 | if [ "$MVNW_VERBOSE" = true ]; then
246 | echo "Found curl ... using curl"
247 | fi
248 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
249 | curl -o "$wrapperJarPath" "$jarUrl" -f
250 | else
251 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
252 | fi
253 |
254 | else
255 | if [ "$MVNW_VERBOSE" = true ]; then
256 | echo "Falling back to using Java to download"
257 | fi
258 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
259 | # For Cygwin, switch paths to Windows format before running javac
260 | if $cygwin; then
261 | javaClass=`cygpath --path --windows "$javaClass"`
262 | fi
263 | if [ -e "$javaClass" ]; then
264 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
265 | if [ "$MVNW_VERBOSE" = true ]; then
266 | echo " - Compiling MavenWrapperDownloader.java ..."
267 | fi
268 | # Compiling the Java class
269 | ("$JAVA_HOME/bin/javac" "$javaClass")
270 | fi
271 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
272 | # Running the downloader
273 | if [ "$MVNW_VERBOSE" = true ]; then
274 | echo " - Running MavenWrapperDownloader.java ..."
275 | fi
276 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
277 | fi
278 | fi
279 | fi
280 | fi
281 | ##########################################################################################
282 | # End of extension
283 | ##########################################################################################
284 |
285 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
286 | if [ "$MVNW_VERBOSE" = true ]; then
287 | echo $MAVEN_PROJECTBASEDIR
288 | fi
289 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
290 |
291 | # For Cygwin, switch paths to Windows format before running java
292 | if $cygwin; then
293 | [ -n "$M2_HOME" ] &&
294 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
295 | [ -n "$JAVA_HOME" ] &&
296 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
297 | [ -n "$CLASSPATH" ] &&
298 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
299 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
300 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
301 | fi
302 |
303 | # Provide a "standardized" way to retrieve the CLI args that will
304 | # work with both Windows and non-Windows executions.
305 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
306 | export MAVEN_CMD_LINE_ARGS
307 |
308 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
309 |
310 | exec "$JAVACMD" \
311 | $MAVEN_OPTS \
312 | $MAVEN_DEBUG_OPTS \
313 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
314 | "-Dmaven.home=${M2_HOME}" \
315 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
316 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
317 |
--------------------------------------------------------------------------------