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: // // CSPS308 Apr 2002 JFG Initialize m_holdSortKey to null instead of // an empty string. Some SLD/SLIC cases have // blank statuses and the empty string was causing // problems with control break logic in WReportSummary. // // Rev 2.0 Aug 2001 AEO LPMO264 - CNB // // Rev 1.1 Sep 2000 RJC // // Rev 1.0 Aug 2000 JFG // Initial revision. //****************************************************************************** package com.ing.connector.report; import java.io.File; import java.io.FileWriter; import java.text.DateFormat; import java.text.DecimalFormat; import java.util.Date; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.Vector; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; import org.apache.pdfbox.pdmodel.font.PDFont; import org.apache.pdfbox.pdmodel.font.PDType1Font; import org.apache.pdfbox.pdmodel.graphics.color.PDGamma; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationLine; import com.ing.connector.interfaces.WFtp; import com.ing.connector.model.WAgentExt; import com.ing.connector.model.WCollection; import com.ing.connector.model.WCompany; import com.ing.connector.model.WDate; import com.ing.connector.model.WPendingCaseExt; import com.ing.connector.server.LookUp; import com.ing.connector.util.FormatUtil; import com.ing.connector.util.WConstants; import com.ing.connector.util.WDateIsoFormat; import com.ing.connector.util.WObjectKeys; import com.ing.connector.util.WResult; import com.ing.connector.util.WStringUtil; //GDB2NY 11/26/08 VXB Starts //GDB2NY 11/26/08 VXB Ends import com.ing.na.cdi.calculator.financial.Financial; public class WReport { Map yPositionAndWidth = new HashMap(); PDGamma colourBlack = new PDGamma(); public WReport() { } protected void finalize() { if (m_rptFileName == null) return; try { File file = new File(m_rptFileName); //file.delete(); } catch (Exception exc) { com.ing.connector.Registrar .logError(getClass().getName() + " errored deleting " + m_rptFileName + " : " + exc); } return; } public synchronized int getUniqueNumber() { //increments, then returns a class variable. Used to uniquely name files m_uniqueNumber++; return m_uniqueNumber; } public void setPendingCases(Object obj) { com.ing.connector.Registrar.logDebugMessage("obj.size = " + ((WCollection) obj).size()); if (m_pendingCases.getClass().getName().equals(obj.getClass().getName())) { Enumeration enumeration = ((WCollection) obj).elements(); WPendingCaseExt pc = null; while (enumeration.hasMoreElements()) { pc = (WPendingCaseExt) enumeration.nextElement(); m_pendingCases.addElement(pc); } } else { WPendingCaseExt pc = null; pc = (WPendingCaseExt) obj; m_pendingCases.addElement(pc); } } public void sortIt() { //sort pending case objects as user requires if (m_reportSort.equals("Agent Number")) m_pendingCases.sort("SortWritingAgentIdPolicyId", true); else if (m_reportSort.equals("Policy Number")) //m_pendingCases.sort("PolicyId", false); //LPMO264 m_pendingCases.sort("SortPolicyIdwithCNB", false); //LPMO264 else if (m_reportSort.equals("Status")) m_pendingCases.sort("SortStatusPolicyId", true); else if (m_reportSort.equals("Received Date")) m_pendingCases.sort("ReceivedDate", true); else if (m_reportSort.equals("Insured Name")) m_pendingCases.sort("SortOwnerLastNamePolicyId", true); } public void setAgent(WAgentExt obj) { m_agent = obj; } public void setReportDate(String reportDate) { WDateIsoFormat isoFormat = new WDateIsoFormat(); m_reportDate = isoFormat.parse(reportDate); m_reportDate1 = reportDate; } public WDate getReportDate() { return m_reportDate; } public String getReportDate1() { return m_reportDate1; } public void setSinglePolicy() { m_singleHold = true; } public boolean getSinglePolicy() { return m_singleHold; } public void setReportType(String reportType) { m_reportType = reportType; } public String getReportType() { return m_reportType; } public void setReportNumCount1(int numCount1) { m_numCount1 = numCount1++; } public int getReportNumCount1() { return m_numCount1; } public void setReportNumCount(int numCount) { m_numCount = numCount++; } public int getReportNumCount() { return m_numCount; } public void setReportAgent(String reportAgent) { m_reportAgent.addElement(reportAgent); } public Vector getReportAgent() { return m_reportAgent; } public void setReportSort(String reportSort) { m_reportSort = reportSort; } public String getReportSort() { return m_reportSort; } public void getReportPolicyNumber(String reportNumber) { m_reportNumber = reportNumber; } public String getReportPolicyNumber() { return m_reportNumber; } public void setReportStatus(String reportStatus) { m_reportStatus.addElement(reportStatus); } public Vector getReportStatus() { return m_reportStatus; } public void setReportRequirements(String reportRqmt) { m_reportRequirements = reportRqmt; } public String getReportRequirements() { return m_reportRequirements; } public void setReportLastUpdateDate(String reportLastUpdateDate) { if (!reportLastUpdateDate.equals("All Cases")) { WDateIsoFormat isoFormat = new WDateIsoFormat(); m_reportLastUpdateDate = isoFormat.parse(reportLastUpdateDate); } else m_reportLastUpdateDate = null; //RL-003632 -@start setReportLastUpdateDate(m_reportLastUpdateDate); // RL-003632 -@End } //RL-003632 -@start public void setReportLastUpdateDate(WDate lastUpdateDate) { m_reportLastUpdateDate = lastUpdateDate; setQVReportLastUpdateDate(lastUpdateDate); } // This is for QV filter only public void setQVReportLastUpdateDate(WDate lastUpdateDate) { //Taking copy of m_date. if (lastUpdateDate != null) { long tmpTime = lastUpdateDate.toDate().getTime(); Date tmpDate = new Date(tmpTime); String tmpDatestr = FormatUtil.formatDateTime(tmpDate, FormatUtil.longFormat); Date tmpDate1 = FormatUtil.getAsDateObject(tmpDatestr, FormatUtil.LONGFORMAT); m_qv_reportLastUpdateDate = new WDate(tmpDate1); } } //RL-003632 -@End public WDate getReportLastUpdateDateForQV() { return m_qv_reportLastUpdateDate; } public WDate getReportLastUpdateDate() { return m_reportLastUpdateDate; } public void setReportLastUpdateToDate(String reportLastUpdateToDate) { if (!reportLastUpdateToDate.equals("All Cases")) { WDateIsoFormat isoFormat = new WDateIsoFormat(); m_reportLastUpdateToDate = isoFormat.parse(reportLastUpdateToDate); } else { m_reportLastUpdateToDate = null; } setReportLastUpdateToDate(m_reportLastUpdateToDate); } public void setReportLastUpdateToDate(WDate lastUpdateToDate) { m_reportLastUpdateToDate = lastUpdateToDate; setQVReportLastUpdateToDate(lastUpdateToDate); } public void setQVReportLastUpdateToDate(WDate lastUpdateToDate) { if (lastUpdateToDate != null) { long tmpTime = lastUpdateToDate.toDate().getTime(); Date tmpDate = new Date(tmpTime); String tmpDatestr = FormatUtil.formatDateTime(tmpDate, FormatUtil.longFormat); Date tmpDate1 = FormatUtil.getAsDateObject(tmpDatestr, FormatUtil.LONGFORMAT); m_qv_reportLastUpdateToDate = new WDate(tmpDate1); } } public WDate getReportLastUpdateToDateForQV() { return m_qv_reportLastUpdateToDate; } public WDate getReportLastUpdateToDate() { return m_reportLastUpdateToDate; } public void setReportLastUpdateDate2(String reportLastUpdateDate) { m_reportLastUpdateDate2 = reportLastUpdateDate; } public String getReportLastUpdateDate2() { return m_reportLastUpdateDate2; } public void setReportFileName(String str) { m_rptFileName = str; } public String getReportFileName() { return m_rptFileName; } public void setOverAgentId(String str) { m_overAgentId = str; } public String getOverAgentId() { return m_overAgentId; } public void setPrimaryAgentId(String str) { m_primaryAgentId = str; } public String getPrimaryAgentId() { return m_primaryAgentId; } public void setPrimaryAgentName(String str) { m_primaryAgentName = str; } public String getPrimaryAgentName() { return m_primaryAgentName; } public String getReportRoot() { WReportRoot rptRoot = new WReportRoot(); return rptRoot.getReportRoot(); } public String changeToCurrency(Double dub) { DecimalFormat dec1 = new DecimalFormat("$#,##0.00"); String dec2 = dec1.format(dub); return dec2; } public String changeToCurrency(double dub) { DecimalFormat dec1 = new DecimalFormat("$#,##0.00"); String dec2 = dec1.format(dub); return dec2; } //LPMO264 - Added public String formatPolicyNumber(String polNo, String targetAdmin, String systemSource) { // if (targetAdmin.equalsIgnoreCase(WConstants.INGENIUM) //GDB2NY VXB 11/26/2008 if (targetAdmin.equalsIgnoreCase(WConstants.INGENIUM) || (targetAdmin.trim().equalsIgnoreCase(WConstants.DENV_VTG) && WStringUtil.getSubcompanyFromPolNo(polNo).equals(WConstants.NY_COMPCODE))) //GDB2NY VXB 11/26/2008 { return polNo.substring(6, polNo.trim().length()); } else { if (systemSource.equals(WConstants.SYS_SRC_QV)) { return polNo.substring(6, polNo.trim().length()); } else { return polNo.substring(8, polNo.trim().length()); } } } public void createReportLog() { StringBuffer sb = new StringBuffer(); sb.append( "================================================================================================"); sb.append("\n Requesting Agent Name: " + m_primaryAgentName); sb.append("\n Requesting Agent Number: " + m_primaryAgentId); sb.append("\n Report Parameters"); sb.append("\n Agent Numbers: " + m_reportAgent.toString()); sb.append("\n Statuses: " + m_reportStatus.toString()); sb.append("\n Requirements: " + m_reportRequirements); sb.append("\n Cases Updated as of " + m_reportLastUpdateDate); sb.append("\n Sorted by " + m_reportSort); com.ing.connector.Registrar.logMessage(m_logReportFileName, sb.toString()); } public boolean createReport() { try { if (!openReport()) return false; if (!createRequestedReport()) { closeReport(); return false; } if (!closeReport()) return false; com.ing.connector.Registrar.logInfoMessage(getClass().getName() + " created report " + m_rptFileName); } catch (Exception exc) { com.ing.connector.Registrar.logError(getClass().getName() + exc.getMessage()); } return true; } protected boolean createRequestedReport() { return false; } public boolean openReport() { try { m_pdfReport = new PDDocument(); openPage(); } catch (Exception exc) { com.ing.connector.Registrar .logError(getClass().getName() + " failed to open " + getReportFileName() + " : " + exc); return false; } return true; } public void writeReport(String text, float xCoord, float yCoord) { try { m_pdfStream.moveTextPositionByAmount(xCoord, yCoord); m_pdfStream.drawString(text); m_pdfStream.moveTextPositionByAmount(-1 * xCoord, -1 * yCoord); } catch (Exception exc) { com.ing.connector.Registrar .logError(getClass().getName() + " errored writing to " + m_rptFileName + " : " + exc); // return 0; } } public boolean closeReport() { try { m_pdfStream.endText(); m_pdfStream.close(); drawUnderline(m_newPage.getAnnotations()); m_pdfReport.save(m_rptFileName); m_pdfReport.close(); } catch (Exception exc) { com.ing.connector.Registrar .logError(getClass().getName() + " errored closing " + m_rptFileName + " : " + exc); return false; } return true; } public boolean createSummReport() { return true; } public boolean createDetailReport() { return true; } public String midTrim(String st) { int x = 0; while (x <= st.length() - 2) { if (st.substring(x, x + 2).equals(" ")) st = st.substring(0, x) + st.substring(x + 1, st.length()); else x++; } return st; } public void setCompanyName(String comp) { m_companyName = comp; } public void createSummHeader1() { try { int rj = 0; float xCoord = 0; float yCoord = 0; float lineWidth = 0; float lineHeight = 0; String printMode = ""; m_pageCount++; m_numberOfLines = 1; m_pdfFont = HELVETICA_BOLD; fontSize = 14; m_pdfStream.setFont(m_pdfFont, fontSize); xCoord = 0; yCoord = 810; lineWidth = 595; lineHeight = 15; printMode = CENTER_MODE; alignCenter("Voya Financial", xCoord, yCoord, lineWidth); fontSize = 5; m_pdfStream.setFont(m_pdfFont, fontSize); xCoord = 53; yCoord = 816; lineWidth = 595; lineHeight = 15; printMode = CENTER_MODE; alignCenter("TM", xCoord, yCoord, lineWidth); fontSize = 12; m_pdfStream.setFont(m_pdfFont, fontSize); xCoord = 0; yCoord = 795; lineWidth = 595; lineHeight = 15; printMode = CENTER_MODE; if (m_reportType.equals("summary")) alignCenter("New Business Summary Report For " + getPrimaryAgentName().trim() + " / " + getPrimaryAgentId(), xCoord, yCoord, lineWidth); else alignCenter("New Business Detailed Report For " + getPrimaryAgentName().trim() + " / " + getPrimaryAgentId(), xCoord, yCoord, lineWidth); xCoord = LEFT_EDGE; yCoord = yCoord - 17; lineWidth = 90; lineHeight = 15; printMode = LEFT_MODE; writeReport("Report Date:", xCoord, yCoord); xCoord = 100; yCoord = yCoord; lineWidth = 100; lineHeight = 15; printMode = LEFT_MODE; writeReport(DateFormat.getDateInstance(DateFormat.SHORT).format(getReportDate().toDate()), xCoord, yCoord); xCoord = 535; yCoord = yCoord; lineWidth = 75; lineHeight = 15; printMode = LEFT_MODE; writeReport("Page " + m_pageCount, xCoord, yCoord); fontSize = 8; m_pdfFont = HELVETICA; m_pdfStream.setFont(m_pdfFont, fontSize); if (m_pageCount == 1 && !(m_singleHold)) { fontSize = 10; m_pdfFont = HELVETICA_BOLD; m_pdfStream.setFont(m_pdfFont, fontSize); yCoord = yCoord - 15; xCoord = LEFT_EDGE; lineWidth = 200; lineHeight = 10; printMode = LEFT_MODE; writeReport("CHOSEN PARAMETERS: ", xCoord, yCoord); yCoord = yCoord - 15; xCoord = LEFT_EDGE + 10; lineWidth = 500; lineHeight = 10; printMode = LEFT_MODE; writeReport("AGENT NUMBERS: ", xCoord, yCoord); int r = 0; float aWidth = getStringWidth(m_reportAgent.toString(), fontSize); float sWidth = getStringWidth(m_reportStatus.toString(), fontSize); if (xCoord + aWidth + sWidth + 150 > 520) //12186 { rj = (int) aWidth / 450; // 12.46 yCoord = yCoord - (15 * (rj + 1)); // 760 xCoord = LEFT_EDGE + 10; // 35 +10 ? r = 2; } else { xCoord = xCoord + (aWidth) + 150; // 5796 r = 1; } lineWidth = 500; lineHeight = 10; printMode = LEFT_MODE; writeReport("STATUSES: ", xCoord, yCoord); yCoord = yCoord - 15; xCoord = LEFT_EDGE + 10; lineWidth = 200; lineHeight = 10; printMode = LEFT_MODE; if (m_reportType.equals("summary")) { writeReport("REQUIREMENTS: ", xCoord, yCoord); xCoord = 215; lineWidth = 200; lineHeight = 10; printMode = LEFT_MODE; } writeReport("UPDATED AS OF : ", xCoord, yCoord); if (m_reportType.equals("summary")) xCoord = 400; else xCoord = 250; lineWidth = 395; lineHeight = 10; printMode = LEFT_MODE; writeReport("SORTED BY: ", xCoord, yCoord); m_pdfFont = HELVETICA; m_pdfStream.setFont(m_pdfFont, fontSize); if (r == 1) yCoord = yCoord + 15; else if (r == 2) { yCoord = yCoord + (15 * (rj + 2)); } xCoord = LEFT_EDGE + 100; lineWidth = 500; lineHeight = 10; printMode = LEFT_MODE; yCoord = pdfNextLine(m_reportAgent.toString().trim(), xCoord, yCoord, lineWidth, lineHeight, printMode); if (r == 2) { yCoord = yCoord - (15 * (rj + 1)); xCoord = LEFT_EDGE + getStringWidth("STATUS: ", fontSize) + 20; } else xCoord = xCoord + (aWidth) + 120; if (rj > 0) yCoord = yCoord + 15; lineWidth = 500; lineHeight = 10; printMode = LEFT_MODE; writeReport(" " + m_reportStatus, xCoord, yCoord); yCoord = yCoord - 15; xCoord = LEFT_EDGE + 100; lineWidth = 200; lineHeight = 10; printMode = LEFT_MODE; if (m_reportType.equals("summary")) { writeReport(m_reportRequirements, xCoord, yCoord); xCoord = 307; lineWidth = 200; lineHeight = 10; printMode = LEFT_MODE; } if (m_reportLastUpdateDate == null) writeReport("All Cases", xCoord, yCoord); else writeReport(m_reportLastUpdateDate.toString(), xCoord, yCoord); if (m_reportType.equals("summary")) xCoord = 460; else xCoord = 307; lineWidth = 210; lineHeight = 10; printMode = LEFT_MODE; writeReport(" " + m_reportSort, xCoord, yCoord); m_yCoord = yCoord - 20; } else m_yCoord = 778; } catch (Exception exc) { com.ing.connector.Registrar.logError(getClass().getName() + exc.getMessage()); } } public float pdfNextLine(String subAgent, float xCoord, float yCoord, float lineWidth, float lineHeight, String printMode) { try { String subAgent1 = ""; String subAgent2 = ""; if (getStringWidth(subAgent.trim(), fontSize) > 450) { for (int i = 85; i > 0; i--) { if (subAgent.toString().trim().substring(i - 1, i).equals(" ")) { subAgent1 = subAgent.toString().trim().substring(0, i); subAgent2 = subAgent.toString().substring(i, subAgent.toString().trim().length()); i = 0; } } writeReport(" " + subAgent1, xCoord, yCoord); yCoord = yCoord - 15; if (getStringWidth(subAgent2.trim(), fontSize) > 450) { pdfNextLine(subAgent2, xCoord, yCoord, lineWidth, lineHeight, printMode); } else writeReport(" " + subAgent2, xCoord, yCoord); } else { writeReport(" " + subAgent, xCoord, yCoord); } } catch (Exception exc) { com.ing.connector.Registrar.logError(getClass().getName() + exc.getMessage()); } return yCoord; } public String formatDate(WDate Dat) { String strDate = DateFormat.getDateInstance(DateFormat.SHORT).format(Dat.toDate()).toString(); if (strDate.equals(primeDate)) { return ""; } else { return strDate; } } public boolean noPDFReports() { try { com.ing.connector.Registrar.logInfoMessage("***noPDFs for " + m_reportAgent + " " + m_reportNumber); float xCoord = 0; float yCoord = 0; m_pdfFont = HELVETICA_BOLD; fontSize = 12; m_pdfStream.setFont(m_pdfFont, fontSize); xCoord = LEFT_EDGE; yCoord = 610; m_lineWidth = 595; alignCenter("There are no reports that match these parameters", xCoord, yCoord, m_lineWidth); } catch (Exception exc) { com.ing.connector.Registrar.logError(getClass().getName() + exc.getMessage()); } return true; } //compare user parameters to the cases in pendingCase object public void getUserParameters(String rep) { boolean allowCase = isCaseAllowed(m_pendingCase); try { if (allowCase) { if (!createSummReport()) { com.ing.connector.Registrar.logError(getClass().getName() + " errored while creating report for policy " + m_pendingCase.getPolicyId()); } } } catch (Exception exc) { com.ing.connector.Registrar.logError(getClass().getName() + exc.getMessage()); com.ing.connector.Registrar.logInfoMessage("Report creation was unsuccessful"); noPDFReports(); } } public boolean isCaseAllowed(WPendingCaseExt pendingCaseExt) { boolean caseAllowed = false; try { Enumeration agents = m_reportAgent.elements(); while (agents.hasMoreElements()) { String reportAgentID = (String) agents.nextElement(); Enumeration statuses = m_reportStatus.elements(); while (statuses.hasMoreElements()) { String reportStatusID = (String) statuses.nextElement(); if (reportAgentID.equals("All Agents") || (pendingCaseExt.getWritingAgentId().trim()).equals(reportAgentID.trim())) { if (reportStatusID.equals(WConstants.ALL_STATUS) || reportStatusID.equals("All Statuses") || isCaseStatusMatchingRequest(pendingCaseExt.getStatus().toString(), reportStatusID)) { WDate reportLastUpdateDate = getReportLastUpdateDate(); WDate qv_reportLastUpdateDate = getReportLastUpdateDateForQV(); WDate reportLastUpdateToDate = getReportLastUpdateToDate(); WDate qv_reportLastUpdateToDate = getReportLastUpdateToDateForQV(); WDate caseLastUpdateDate = pendingCaseExt.getLastUpdateDate(); String caseSystemSource = pendingCaseExt.getSystemSource(); if (m_reportLastUpdateDate == null) { caseAllowed = true; } else { if ((WConstants.SYS_SRC_QV).equalsIgnoreCase(caseSystemSource)) { boolean caseAllowedFrom = (qv_reportLastUpdateDate .compareTo(caseLastUpdateDate) <= 0); boolean caseAllowedTo = true; if (qv_reportLastUpdateToDate != null) { caseAllowedTo = (caseLastUpdateDate .compareTo(qv_reportLastUpdateToDate) <= 0); } if (caseAllowedFrom && caseAllowedTo) { caseAllowed = true; } } else { boolean caseAllowedFrom = (reportLastUpdateDate .compareTo(caseLastUpdateDate) <= 0); boolean caseAllowedTo = true; if (reportLastUpdateToDate != null) { caseAllowedTo = (caseLastUpdateDate.compareTo(reportLastUpdateToDate) <= 0); } if (caseAllowedFrom && caseAllowedTo) { caseAllowed = true; } } } } } } } } catch (Exception exc) { com.ing.connector.Registrar.logDebugMessage("Inside IsCaseAllowed exception: " + exc); com.ing.connector.Registrar.logError(getClass().getName() + exc.getMessage()); } return caseAllowed; } public boolean isCaseStatusMatchingRequest(String caseStatus, String requestStatus) { String caseConnectorAppStatus = WConstants.CONN_APP_STATUS_OTHERS; if (WConstants.getConnectorPendingStatuses().contains(caseStatus) || WConstants.getQVPendingStatuses().contains(caseStatus)) { caseConnectorAppStatus = WConstants.CONN_APP_STATUS_PENDING; } else if (WConstants.getConnectorApprovedStatuses().contains(caseStatus) || WConstants.getQVApprovedStatuses().contains(caseStatus)) { caseConnectorAppStatus = WConstants.CONN_APP_STATUS_APPROVED; } else if (WConstants.getConnectorIssuedStatuses().contains(caseStatus) || WConstants.getQVIssuedStatuses().contains(caseStatus)) { caseConnectorAppStatus = WConstants.CONN_APP_STATUS_ISSUED; } else if (WConstants.getConnectorActiveStatuses().contains(caseStatus) || WConstants.getQVActiveStatuses().contains(caseStatus)) { caseConnectorAppStatus = WConstants.CONN_APP_STATUS_ACTIVE; } if (requestStatus.equals(caseConnectorAppStatus)) { return true; } return false; } public int getNumberOfCasesAllowed() { int count = 0; for (int i = 0; i < m_pendingCases.size(); i++) { WPendingCaseExt pendingCaseExt = (WPendingCaseExt) m_pendingCases.elementAt(i); if (isCaseAllowed(pendingCaseExt)) { count++; } } return count; } 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; } 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 void setDownload() { m_download = true; } public boolean reportBackground() { m_reportThread = new WReportThread(this); com.ing.connector.Registrar.logInfoMessage("Printing at WREPORT.java" + this.m_pendingCases.size()); return true; } public WCompany getCompany() { WCompany company = new WCompany(null, null); if (m_company == null) { WObjectKeys keys = new WObjectKeys(null); keys.addKey(m_pendingCase.getCompanyId()); WResult result = com.ing.connector.model.WFactory.getObject("WCompanies", keys); company = (WCompany) result.getModelObject(); } return company; } /** * 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 m_outFile = new FileWriter(m_fileName, true); } 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; } 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 void setIFileName(String name) { m_iFileName = name; } 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 int m_recCount = 0; protected int m_pageCount = 0; protected int m_pendingCaseCount = 0; protected boolean m_download = false; protected float m_xCoord = 0; protected float m_yCoord = 0; protected float m_yCoordDecrement = 0; protected float m_lineWidth = 0; protected float m_lineHeight = 0; protected String m_printMode = ""; protected int m_numberOfLines = 0; protected WCompany m_company = null; protected WCollection m_pendingCases = new WCollection("com.ing.connector.model.WPendingCaseExt"); protected WPendingCaseExt m_pendingCase; protected WAgentExt m_agent; protected boolean m_singleHold = false; protected String m_primaryAgentId = ""; protected String m_primaryAgentName = ""; protected String m_overAgentId = ""; protected String m_companyName = ""; protected PDPageContentStream m_pdfStream = null; //dxr protected PDPage m_newPage = null; //dxr protected PDFont m_pdfFont = null; //dxr protected PDDocument m_pdfReport = null; protected static final PDType1Font HELVETICA_BOLD = PDType1Font.HELVETICA_BOLD; protected static final PDType1Font HELVETICA = PDType1Font.HELVETICA; protected static final PDType1Font HELVETICA_BOLDITALIC = PDType1Font.HELVETICA_BOLD_OBLIQUE; protected String m_rptFileName = "report.pdf"; protected String m_reportSort = ""; protected Vector m_reportStatus = new Vector(); protected String m_reportRequirements = ""; protected String m_reportNumber = ""; protected static String primeDate = new String("12/31/69"); protected int i = 0; protected String m_fileName = "export.txt"; // CSPS308 protected String m_holdSortKey = ""; protected String m_holdSortKey = null; //CSPS308 protected String m_sortKey = ""; protected WReportThread m_reportThread = null; protected Date date = new Date(); //protected String m_logReportFileName = "d:\\bali\\ReportLog.txt"; protected String m_logReportFileName = FormatUtil.formatLogFilewithDate(LookUp.getInstance().getReportLog(), date) + ".txt"; protected String m_iFileName = ""; protected String m_iniFileName = ""; protected FileWriter m_outIniFile; protected String m_exportType = "A"; protected FileWriter m_outFile; //protected FileWriter m_outFileBackground; protected String m_fieldDelimiter = ""; protected String m_reportLastUpdateDate2 = ""; protected String m_reportType = null; protected Vector m_reportAgent = new Vector(); protected int m_numCount = 0; protected int m_numCount1 = 0; protected int fontSize = 10; protected String m_reportDate1 = ""; protected WDate m_reportDate = null; protected WDate m_reportLastUpdateDate = null; protected WDate m_qv_reportLastUpdateDate = null; protected WDate m_reportLastUpdateToDate = null; protected WDate m_qv_reportLastUpdateToDate = null; protected static int m_uniqueNumber = 0; protected static final float PAGE_WIDTH = 595; protected static final float PAGE_HEIGHT = 842; protected static final int LEFT_EDGE = 25; protected static final String CENTER_MODE = "center"; protected static final String LEFT_MODE = "left"; class WReportThread implements Runnable { public WReportThread(WReport report) { Thread reportThread = new Thread(this); m_reportThread = report; reportThread.start(); } public void run() { /*** Modified for RL-6719 ****/ //m_reportThread.m_iniFileName = m_reportThread.getReportRoot() + "\\" + m_iFileName + ".ini"; if (m_iFileName.contains("MR")) { m_reportThread.m_iniFileName = m_reportThread.getReportRoot() + File.separator + m_iFileName + ".ini"; } else { m_reportThread.m_iniFileName = LookUp.getInstance().getAutoReportsFolder() + File.separator + m_iFileName + ".ini"; } m_reportThread.openIni(false); m_reportThread.writeIni("[Start]" + "\r\n"); Date now = new Date(); m_reportThread.writeIni(now.toString() + "\r\n"); m_reportThread.closeIni(); if (m_reportThread.open()) { // m_reportThread.getAgents(); // m_reportThread.getAllPendingCases(); if (m_reportThread.createReport()/*exportRequestedObjects()*/) { m_reportThread.close(); m_reportThread.openIni(true); m_reportThread.writeIni("[End]" + "\r\n"); } else { m_reportThread.close(); m_reportThread.openIni(true); m_reportThread.writeIni("[Failed]" + "\r\n"); } now = new Date(); m_reportThread.writeIni(now.toString() + "\r\n"); m_reportThread.closeIni(); } } protected WReport m_reportThread = null; } void openPage() throws Exception { com.ing.connector.Registrar.logInfoMessage("********OPENED NEW PAGE***********"); yPositionAndWidth.clear(); m_newPage = new PDPage(); m_newPage.setMediaBox(PDPage.PAGE_SIZE_A4); m_pdfReport.addPage(m_newPage); m_pdfStream = new PDPageContentStream(m_pdfReport, m_newPage); m_pdfStream.setFont(m_pdfFont, 10); m_pdfStream.beginText(); } void closePage() throws Exception { m_pdfStream.endText(); m_pdfStream.close(); drawUnderline(m_newPage.getAnnotations()); } private void drawUnderline(List annotations) { //Registrar.logInfoMessage("Inside drawUnderline"); Set keys = yPositionAndWidth.keySet(); //Registrar.logInfoMessage("yPositionAndWidth.keySet().size()" + yPositionAndWidth.keySet().size()); for (Iterator iterator = keys.iterator(); iterator.hasNext();) { //Registrar.logInfoMessage("Inside drawUnderline iterator"); float yPosition = (Float) iterator.next(); float textWidth = (Float) yPositionAndWidth.get(yPosition); PDAnnotationLine underline = new PDAnnotationLine(); PDRectangle position = new PDRectangle(); position.setLowerLeftX(LEFT_EDGE); position.setLowerLeftY(yPosition - 3); //Registrar.logInfoMessage("LEFT_EDGE: " + LEFT_EDGE); //Registrar.logInfoMessage("yPosition: " + yPosition); position.setUpperRightX(LEFT_EDGE + 10); position.setUpperRightY(yPosition - 3); underline.setRectangle(position); float[] linepos = new float[4]; linepos[0] = LEFT_EDGE; linepos[1] = yPosition - 3; linepos[2] = LEFT_EDGE + textWidth; linepos[3] = yPosition - 3; underline.setLine(linepos); underline.setColour(colourBlack); // add to the annotations on the page annotations.add(underline); } } void alignCenter(String text, float xCoord, float yCoord, float lineWidth) throws Exception { float titleWidth = getStringWidth(text, fontSize); writeReport(text, xCoord + (lineWidth - titleWidth) / 2, yCoord); } void drawRectangle(float xOffset, float yOffset, float width, float height) throws Exception { float x1, x2, x3, x4, y1, y2, y3, y4; x1 = x2 = xOffset; x3 = x4 = xOffset + width; y1 = y4 = yOffset; y2 = y3 = yOffset + height; m_pdfStream.drawPolygon(new float[] { x1, x2, x3, x4 }, new float[] { y1, y2, y3, y4 }); } float getStringWidth(String text, float size) throws Exception { float stringWidth = m_pdfFont.getStringWidth(text) * size / 1000; return stringWidth; } protected int getOverflowChars(String text, float width) throws Exception { int overflowChars = 0; float stringWidth = getStringWidth(text.trim(), fontSize); if (stringWidth <= width) { return overflowChars; } else { for (int i = text.length() - 1; i > 1; i--) { overflowChars++; text = text.substring(0, i); stringWidth = getStringWidth(text, fontSize); if (stringWidth <= width) { return overflowChars; } } } return overflowChars; } String trimString(String text, float width) throws Exception { try { int startPos = 0; int endPos = 0; int overflowChars = 0; int textLength = text.trim().length(); endPos = textLength; overflowChars = getOverflowChars(text.trim().substring(startPos, endPos), width); if (overflowChars > 0) endPos = text.trim().length() - overflowChars; text = text.trim().substring(startPos, endPos); return text; } catch (Exception exc) { com.ing.connector.Registrar.logError(getClass().getName() + exc.getMessage()); } return text; } }