/**
*
*/
package net.fp.rp.drools.servlet;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.fp.rp.drools.CalculatorBean;
import net.fp.rp.drools.SpringDecisionTableLoader;
/**
* @version 1.2 Jul 1, 2006
* @author Administrator
*
*/
public class CalculateMortgage extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response) {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) {
RequestDispatcher rd = null;
try {
CalculatorBean hl = new CalculatorBean();
hl = parseRequest(request);
//todo - test this - this will probably fail to run with a nullpointerexceptino
SpringDecisionTableLoader dtLoader = new SpringDecisionTableLoader();
hl = (CalculatorBean)dtLoader.executeDecisionTable(hl,true);
request.setAttribute("result", hl);
rd = request.getRequestDispatcher("/jsp/m3/result.jsp");
rd.forward(request, response);
}
catch (Throwable t) {
//Just catch and log the exception
//We wouldn't recommend this for production code, remember that this is just a sample
t.printStackTrace();
}
}
public CalculatorBean parseRequest(HttpServletRequest request) throws Exception {
CalculatorBean hl = new CalculatorBean();
double loanSought = 0;
double purchasePrice = 0;
int termSought = 0;
int mortgageType = 0;
int status1 = 0;
int status2 = 0;
int employmentType1 = 0;
int employmentType2 = 0;
int occupationType1 = 0;
int occupationType2 = 0;
double actualBasicIncome1 = 0;
double actualBasicIncome2 = 0;
double actualOvertime1 = 0;
double actualOvertime2 = 0;
double actualBonus1 = 0;
double actualBonus2 = 0;
double actualCommission1 = 0;
double actualCommission2 = 0;
double actualOtherIncome1 = 0;
double actualOtherIncome2 = 0;
int standardVariableRateId = 0;
double standardVariableRate = 0;
if (request.getParameter("loanAmount") != null) {
loanSought = Double.parseDouble(request.getParameter("loanAmount"));
}
if (request.getParameter("purchasePrice") != null) {
purchasePrice = Double.parseDouble(request.getParameter("purchasePrice"));
}
if (request.getParameter("termSought") != null) {
termSought = Integer.parseInt(request.getParameter("termSought"));
}
if (request.getParameter("mortgageType") != null) {
mortgageType = Integer.parseInt(request.getParameter("mortgageType"));
}
if (request.getParameter("status1") != null) {
status1 = Integer.parseInt(request.getParameter("status1"));
}
if (request.getParameter("status2") != null) {
status2 = Integer.parseInt(request.getParameter("status2"));
}
if (request.getParameter("employmentType1") != null) {
employmentType1 = Integer.parseInt(request.getParameter("employmentType1"));
}
if (request.getParameter("employmentType2") != null) {
employmentType2 = Integer.parseInt(request.getParameter("employmentType2"));
}
if (request.getParameter("occupationType1") != null) {
occupationType1 = Integer.parseInt(request.getParameter("occupationType1"));
}
if (request.getParameter("occupationType2") != null) {
occupationType2 = Integer.parseInt(request.getParameter("occupationType2"));
}
if (request.getParameter("actualBasicIncome1") != null) {
actualBasicIncome1 = Double.parseDouble(request.getParameter("actualBasicIncome1"));
}
if (request.getParameter("actualBasicIncome2") != null) {
actualBasicIncome2 = Double.parseDouble(request.getParameter("actualBasicIncome2"));
}
if (request.getParameter("actualOvertime1") != null) {
actualOvertime1 = Double.parseDouble(request.getParameter("actualOvertime1"));
}
if (request.getParameter("actualOvertime2") != null) {
actualOvertime2 = Double.parseDouble(request.getParameter("actualOvertime2"));
}
if (request.getParameter("actualBonus1") != null) {
actualBonus1 = Double.parseDouble(request.getParameter("actualBonus1"));
}
if (request.getParameter("actualBonus2") != null) {
actualBonus2 = Double.parseDouble(request.getParameter("actualBonus2"));
}
if (request.getParameter("actualCommission1") != null) {
actualCommission1 = Double.parseDouble(request.getParameter("actualCommission1"));
}
if (request.getParameter("actualCommission2") != null) {
actualCommission2 = Double.parseDouble(request.getParameter("actualCommission2"));
}
if (request.getParameter("actualOtherIncome1") != null) {
actualOtherIncome1 = Double.parseDouble(request.getParameter("actualOtherIncome1"));
}
if (request.getParameter("actualOtherIncome2") != null) {
actualOtherIncome2 = Double.parseDouble(request.getParameter("actualOtherIncome2"));
}
if (request.getParameter("standardVariableRateId") != null) {
standardVariableRateId = Integer.parseInt(request.getParameter("standardVariableRateId"));
}
if (request.getParameter("standardVariableRate") != null) {
standardVariableRate = Double.parseDouble(request.getParameter("standardVariableRate"));
}
hl.setLoanSought(loanSought);
hl.setValuationValueOrPurchasePrice(purchasePrice);
hl.setTermSought(termSought);
hl.setMortgageType(mortgageType);
hl.getApplicant1().setStatus(status1);
hl.getApplicant2().setStatus(status2);
hl.getApplicant1().setEmploymentType(employmentType1);
hl.getApplicant2().setEmploymentType(employmentType2);
hl.getApplicant1().setOccupationType(occupationType1);
hl.getApplicant2().setOccupationType(occupationType2);
hl.getApplicant1().setActualBasicIncome(actualBasicIncome1);
hl.getApplicant2().setActualBasicIncome(actualBasicIncome2);
hl.getApplicant1().setActualOvertime(actualOvertime1);
hl.getApplicant2().setActualOvertime(actualOvertime2);
hl.getApplicant1().setActualBonus(actualBonus1);
hl.getApplicant2().setActualBonus(actualBonus2);
hl.getApplicant1().setActualCommission(actualCommission1);
hl.getApplicant2().setActualCommission(actualCommission2);
hl.getApplicant1().setActualOtherIncome(actualOtherIncome1);
hl.getApplicant2().setActualOtherIncome(actualOtherIncome2);
hl.setRateType(standardVariableRateId);
hl.setRateTypeValue(standardVariableRate);
return hl;
}
}