package ibase.webitm.ejb.sys;

import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

import javax.naming.InitialContext;

import org.w3c.dom.Document;

import ibase.system.config.AppConnectParm;
import ibase.system.config.ConnDriver;
import ibase.utility.BaseLogger;
import ibase.utility.E12GenericUtility;
import ibase.utility.GenericUtility;
import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.ActionHandlerEJB;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.MasterStatefulLocal;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;

public class ManageSqlReleaseToQC extends ActionHandlerEJB{
	
	E12GenericUtility genericUtility = new E12GenericUtility();
	public String updateStatus()throws RemoteException,ITMException
	{
		return "";
	}
	
	public String updateStatus(String tranID, String xtraParams, String forcedFlag) throws RemoteException,ITMException
	{
		ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();

		String retVal = "";
		String refSer = "";
		String signStatus = "";
		String enterprises1 = "";
		boolean isLocalConn = false;
		PreparedStatement mSqlPstmt = null;
		ResultSet mSqlRs = null;
		PreparedStatement mSqlDetPstmt = null;
		ResultSet mSqlDetRs = null;
		String empCode = "";
		String entityCode = "",reportTo="",allocatedTo;
		LocalDate tranDate = LocalDate.now();// for tranDate
		LocalTime tranTime = LocalTime.now();
		String tranDateStr = formatDateTime(tranDate, tranTime);
		String tranId = "";
		String reqId = "";
		String custCode = "";
		String empCodeGiven = "";
		String empCodeMerge = "";
		String executed = "";
		String tranIdOrg = "";
		String activeYn = "";
		String itmVer = "";
		String chgUser = "";
		String chgTerm = "";
		String confirmed = "";
		String empCodeAprv = "";
		String enterprises = "";
		String applDb = "";
		String execRights = "";
		String tranIdRef = "";
		String signRemarks = "";
		String db2Statement = "";
		String lineNo = "";
		String oracleStatement = "";
		String statementType = "";
		//InitialContext ctx = null;
		String retString = null;
		String executionRights = "";
		String remarks = "";
		Connection conn = null;
//		MasterStatefulLocal masterStateful = null; // for ejb3
		
		try
		{
		    UserInfoBean userInfo = getUserInfo(); 
		    BaseLogger.log("3", null, null, "userInfo 91::" +  userInfo.toString() + "]");
			
			if (conn == null)
			{
				ConnDriver connDriver = new ConnDriver();
				conn = connDriver.getConnectDB(userInfo.getTransDB());
			}
			//
			int existingAprvLvl = 0;
			int qcTranCount = 0;
			String executiveApproval = "";
			String tranIdRefForVal = "";
			String wfStatus = "";
			String review = "";
			String txnStatus = "";



			String getAprvLvlSql = "select APRV_LEVEL,EXEC_APRV,TRAN_ID__REF,WF_STATUS, REVIEW_YN, TXN_STATUS from sql_changes where tran_id = ?";
			PreparedStatement getAprvLvlPs = conn.prepareStatement(getAprvLvlSql);
			getAprvLvlPs.setString(1, tranID);
			ResultSet getAprvLvlRs = getAprvLvlPs.executeQuery();
			while (getAprvLvlRs.next()) {
				existingAprvLvl = getAprvLvlRs.getInt("APRV_LEVEL");
				executiveApproval = checkNull(getAprvLvlRs.getString("EXEC_APRV"));
				tranIdRefForVal = checkNull(getAprvLvlRs.getString("TRAN_ID__REF"));
				wfStatus = checkNull(getAprvLvlRs.getString("WF_STATUS"));
				review = checkNull(getAprvLvlRs.getString("REVIEW_YN"));
				txnStatus = checkNull(getAprvLvlRs.getString("TXN_STATUS"));

			}

			 if (getAprvLvlRs != null) { getAprvLvlRs.close(); }
    	    if (getAprvLvlPs != null) { getAprvLvlPs.close(); }
			BaseLogger.log("3", null, null, "existingAprvLvl::" +  existingAprvLvl + "]");
			BaseLogger.log("3", null, null, "executeRights::" +  executiveApproval + "]");
			BaseLogger.log("3", null, null, "review::" +  review + "]");
			BaseLogger.log("3", null, null, "txnStatus::" +  txnStatus + "]");
            BaseLogger.log("3", null, null, "tranIdRefForVal::" +  tranIdRefForVal + "]");

			if(!review.trim().equalsIgnoreCase("N")){
				if(!txnStatus.trim().equalsIgnoreCase("N")){
				    BaseLogger.log("3", null, null, "Transaction not reviewed");
					return itmDBAccessEJB.getErrorString("", "MSQLNR", "", "", conn);
				}
			}


			String checkQcTranCountSql = "select count(tran_id) as qcTranCount from sql_changes where tran_id__ref = ?";
             PreparedStatement checkQcTranCountPs = conn.prepareStatement(checkQcTranCountSql);
			checkQcTranCountPs.setString(1, tranIdRefForVal);
			ResultSet checkQcTranCountRs = checkQcTranCountPs.executeQuery();
			while (checkQcTranCountRs.next()) {
				qcTranCount = checkQcTranCountRs.getInt("qcTranCount");

			}
            if (checkQcTranCountPs != null) { checkQcTranCountPs.close(); }
    	    if (checkQcTranCountRs != null) { checkQcTranCountRs.close(); }

			if(existingAprvLvl>2) {
				return itmDBAccessEJB.getErrorString("", "MSQLARQC", "", "", conn);
			}

			else if (wfStatus.trim().equalsIgnoreCase("R")) {
					BaseLogger.log("3", null, null, "Workflow is rejected");

					return itmDBAccessEJB.getErrorString("", "MSQLWFR", "", "", conn);

				}
			else if (executiveApproval.trim().equalsIgnoreCase("Y")) {

				if (!wfStatus.trim().equalsIgnoreCase("A")) {
					BaseLogger.log("3", null, null, "Workflow not approved");

					return itmDBAccessEJB.getErrorString("", "MSQLWNA", "", "", conn);

				}
			}
			else if(existingAprvLvl<1){
				BaseLogger.log("3", null, null, "Transaction is no processed");
				return itmDBAccessEJB.getErrorString("", "MSQLNPROC", "", "", conn);

			}
			else if(qcTranCount>0){
				BaseLogger.log("3", null, null, "Transaction already created for the QC");
				return itmDBAccessEJB.getErrorString("", "MSQLARQC", "", "", conn);
			}
			else{
				if(executiveApproval.trim().equalsIgnoreCase("Y")){
				String updateSqlTxnStatus = "update sql_changes set txn_status = 'K' where tran_id = ?";
                PreparedStatement updateSqlTxnStatusPs = conn.prepareStatement(updateSqlTxnStatus);
			    updateSqlTxnStatusPs.setString(1, tranID);
			    int updateTxnStatusCount = updateSqlTxnStatusPs.executeUpdate();
			    BaseLogger.log("3", null, null, "updateTxnStatusCount::" +  updateTxnStatusCount + "]");
				}

				

			}
			
			//
			//ValidatorEJB validatorEJB = new ValidatorEJB();
	
//            CommonDBAccessEJB commonDBAccessEJB = new CommonDBAccessEJB();
			//AppConnectParm appConnect = new AppConnectParm();
			//ctx = new InitialContext(appConnect.getProperty());
//			masterStateful = (MasterStatefulLocal)ctx.lookup("ibase/MasterStatefulEJB/local");
			
			AppConnectParm appConnect = new AppConnectParm();
			InitialContext initialContext = new InitialContext(appConnect.getProperty());
			
			System.out.println("ManageSQLAprv.updateWFStatus() tranId testtttttttt["+tranID+"]");
			System.out.println("ManageSQLAprv.updateWFStatus() xtraParams testtttttttt["+xtraParams+"]");

			

		
			
			
			String msqlDetSql = "SELECT TRAN_ID, TRAN_DATE, REQ_ID, REQ_DATE, CUST_CODE, EMP_CODE__GIVEN, EMP_CODE__MERGE, "
			        + "EXECUTED, TRAN_ID__ORG, ACTIVE_YN, ITM_VER, CHG_USER, CHG_TERM, CHG_DATE, CONFIRMED, CONF_DATE, "
			        + "EMP_CODE_APRV, ENTERPRISES, APPL_DB, EXEC_RIGHTS, TRAN_ID__REF, REMARKS "
			        + "FROM sql_changes where tran_id = ?";

			 mSqlPstmt = conn.prepareStatement(msqlDetSql);
			 mSqlPstmt.setString(1, tranID);
			 mSqlRs = mSqlPstmt.executeQuery();

			while (mSqlRs.next()) {
			    // Directly fetching and using values from result set without declaring variables
				 tranId = checkNull(mSqlRs.getString("TRAN_ID")); 
                 reqId = checkNull(mSqlRs.getString("REQ_ID"));
                 custCode = checkNull(mSqlRs.getString("CUST_CODE"));
                 empCodeGiven = checkNull(mSqlRs.getString("EMP_CODE__GIVEN"));
                 empCodeMerge = checkNull(mSqlRs.getString("EMP_CODE__MERGE"));
                 executed = checkNull(mSqlRs.getString("EXECUTED"));
                 tranIdOrg = checkNull(mSqlRs.getString("TRAN_ID__ORG"));
                 activeYn = checkNull(mSqlRs.getString("ACTIVE_YN"));
                 itmVer = checkNull(mSqlRs.getString("ITM_VER"));
                 chgUser = checkNull(mSqlRs.getString("CHG_USER"));
                 chgTerm = checkNull(mSqlRs.getString("CHG_TERM"));
                 confirmed = checkNull(mSqlRs.getString("CONFIRMED"));
                 empCodeAprv = checkNull(mSqlRs.getString("EMP_CODE_APRV"));
                 enterprises = checkNull(mSqlRs.getString("ENTERPRISES"));
                 applDb = checkNull(mSqlRs.getString("APPL_DB"));
                 execRights = checkNull(mSqlRs.getString("EXEC_RIGHTS"));
                 tranIdRef = checkNull(mSqlRs.getString("TRAN_ID__REF"));
                 remarks = checkNull(mSqlRs.getString("REMARKS"));

			    // Do something with these values directly (e.g., use them in logic, or store in a collection)
			    
			    System.out.println("TRAN_ID: " + tranId + ", " +
	                       "TRAN_DATE: " + tranDate + ", " +
	                       "REQ_ID: " + reqId + ", " +
	                       "CUST_CODE: " + custCode + ", " +
	                       "EMP_CODE__GIVEN: " + empCodeGiven + ", " +
	                       "EMP_CODE__MERGE: " + empCodeMerge + ", " +
	                       "EXECUTED: " + executed + ", " +
	                       "TRAN_ID__ORG: " + tranIdOrg + ", " +
	                       "ACTIVE_YN: " + activeYn + ", " +
	                       "ITM_VER: " + itmVer + ", " +
	                       "CHG_USER: " + chgUser + ", " +
	                       "CHG_TERM: " + chgTerm + ", " +
	                       "CONFIRMED: " + confirmed + ", " +
	                       "EMP_CODE_APRV: " + empCodeAprv + ", " +
	                       "ENTERPRISES: " + enterprises + ", " +
	                       "APPL_DB: " + applDb + ", " +
	                       "EXEC_RIGHTS: " + execRights + ", " +
	                       "REMARKS: " + remarks + ", " +
	                       "TRAN_ID__REF: " + tranIdRef);
			}
			
			
			
			
			
			StringBuffer processDynXmlString = new StringBuffer();

			// Start building the XML string
			processDynXmlString.append("<DocumentRoot><description>Datawindow Root</description><group0>");
			processDynXmlString.append(
					"<description>Group0 description</description><Header0><description>Header0 members</description>");
			processDynXmlString.append("<objName><![CDATA[sql_changes]]></objName>");
			processDynXmlString.append("<pageContext><![CDATA[1]]></pageContext>");
			processDynXmlString.append("<objContext><![CDATA[1]]></objContext>");
			processDynXmlString.append("<editFlag><![CDATA[A]]></editFlag>");
			processDynXmlString.append("<focusedColumn><![CDATA[]]></focusedColumn>");
			processDynXmlString.append("<action><![CDATA[SAVE]]></action>");
			processDynXmlString.append("<elementName><![CDATA[]]></elementName>");
			processDynXmlString.append("<keyValue><![CDATA[1]]></keyValue>");
			processDynXmlString.append("<saveLevel><![CDATA[1]]></saveLevel>");
			processDynXmlString.append("<forcedSave><![CDATA[false]]></forcedSave>");
			processDynXmlString.append("<Detail1 dbID='' domID='1'  objContext='1'  objName='sql_changes'>");
			processDynXmlString
					.append("<attribute IS_CHANGE='Y' pkNames='TRAN_ID' selected='N' status='N' updateFlag='A'/>");
			
			
			//processDynXmlString.append("<tran_id/>");
			processDynXmlString.append("<tran_date><![CDATA[" + dateFormatter(tranDateStr) + "]]></tran_date>");
			processDynXmlString.append("<req_id><![CDATA["+ reqId +"]]></req_id>");
			processDynXmlString.append("<req_date><![CDATA[" + dateFormatter(tranDateStr) + "]]></req_date>");
			processDynXmlString.append("<emp_code__given><![CDATA[" + empCodeGiven + "]]></emp_code__given>");
			processDynXmlString.append("<emp_code__merge><![CDATA[" + empCodeMerge + "]]></emp_code__merge>");
			processDynXmlString.append("<executed><![CDATA[N]]></executed>");
			processDynXmlString.append("<tran_id__org><![CDATA[" + tranIdOrg + "]]></tran_id__org>");
			processDynXmlString.append("<active_yn><![CDATA[" + activeYn + "]]></active_yn>");
			processDynXmlString.append("<chg_user><![CDATA[" + chgUser + "]]></chg_user>");
			processDynXmlString.append("<chg_term><![CDATA[" + chgTerm + "]]></chg_term>");
			processDynXmlString.append("<confirmed><![CDATA[N]]></confirmed>");
			processDynXmlString.append("<conf_date><![CDATA[]]></conf_date>");
			processDynXmlString.append("<itm_ver><![CDATA[]]></itm_ver>");
			processDynXmlString.append("<enterprises><![CDATA[{{enterprises}}]]></enterprises>");
			processDynXmlString.append("<emp_code_aprv><![CDATA[]]></emp_code_aprv>");
			processDynXmlString.append("<chg_date><![CDATA[" + dateFormatter(tranDateStr) + "]]></chg_date>");
			processDynXmlString.append("<appl_db><![CDATA[" + applDb + "]]></appl_db>");
			processDynXmlString.append("<exec_rights><![CDATA[{{executionRights}}]]></exec_rights>");
			processDynXmlString.append("<tran_id__ref><![CDATA[" + tranId + "]]></tran_id__ref>");
			processDynXmlString.append("<remarks><![CDATA[" + remarks + "]]></remarks>");
			processDynXmlString.append("</Detail1>");

			String msqlDet1Sql = "SELECT LINE_NO, ORA_STMNT, DB2_STMNT, STMNT_TYPE FROM sql_changes_det WHERE tran_id = ?";
			mSqlDetPstmt = conn.prepareStatement(msqlDet1Sql);
			mSqlDetPstmt.setString(1, tranID);
			mSqlDetRs = mSqlDetPstmt.executeQuery();

			while (mSqlDetRs.next()) {
			     lineNo = checkNull(mSqlDetRs.getString("LINE_NO"));
			     oracleStatement = checkNull(mSqlDetRs.getString("ORA_STMNT"));
			     db2Statement = checkNull(mSqlDetRs.getString("DB2_STMNT"));
			     statementType = checkNull(mSqlDetRs.getString("STMNT_TYPE"));

			    processDynXmlString.append("<Detail2 dbID=':' domID='2' objName=\"sql_changes\" objContext=\"2\">");
			    processDynXmlString.append("<attribute pkNames=\"\" selected=\"N\" updateFlag=\"A\" status=\"N\" />");
			    processDynXmlString.append("<line_no><![CDATA[").append(lineNo).append("]]></line_no>");
			    processDynXmlString.append("<ora_stmnt><![CDATA[").append(oracleStatement).append("]]></ora_stmnt>");
			    processDynXmlString.append("<db2_stmnt><![CDATA[").append(db2Statement).append("]]></db2_stmnt>");
			    processDynXmlString.append("<stmnt_type><![CDATA[").append(statementType).append("]]></stmnt_type>");
			    processDynXmlString.append("</Detail2>");
			}

			if (mSqlDetRs != null) {
			    mSqlDetRs.close();
			    mSqlDetRs = null;
			}
			if (mSqlDetPstmt != null) {
			    mSqlDetPstmt.close();
			    mSqlDetPstmt = null;
			}

			processDynXmlString.append("</Header0></group0></DocumentRoot>");

			// Now, processDynXmlString contains the dynamically generated XML with the values from your query
			System.out.println(processDynXmlString.toString());
//			String  tranIDNew = commonDBAccessEJB.generateSeq("asset_assign_seq", 10, userInfo.getTransDB());
//		    BaseLogger.log("3", null, null, " generated tranID :: " + tranIDNew); // tran_id
//			processDynXmlString.toString().replace("{{tranId}}", tranIdNew);
			String xmlWithQ = processDynXmlString.toString().replace("{{executionRights}}", "Q");
			xmlWithQ = xmlWithQ.toString().replace("{{enterprises}}", "APPVISQC");
        	BaseLogger.log("3", null, null, "xmlWithQ XML:::" +  xmlWithQ + "]");
			String xmlWithD = processDynXmlString.toString().replace("{{executionRights}}", "D");
//			xmlWithD = xmlWithD.toString().replace("{{enterprises}}", "APPVISDEV");
//        	BaseLogger.log("3", null, null, "userInfo::" +  userInfo.toString() + "]");
        	
        	MasterStatefulLocal masterStateful = (MasterStatefulLocal) initialContext
					.lookup("ibase/MasterStatefulEJB/local"); 
        	
//            String processRequestResultDev = masterStateful.processRequest(userInfo, xmlWithD, false, conn);
//        	BaseLogger.log("3", null, null, "processRequest processRequestResultD" +  processRequestResultDev + "]");
        	
        	masterStateful = null;
        	appConnect = null;
        	initialContext = null;
        	
        	appConnect = new AppConnectParm();
			initialContext = new InitialContext(appConnect.getProperty());
        	masterStateful = (MasterStatefulLocal) initialContext
					.lookup("ibase/MasterStatefulEJB/local"); 
        	
        	String processRequestResultQC = masterStateful.processRequest(userInfo, xmlWithQ, false, conn);
        	BaseLogger.log("3", null, null, "processRequest gsbnice processRequestResultQ" +  processRequestResultQC + "]");
        	GenericUtility genericUtility = new GenericUtility();
        	Document dom = genericUtility.parseString(processRequestResultQC);
			String tranSuccessFlag = checkNull(genericUtility.getColumnValue("Detail",dom));
			if(tranSuccessFlag.trim().equalsIgnoreCase("Success")) {
				Connection conn1 = getConnection();
				String updateAprvLvlSql = "update sql_changes set APRV_LEVEL = '3', TXN_STATUS = 'Q' where tran_id = ?";
				PreparedStatement updateAprvLvlPs = conn1.prepareStatement(updateAprvLvlSql);
				updateAprvLvlPs.setString(1, tranID);
				int updateAprvLvlCnt = updateAprvLvlPs.executeUpdate();	
				conn1.commit();

	        	BaseLogger.log("3", null, null, "updateAprvLvlCnt::" +  updateAprvLvlCnt + "]");
	        	if (updateAprvLvlPs != null) {
	        		updateAprvLvlPs.close();
	        		updateAprvLvlPs = null;
				}
	        	if(conn1!= null) {
	        		conn1.close();
	        		conn1 = null;
	        	}
				return itmDBAccessEJB.getErrorString("", "MSQLRQC", "", "", conn);
			}

			else {
				return itmDBAccessEJB.getErrorString("", "MSQLFQC", "", "", conn);
	
			}
			/*
			 * retString = processRequestResultQC;
			 * 
			 * // Added for PILOT transaction -- START // Fetch DB_PILOT from ENTERPRISE
			 * table to use as the enterprise for the PILOT transaction String
			 * dbPilotEnterprise = ""; Connection pilotEntConn = null; PreparedStatement
			 * pilotPstmt = null; ResultSet pilotRs = null; try { ConnDriver pilotConnDriver
			 * = new ConnDriver(); pilotEntConn = pilotConnDriver.getConnectDB("Driver");
			 * 
			 * // Use the first enterprise from the original transaction to look up DB_PILOT
			 * String entForLookup = enterprises; if (entForLookup.contains(",")) {
			 * entForLookup = entForLookup.split(",")[0].trim(); }
			 * 
			 * String pilotSql = "SELECT DB_PILOT FROM ENTERPRISE WHERE ENTERPRISE = ?";
			 * pilotPstmt = pilotEntConn.prepareStatement(pilotSql); pilotPstmt.setString(1,
			 * entForLookup); pilotRs = pilotPstmt.executeQuery(); if (pilotRs.next()) {
			 * dbPilotEnterprise = checkNull(pilotRs.getString("DB_PILOT")); } } finally {
			 * if (pilotRs != null) { pilotRs.close(); } if (pilotPstmt != null) {
			 * pilotPstmt.close(); } if (pilotEntConn != null) { pilotEntConn.close(); } }
			 * 
			 * BaseLogger.log("3", null, null, "DB_PILOT enterprise fetched: [" +
			 * dbPilotEnterprise + "]");
			 * 
			 * if (!dbPilotEnterprise.isEmpty()) { // Create PILOT XML with exec_rights =
			 * "P" and enterprise from DB_PILOT column String xmlWithP =
			 * processDynXmlString.toString().replace("{{executionRights}}", "P"); xmlWithP
			 * = xmlWithP.replace("{{enterprises}}", enterprises); BaseLogger.log("3", null,
			 * null, "xmlWithP XML:::" + xmlWithP + "]");
			 * 
			 * masterStateful = null; appConnect = null; initialContext = null;
			 * 
			 * appConnect = new AppConnectParm(); initialContext = new
			 * InitialContext(appConnect.getProperty()); masterStateful =
			 * (MasterStatefulLocal) initialContext
			 * .lookup("ibase/MasterStatefulEJB/local");
			 * 
			 * String processRequestResultPilot = masterStateful.processRequest(userInfo,
			 * xmlWithP, false, conn); BaseLogger.log("3", null, null,
			 * "processRequest processRequestResultPilot" + processRequestResultPilot +
			 * "]");
			 * 
			 * retString = processRequestResultPilot; } else { BaseLogger.log("3", null,
			 * null, "DB_PILOT is empty, skipping PILOT transaction creation."); }
			 */
        	// Added for PILOT transaction -- END
			
		}
		catch(Exception e)
		{
			BaseLogger.log("3", null, null, "Exception 1746. [" + E12GenericUtility.getStackTrace(e) + "]");
			throw new ITMException(e);
		}
		finally {
		    try {
		        if (mSqlRs != null) mSqlRs.close();
		        if (mSqlPstmt != null) mSqlPstmt.close();
		        if (mSqlDetRs != null) mSqlDetRs.close();
		        if (mSqlDetPstmt != null) mSqlDetPstmt.close();

		        if (conn != null) {
		            conn.close();  // returns to pool
		        }
		    } catch(Exception e) {
				BaseLogger.log("3", null, null, "Exception 1746. [" + E12GenericUtility.getStackTrace(e) + "]");
		    }
		}
		//return retString;
	}
	 public static String formatDateTime(LocalDate tranDate, LocalTime tranTime) {
			LocalDateTime tranDateTime = LocalDateTime.of(tranDate, tranTime);
			DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
			String formattedDateTime = tranDateTime.format(formatter);
			return formattedDateTime;
		}
	 
	    public static String dateFormatter(String inputDateString ) {
			String result = "";
	        String inputFormat = "yyyy-MM-dd HH:mm:ss";
	        String outputFormat = "dd/MM/yy HH:mm:ss";

	        try {
	            // Parse input date string
	            SimpleDateFormat inputFormatter = new SimpleDateFormat(inputFormat);
	            Date date = inputFormatter.parse(inputDateString);

	            // Format the date in the desired output format
	            SimpleDateFormat outputFormatter = new SimpleDateFormat(outputFormat);
	            String outputDateString = outputFormatter.format(date);

	            System.out.println("Input Date: " + inputDateString);
	            System.out.println("Formatted Date: " + outputDateString);
	            result = outputDateString;

	        } catch (Exception e) {
	        	BaseLogger.log("3", null, null, "Exception in dateFormatter. [" +  E12GenericUtility.getStackTrace(e) + "]");
	        }
	        return result;
		}
	    
	    private void closeResources(ResultSet rs, PreparedStatement pstmt, Connection conn) {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (pstmt != null) {
				try {
					pstmt.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (conn != null) {
				try {
					conn.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	    
		private String checkNull(String input)
		{
			if(input == null)
			{
				input = "";
			}
			return input;
		}
}
