Loan
Loan
Loan
properties
#DO NOT CHANGE THE BELOW VALUES
server.port=8085
logging.level.org.springframework.web=DEBUG
spring.mvc.view.prefix = /WEB-INF/jsp/
spring.mvc.view.suffix = .jsp
controller/LoanEligibilityController.java
package com.cts.loanbazaar.loaneligibility.controller;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.cts.loanbazaar.loaneligibility.exception.ApplicationException;
import com.cts.loanbazaar.loaneligibility.model.CustomerDetails;
import com.cts.loanbazaar.loaneligibility.model.LoanProduct;
import com.cts.loanbazaar.loaneligibility.service.LoanEligibilityService;
/**
*/
@Controller
@Autowired
LoanEligibilityService loanEligibilityService;
/**
* @param model
* @return String
*/
model.addAttribute("customerDetails", customerDetails);
return "loanEligibility";
/**
* @param model
* @param request
* @param response
* @param customerDetails
* @param result
* @return String
* @throws ApplicationException
*/
if (!result.hasErrors()) {
data = loanEligibilityService.checkEligibleLoanProducts(customerDetails);
if (data.isEmpty()) {
} else {
model.addAttribute("data", data);
model.addAttribute("msg", "Congratulations. You are Eligible for the
below Loan Products:");
return (result.hasErrors()?"loanEligibility":"results");
/**
* @return List<String>
*/
@ModelAttribute("cityList")
cityList.add("");
cityList.add("Chennai");
cityList.add("Mumbai");
cityList.add("Bangalore");
cityList.add("Delhi");
// cityList.add("Pune");
cityList.add("Kolkatta");
// cityList.add("Delhi");
// cityList.add("Bangalore");
return cityList;
}
/**
* @return List<String>
*/
@ModelAttribute("employeeList")
employeeList.add("");
employeeList.add("Salaried");
employeeList.add("Self-Employed");
employeeList.add("Contractual Employment");
employeeList.add("Student");
employeeList.add("Pensioner");
return employeeList;
/**
* @return List<String>
*/
@ModelAttribute("genderList")
genderList.add("Male");
genderList.add("Female");
return genderList;
}
}
Exception/ApplicationException.java
package com.cts.loanbazaar.loaneligibility.exception;
/**
*/
super(message);
exception/ ExceptionHandlerControllerAdvice.java
package com.cts.loanbazaar.loaneligibility.exception;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.http.HttpStatus;
import com.cts.loanbazaar.loaneligibility.model.ErrorResponse;
@ControllerAdvice
@ExceptionHandler(ApplicationException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody
int statusCode = 0;
err.setErrorMessage(exception.getMessage());
err.setRequestedURI("http://localhost:8085/" + request.getRequestURI());
try {
mav.addObject("code", statusCode);
mav.addObject("message", err.getErrorMessage());
mav.setViewName("error");
} catch (IOException e) {
System.out.println(e);
main/ LoanEligibilityServiceApplication.java
package com.cts.loanbazaar.loaneligibility.main;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan(basePackages =
{"com.cts.loanbazaar.loaneligibility.controller","com.cts.loanbazaar.loaneligibility.model","com.cts.loan
bazaar.loaneligibility.service","com.cts.loanbazaar.loaneligibility.exception"})
SpringApplication.run(LoanEligibilityServiceApplication.class, args);
model/ CustomerDetails.java
package com.cts.loanbazaar.loaneligibility.model;
import javax.validation.constraints.Size;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/// DO NOT CHANGE THE VARIABLE NAMES OR DATA TYPES OR ACCESS SPECIFIERS
return name;
this.name = name;
}
public String getGender() {
return gender;
this.gender = gender;
return email;
this.email = email;
return monthlyIncome;
this.monthlyIncome = monthlyIncome;
}
public String getCustomerCity() {
return customerCity;
this.customerCity = customerCity;
return employmentType;
this.employmentType = employmentType;
return desiredLoanAmount;
this.desiredLoanAmount = desiredLoanAmount;
}
model/ErrorResponse.java
package com.cts.loanbazaar.loaneligibility.model;
/**
*/
/// DO NOT CHANGE THE VARIABLE NAMES OR DATA TYPES OR ACCESS SPECIFIERS
return errorMessage;
this.errorMessage = errorMessage;
return requestedURI;
this.requestedURI = requestedURI;
}
}
model/LoanProduct.java
package com.cts.loanbazaar.loaneligibility.model;
///DO NOT CHANGE THE VARIABLE NAMES OR DATA TYPES OR ACCESS SPECIFIERS
/**
*/
return bankName;
/**
*/
this.bankName = bankName;
}
/**
*/
return loanProductName;
/**
*/
this.loanProductName = loanProductName;
/**
*/
return maxLoanAmount;
/**
*/
this.maxLoanAmount = maxLoanAmount;
}
/**
*/
return tenure;
/**
*/
this.tenure = tenure;
/**
*/
return interest;
/**
*/
this.interest = interest;
/**
* @return the monthlyInstallment
*/
return monthlyInstallment;
/**
*/
this.monthlyInstallment = monthlyInstallment;
service/ LoanEligibilityService.java
package com.cts.loanbazaar.loaneligibility.service;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Service;
import com.cts.loanbazaar.loaneligibility.exception.ApplicationException;
import com.cts.loanbazaar.loaneligibility.model.CustomerDetails;
import com.cts.loanbazaar.loaneligibility.model.LoanProduct;
@Service
/**
* @param details
* @return List<LoanProduct>
* @throws ApplicationException
*/
if(details.getDesiredLoanAmount()> (12*details.getMonthlyIncome())) {
if(details.getEmploymentType().length()>=4
&&details.getEmploymentType().length()<=30) {
product = buildLoanProducts();
for(int i=0;i<product.size();i++) {
if(product.get(i).getLoanProductName().contains(employmentType)) {
data.add(product.get(i));
}
/**
* Use the below method to test the appropriate loan products based on employment type of
the customer
* @return List<LoanProduct>
*/
product1.setBankName("MNQ Bank");
product1.setMaxLoanAmount(500000.00);
product1.setMonthlyInstallment(7000.00);
product1.setTenure(24);
product1.setInterest(16.40);
products.add(product1);
LoanProduct product2 = new LoanProduct();
product2.setBankName("PMT Bank");
product2.setMaxLoanAmount(1200000.00);
product2.setMonthlyInstallment(11000.00);
product2.setTenure(48);
product2.setInterest(12.40);
products.add(product2);
product3.setBankName("MNQ Bank");
product3.setMaxLoanAmount(1000000.00);
product3.setMonthlyInstallment(9000.00);
product3.setTenure(36);
product3.setInterest(15.40);
products.add(product3);
product4.setBankName("MNQ Bank");
product4.setMaxLoanAmount(700000.00);
product4.setMonthlyInstallment(8000.00);
product4.setTenure(24);
product4.setInterest(15.20);
products.add(product4);
product5.setBankName("MNQ Bank");
product5.setMaxLoanAmount(2500000.00);
product5.setMonthlyInstallment(34000.00);
product5.setTenure(720);
product5.setInterest(11.40);
products.add(product5);
return products;
JSP
Error.jsp
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
pageEncoding="ISO-8859-1" isELIgnored="false"%>
<head>
</head>
<form:form id="error">
</form:form>
</body>
</html>
loanEligibility.jsp
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
pageEncoding="ISO-8859-1" isELIgnored="false"%>
<html>
<head>
</head>
<center>
<h3 style="color: blue">Loan Bazaar - Find the Best Loan For You</h3>
method="post" id="loanEligibilityForm">
<table>
<tr>
<td>Name</td>
<td><form:errors path="name"
cssStyle="color:red"></form:errors></td>
</tr>
<tr>
<td>Gender</td>
<td><form:errors path="gender"
cssStyle="color:red"></form:errors>
</td>
</tr>
<tr>
<td>Email</td>
</tr>
<tr>
<td>Customer City</td>
id="customerCity"/></td>
<td><form:errors path="customerCity"
cssStyle="color:red"></form:errors></td>
</tr>
<tr>
<td>Employment Type</td>
<td><form:select path="employmentType"
items="${employeeList}"
id="employmentType" /></td>
<td><form:errors path="employmentType"
cssStyle="color:red"></form:errors></td>
</tr>
<tr>
id="monthlyIncome" /></td>
<td><form:errors path="monthlyIncome"
cssStyle="color:red"></form:errors></td>
</tr>
<tr>
id="desiredLoanAmount" /></td>
<td><form:errors path="desiredLoanAmount"
cssStyle="color:red"></form:errors></td>
</tr>
</table>
</form:form>
</center>
</body>
</html>
Result.jsp
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
pageEncoding="ISO-8859-1" isELIgnored="false"%>
<html>
<head>
</head>
<body style="background-color: rgb(200, 250, 300)">
<h3>${msg}</h3>
<form:form id="results">
<tr>
<td>Bank Name</td>
<td>Tenure</td>
<td>Interest</td>
<td>EMI in Rupees</td>
</tr>
<tr>
<td>${a.bankName}</td>
<td>${a.loanProductName}</td>
<td>${a.maxLoanAmount}</td>
<td>${a.tenure}</td>
<td>${a.interest}</td>
<td>${a.monthlyInstallment}</td>
</tr>
</c:forEach>
</table>
</c:if>
</form:form>
</html>