Untitled
unknown
plain_text
a year ago
14 kB
7
Indexable
package com.dcx.service.writeup.markettransfer.servlet;
import com.dcx.dealerconnect.servlet.*;
import com.dcx.dealerconnect.user.DCUser;
import com.dcx.dealerconnect.log.*;
import com.dcx.dealerconnect.config.*;
import com.dcx.dealerconnect.organization.*;
import com.dcx.dealerconnect.security.*;
import com.dcx.dealerconnect.session.*;
import com.dcx.dealerconnect.session.client.*;
import java.io.*;
import java.sql.Date;
import java.sql.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.*;
/**
* @version 1.0
* @author
*/
public class MarketTransfer
extends DCServlet
implements MarketTransferConstant {
private String errorMessage = "";
public String getAppName() {
return appName;
}
/**
* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
performTask(req, resp);
}
/**
* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
performTask(req, resp);
}
private Connection conn = null;
public void performTask(
HttpServletRequest request,
HttpServletResponse response) {
appLogger.debug(" Market Transfer begin*******************************");
try {
conn = dataSource.getConnection(appConfig, appLogger);
// request.setAttribute("appLogger", appLogger);
appLogger.debug(" try block started conn=" + conn.toString());
// String SID = "T1304JC";
String SID = DCUtil.getUserId(request);
String warningMessage = "";
boolean WCCOK = true;
String VINWhere = "";
final java.util.Calendar calendaer20030930 = java.util.Calendar.getInstance();
calendaer20030930.set(2003,8,30);
final java.sql.Date date20030930 =
new java.sql.Date(calendaer20030930.getTime().getTime());
final java.util.Calendar now = java.util.Calendar.getInstance();
// int dayOfToday = now.get(Calendar.DAY_OF_MONTH);
// int moOfToday = now.get(Calendar.MONTH)+1;
// int yrOfToday = now.get(Calendar.YEAR);
final java.sql.Date today =
new java.sql.Date(now.getTime().getTime());
DateFormat defaultDate = DateFormat.getDateInstance(DateFormat.LONG);
//get the entered data
String vin = request.getParameter("vin");
if (vin == null) {
vin = "";
}
String odometer = request.getParameter("odom");
int odom = 0;
if (odometer == null) {
odometer = "";
} else {
odom = Integer.parseInt(odometer);
}
String odomtype = request.getParameter("odomtype");
if (odomtype == null) {
odomtype = "";
}
String transfer = request.getParameter("transfer");
if (transfer == null) {
transfer = "";
}
String printPDF = request.getParameter("printPDF");
if (printPDF == null) {
printPDF = "";
}
request.setAttribute("vin", vin);
request.setAttribute("odom", odometer);
request.setAttribute("odomtype", odomtype);
request.setAttribute("transfer", transfer);
request.setAttribute("printPDF", printPDF);
appLogger.debug(" today=" + today.toString() +" vin="+vin +" odom="+odom +" odomtype="+odomtype +" transfer="+transfer +" printPDF="+printPDF);
// if not print the pdf
if (!"Y".equals(printPDF)) {
conn.setAutoCommit(false);
appLogger.debug("MT: setAutoCommit(false)");
/// Get vehicle information
VehicleDTO VDTO = null;
VehicleDTO NEWVDTO = null;
if (!"".equals(vin) && !"".equals(odometer)) {
vin = vin.toUpperCase();
if (vin.length() == 17) {
VINWhere = " I_VIN ='" + vin + "'";
} else if (vin.length() == 8) {
VINWhere = " I_VIN_LAST_8 = '" + vin + "'";
}
VehicleDAO VDAO = new VehicleDAO(conn);
VDTO = VDAO.getWarranty(VINWhere, appLogger);
appLogger.debug("MT: got VDTO");
//1. check WCC 395, 396, 397, 510, 516, 571, 572, 795 or 796
if( VDTO.getC_CURR_WCC() != 395 && VDTO.getC_CURR_WCC() != 396 &&
VDTO.getC_CURR_WCC() != 397 && VDTO.getC_CURR_WCC() != 510 &&
VDTO.getC_CURR_WCC() != 516 && VDTO.getC_CURR_WCC() != 571 &&
VDTO.getC_CURR_WCC() != 572 && VDTO.getC_CURR_WCC() != 795 &&
VDTO.getC_CURR_WCC() != 796 && VDTO.getC_CURR_WCC() != 595 &&
VDTO.getC_CURR_WCC() != 596 && VDTO.getC_CURR_WCC() != 597 &&
VDTO.getC_CURR_WCC() != 336
){
warningMessage = warningMessage + ".<BR>" + WCCWarning;
WCCOK = false;
}
// new amendament added by Jack, requested by carl
if( VDTO.getC_CURR_WCC() == 336 && VDTO.getI_VIN_MOD_YR() !=1997 && VDTO.getI_VIN_MOD_YR() !=1998
&& VDTO.getI_VIN_MOD_YR() !=1999 && VDTO.getI_VIN_MOD_YR() !=2000
){
if(WCCOK){warningMessage = warningMessage + ".<BR>" + WCCWarning;}
WCCOK = false;
}
if( (VDTO.getC_CURR_WCC() == 510 || VDTO.getC_CURR_WCC() == 516 )&& VDTO.getI_VIN_MOD_YR() >2002
){
if(WCCOK){warningMessage = warningMessage + ".<BR>" + WCCWarning;}
WCCOK = false;
}
// check WCC 395, 396, 397, 795 or 796
if( VDTO.getC_CURR_WCC() != 510 && VDTO.getC_CURR_WCC() != 516 && VDTO.getC_CURR_WCC() != 336 &&
VDTO.getC_CURR_WCC() != 571 && VDTO.getC_CURR_WCC() != 572 ){
//2. mileage less than 9314 miles or 14986 kms
if (odom < 9314 && "M".equals(odomtype) && odom != 0) {
if(WCCOK){warningMessage = warningMessage + ".<BR>" + mileageWarning;}
}
if (odom < 14986 && "K".equals(odomtype) && odom != 0) {
if(WCCOK){warningMessage = warningMessage + ".<BR>" + mileageWarning;}
}
//4. months in service less than six months
java.sql.Date rentDate = new java.sql.Date(0);
if( !"0001-01-01".equals(VDTO.getD_VHCL_IN_SERV().toString())
&& !"9999-12-31".equals(VDTO.getD_VHCL_IN_SERV().toString())
&& !"1969-12-31".equals(VDTO.getD_VHCL_IN_SERV().toString()) ){
rentDate = VDTO.getD_VHCL_IN_SERV();
}
else{
rentDate = VDTO.getD_WARR_STRT() ;
}
int inServiceDays = (int) (today.getTime()/1000 -rentDate.getTime()/1000)/(3600*24); appLogger.debug(" rentDate"+rentDate+ " inServiceDays" + inServiceDays +" VDTO.getD_WARR_STRT()"+VDTO.getD_WARR_STRT() + " VDTO.getD_VHCL_IN_SERV()" + VDTO.getD_VHCL_IN_SERV()); if (inServiceDays < 180) {
if(WCCOK){warningMessage = warningMessage + ".<BR>" + monthWarning;}
}
}
//3. check mileage less than previous reported
if( "K".equals(odomtype) && "M".equals(VDTO.getC_ODOM_TYP()) ){
if (odom < VDTO.getQ_MILG_REPTD_LAST()*1.609 ) {
if(WCCOK){warningMessage = warningMessage + ".<BR>" + mileageWarning2;}
}
} else if( "M".equals(odomtype) && "K".equals(VDTO.getC_ODOM_TYP()) ){
if (odom *1.609 < VDTO.getQ_MILG_REPTD_LAST() ) {
if(WCCOK){warningMessage = warningMessage + ".<BR>" + mileageWarning2;}
}
} else{
if (odom < VDTO.getQ_MILG_REPTD_LAST() ) {
if(WCCOK){warningMessage = warningMessage + ".<BR>" + mileageWarning2;}
}
}
appLogger.debug("warningMessage="+warningMessage);
// update the datas
if("Y".equals(transfer) )
{
appLogger.debug("MT: Start DB update");
int I_LINE_SEQ = VDAO.getSVEHNAR(VDTO.getI_PRTITN(),VDTO.getI_VHCL_SAN(),appLogger);
double odomSave = odom ;
if( "K".equals(odomtype)){ odomSave = odom/1.609;}
String webUpdSQLs = " INSERT INTO S.SWEBUPD (I_PRTITN,I_VHCL_SAN,T_STMP_UPD,I_VIN,C_SVEHCLM_FLAG,C_SVEHWAR_FLAG,X_NARR_VEH_DESC) VALUES ("
+ VDTO.getI_PRTITN() + "," + VDTO.getI_VHCL_SAN() + ",CURRENT TIMESTAMP,'" + VDTO.getI_VIN();
String vehNar1 ="Mkt Veh Registered updated From C to U; "
+ "DATE FROM "+VDTO.getD_ODOM_CONV()+" TO "+ today ;
String vehNar2 ="Odom Last Repair upd From "+VDTO.getQ_MILG_REPTD_LAST()+" to "+(int)odomSave+"; "
+ "DATE "+VDTO.getD_VHCL_MILG_LAST()+" TO "+ today ;
String vehNar3 ="Current Odom Type updated From K to M; "
+ "DATE FROM "+VDTO.getD_ODOM_CONV()+" TO "+ today ;
VDAO.updVEHCLM(today.toString(),(int)odomSave,N_CMPTRPGM,SID,VDTO.getI_PRTITN(),VDTO.getI_VHCL_SAN(),appLogger);
I_LINE_SEQ++;
VDAO.updVEHNAR(VDTO.getI_PRTITN(),VDTO.getI_VHCL_SAN(),N_CMPTRPGM,SID,I_LINE_SEQ,vehNar1,appLogger);
I_LINE_SEQ++;
VDAO.updVEHNAR(VDTO.getI_PRTITN(),VDTO.getI_VHCL_SAN(),N_CMPTRPGM,SID,I_LINE_SEQ,vehNar2,appLogger);
I_LINE_SEQ++;
VDAO.updVEHNAR(VDTO.getI_PRTITN(),VDTO.getI_VHCL_SAN(),N_CMPTRPGM,SID,I_LINE_SEQ,vehNar3,appLogger);
VDAO.updWEBUPD(VDTO.getI_PRTITN(),VDTO.getI_VHCL_SAN(),VDTO.getI_VIN(),"Y","Y",vehNar1,appLogger);
VDAO.updWEBUPD(VDTO.getI_PRTITN(),VDTO.getI_VHCL_SAN(),VDTO.getI_VIN(),"N","N",vehNar2,appLogger);
VDAO.updWEBUPD(VDTO.getI_PRTITN(),VDTO.getI_VHCL_SAN(),VDTO.getI_VIN(),"N","N",vehNar3,appLogger);
//update WCC
int WCC ;
appLogger.debug("TT="+VDTO.getT_STMP_BLT_WARR().toString());
appLogger.debug("TT1="+date20030930.toString());
if(VDTO.getC_CURR_WCC() == 795 && VDTO.getT_STMP_BLT_WARR().before(date20030930))
{
WCC = 770;
} else if(VDTO.getC_CURR_WCC() == 795)
{
WCC = 333;
}else if(VDTO.getC_CURR_WCC() == 796 && VDTO.getT_STMP_BLT_WARR().before(date20030930))
{
WCC = 710;
}else if(VDTO.getC_CURR_WCC() == 796)
{
WCC = 334;
} else if(VDTO.getC_CURR_WCC() == 395 || VDTO.getC_CURR_WCC() == 595)
{
WCC = 333;
} else if(VDTO.getC_CURR_WCC() == 396 || VDTO.getC_CURR_WCC() == 596)
{
WCC = 334;
} else if(VDTO.getC_CURR_WCC() == 397 || VDTO.getC_CURR_WCC() == 597)
{
WCC = 335;
} else if(VDTO.getC_CURR_WCC() == 510 || VDTO.getC_CURR_WCC() == 571)
{
WCC = 336;
} else if(VDTO.getC_CURR_WCC() == 516 || VDTO.getC_CURR_WCC() == 572)
{
WCC = 300;
} else
{
WCC= VDTO.getC_CURR_WCC();
}
appLogger.debug("MT: WCC "+VDTO.getC_CURR_WCC()+ " --> "+WCC);
//skip WCC 336
if (VDTO.getC_CURR_WCC() != 336) {
VDAO.UpdWCC(VDTO,WCC,today,odomSave,SID,appLogger);
String wccNar = "WCC UPDATED FROM "+ VDTO.getC_CURR_WCC() +" TO "+ WCC +"; "
+ "DATE FROM "+VDTO.getD_COVRG_CURR_EFF().toString()+" TO "+ today +"";
I_LINE_SEQ++;
VDAO.updVEHNAR(VDTO.getI_PRTITN(),VDTO.getI_VHCL_SAN(),N_CMPTRPGM,SID,I_LINE_SEQ,wccNar,appLogger);
VDAO.updWEBUPD(VDTO.getI_PRTITN(),VDTO.getI_VHCL_SAN(),VDTO.getI_VIN(),"N","N",wccNar,appLogger);
}
}
conn.commit();
NEWVDTO = VDAO.getWarranty(VINWhere, appLogger);
appLogger.debug("MT:end of DB update");
}
/// End of Get vehicle information
request.setAttribute("VDTO", VDTO);
request.setAttribute("NEWVDTO", NEWVDTO);
request.setAttribute("warningMessage", warningMessage);
// getServletConfig().getServletContext().getRequestDispatcher(JSP_PAGE).forward(request,response) ;
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(JSP_PAGE);
appLogger.debug("OK Before call dispatcher: " + dispatcher.toString());
dispatcher.forward(request, response);
}
// if print the pdf
else
{
MTAckPDF AckDao =
new MTAckPDF(
GCS_PDF_FONT_PATH,
request.getParameter("vin"),
request.getParameter("desc"),
request.getParameter("mktOld"),
request.getParameter("WCCOld"),
request.getParameter("odomOld"),
request.getParameter("odomtypeOld"),
request.getParameter("mktNew"),
request.getParameter("WCCNew"),
request.getParameter("odomNew"),
request.getParameter("odomtypeNew"),
defaultDate.format(today).toString(),
request.getParameter("year"),
request.getParameter("desc")
);
ByteArrayOutputStream ba = AckDao.generateReport(null);
if (ba != null) {
response.setContentType("application/pdf");
response.setContentLength(ba.size());
response.setHeader("Cache-Control","max-age=5");
ServletOutputStream output = response.getOutputStream();
ba.writeTo(output);
output.flush();
appLogger.debug("Print preview done*******************");
return;
}
}
}catch ( SQLException se ) {
request.setAttribute("errorMessage", se.toString());
appLogger.error(se.toString());
try {
conn.rollback();
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(JSP_PAGE);
appLogger.error("SEQException block,Before call dispatcher " + se.toString());
dispatcher.forward(request, response);
}catch (Exception ec)
{
appLogger.error("SQLException Can not dispatch:"+ec.toString());
}
} catch (Exception e) {
request.setAttribute("errorMessage", e.toString());
e.printStackTrace();
try {
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(JSP_PAGE);
appLogger.error("Exception block,Before call dispatcher "+ JSP_PAGE+" " +e.toString());
e.printStackTrace();
dispatcher.forward(request, response);
}catch (Exception ec)
{
ec.printStackTrace();
appLogger.error("Exception Can not dispatch:"+ec.toString());
}
} finally {
try {
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception ce) {
appLogger.error("Close con failed");
}
}
}
}Editor is loading...
Leave a Comment