From 33de75633647b0fac7a49b756fb5ba8291476d50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Tak=C3=A1cs?= <93127072+PeterTakacs300@users.noreply.github.com> Date: Tue, 4 Apr 2023 08:32:57 +0200 Subject: [PATCH] IDEMPIERE-5645 - Print Format Script Column cannot find Columns from context (#1760) * IDEMPIERE-5645 - Print Format Script Column cannot find Columns from context * IDEMPIERE-5645 - move script columnd parsing after 'all rows' loop * IDEMPIERE-5645 - fixes --- .../src/org/compiere/print/DataEngine.java | 39 ++++++++++++++----- .../org/compiere/print/PrintDataElement.java | 16 ++++++++ 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/print/DataEngine.java b/org.adempiere.base/src/org/compiere/print/DataEngine.java index 6771cc704b..0af89231f8 100644 --- a/org.adempiere.base/src/org/compiere/print/DataEngine.java +++ b/org.adempiere.base/src/org/compiere/print/DataEngine.java @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import java.util.Properties; import java.util.logging.Level; import java.util.regex.Pattern; @@ -895,6 +896,7 @@ public class DataEngine boolean hasLevelNo = pd.hasLevelNo(); int levelNo = 0; int reportLineID = 0; + ArrayList scriptColumns = new ArrayList(); // PreparedStatement pstmt = null; ResultSet rs = null; @@ -1061,18 +1063,13 @@ public class DataEngine int displayType = pdc.getDisplayType(); if(MPrintFormatItem.PRINTFORMATTYPE_Script.equalsIgnoreCase(pdc.getPrintFormatType())) { // ScriptColumn Object value = rs.getObject(displayIndex); - displayType = getDisplayType(value); if (display.startsWith("@SCRIPT")) { - display = display.replace("@SCRIPT", ""); - value = parseVariable(display, pdc, pd); - Interpreter bsh = new Interpreter (); - try { - value = bsh.eval(value.toString()); - } - catch (EvalError e) { - log.severe(e.getMessage()); - } + if(!scriptColumns.contains(pdc)) + scriptColumns.add(pdc); + displayType = DisplayType.Text; + } + else { displayType = getDisplayType(value); } pde = new PrintDataElement(pdc.getAD_PrintFormatItem_ID(), pdc.getColumnName(), (Serializable) value, displayType, pdc.getFormatPattern()); @@ -1167,6 +1164,28 @@ public class DataEngine rs = null; pstmt = null; } + // Parse Script column values + if(scriptColumns.size() > 0) { + for(int i = 0; i < pd.getRowCount(); i++) { + for(PrintDataColumn c : scriptColumns) { + pd.setRowIndex(i); + PrintDataElement e = (PrintDataElement) pd.getNodeByPrintFormatItemId(c.getAD_PrintFormatItem_ID()); + Object value = parseVariable(e.getValueAsString().replace("@SCRIPT", ""), c, pd); + Interpreter bsh = new Interpreter(); + try { + value = bsh.eval(value.toString()); + } + catch (EvalError err) { + log.severe(err.getMessage()); + } + e.setDisplayType(getDisplayType(value)); + if(value instanceof Serializable) + e.setValue((Serializable) value); + else + e.setValue(Objects.toString(value, "")); + } + } + } // -- we have all rows - finish // Check last Group Change if (m_group.getGroupColumnCount() > 1) // one is TOTAL diff --git a/org.adempiere.base/src/org/compiere/print/PrintDataElement.java b/org.adempiere.base/src/org/compiere/print/PrintDataElement.java index 3c996567be..e5abca681b 100644 --- a/org.adempiere.base/src/org/compiere/print/PrintDataElement.java +++ b/org.adempiere.base/src/org/compiere/print/PrintDataElement.java @@ -160,6 +160,14 @@ public class PrintDataElement implements Serializable return m_value; } // getValue + /** + * Set Node Value + * @param value + */ + public void setValue(Serializable value) { + this.m_value = value; + } + /** * Get Function Value * @return length or numeric value @@ -323,6 +331,14 @@ public class PrintDataElement implements Serializable return m_displayType; } // getDisplayType + /** + * Set Display Type + */ + public void setDisplayType(int displayType) + { + this.m_displayType = displayType; + } // setDisplayType + /** * Is Value numeric * @return true if value is a numeric