From ba13d8584ea0f008a48ce50fb90a4889ea0e2a0d Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Sat, 18 May 2019 12:54:37 +0200 Subject: [PATCH] IDEMPIERE-2479 fix a problem with switching from columnnary reports to form back and forth - index out of bounds - suppresscolumns is just intended for columnnary reports --- .../src/org/adempiere/pdf/Document.java | 5 ++-- .../src/org/compiere/print/ReportEngine.java | 24 +++++++++++++------ .../compiere/print/layout/LayoutEngine.java | 3 +++ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/org.adempiere.base/src/org/adempiere/pdf/Document.java b/org.adempiere.base/src/org/adempiere/pdf/Document.java index 9d315d4168..8f875be188 100644 --- a/org.adempiere.base/src/org/adempiere/pdf/Document.java +++ b/org.adempiere.base/src/org/adempiere/pdf/Document.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; +import org.adempiere.exceptions.AdempiereException; import org.compiere.model.MSysConfig; import com.itextpdf.text.FontFactory; @@ -86,7 +87,7 @@ public class Document { document.close(); } catch (Exception e) { - e.printStackTrace(); + throw new AdempiereException(e); } } @@ -96,7 +97,7 @@ public class Document { try { writePDF(pageable, new FileOutputStream(result)); } catch (Exception e) { - e.printStackTrace(); + throw new AdempiereException(e); } return result; diff --git a/org.adempiere.base/src/org/compiere/print/ReportEngine.java b/org.adempiere.base/src/org/compiere/print/ReportEngine.java index f8577f1ee5..bd87d854da 100644 --- a/org.adempiere.base/src/org/compiere/print/ReportEngine.java +++ b/org.adempiere.base/src/org/compiere/print/ReportEngine.java @@ -60,6 +60,7 @@ import javax.print.event.PrintServiceAttributeEvent; import javax.print.event.PrintServiceAttributeListener; import javax.xml.transform.stream.StreamResult; +import org.adempiere.exceptions.AdempiereException; import org.adempiere.pdf.Document; import org.adempiere.print.export.PrintDataExcelExporter; import org.apache.ecs.XhtmlDocument; @@ -578,6 +579,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) catch (Exception e) { log.log(Level.SEVERE, "(f)", e); + throw new AdempiereException(e); } return false; } // createHTML @@ -674,7 +676,11 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) tbody.setNeedClosingTag(false); Boolean [] colSuppressRepeats = m_layout == null || m_layout.colSuppressRepeats == null? LayoutEngine.getColSuppressRepeats(m_printFormat):m_layout.colSuppressRepeats; - Object [] preValues = new Object [colSuppressRepeats.length]; + Object [] preValues = null; + if (colSuppressRepeats != null){ + preValues = new Object [colSuppressRepeats.length]; + } + int printColIndex = -1; // for all rows (-1 = header row) for (int row = -1; row < m_printData.getRowCount(); row++) @@ -732,7 +738,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) Object obj = m_printData.getNode(Integer.valueOf(item.getAD_Column_ID())); if (obj == null){ td.addElement(" "); - if (colSuppressRepeats[printColIndex]){ + if (colSuppressRepeats != null && colSuppressRepeats[printColIndex]){ preValues[printColIndex] = null; } } @@ -741,7 +747,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) PrintDataElement pde = (PrintDataElement) obj; String value = pde.getValueDisplay(language); // formatted - if (colSuppressRepeats[printColIndex]){ + if (colSuppressRepeats != null && colSuppressRepeats[printColIndex]){ if (value.equals(preValues[printColIndex])){ td.addElement(" "); continue; @@ -858,6 +864,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) catch (Exception e) { log.log(Level.SEVERE, "(w)", e); + throw new AdempiereException(e); } return false; } // createHTML @@ -916,7 +923,10 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) try { Boolean [] colSuppressRepeats = m_layout == null || m_layout.colSuppressRepeats == null? LayoutEngine.getColSuppressRepeats(m_printFormat):m_layout.colSuppressRepeats; - Object [] preValues = new Object [colSuppressRepeats.length]; + Object [] preValues = null; + if (colSuppressRepeats != null){ + preValues = new Object [colSuppressRepeats.length]; + } int printColIndex = -1; // for all rows (-1 = header row) for (int row = -1; row < m_printData.getRowCount(); row++) @@ -948,7 +958,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) Object obj = m_printData.getNode(Integer.valueOf(item.getAD_Column_ID())); String data = ""; if (obj == null){ - if (colSuppressRepeats[printColIndex]){ + if (colSuppressRepeats != null && colSuppressRepeats[printColIndex]){ preValues[printColIndex] = null; } } @@ -960,7 +970,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) else data = pde.getValueDisplay(language); // formatted - if (colSuppressRepeats[printColIndex]){ + if (colSuppressRepeats != null && colSuppressRepeats[printColIndex]){ if (data.equals(preValues[printColIndex])){ continue; }else{ @@ -1149,7 +1159,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) catch (Exception e) { log.log(Level.SEVERE, "PDF", e); - return false; + throw new AdempiereException(e); } File file2 = new File(fileName); diff --git a/org.adempiere.base/src/org/compiere/print/layout/LayoutEngine.java b/org.adempiere.base/src/org/compiere/print/layout/LayoutEngine.java index 4e551fb4c8..69916c91e2 100644 --- a/org.adempiere.base/src/org/compiere/print/layout/LayoutEngine.java +++ b/org.adempiere.base/src/org/compiere/print/layout/LayoutEngine.java @@ -250,6 +250,7 @@ public class LayoutEngine implements Pageable, Printable, Doc public void setPrintFormat (MPrintFormat format, boolean doLayout) { m_format = format; + this.colSuppressRepeats = null; // Initial & Default Settings m_printCtx = new Properties(format.getCtx()); @@ -1980,6 +1981,8 @@ public class LayoutEngine implements Pageable, Printable, Doc } public static Boolean [] getColSuppressRepeats (MPrintFormat format){ + if (format.isForm()) + return null; List colSuppressRepeats = new ArrayList<>(); for (int c = 0; c < format.getItemCount(); c++) {