diff options
author | 2019-05-20 16:19:57 +0100 | |
---|---|---|
committer | 2019-07-16 14:52:27 +0100 | |
commit | f55fa6a1f3c427ff035970635aedaec16c0de4f1 (patch) | |
tree | ea58389563b6468964096f94f299acf5320722f4 /ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/pdf | |
parent | 7d7b74d4d92e7fa45471fb0e8678837f71da3d02 (diff) |
Fixed Sonar "Blocker Bugs"
Fixed potential "thread-Leak"
Change-Id: I7efcbd4d7b6b69ca1f234bed8d28cbb8e51e3e25
Signed-off-by: Vasyl Razinkov <vasylrazinkov@sidero.ie>
Issue-ID: PORTAL-584
Diffstat (limited to 'ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/pdf')
-rw-r--r-- | ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/pdf/PdfReportHandler.java | 766 |
1 files changed, 306 insertions, 460 deletions
diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/pdf/PdfReportHandler.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/pdf/PdfReportHandler.java index 612ed960..3a50a99c 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/pdf/PdfReportHandler.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/pdf/PdfReportHandler.java @@ -55,6 +55,24 @@ */ package org.onap.portalsdk.analytics.model.pdf; +import com.lowagie.text.BadElementException; +import com.lowagie.text.Chunk; +import com.lowagie.text.Document; +import com.lowagie.text.DocumentException; +import com.lowagie.text.Element; +import com.lowagie.text.ElementTags; +import com.lowagie.text.Font; +import com.lowagie.text.FontFactory; +import com.lowagie.text.Image; +import com.lowagie.text.PageSize; +import com.lowagie.text.Paragraph; +import com.lowagie.text.Phrase; +import com.lowagie.text.Rectangle; +import com.lowagie.text.html.simpleparser.HTMLWorker; +import com.lowagie.text.html.simpleparser.StyleSheet; +import com.lowagie.text.pdf.PdfPCell; +import com.lowagie.text.pdf.PdfPTable; +import com.lowagie.text.pdf.PdfWriter; import java.awt.Color; import java.io.File; import java.io.FileNotFoundException; @@ -80,11 +98,9 @@ import java.util.Set; import java.util.TimeZone; import java.util.TreeMap; import java.util.Vector; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; - import org.onap.portalsdk.analytics.error.RaptorException; import org.onap.portalsdk.analytics.error.ReportSQLException; import org.onap.portalsdk.analytics.model.ReportHandler; @@ -110,25 +126,6 @@ import org.onap.portalsdk.analytics.view.RowHeaderCol; import org.onap.portalsdk.analytics.xmlobj.DataColumnType; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import com.lowagie.text.BadElementException; -import com.lowagie.text.Chunk; -import com.lowagie.text.Document; -import com.lowagie.text.DocumentException; -import com.lowagie.text.Element; -import com.lowagie.text.ElementTags; -import com.lowagie.text.Font; -import com.lowagie.text.FontFactory; -import com.lowagie.text.Image; -import com.lowagie.text.PageSize; -import com.lowagie.text.Paragraph; -import com.lowagie.text.Phrase; -import com.lowagie.text.Rectangle; -import com.lowagie.text.html.simpleparser.HTMLWorker; -import com.lowagie.text.html.simpleparser.StyleSheet; -import com.lowagie.text.pdf.PdfPCell; -import com.lowagie.text.pdf.PdfPTable; -import com.lowagie.text.pdf.PdfWriter; - /** * @author mwliu and sundar * @@ -942,448 +939,297 @@ public class PdfReportHandler extends org.onap.portalsdk.analytics.RaptorObject{ */ private final int DEFAULT_PDF_DISPLAY_WIDTH = 10; - private int paintPdfData(HttpServletRequest request, Document document, ReportData rd, ReportRuntime rr, String sql_whole) throws DocumentException, RaptorException, IOException { - - int mb = 1024*1024; - Runtime runtime = Runtime.getRuntime(); - int returnValue = 0; - //sql_whole = rr.getWholeSQL(); - //if(rd.getDataRowCount() >= rr.getReportDataSize()) { - //sql_whole=""; - //} - float f[] = getRelativeWidths(rd, rr.getReportType().equals(AppConstants.RT_CROSSTAB)); - PdfPTable table = new PdfPTable(f); - table.setWidthPercentage(100f); - table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER); - table.getDefaultCell().setVerticalAlignment(Rectangle.ALIGN_BOTTOM); - - ReportDefinition rdef = (new ReportHandler()).loadReportDefinition(request, rr.getReportID()); - - List allColumns = rdef.getAllColumns(); - - float[] repotWidths = new float[rdef.getVisibleColumnCount()]; - int columnIdx = 0; - float pdfDisplayWidth = 0; - for(Iterator iter = allColumns.iterator(); iter.hasNext();){ - DataColumnType dct = (DataColumnType) iter.next(); - if(dct.isVisible()) { - - if(dct.getPdfDisplayWidthInPxls() == null || dct.getPdfDisplayWidthInPxls().equals("") || dct.getPdfDisplayWidthInPxls().startsWith("null")) - pdfDisplayWidth = DEFAULT_PDF_DISPLAY_WIDTH; - else - pdfDisplayWidth = Float.parseFloat(dct.getPdfDisplayWidthInPxls()); - - repotWidths [columnIdx++] = pdfDisplayWidth; - } - } - - table.setWidths(repotWidths); - - //table.setH - - //TODO: check title and subtitle - HttpSession session = request.getSession(); - String drilldown_index = (String) session.getAttribute("drilldown_index"); - int index = 0; - try { - index = Integer.parseInt(drilldown_index); - } catch (NumberFormatException ex) { - index = 0; - } - String titleRep = (String) session.getAttribute("TITLE_"+index); - String subtitle = (String) session.getAttribute("SUBTITLE_"+index); - - if(nvl(titleRep).length()>0 && nvl(subtitle).length()>0) - table.setHeaderRows(3); - else if (nvl(titleRep).length()>0) - table.setHeaderRows(2); - else - table.setHeaderRows(1); - table = paintPdfReportHeader(request, document, table, rr, f); - paintPdfTableHeader(document, rd, table); - - int idx = 0; - int fragmentsize = 30; //for memory management - - ResultSet rs = null; - Connection conn = null; - Statement st = null; - ResultSetMetaData rsmd = null; + + private int paintPdfData(final HttpServletRequest request, final Document document, final ReportData rd, + final ReportRuntime rr, final String sql_whole) throws DocumentException, RaptorException, IOException { + + final int mb = 1024 * 1024; + final Runtime runtime = Runtime.getRuntime(); + int returnValue = 0; + + final float f[] = getRelativeWidths(rd, AppConstants.RT_CROSSTAB.equals(rr.getReportType())); + PdfPTable table = new PdfPTable(f); + table.setWidthPercentage(100f); + table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER); + table.getDefaultCell().setVerticalAlignment(Rectangle.ALIGN_BOTTOM); + + final ReportDefinition rdef = (new ReportHandler()).loadReportDefinition(request, rr.getReportID()); + + final List allColumns = rdef.getAllColumns(); + + final float[] repotWidths = new float[rdef.getVisibleColumnCount()]; + int columnIdx = 0; + float pdfDisplayWidth = 0; + for (final Iterator iter = allColumns.iterator(); iter.hasNext(); ) { + final DataColumnType dct = (DataColumnType) iter.next(); + if (dct.isVisible()) { + + if (dct.getPdfDisplayWidthInPxls() == null || dct.getPdfDisplayWidthInPxls().isEmpty() || dct + .getPdfDisplayWidthInPxls().startsWith("null")) { + pdfDisplayWidth = DEFAULT_PDF_DISPLAY_WIDTH; + } else { + pdfDisplayWidth = Float.parseFloat(dct.getPdfDisplayWidthInPxls()); + } + + repotWidths[columnIdx++] = pdfDisplayWidth; + } + } + + table.setWidths(repotWidths); + + //TODO: check title and subtitle + final HttpSession session = request.getSession(); + final String drilldown_index = (String) session.getAttribute("drilldown_index"); + int index = 0; + try { + index = Integer.parseInt(drilldown_index); + } catch (NumberFormatException ex) { + index = 0; + } + final String titleRep = (String) session.getAttribute("TITLE_" + index); + final String subtitle = (String) session.getAttribute("SUBTITLE_" + index); + + if (nvl(titleRep).length() > 0 && nvl(subtitle).length() > 0) { + table.setHeaderRows(3); + } else if (nvl(titleRep).length() > 0) { + table.setHeaderRows(2); + } else { + table.setHeaderRows(1); + } + table = paintPdfReportHeader(request, document, table, rr, f); + paintPdfTableHeader(document, rd, table); + + int idx = 0; + final int fragmentsize = 30; //for memory management + rd.reportDataRows.resetNext(); DataRow dr = rd.reportDataRows.getNext(); - - //addRowHeader(table,dr,idx,rd); - - //addRowColumns(table,dr,idx); - if(nvl(sql_whole).length() >0 && rr.getReportType().equals(AppConstants.RT_LINEAR)) { - try { - conn = ConnectionUtils.getConnection(rr.getDbInfo()); - st = conn.createStatement(); - logger.debug(EELFLoggerDelegate.debugLogger, ("************* Map Whole SQL *************")); - logger.debug(EELFLoggerDelegate.debugLogger, (sql_whole)); - logger.debug(EELFLoggerDelegate.debugLogger, ("*****************************************")); - rs = st.executeQuery(sql_whole); - rsmd = rs.getMetaData(); - int numberOfColumns = rsmd.getColumnCount(); - HashMap colHash = new HashMap(); - dr = null; - int j = 0; - int rowCount = 0; - String title = ""; - while(rs.next()) { - -/* if(runtime.freeMemory()/mb <= ((runtime.maxMemory()/mb)*Globals.getMemoryThreshold()/100) ) { - returnValue = 1; - String cellValue = Globals.getUserDefinedMessageForMemoryLimitReached() + " "+ rowCount +" records out of " + rr.getReportDataSize() + " were downloaded to PDF."; - Font cellFont = FontFactory.getFont(Globals.getDataFontFamily(), - Globals.getDataFontSize(), - Font.NORMAL, Color.BLACK); - PdfPCell cell = new PdfPCell(new Paragraph(cellValue,cellFont)); - table.addCell(cell); - document.add(table); - return returnValue; - } -*/ rowCount++; - colHash = new HashMap(); - for (int i = 1; i <= numberOfColumns; i++) { - colHash.put(rsmd.getColumnLabel(i).toUpperCase(), rs.getString(i)); - } - rd.reportDataRows.resetNext(); - - dr = rd.reportDataRows.getNext(); - - j = 0; - /*if(rd.reportTotalRowHeaderCols!=null) { - - HtmlFormatter rfmt = dr.getRowFormatter(); - - Font cellFont = FontFactory.getFont(Globals.getDataFontFamily(), - Globals.getDataFontSize(), - Font.NORMAL, Color.BLACK); - if(rfmt != null) { - cellFormatterFont(rfmt,cellFont); - } - - String cellValue = new Integer(rowCount).toString(); - PdfPCell cell = new PdfPCell(new Paragraph(cellValue,cellFont)); - - //row background color can be overwritten by cell background color - cell.setBackgroundColor(getRowBackgroundColor(dr, idx)); - - cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER); - - if(rfmt != null) { - formatterCell(rfmt,cell); - } - table.addCell(cell); - }*/ - - for (dr.resetNext(); dr.hasNext();j++) { - DataValue dv = dr.getNext(); - /*if(j == 0) { - HtmlFormatter cfmt = dv.getCellFormatter(); - HtmlFormatter rfmt = dv.getRowFormatter(); - - Font cellFont = FontFactory.getFont(Globals.getDataFontFamily(), - Globals.getDataFontSize(), - Font.NORMAL, Color.BLACK); - if(cfmt!= null) { - cellFormatterFont(cfmt,cellFont); - } - else if(rfmt != null) { - cellFormatterFont(rfmt,cellFont); - } - else { - if(dv.isBold()) { - cellFont.setStyle(Font.BOLD); - } - } - - //String cellValue = strip.stripHtml(value.trim()); - PdfPCell cell = new PdfPCell(new Paragraph(rowCount+"",cellFont)); - - //row background color can be overwritten by cell background color - cell.setBackgroundColor(getRowBackgroundColor(dr, idx)); - - if(nvl(dv.getAlignment()).trim().length()>0) - cell.setHorizontalAlignment(ElementTags.alignmentValue(dv.getAlignment())); - else - cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER); - - if(cfmt!= null) { - formatterCell(cfmt,cell); - } - else if(rfmt != null) { - formatterCell(rfmt,cell); - } - table.addCell(cell); - }*/ - - //for (chr.resetNext(); chr.hasNext();) { - //ColumnHeader ch = chr.getNext(); - String value = nvl((String)colHash.get(dv.getColId().toUpperCase())); - if(dv.isVisible()) { - - HtmlFormatter cfmt = dv.getCellFormatter(); - HtmlFormatter rfmt = dv.getRowFormatter(); - - Font cellFont = FontFactory.getFont(FONT_FAMILY, - FONT_SIZE, - Font.NORMAL, Color.BLACK); - if(cfmt!= null) { - cellFormatterFont(cfmt,cellFont); - } - else if(rfmt != null) { - cellFormatterFont(rfmt,cellFont); - } - else { - if(dv.isBold()) { - cellFont.setStyle(Font.BOLD); - } - } - - String cellValue = strip.stripHtml(value.trim()); - PdfPCell cell = new PdfPCell(new Paragraph(cellValue,cellFont)); - - //row background color can be overwritten by cell background color - cell.setBackgroundColor(getRowBackgroundColor(dr, idx)); - - if(nvl(dv.getAlignment()).trim().length()>0) - cell.setHorizontalAlignment(ElementTags.alignmentValue(dv.getAlignment())); - else - cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER); - - if(cfmt!= null) { - formatterCell(cfmt,cell); - } - else if(rfmt != null) { - formatterCell(rfmt,cell); - } - - - - table.addCell(cell); - - }//if isVisible() - - - } - - } - if(rd.reportDataTotalRow!=null) { - for (rd.reportDataTotalRow.resetNext(); rd.reportDataTotalRow.hasNext();idx++) { - dr = rd.reportDataTotalRow.getNext(); - table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER); - Font rowHeaderFont = FontFactory.getFont(FONT_FAMILY, - FONT_SIZE, - Font.NORMAL, Color.BLACK); - rowHeaderFont.setStyle(Font.BOLD); - rowHeaderFont.setSize(FONT_SIZE+1f); - table.getDefaultCell().setBackgroundColor(getRowBackgroundColor(dr, idx)); - table.addCell(new Paragraph("Total",rowHeaderFont)); - - - addTotalRowColumns(table,dr,idx); - if (idx % fragmentsize == fragmentsize - 1) { - document.add(table); - table.deleteBodyRows(); - table.setSkipFirstHeader(true); - } - - } - } - } catch (SQLException ex) { - throw new RaptorException(ex); - } catch (ReportSQLException ex) { - throw new RaptorException(ex); - } catch (Exception ex) { - if(!(ex.getCause() instanceof java.net.SocketException) ) - throw new RaptorException (ex); - } finally { - try { - if(conn!=null) - conn.close(); - if(st!=null) - st.close(); - if(rs!=null) - rs.close(); - } catch (SQLException ex) { - throw new RaptorException(ex); - } - } - - -// if (idx % fragmentsize == fragmentsize - 1) { -// document.add(table); -// table.deleteBodyRows(); -// table.setSkipFirstHeader(true); -// } - - //document.add(table); - } else { - if(rr.getReportType().equals(AppConstants.RT_LINEAR)) { - int rowCount = 0; - for(rd.reportDataRows.resetNext();rd.reportDataRows.hasNext();idx++) - { - rowCount++; - - /*if(rd.reportTotalRowHeaderCols!=null) { - HtmlFormatter rfmt = dr.getRowFormatter(); - - Font cellFont = FontFactory.getFont(Globals.getDataFontFamily(), - Globals.getDataFontSize(), - Font.NORMAL, Color.BLACK); - if(rfmt != null) { - cellFormatterFont(rfmt,cellFont); - } - - //String cellValue = new Integer(rowCount).toString(); - //PdfPCell cell = new PdfPCell(new Paragraph(cellValue,cellFont)); - - //row background color can be overwritten by cell background color - //cell.setBackgroundColor(getRowBackgroundColor(dr, idx)); - - //cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER); - - //if(rfmt != null) { - //formatterCell(rfmt,cell); - //} - //table.addCell(cell); - }*/ - - - - if(runtime.freeMemory()/mb <= ((runtime.maxMemory()/mb)*Globals.getMemoryThreshold()/100) ) { - returnValue = 1; - } - - dr = rd.reportDataRows.getNext(); - - addRowHeader(table,dr,idx,rd); - - addRowColumns(table,dr,idx); - - if (idx % fragmentsize == fragmentsize - 1) { - document.add(table); - table.deleteBodyRows(); - table.setSkipFirstHeader(true); - } - } - - if(rd.reportDataTotalRow!=null) { - for (rd.reportDataTotalRow.resetNext(); rd.reportDataTotalRow.hasNext();idx++) { - dr = rd.reportDataTotalRow.getNext(); - table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER); - Font rowHeaderFont = FontFactory.getFont(FONT_FAMILY, - FONT_SIZE, - Font.NORMAL, Color.BLACK); - rowHeaderFont.setStyle(Font.BOLD); - rowHeaderFont.setSize(FONT_SIZE+1f); - table.getDefaultCell().setBackgroundColor(getRowBackgroundColor(dr, idx)); - table.addCell(new Paragraph("Total",rowHeaderFont)); - - addTotalRowColumns(table,dr,idx); - if (idx % fragmentsize == fragmentsize - 1) { - document.add(table); - table.deleteBodyRows(); - table.setSkipFirstHeader(true); - } - - } - } - - } else if (rr.getReportType().equals(AppConstants.RT_CROSSTAB)) { - int rowCount = 0; - List l = rd.getReportDataList(); - boolean first = true; - for (int dataRow = 0; dataRow < l.size(); dataRow++) { - first = true; - rowCount++; - dr = (DataRow) l.get(dataRow); - Vector<DataValue> rowNames = dr.getRowValues(); - for(dr.resetNext(); dr.hasNext(); ) { - - if(first) { - HtmlFormatter rfmt = dr.getRowFormatter(); - - Font cellFont = FontFactory.getFont(FONT_FAMILY, - FONT_SIZE, - Font.NORMAL, Color.BLACK); - if(rfmt != null) { - cellFormatterFont(rfmt,cellFont); - } - String cellValue = ""; - PdfPCell cell = null; - //String cellValue = new Integer(rowCount).toString(); - //PdfPCell cell = new PdfPCell(new Paragraph(cellValue,cellFont)); - //row background color can be overwritten by cell background color - //cell.setBackgroundColor(getRowBackgroundColor(dr, idx)); - - //cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER); - - //if(rfmt != null) { - //formatterCell(rfmt,cell); - // } - //table.addCell(cell); - if(rowNames!=null) { - for(int i=0; i<rowNames.size(); i++) { - DataValue dv = rowNames.get(i); - rfmt = dr.getRowFormatter(); - - cellFont = FontFactory.getFont(FONT_FAMILY, - FONT_SIZE, - Font.NORMAL, Color.BLACK); - if(rfmt != null) { - cellFormatterFont(rfmt,cellFont); - } - cellValue = dv.getDisplayValue(); - if(cellValue.indexOf("|#")!=-1) - cellValue = cellValue.substring(0,cellValue.indexOf("|")); - - cell = new PdfPCell(new Paragraph(cellValue,cellFont)); - //row background color can be overwritten by cell background color - cell.setBackgroundColor(getRowBackgroundColor(dr, idx)); - - cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER); - - if(rfmt != null) { - formatterCell(rfmt,cell); - } - table.addCell(cell); - } - } - } - first = false; - - if(runtime.freeMemory()/mb <= ((runtime.maxMemory()/mb)*Globals.getMemoryThreshold()/100) ) { - returnValue = 1; - } - - //addRowHeader(table,dr,idx,rd); - - addRowColumns(table,dr,idx); - - if (idx % fragmentsize == fragmentsize - 1) { - document.add(table); - table.deleteBodyRows(); - table.setSkipFirstHeader(true); - } - } - - } - } - - //document.add(table); - - } - - document.add(table); - paintPdfReportFooter(request, document, rr, f); - - return returnValue; - } - + if (nvl(sql_whole).length() > 0 && AppConstants.RT_LINEAR.equals(rr.getReportType())) { + try (final Connection conn = ConnectionUtils.getConnection(rr.getDbInfo()); + final Statement st = conn.createStatement(); + final ResultSet rs = st.executeQuery(sql_whole);) { + + logger.debug(EELFLoggerDelegate.debugLogger, ("************* Map Whole SQL *************")); + logger.debug(EELFLoggerDelegate.debugLogger, (sql_whole)); + logger.debug(EELFLoggerDelegate.debugLogger, ("*****************************************")); + + final ResultSetMetaData rsmd = rs.getMetaData(); + final int numberOfColumns = rsmd.getColumnCount(); + dr = null; + int rowCount = 0; + while (rs.next()) { + + rowCount++; + final Map colHash = new HashMap(); + for (int i = 1; i <= numberOfColumns; i++) { + colHash.put(rsmd.getColumnLabel(i).toUpperCase(), rs.getString(i)); + } + rd.reportDataRows.resetNext(); + + dr = rd.reportDataRows.getNext(); + + for (dr.resetNext(); dr.hasNext(); ) { + final DataValue dv = dr.getNext(); + + final String value = nvl((String) colHash.get(dv.getColId().toUpperCase())); + if (dv.isVisible()) { + + final HtmlFormatter cfmt = dv.getCellFormatter(); + final HtmlFormatter rfmt = dv.getRowFormatter(); + + final Font cellFont = FontFactory.getFont(FONT_FAMILY, + FONT_SIZE, + Font.NORMAL, Color.BLACK); + if (cfmt != null) { + cellFormatterFont(cfmt, cellFont); + } else if (rfmt != null) { + cellFormatterFont(rfmt, cellFont); + } else { + if (dv.isBold()) { + cellFont.setStyle(Font.BOLD); + } + } + + final String cellValue = strip.stripHtml(value.trim()); + final PdfPCell cell = new PdfPCell(new Paragraph(cellValue, cellFont)); + + //row background color can be overwritten by cell background color + cell.setBackgroundColor(getRowBackgroundColor(dr, idx)); + + if (nvl(dv.getAlignment()).trim().length() > 0) { + cell.setHorizontalAlignment(ElementTags.alignmentValue(dv.getAlignment())); + } else { + cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER); + } + + if (cfmt != null) { + formatterCell(cfmt, cell); + } else if (rfmt != null) { + formatterCell(rfmt, cell); + } + + table.addCell(cell); + + }//if isVisible() + + } + + } + if (rd.reportDataTotalRow != null) { + for (rd.reportDataTotalRow.resetNext(); rd.reportDataTotalRow.hasNext(); idx++) { + dr = rd.reportDataTotalRow.getNext(); + table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER); + final Font rowHeaderFont = FontFactory.getFont(FONT_FAMILY, + FONT_SIZE, + Font.NORMAL, Color.BLACK); + rowHeaderFont.setStyle(Font.BOLD); + rowHeaderFont.setSize(FONT_SIZE + 1f); + table.getDefaultCell().setBackgroundColor(getRowBackgroundColor(dr, idx)); + table.addCell(new Paragraph("Total", rowHeaderFont)); + + addTotalRowColumns(table, dr, idx); + if (idx % fragmentsize == fragmentsize - 1) { + document.add(table); + table.deleteBodyRows(); + table.setSkipFirstHeader(true); + } + + } + } + } catch (final SQLException | ReportSQLException ex) { + throw new RaptorException(ex); + } catch (final Exception ex) { + if (!(ex.getCause() instanceof java.net.SocketException)) { + throw new RaptorException(ex); + } + } + //document.add(table); + } else { + if (rr.getReportType().equals(AppConstants.RT_LINEAR)) { + for (rd.reportDataRows.resetNext(); rd.reportDataRows.hasNext(); idx++) { + + if (runtime.freeMemory() / mb <= ((runtime.maxMemory() / mb) * Globals.getMemoryThreshold() + / 100)) { + returnValue = 1; + } + + dr = rd.reportDataRows.getNext(); + + addRowHeader(table, dr, idx, rd); + + addRowColumns(table, dr, idx); + + if (idx % fragmentsize == fragmentsize - 1) { + document.add(table); + table.deleteBodyRows(); + table.setSkipFirstHeader(true); + } + } + + if (rd.reportDataTotalRow != null) { + for (rd.reportDataTotalRow.resetNext(); rd.reportDataTotalRow.hasNext(); idx++) { + dr = rd.reportDataTotalRow.getNext(); + table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER); + Font rowHeaderFont = FontFactory.getFont(FONT_FAMILY, + FONT_SIZE, + Font.NORMAL, Color.BLACK); + rowHeaderFont.setStyle(Font.BOLD); + rowHeaderFont.setSize(FONT_SIZE + 1f); + table.getDefaultCell().setBackgroundColor(getRowBackgroundColor(dr, idx)); + table.addCell(new Paragraph("Total", rowHeaderFont)); + + addTotalRowColumns(table, dr, idx); + if (idx % fragmentsize == fragmentsize - 1) { + document.add(table); + table.deleteBodyRows(); + table.setSkipFirstHeader(true); + } + + } + } + + } else if (AppConstants.RT_CROSSTAB.equals(rr.getReportType())) { + int rowCount = 0; + final List l = rd.getReportDataList(); + boolean first = true; + for (int dataRow = 0; dataRow < l.size(); dataRow++) { + first = true; + rowCount++; + dr = (DataRow) l.get(dataRow); + final Vector<DataValue> rowNames = dr.getRowValues(); + for (dr.resetNext(); dr.hasNext(); ) { + + if (first) { + HtmlFormatter rfmt = dr.getRowFormatter(); + + Font cellFont = FontFactory.getFont(FONT_FAMILY, + FONT_SIZE, + Font.NORMAL, Color.BLACK); + if (rfmt != null) { + cellFormatterFont(rfmt, cellFont); + } + + if (rowNames != null) { + for (int i = 0; i < rowNames.size(); i++) { + final DataValue dv = rowNames.get(i); + rfmt = dr.getRowFormatter(); + + cellFont = FontFactory.getFont(FONT_FAMILY, + FONT_SIZE, + Font.NORMAL, Color.BLACK); + if (rfmt != null) { + cellFormatterFont(rfmt, cellFont); + } + String cellValue = dv.getDisplayValue(); + if (cellValue.indexOf("|#") != -1) { + cellValue = cellValue.substring(0, cellValue.indexOf("|")); + } + + final PdfPCell cell = new PdfPCell(new Paragraph(cellValue, cellFont)); + //row background color can be overwritten by cell background color + cell.setBackgroundColor(getRowBackgroundColor(dr, idx)); + + cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER); + + if (rfmt != null) { + formatterCell(rfmt, cell); + } + table.addCell(cell); + } + } + } + first = false; + + if (runtime.freeMemory() / mb <= ((runtime.maxMemory() / mb) * Globals.getMemoryThreshold() + / 100)) { + returnValue = 1; + } + + //addRowHeader(table,dr,idx,rd); + + addRowColumns(table, dr, idx); + + if (idx % fragmentsize == fragmentsize - 1) { + document.add(table); + table.deleteBodyRows(); + table.setSkipFirstHeader(true); + } + } + + } + } + + //document.add(table); + + } + + document.add(table); + paintPdfReportFooter(request, document, rr, f); + + return returnValue; + } + private void addRowHeader(PdfPTable table, DataRow dr, int idx, ReportData rd) { table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER); |