Java tutorial
//****************************************************************************** // THE SOFTWARE COMPRISING THIS SYSTEM IS THE PROPERTY OF ELECTRONIC DATA // SYSTEMS CORP. OR ITS LICENSORS. // // ALL COPYRIGHT, PATENT, TRADE SECRET, AND OTHER INTELLECTUAL PROPERTY RIGHTS // IN THE SOFTWARE COMPRISING THIS SYSTEM ARE, AND SHALL REMAIN, THE VALUABLE // PROPERTY OF ELECTRONIC DATA SYSTEMS CORP. OR ITS LICENSORS. // // USE, DISCLOSURE, OR REPRODUCTION OF THIS SOFTWARE IS STRICTLY PROHIBITED, // EXCEPT UNDER WRITTEN LICENSE FROM ELECTRONIC DATA SYSTEMS CORP. OR ITS // LICENSORS. // // (C) COPYRIGHT 1999, 2000 ELECTRONIC DATA SYSTEMS CORP. ALL RIGHTS RESERVED //****************************************************************************** //****************************************************************************** // $Log: // IGA change Aug 2003 Steve Eaton // Added previous file name check to open(). This allows pending to file if // previous file name is the same as current file name. Otherwise the file is // overwritten. // // CSST509 Sep 2002 David LaRocque // Change the file extension from EXE to RPT to allow for the delivery // of the reports. The EXE files are being filtered. This is a short-term solution // until another delivery mechanism is implemented. // // Rev 3.0 Apr 2001 JFG // Added override agent id // // Rev 2.4 July 2000 BDL // Add exportPending method that will export pending cases within the same thread. // This is used by the WAutoExportPending process. // // Rev 2.3 Mar 2000 JFG // Moved open,write and close ini methods up to the exporter from the exporter thread. // Allows us to write to the ini files from the exporter themselves. // // Rev 2.2 Mar 2000 JFG // Added getAllPendingCases. // // Rev 2.1 Feb 2000 WAT // Log completed exports. Combined some background specific functions with foregrounds. // // Rev 2.0 Oct 1999 JFG // Added support for Quickview. // // Rev 1.2 Sep 1999 JFG // Added last update date and time. // // Rev 1.1 Jun 1999 JFG // Expanded for NAILBA Pending Download // // Rev 1.0 Feb 1999 WAT // Initial revision. //****************************************************************************** package com.ing.connector.interfaces; import java.text.*; import java.io.*; import java.util.*; import org.apache.commons.lang.NumberUtils; import com.ing.connector.model.*; import com.ing.connector.util.WObjectKeys; import com.ing.connector.util.WResult; import com.ing.connector.util.WStringUtil; public class WExporter { public WExporter() { } protected void finalize() { //delete the filename if it still exists if (m_fileName == null) return; try { if (m_fileName.indexOf(".exe") >= 0) { File file = new File(m_fileName); file.delete(); } //CSST509 added if (m_fileName.indexOf(".rpt") >= 0) { File file = new File(m_fileName); file.delete(); } } catch (Exception exc) { } return; } public synchronized int getUniqueNumber() { //increments, then returns a class variable. Used to uniquely name files m_uniqueNumber++; return m_uniqueNumber; } //public void setPolicies(String polNum) //{ // m_agent.setPolicies(polNum); //} public void setPolicyKeys(Vector keys) { m_policyKeys = keys; } public void setPolicyKeys(String str, String delim) { m_policyKeys = new Vector(); // need to tokenize the string to handle multiple keys m_policyKeys.addElement(str); } public void setPolicy(WPolicyExt obj) { m_policy = obj; } public WPolicyExt getPolicy() { if (m_policy == null) { WResult result = null; WObjectKeys keys = new WObjectKeys(null); keys.addKey("xxxxx"); result = (WResult) WFactory.getObject("WPolicyExt", keys); m_policy = (WPolicyExt) result.getModelObject(); } return m_policy; } public void setPendingCase(WPendingCaseExt obj) { m_pendingCase = obj; } public WPendingCaseExt getPendingCase() { if (m_pendingCase == null) { //??; } return m_pendingCase; } public void setPendingCases(WCollection obj) { m_pendingCases = obj; } public WCollection getPendingCases() { if (m_pendingCases == null) { //m_pendingCases = getAgent().getPendingCases(); } return m_pendingCases; } public void setAgent(WAgentExt obj) { m_agent = obj; } public WAgentExt getAgent() { if (m_agent == null) { //??; } return m_agent; } public void setAgencyId(String AgencyId) { m_agencyId = AgencyId; } public String getAgencyId() { return m_agencyId; } // JFG1990614 added public void setDownloadDate(String DownloadDate) { Date dt = null; ParsePosition pos = new ParsePosition(0); dt = formatter.parse(DownloadDate, pos); Calendar cal = Calendar.getInstance(); cal.setTime(dt); cal.set(Calendar.HOUR_OF_DAY, 3); //03:00 hours is what the old jdk set it to dt = cal.getTime(); m_downloadDate = new WDate(dt); } // JFG1990614 added public WDate getDownloadDate() { return m_downloadDate; } public void setDownloadType(String DownloadType) { m_downloadType = DownloadType; } // JFG1990614 added public String getDownloadType() { return m_downloadType; } public void setLogonId(String LogonId) //Erik D. 6/27/2006 { m_logonId = LogonId; } public String getLogonId() //Erik D. 6/27/2006 { return m_logonId; } public void setIdName(String idName) //Erik D. 6/27/2006 { m_idName = idName; } public String getIdName() //Erik D. 6/27/2006 { return m_idName; } public void setAgents(WCollection obj) { m_agents = obj; } // JFG1990614 added public WCollection getAgents() { if (m_agents == null) { WObjectKeys keys = new WObjectKeys(m_agent); keys.addKey(getCompanyId()); keys.addKey(getAgentId()); keys.addKey(getLastUpdateFromDate()); //brb498 keys.addKey(getLastUpdateDate()); //JFG1.2 keys.addKey(getLastUpdateTime()); //JFG1.2 keys.addKey(getSystemSource()); //JFG2.0 keys.addKey(getType()); //JFG2.0 if (getGroups().size() > 0) keys.addKey(m_groups); WResult result = com.ing.connector.model.WFactory.getObject("WAgents", keys); m_agents = (WCollection) result.getModelObject(); com.ing.connector.Registrar.logMessage("inside == null "); } return m_agents; } //JFG1.2 - Added public String getLastUpdateDate() { return m_lastUpdateDate; } public void setLastUpdateDate(String updateDate) { m_lastUpdateDate = updateDate; } //brb498 public String getLastUpdateFromDate() { return m_lastUpdateFromDate; } public void setLastUpdateFromDate(String updateDate) { m_lastUpdateFromDate = updateDate; } //JFG1.2 - Added public String getLastUpdateTime() { return m_lastUpdateTime; } public void setLastUpdateTime(String updateTime) { m_lastUpdateTime = updateTime; } //JFG2.0 - Added public String getSystemSource() { return m_systemSource; } public void setSystemSource(String systemSource) { m_systemSource = systemSource; } //JFG2.0 - Added public String getType() { return m_type; } //JFG2.0 - Added public void setType(String code) { m_type = code; } //JFG5.0 added public String getOverrideAgentId() { return m_overrideAgentId; } public void setOverrideAgentId(String id) { m_overrideAgentId = WStringUtil.trim(id); } //JFG2.2 - Added public WCollection getAllPendingCases() { if (m_pendingCases == null) { WObjectKeys keys = new WObjectKeys(m_pendingCases); keys.addKey(getCompanyId()); keys.addKey(getAgentId()); keys.addKey(getLastUpdateFromDate()); //brb498 keys.addKey(getLastUpdateDate()); keys.addKey(getLastUpdateTime()); keys.addKey("GA"); keys.addKey(getSystemSource()); keys.addKey(getType()); keys.addKey(getOverrideAgentId()); //JFG5.0 if (getGroups().size() > 0) keys.addKey(m_groups); //SixSigma:RL-3066: keys.addKey("");//Empty keys.addKey("N"); // Passing 12 th params for batch //SixSigma:RL-3066: WResult result = com.ing.connector.model.WFactory.getObject("WPendingCases", keys); m_pendingCases = (WCollection) result.getModelObject(); } return m_pendingCases; } /* * RL-003632 * This method is called from PendingDownload Batch cycle only. * We will pass batchdownload to Y. The Stored Proc will * use row_last_update_date to filter out the pendingcases. */ public WCollection getAllPendingCases4Batch() { String batchdownload = "Y"; //y means yes if (m_pendingCases == null) { WObjectKeys keys = new WObjectKeys(m_pendingCases); keys.addKey(getCompanyId()); keys.addKey(getAgentId()); keys.addKey(getLastUpdateFromDate()); keys.addKey(getLastUpdateDate()); keys.addKey(getLastUpdateTime()); keys.addKey("GA"); keys.addKey(getSystemSource()); keys.addKey(getType()); keys.addKey(getOverrideAgentId()); keys.addKey(getGroups()); keys.addKey("");//Empty keys.addKey(batchdownload); // Passing 12 th params for batch WResult result = com.ing.connector.model.WFactory.getObject("WPendingCases", keys); m_pendingCases = (WCollection) result.getModelObject(); } return m_pendingCases; } // JFG1990614 added public WCollection getGroups() { if (m_groups == null) { WObjectKeys keys = new WObjectKeys(m_agent); keys.addKey(getCompanyId()); keys.addKey(getAgentId()); WResult result = com.ing.connector.model.WFactory.getObject("WGroups", keys); m_groups = (WCollection) result.getModelObject(); } return m_groups; } // JFG1990614 added public String getCompanyId() { return m_companyId; } public void setCompanyId(String companyId) { m_companyId = companyId; } // JFG1990614 added public String getAgentId() { return m_agentId; } public void setAgentId(String id) { m_agentId = WStringUtil.trim(id); } public void setFileName(String str) { m_fileName = str; } public String getFileName() { return m_fileName; } // JFG1990614 added, WAT000218 removed //public void setFileNameBackground(String str) //{ // m_fileNameBackground = str; //} //public String getFileNameBackground() //{ // return m_fileNameBackground; //} public String getFtpRoot() { WFtp ftp = new WFtp(); return ftp.getFtpRoot(); } public String getShortFileName() { if (m_fileName == null) return ""; int lastSep = m_fileName.lastIndexOf(File.separator); if (lastSep >= 0) return m_fileName.substring(lastSep + 1, m_fileName.length()); else return m_fileName; } public void setShortFileName(String str) { String path = this.getFilePath(); if (path.length() == 0 || path.endsWith(File.separator)) m_fileName = path + str; else m_fileName = path + File.separator + str; } public String getFilePath() { if (m_fileName == null) return ""; int lastSep = m_fileName.lastIndexOf(File.separator, m_fileName.length() - 1); if (lastSep >= 0) return m_fileName.substring(0, lastSep); else return ""; } public void setExportType(String str) { m_exportType = str; } // Added by SXL for RL_010156 - START public void setMaxUpdateDate(WDate maxUpdateDate) { m_max_update_date = maxUpdateDate; } public WDate getMaxUpdateDate() { return m_max_update_date; } public int getPendingCaseCount() { return m_pendingCaseCount; } public void setPendingCaseCount(int mPendingCaseCount) { m_pendingCaseCount = mPendingCaseCount; } // Added by SXL for RL_010156 - END public void setFieldDelimiter(String str) { m_fieldDelimiter = str; } public String getFieldDelimiter() { return m_fieldDelimiter; } public boolean useAsciiFile() { if (m_exportType == "A" || m_exportType == "T") return true; return false; } public boolean useDatabase() { if (m_exportType == "D") return true; return false; } /** * export() opens, processes, then closes. The processes is unique for each export */ public boolean export() { if (!this.open()) return false; if (!this.exportRequestedObjects()) { this.close(); return false; } if (!this.close()) return false; com.ing.connector.Registrar.logInfoMessage(getClass().getName() + " exported to " + m_fileName); return true; } // JFG1990614 added public boolean exportBackground() { m_exportThread = new WExportThread(this); return true; } /** * exportPending() opens, gets pending cases, processes, then closes. The processes is unique for each export */ public boolean exportPending(String extractLogFileName) { if (!this.open()) return false; //Added by SXL for RL_010156 - START if (isIntradayDownload && (extractLogFileName != null && extractLogFileName.length() > 10)) { int fileNameIndex = extractLogFileName.lastIndexOf(File.separator); String fileName = extractLogFileName.substring(fileNameIndex); if (fileName.length() > 15) { String intradate = fileName.substring(fileName.indexOf("_") + 1, fileName.indexOf("_") + 15); if (NumberUtils.isNumber(intradate)) { exportDate = new java.util.Date(); } } } // RL_010156 - END //getAllPendingCases(); getAllPendingCases4Batch(); //RL-003632 if (exportDate == null) { exportDate = new java.util.Date(); } if (!this.exportRequestedObjects(extractLogFileName)) { this.close(); return false; } if (!this.close()) return false; return true; } private java.util.Date exportDate = null; public Date getDataFetchCompletionDate() { //exportDate will be Null when running for Commission if (exportDate == null) return new java.util.Date(); else return exportDate; } /** * exportRequestedObjects is overriden for the "meat" of each download. It exports info * from the appropriate requested objects into output objects as needed. */ protected boolean exportRequestedObjects() { return false; } /** * exportRequestedObjects is overridden for the "meat" of each download. * It exports info from the appropriate requested objects into output * objects as needed. */ protected boolean exportRequestedObjects(String autoExtractLogFileName) { return false; } /** * write(String) writes a string to the appropriate device */ public boolean write(String str) { if (this.useAsciiFile()) { try { m_outFile.write(str); } catch (Exception exc) { com.ing.connector.Registrar .logError(getClass().getName() + " errored writing to " + m_fileName + " : " + exc); return false; } } else { // db write may go here return false; } return true; } /** * open() prepares the export device for use */ public boolean open() { if (this.useAsciiFile()) { try { if (m_outFile == null) { m_outFile = new FileWriter(m_fileName); } else { if (m_fileName.equals(m_previousFileName)) { m_outFile = new FileWriter(m_fileName, true); } else { m_outFile = new FileWriter(m_fileName); } } m_previousFileName = m_fileName; } catch (Exception exc) { com.ing.connector.Registrar .logError(getClass().getName() + " failed to open " + m_fileName + " : " + exc); return false; } } else { // db connect would go here return false; } return true; } /** * close() releases the export device */ public boolean close() { if (this.useAsciiFile()) { try { m_outFile.close(); } catch (Exception exc) { com.ing.connector.Registrar .logError(getClass().getName() + " errored closing " + m_fileName + " : " + exc); return false; } } else { // db connect would go here return false; } return true; } public boolean writeIni(String str) { try { m_outIniFile.write(str); } catch (Exception exc) { com.ing.connector.Registrar .logError(getClass().getName() + " errored writing to " + m_iniFileName + " : " + exc); return false; } return true; } public boolean openIni(boolean swAppend) { try { m_outIniFile = new FileWriter(m_iniFileName, swAppend); } catch (Exception exc) { com.ing.connector.Registrar .logError(getClass().getName() + " failed to open " + m_iniFileName + " : " + exc); return false; } return true; } public boolean closeIni() { try { m_outIniFile.close(); } catch (Exception exc) { com.ing.connector.Registrar .logError(getClass().getName() + " errored closing " + m_iniFileName + " : " + exc); return false; } return true; } //************************************************************************** // Properties //************************************************************************** protected WPolicyExt m_policy; protected Vector m_policyKeys; protected WCollection m_inforceCases; protected WCollection m_pendingCases; protected WPendingCaseExt m_pendingCase; protected int m_pendingCaseCount = 0; // Added by SXL for RL_010156 protected WCollection m_agents; protected WAgentExt m_agent; protected String m_lastUpdateFromDate = ""; //brb498 protected String m_lastUpdateDate = ""; //JFG1.8 protected String m_lastUpdateTime = ""; //JFG1.8 protected String m_iniFileName = null; protected FileWriter m_outIniFile; protected String m_exportType = "A"; protected FileWriter m_outFile; //protected FileWriter m_outFileBackground; // JFG1990614 added WAT000218 removed protected String m_fieldDelimiter = ""; protected String m_fileName = "export.txt"; protected String m_previousFileName = ""; //protected String m_fileNameBackground = ""; // JFG1990614 added WAT000218 removed protected String m_agencyId = null; // JFG1990614 added protected String m_downloadType = null; // JFG1990614 added protected String m_logonId = null; protected String m_idName = null; protected WDate m_downloadDate = null; // JFG1990614 added protected WCollection m_groups = null; // JFG1990614 added protected String m_companyId = ""; // JFG1990614 added protected String m_agentId = ""; // JFG1990614 added protected String m_systemSource; // JFG2.0 protected String m_type = ""; // JFG2.0 protected String m_overrideAgentId = ""; //JFG5.0 protected WExportThread m_exportThread = null; // JFG1990614 added private static SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); // JFG1990614 added //static class counter to give a unique number across all //active sessions protected static int m_uniqueNumber = 0; protected WDate m_max_update_date = null; // Added by SXL for RL_010156 protected boolean isIntradayDownload = false; } // JFG1990614 added class WExportThread implements Runnable { public WExportThread(WExporter exporter) { Thread exportThread = new Thread(this); m_exporterThread = exporter; exportThread.start(); } public void run() { m_exporterThread.m_iniFileName = m_exporterThread.getFtpRoot() + File.separator + "P" + m_exporterThread.getAgencyId() + ".ini"; m_exporterThread.openIni(false); m_exporterThread.writeIni("[Start]" + "\r\n"); Date now = new Date(); m_exporterThread.writeIni(now.toString() + "\r\n"); m_exporterThread.closeIni(); if (m_exporterThread.open()) { // m_exporterThread.getAgents(); //JFG2.2 m_exporterThread.getAllPendingCases(); //JFG2.2 if (m_exporterThread.exportRequestedObjects()) { m_exporterThread.close(); m_exporterThread.openIni(true); m_exporterThread.writeIni("[End]" + "\r\n"); com.ing.connector.Registrar.logInfoMessage(m_exporterThread.getClass().getName() + " exported(bkgrnd) to " + m_exporterThread.getFileName()); } else { m_exporterThread.close(); m_exporterThread.openIni(true); m_exporterThread.writeIni("[Failed]" + "\r\n"); } now = new Date(); m_exporterThread.writeIni(now.toString() + "\r\n"); m_exporterThread.closeIni(); } } protected WExporter m_exporterThread = null; }