From 14c27c58ca1322c911f05607ee48d5a1382f63aa Mon Sep 17 00:00:00 2001 From: Deepak Pansheriya Date: Thu, 14 May 2020 22:06:15 +0530 Subject: [PATCH] Idempiere 3333 (#60) * IDEMPIERE-3333: Respecting ReportView order by clause when there is no orderby field on print format configured. * IDEMPIERE-3333: Adding cached method as per peer review comment. * IDEMPIERE-3333: Refactoring as per feedback from Carlos Ruiz. --- .../src/org/compiere/model/MReportView.java | 65 +++++++++++++++++++ .../src/org/compiere/print/DataEngine.java | 13 +++- 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 org.adempiere.base/src/org/compiere/model/MReportView.java diff --git a/org.adempiere.base/src/org/compiere/model/MReportView.java b/org.adempiere.base/src/org/compiere/model/MReportView.java new file mode 100644 index 0000000000..77251f1b04 --- /dev/null +++ b/org.adempiere.base/src/org/compiere/model/MReportView.java @@ -0,0 +1,65 @@ +/****************************************************************************** + * Product: iDempiere ERP & CRM Smart Business Solution * + * Copyright (C) 1999-2012 ComPiere, Inc. All Rights Reserved. * + * This program is free software, you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY, without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program, if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + * For the text or an alternative of this public license, you may reach us * + * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * + * or via info@compiere.org or http://www.compiere.org/license.html * + *****************************************************************************/ +package org.compiere.model; +import java.sql.ResultSet; +import java.util.Properties; + +import org.compiere.util.CCache; +import org.compiere.util.CLogger; + +public class MReportView extends X_AD_ReportView { + + /** + * + */ + private static final long serialVersionUID = -5674822764517548357L; + + /** Static Logger */ + private static CLogger s_log = CLogger.getCLogger (MReportView.class); + /** Cache */ + static private CCache s_cache = new CCache(Table_Name, 30, 60); + + + public MReportView(Properties ctx, int AD_ReportView_ID, String trxName) { + super(ctx, AD_ReportView_ID, trxName); + } + + public MReportView(Properties ctx, ResultSet rs, String trxName) { + super(ctx, rs, trxName); + } + + /** + * + * @param ctx + * @param AD_ReportView_ID + * @return + */ + public static MReportView get (Properties ctx, int AD_ReportView_ID) { + if(AD_ReportView_ID==0) { + return null; + } + + Integer key = Integer.valueOf(AD_ReportView_ID); + MReportView retValue = (MReportView)s_cache.get(key); + if (retValue == null) + { + retValue = new MReportView (ctx, AD_ReportView_ID, null); + s_cache.put(key, retValue); + } + return retValue; + } // get +} diff --git a/org.adempiere.base/src/org/compiere/print/DataEngine.java b/org.adempiere.base/src/org/compiere/print/DataEngine.java index 83a89d3021..a3f74b2719 100644 --- a/org.adempiere.base/src/org/compiere/print/DataEngine.java +++ b/org.adempiere.base/src/org/compiere/print/DataEngine.java @@ -30,6 +30,7 @@ import java.util.regex.Pattern; import org.adempiere.exceptions.AdempiereException; import org.compiere.model.MLookupFactory; import org.compiere.model.MQuery; +import org.compiere.model.MReportView; import org.compiere.model.MRole; import org.compiere.model.MTable; import org.compiere.util.CLogMgt; @@ -709,7 +710,7 @@ public class DataEngine } // Add ORDER BY clause - if (orderColumns != null) + if (orderColumns != null && orderColumns.size() > 0) { for (int i = 0; i < orderColumns.size(); i++) { @@ -723,7 +724,15 @@ public class DataEngine finalSQL.append(by); } } // order by - + else if (format.getAD_ReportView_ID() > 0) + { + MReportView reportView = MReportView.get(Env.getCtx(),format.getAD_ReportView_ID()); + + if (reportView!=null && !Util.isEmpty(reportView.getOrderByClause(), true)) + { + finalSQL.append(" ORDER BY ").append(reportView.getOrderByClause()); + } + } // Report view order by clause. // Print Data PrintData pd = new PrintData (ctx, reportName);