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
This commit is contained in:
Peter Takács 2023-04-04 08:32:57 +02:00 committed by GitHub
parent 9e18bc725e
commit 33de756336
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 10 deletions

View File

@ -28,6 +28,7 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -895,6 +896,7 @@ public class DataEngine
boolean hasLevelNo = pd.hasLevelNo(); boolean hasLevelNo = pd.hasLevelNo();
int levelNo = 0; int levelNo = 0;
int reportLineID = 0; int reportLineID = 0;
ArrayList<PrintDataColumn> scriptColumns = new ArrayList<PrintDataColumn>();
// //
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -1061,18 +1063,13 @@ public class DataEngine
int displayType = pdc.getDisplayType(); int displayType = pdc.getDisplayType();
if(MPrintFormatItem.PRINTFORMATTYPE_Script.equalsIgnoreCase(pdc.getPrintFormatType())) { // ScriptColumn if(MPrintFormatItem.PRINTFORMATTYPE_Script.equalsIgnoreCase(pdc.getPrintFormatType())) { // ScriptColumn
Object value = rs.getObject(displayIndex); Object value = rs.getObject(displayIndex);
displayType = getDisplayType(value);
if (display.startsWith("@SCRIPT")) { if (display.startsWith("@SCRIPT")) {
display = display.replace("@SCRIPT", ""); if(!scriptColumns.contains(pdc))
value = parseVariable(display, pdc, pd); scriptColumns.add(pdc);
Interpreter bsh = new Interpreter (); displayType = DisplayType.Text;
try { }
value = bsh.eval(value.toString()); else {
}
catch (EvalError e) {
log.severe(e.getMessage());
}
displayType = getDisplayType(value); displayType = getDisplayType(value);
} }
pde = new PrintDataElement(pdc.getAD_PrintFormatItem_ID(), pdc.getColumnName(), (Serializable) value, displayType, pdc.getFormatPattern()); 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; 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 // -- we have all rows - finish
// Check last Group Change // Check last Group Change
if (m_group.getGroupColumnCount() > 1) // one is TOTAL if (m_group.getGroupColumnCount() > 1) // one is TOTAL

View File

@ -160,6 +160,14 @@ public class PrintDataElement implements Serializable
return m_value; return m_value;
} // getValue } // getValue
/**
* Set Node Value
* @param value
*/
public void setValue(Serializable value) {
this.m_value = value;
}
/** /**
* Get Function Value * Get Function Value
* @return length or numeric value * @return length or numeric value
@ -323,6 +331,14 @@ public class PrintDataElement implements Serializable
return m_displayType; return m_displayType;
} // getDisplayType } // getDisplayType
/**
* Set Display Type
*/
public void setDisplayType(int displayType)
{
this.m_displayType = displayType;
} // setDisplayType
/** /**
* Is Value numeric * Is Value numeric
* @return true if value is a numeric * @return true if value is a numeric