IDEMPIERE-5326: Parsing error for report view if where clause and vir… (#1385)

* IDEMPIERE-5326: Parsing error for report view if where clause and virtual column used in print format

* IDEMPIERE-5326: Fixing Compilation error

* IDEMPIERE-5326: Adding method back for backward compitability

* IDEMPIERE-5326: Adding constructors  for backward compitability
This commit is contained in:
Deepak Pansheriya 2022-09-07 19:15:23 +05:30 committed by GitHub
parent 1f4a23657a
commit 8c5c0ecbfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 155 additions and 43 deletions

View File

@ -86,18 +86,28 @@ public class DataEngine
*/
public DataEngine (Language language)
{
this(language, null);
this(language, null, 0);
} // DataEngine
/**
* Constructor
* @param language Language of the data (for translation)
* @param language
* @param trxName
*/
public DataEngine (Language language, String trxName){
this(language,trxName,0);
}
/**
* Constructor
* @param language Language of the data (for translation)
* @param trxName
* @param windowNo
*/
public DataEngine (Language language, String trxName, int windowNo){
if (language != null)
m_language = language;
m_trxName = trxName;
m_windowNo = windowNo;
} // DataEngine
/** Logger */
@ -123,6 +133,8 @@ public class DataEngine
private boolean m_summary = false;
/** Key Indicator in Report */
public static final String KEY = "*";
/** Window No */
private int m_windowNo = 0;
private Map<Object, Object> m_summarized = new HashMap<Object, Object>();
@ -188,7 +200,7 @@ public class DataEngine
if (whereClause.indexOf("@") == -1) {
queryCopy.addRestriction(whereClause);
} else { // replace context variables
queryCopy.addRestriction(Env.parseContext(ctx, 0, whereClause.toString(), false, true));
queryCopy.addRestriction(Env.parseContext(ctx, m_windowNo, whereClause.toString(), false, true));
}
}
}
@ -332,7 +344,7 @@ public class DataEngine
if (ColumnSQL != null && ColumnSQL.length() > 0 && ColumnSQL.startsWith("@SQL="))
ColumnSQL = "NULL";
if (ColumnSQL != null && ColumnSQL.contains("@"))
ColumnSQL = Env.parseContext(Env.getCtx(), -1, ColumnSQL, false, true);
ColumnSQL = Env.parseContext(Env.getCtx(), m_windowNo, ColumnSQL, false, true);
if (ColumnSQL == null)
ColumnSQL = "";
else{
@ -412,7 +424,7 @@ public class DataEngine
if (script.startsWith("@SQL="))
{
script = "(" + script.replace("@SQL=", "").trim() + ")";
script = Env.parseContext(Env.getCtx(), 0, script, false);
script = Env.parseContext(Env.getCtx(), m_windowNo, script, false);
}
else
script = "'@SCRIPT" + script + "'";
@ -1385,6 +1397,15 @@ public class DataEngine
query.addRestriction("AD_Table_ID", MQuery.LESS, 105);
}
public int getWindowNo()
{
return m_windowNo;
}
public void setWindowNo(int windowNo)
{
this.m_windowNo = windowNo;
}
} // DataEngine
/**

View File

@ -190,6 +190,34 @@ public class ReportEngine implements PrintServiceAttributeListener
* @param trxName
*/
public ReportEngine (Properties ctx, MPrintFormat pf, MQuery query, PrintInfo info, boolean isSummary, String trxName)
{
this(ctx, pf, query, info, false, trxName, 0);
}
/**
* Set report engine with summary = false
* @param ctx
* @param pf
* @param query
* @param info
* @param trxName
* @param windowNo
*/
public ReportEngine (Properties ctx, MPrintFormat pf, MQuery query, PrintInfo info, String trxName, int windowNo){
this(ctx, pf, query, info, false, trxName, windowNo);
}
/**
* Constructor
* @param ctx context
* @param pf Print Format
* @param query Optional Query
* @param info print info
* @param isSummary
* @param trxName
* @param windowNo
*/
public ReportEngine (Properties ctx, MPrintFormat pf, MQuery query, PrintInfo info, boolean isSummary, String trxName, int windowNo)
{
m_summary = isSummary;
if (pf == null)
@ -200,6 +228,7 @@ public class ReportEngine implements PrintServiceAttributeListener
m_printFormat = pf;
m_info = info;
m_trxName = trxName;
m_windowNo = windowNo;
initName();
setQuery(query); // loads Data
@ -320,7 +349,7 @@ public class ReportEngine implements PrintServiceAttributeListener
if (m_query == null)
return;
DataEngine de = new DataEngine(m_printFormat.getLanguage(),m_trxName);
DataEngine de = new DataEngine(m_printFormat.getLanguage(),m_trxName, m_windowNo);
setPrintData(de.getPrintData (m_ctx, m_printFormat, m_query, m_summary));
// m_printData.dump();
} // setPrintData
@ -356,7 +385,7 @@ public class ReportEngine implements PrintServiceAttributeListener
throw new IllegalStateException ("No print format");
if (m_printData == null)
throw new IllegalStateException ("No print data (Delete Print Format and restart)");
m_layout = new LayoutEngine (m_printFormat, m_printData, m_query, m_info, m_trxName);
m_layout = new LayoutEngine (m_printFormat, m_printData, m_query, m_info, m_trxName, m_windowNo);
} // layout
/**
@ -1791,6 +1820,18 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
* @return report engine or null
*/
static public ReportEngine get (Properties ctx, ProcessInfo pi)
{
return get(ctx, pi, 0);
}
/**************************************************************************
* Get Report Engine for process info
* @param ctx context
* @param pi process info with AD_PInstance_ID
* @param windowNo Window No
* @return report engine or null
*/
static public ReportEngine get (Properties ctx, ProcessInfo pi, int windowNo)
{
int AD_Client_ID = pi.getAD_Client_ID();
//
@ -1921,7 +1962,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
PrintInfo info = new PrintInfo (pi);
info.setAD_Table_ID(AD_Table_ID);
return new ReportEngine(ctx, format, query, info, pi.isSummary(), pi.getTransactionName());
return new ReportEngine(ctx, format, query, info, pi.isSummary(), pi.getTransactionName(), windowNo);
} // get
/*************************************************************************/
@ -1976,7 +2017,19 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
*/
public static ReportEngine get (Properties ctx, int type, int Record_ID)
{
return get(ctx, type, Record_ID, null);
return get(ctx, type, Record_ID, null, 0);
}
/**************************************************************************
* Get Document Print Engine for Document Type.
* @param ctx context
* @param type document type
* @param Record_ID id
* @return Report Engine or null
*/
public static ReportEngine get (Properties ctx, int type, int Record_ID, int windowNo)
{
return get(ctx, type, Record_ID, null, windowNo);
}
/**************************************************************************
@ -1988,6 +2041,20 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
* @return Report Engine or null
*/
public static ReportEngine get (Properties ctx, int type, int Record_ID, String trxName)
{
return get(ctx, type, Record_ID, trxName, 0);
}
/**************************************************************************
* Get Document Print Engine for Document Type.
* @param ctx context
* @param type document type
* @param Record_ID id
* @param trxName
* @param windowNo
* @return Report Engine or null
*/
public static ReportEngine get(Properties ctx, int type, int Record_ID, String trxName, int windowNo)
{
if (Record_ID < 1)
{
@ -2215,7 +2282,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
info.setPrinterName(format.getPrinterName());
// Engine
ReportEngine re = new ReportEngine(ctx, format, query, info, trxName);
ReportEngine re = new ReportEngine(ctx, format, query, info, trxName, windowNo);
return re;
} // get

View File

@ -108,25 +108,53 @@ import org.idempiere.print.StandardHeaderFooter;
public class LayoutEngine implements Pageable, Printable, Doc
{
/**
* Detail Constructor
* @param format Print Format
* @param data Print Data
* @param query query for parameter info
* Constructor
* @param format
* @param data
* @param query
* @param info
*/
public LayoutEngine (MPrintFormat format, PrintData data, MQuery query, PrintInfo info )
public LayoutEngine (MPrintFormat format, PrintData data, MQuery query, PrintInfo info)
{
this(format, data, query, info , null);
} // LayoutEngine
this(format,data,query,info,0);
}
/**
* Detail Constructor
* @param format Print Format
* @param data Print Data
* @param query query for parameter info
* @param info
* @param windowNo
*/
public LayoutEngine (MPrintFormat format, PrintData data, MQuery query, PrintInfo info, int windowNo )
{
this(format, data, query, info , null, windowNo);
} // LayoutEngine
/**
* Detail Constructor
* @param format
* @param data
* @param query
* @param info
* @param trxName
*/
public LayoutEngine (MPrintFormat format, PrintData data, MQuery query, PrintInfo info , String trxName)
{
this(format,data,query,info,trxName,0);
}
/**
* Detail Constructor
* @param format Print Format
* @param data Print Data
* @param query query for parameter info
* @param info
* @param trxName
* @param windowNo
*/
public LayoutEngine (MPrintFormat format, PrintData data, MQuery query, PrintInfo info , String trxName, int windowNo)
{
m_windowNo = windowNo;
m_TrxName = trxName;
if (log.isLoggable(Level.INFO)) log.info(format + " - " + data + " - " + query);
// s_FASTDRAW = MClient.get(format.getCtx()).isUseBetaFunctions();
@ -163,6 +191,8 @@ public class LayoutEngine implements Pageable, Printable, Doc
/** PrintInfo **/
private PrintInfo m_PrintInfo = null;
/** Window No */
private int m_windowNo = 0;
/** Paper - default: standard portrait */
private CPaper m_paper;
@ -290,7 +320,7 @@ public class LayoutEngine implements Pageable, Printable, Doc
// Print Context
Env.setContext(m_printCtx, Page.CONTEXT_REPORTNAME, m_format.get_Translation(MPrintFormat.COLUMNNAME_Name));
Env.setContext(m_printCtx, Page.CONTEXT_HEADER, Env.getHeader(m_printCtx, 0));
Env.setContext(m_printCtx, Page.CONTEXT_HEADER, Env.getHeader(m_printCtx, m_windowNo));
Env.setContext(m_printCtx, Env.LANGUAGE, m_format.getLanguage().getAD_Language());
if (m_hasLayout && doLayout)
@ -1260,7 +1290,7 @@ public class LayoutEngine implements Pageable, Printable, Doc
if (log.isLoggable(Level.FINE))
log.fine(query.toString());
//
DataEngine de = new DataEngine(format.getLanguage(),m_TrxName);
DataEngine de = new DataEngine(format.getLanguage(),m_TrxName, m_windowNo);
PrintData includedData = de.getPrintData(data.getCtx(), format, query);
if (includedData == null)
return null;

View File

@ -566,7 +566,7 @@ public class ProcessDialog extends AbstractProcessDialog implements EventListene
for (int i = 0; i < m_ids.length; i++)
{
int M_InOut_ID = m_ids[i];
ReportEngine re = ReportEngine.get (Env.getCtx(), ReportEngine.SHIPMENT, M_InOut_ID);
ReportEngine re = ReportEngine.get (Env.getCtx(), ReportEngine.SHIPMENT, M_InOut_ID, getWindowNo());
pdfList.add(re.getPDF());
}
@ -651,7 +651,7 @@ public class ProcessDialog extends AbstractProcessDialog implements EventListene
for (int i = 0; i < m_ids.length; i++)
{
int C_Invoice_ID = m_ids[i];
ReportEngine re = ReportEngine.get (Env.getCtx(), ReportEngine.INVOICE, C_Invoice_ID);
ReportEngine re = ReportEngine.get (Env.getCtx(), ReportEngine.INVOICE, C_Invoice_ID, getWindowNo());
pdfList.add(re.getPDF());
}

View File

@ -196,9 +196,8 @@ public class WReport implements EventListener<Event> {
else
{
// It's a default report using the standard printing engine
ReportEngine re = new ReportEngine (Env.getCtx(), pf, m_query, info);
ReportEngine re = new ReportEngine (Env.getCtx(), pf, m_query, info, null, WindowNo);
re.setWhereExtended(whereExtended);
re.setWindowNo(WindowNo);
ReportCtl.preview(re);
}
} // launchReport

View File

@ -423,11 +423,11 @@ public class WGenForm extends ADForm implements EventListener<Event>, WTableMode
query.addRestriction(table.getTableName() + "_ID", MQuery.EQUAL, RecordID);
// Engine
PrintInfo info = new PrintInfo(table.getTableName(),table.get_Table_ID(), RecordID);
re = new ReportEngine(Env.getCtx(), format, query, info);
re = new ReportEngine(Env.getCtx(), format, query, info, null, m_WindowNo);
}
else
{
re = ReportEngine.get (Env.getCtx(), genForm.getReportEngineType(), RecordID);
re = ReportEngine.get (Env.getCtx(), genForm.getReportEngineType(), RecordID, m_WindowNo);
}
pdfList.add(re.getPDF());

View File

@ -529,7 +529,7 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
MPaySelectionCheck.confirmPrint(m_checks[i], m_batch);
// ReportCtrl will check BankAccountDoc for PrintFormat
ReportEngine re = ReportEngine.get(Env.getCtx(), ReportEngine.CHECK, check.get_ID());
ReportEngine re = ReportEngine.get(Env.getCtx(), ReportEngine.CHECK, check.get_ID(), m_WindowNo);
try
{
MPrintFormat format = re.getPrintFormat();
@ -602,7 +602,7 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene
for (int i = 0; i < m_checks.length; i++)
{
MPaySelectionCheck check = m_checks[i];
ReportEngine re = ReportEngine.get(Env.getCtx(), ReportEngine.REMITTANCE, check.get_ID());
ReportEngine re = ReportEngine.get(Env.getCtx(), ReportEngine.REMITTANCE, check.get_ID(), m_WindowNo);
try
{
MPrintFormat format = re.getPrintFormat();

View File

@ -373,9 +373,8 @@ public class ReportAction implements EventListener<Event>
else
{
// It's a default report using the standard printing engine
ReportEngine re = new ReportEngine (Env.getCtx(), pf, query, info);
ReportEngine re = new ReportEngine (Env.getCtx(), pf, query, info, null, gridTab.getWindowNo());
re.setWhereExtended(gridTab.getWhereExtended());
re.setWindowNo(gridTab.getWindowNo());
if (export)
export(re);

View File

@ -387,8 +387,7 @@ public class DrillReportCtl {
info.setDescription(m_Query.getInfo());
// It's a default report using the standard printing engine
ReportEngine re = new ReportEngine (Env.getCtx(), pf, m_Query, info);
re.setWindowNo(m_WindowNo);
ReportEngine re = new ReportEngine (Env.getCtx(), pf, m_Query, info,null,m_WindowNo);
ReportCtl.preview(re);
} // launchReport

View File

@ -255,12 +255,12 @@ public class ReportCtl
String TableName = MTable.getTableName(ctx, format.getAD_Table_ID());
MQuery query = MQuery.get (ctx, pi.getAD_PInstance_ID(), TableName);
PrintInfo info = new PrintInfo(pi);
re = new ReportEngine(ctx, format, query, info, pi.isSummary());
re = new ReportEngine(ctx, format, query, info, pi.isSummary(), null, WindowNo);
}
//
// Create Report Engine normally
else {
re = ReportEngine.get(Env.getCtx(), pi);
re = ReportEngine.get(Env.getCtx(), pi, WindowNo);
if (re == null)
{
pi.setSummary("No ReportEngine");
@ -272,7 +272,6 @@ public class ReportCtl
re.setReportType(pi.getReportType());
}
re.setLanguageID(pi.getLanguageID());
re.setWindowNo(WindowNo);
re.setIsReplaceTabContent(pi.isReplaceTabContent());
createOutput(re, pi.isPrintPreview(), null);
return true;
@ -314,8 +313,7 @@ public class ReportCtl
}
PrintInfo info = new PrintInfo(pi);
ReportEngine re = new ReportEngine(Env.getCtx(), format, query, info, pi.isSummary());
re.setWindowNo(WindowNo);
ReportEngine re = new ReportEngine(Env.getCtx(), format, query, info, pi.isSummary(), null, WindowNo);
if (pi.getReportType() != null) {
re.setReportType(pi.getReportType());
}
@ -382,12 +380,11 @@ public class ReportCtl
public static boolean startDocumentPrint (int type, MPrintFormat customPrintFormat, int Record_ID, IProcessUI parent, int WindowNo,
boolean IsDirectPrint, String printerName)
{
ReportEngine re = ReportEngine.get (Env.getCtx(), type, Record_ID);
ReportEngine re = ReportEngine.get (Env.getCtx(), type, Record_ID, WindowNo);
if (re == null)
{
throw new AdempiereException("NoDocPrintFormat");
}
re.setWindowNo(WindowNo);
if (customPrintFormat!=null) {
// Use custom print format if available
re.setPrintFormat(customPrintFormat);