From 5a5712fb71eb697eaaab54ced2cc921da10c2060 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Thu, 28 Mar 2013 20:03:57 -0500 Subject: [PATCH 1/3] IDEMPIERE-812 Improve statistics for reports --- .../src/org/compiere/process/ProcessInfo.java | 14 +++++++++++++- .../src/org/compiere/report/ReportStarter.java | 16 +++++++++++++--- .../server.product.launch | 2 +- .../org/compiere/apps/AbstractProcessCtl.java | 18 ++++++++++++++++++ .../src/org/compiere/print/ReportCtl.java | 15 ++++++++++++++- 5 files changed, 59 insertions(+), 6 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/process/ProcessInfo.java b/org.adempiere.base/src/org/compiere/process/ProcessInfo.java index 56c2e52d03..0742c93d4c 100644 --- a/org.adempiere.base/src/org/compiere/process/ProcessInfo.java +++ b/org.adempiere.base/src/org/compiere/process/ProcessInfo.java @@ -42,7 +42,7 @@ public class ProcessInfo implements Serializable /** * */ - private static final long serialVersionUID = 1426147857271483561L; + private static final long serialVersionUID = 1371812474929601477L; /** * Constructor @@ -137,6 +137,9 @@ public class ProcessInfo implements Serializable /** Export File */ private File m_exportFile = null; + /** Row count */ + private int m_rowCount; + /** * String representation * @return String representation @@ -761,4 +764,13 @@ public class ProcessInfo implements Serializable { m_Record_IDs = Record_IDs; } + + public void setRowCount(int rowCount) { + m_rowCount = rowCount; + } + + public int getRowCount() { + return m_rowCount; + } + } // ProcessInfo diff --git a/org.adempiere.report.jasper/src/org/compiere/report/ReportStarter.java b/org.adempiere.report.jasper/src/org/compiere/report/ReportStarter.java index 9f213ed9f9..2e5b420423 100644 --- a/org.adempiere.report.jasper/src/org/compiere/report/ReportStarter.java +++ b/org.adempiere.report.jasper/src/org/compiere/report/ReportStarter.java @@ -53,8 +53,8 @@ import net.sf.jasperreports.engine.JRExporterParameter; import net.sf.jasperreports.engine.JRParameter; import net.sf.jasperreports.engine.JRPropertiesUtil; import net.sf.jasperreports.engine.JRQuery; +import net.sf.jasperreports.engine.JRVariable; import net.sf.jasperreports.engine.JasperCompileManager; -import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperReport; import net.sf.jasperreports.engine.design.JRDesignQuery; @@ -67,6 +67,8 @@ import net.sf.jasperreports.engine.export.JRPrintServiceExporterParameter; import net.sf.jasperreports.engine.export.JRTextExporter; import net.sf.jasperreports.engine.export.JRXlsExporter; import net.sf.jasperreports.engine.export.JRXmlExporter; +import net.sf.jasperreports.engine.fill.JRBaseFiller; +import net.sf.jasperreports.engine.fill.JRFiller; import net.sf.jasperreports.engine.fill.JRSwapFileVirtualizer; import net.sf.jasperreports.engine.util.JRLoader; import net.sf.jasperreports.engine.util.JRSwapFile; @@ -351,6 +353,8 @@ public class ReportStarter implements ProcessCall, ClientProcess private boolean startProcess0(Properties ctx, ProcessInfo pi, Trx trx) { processInfo = pi; + int nrows = 0; + Object onrows = null; String Name=pi.getTitle(); int AD_PInstance_ID=pi.getAD_PInstance_ID(); int Record_ID=pi.getRecord_ID(); @@ -603,8 +607,10 @@ public class ReportStarter implements ProcessCall, ClientProcess params.put(JRParameter.REPORT_VIRTUALIZER, virtualizer); DefaultJasperReportsContext jasperContext = DefaultJasperReportsContext.getInstance(); JRPropertiesUtil.getInstance(jasperContext).setProperty("net.sf.jasperreports.awt.ignore.missing.font", "true"); - JasperPrint jasperPrint = JasperFillManager.fillReport( jasperReport, params, conn); - + JRBaseFiller filler = JRFiller.createFiller(jasperContext, jasperReport); + JasperPrint jasperPrint = filler.fill(params, conn); + onrows = filler.getVariableValue(JRVariable.REPORT_COUNT); + if (!processInfo.isExport()) { if (reportData.isDirectPrint()) @@ -734,6 +740,10 @@ public class ReportStarter implements ProcessCall, ClientProcess } } + if (onrows != null && onrows instanceof Integer) { + nrows = (Integer) onrows; + processInfo.setRowCount(nrows); + } reportResult( AD_PInstance_ID, null, trxName); return true; } diff --git a/org.adempiere.server-feature/server.product.launch b/org.adempiere.server-feature/server.product.launch index 07a3f843fe..55d4794405 100644 --- a/org.adempiere.server-feature/server.product.launch +++ b/org.adempiere.server-feature/server.product.launch @@ -21,7 +21,7 @@ - + diff --git a/org.adempiere.ui/src/org/compiere/apps/AbstractProcessCtl.java b/org.adempiere.ui/src/org/compiere/apps/AbstractProcessCtl.java index def4c8350f..d893aa7bed 100644 --- a/org.adempiere.ui/src/org/compiere/apps/AbstractProcessCtl.java +++ b/org.adempiere.ui/src/org/compiere/apps/AbstractProcessCtl.java @@ -26,6 +26,7 @@ import org.adempiere.util.IProcessUI; import org.adempiere.util.ProcessUtil; import org.compiere.db.CConnection; import org.compiere.interfaces.Server; +import org.compiere.model.MPInstance; import org.compiere.model.MRule; import org.compiere.print.ReportCtl; import org.compiere.process.ClientProcess; @@ -37,6 +38,7 @@ import org.compiere.util.Env; import org.compiere.util.Ini; import org.compiere.util.Msg; import org.compiere.util.Trx; +import org.compiere.util.Util; import org.compiere.wf.MWFProcess; /** @@ -268,6 +270,14 @@ public abstract class AbstractProcessCtl implements Runnable m_pi.setReportingProcess(true); m_pi.setClassName(ProcessUtil.JASPER_STARTER_CLASS); startProcess(); + MPInstance pinstance = new MPInstance(Env.getCtx(), m_pi.getAD_PInstance_ID(), null); + String errmsg = pinstance.getErrorMsg(); + if (Util.isEmpty(errmsg, true)) + errmsg = "Rows=" + String.valueOf(m_pi.getRowCount()); + else + errmsg += " Rows=" + m_pi.getRowCount(); + pinstance.setErrorMsg(errmsg); + pinstance.saveEx(); unlock(); return; } @@ -278,6 +288,14 @@ public abstract class AbstractProcessCtl implements Runnable // Start Report ----------------------------------------------- boolean ok = ReportCtl.start(m_processUI, windowno, m_pi, IsDirectPrint); m_pi.setSummary("Report", !ok); + MPInstance pinstance = new MPInstance(Env.getCtx(), m_pi.getAD_PInstance_ID(), null); + String errmsg = pinstance.getErrorMsg(); + if (Util.isEmpty(errmsg, true)) + errmsg = "Rows=" + String.valueOf(m_pi.getRowCount()); + else + errmsg += " Rows=" + m_pi.getRowCount(); + pinstance.setErrorMsg(errmsg); + pinstance.saveEx(); unlock (); } /********************************************************************** diff --git a/org.adempiere.ui/src/org/compiere/print/ReportCtl.java b/org.adempiere.ui/src/org/compiere/print/ReportCtl.java index 3d4cb6d6ac..08e75c5b20 100644 --- a/org.adempiere.ui/src/org/compiere/print/ReportCtl.java +++ b/org.adempiere.ui/src/org/compiere/print/ReportCtl.java @@ -16,6 +16,16 @@ *****************************************************************************/ package org.compiere.print; +import static org.compiere.model.SystemIDs.PROCESS_RPT_C_DUNNING; +import static org.compiere.model.SystemIDs.PROCESS_RPT_C_INVOICE; +import static org.compiere.model.SystemIDs.PROCESS_RPT_C_ORDER; +import static org.compiere.model.SystemIDs.PROCESS_RPT_C_PAYMENT; +import static org.compiere.model.SystemIDs.PROCESS_RPT_C_PROJECT; +import static org.compiere.model.SystemIDs.PROCESS_RPT_C_RFQRESPONSE; +import static org.compiere.model.SystemIDs.PROCESS_RPT_FINREPORT; +import static org.compiere.model.SystemIDs.PROCESS_RPT_FINSTATEMENT; +import static org.compiere.model.SystemIDs.PROCESS_RPT_M_INOUT; + import java.util.Properties; import java.util.logging.Level; @@ -27,7 +37,6 @@ import org.compiere.model.MProcess; import org.compiere.model.MQuery; import org.compiere.model.MTable; import org.compiere.model.PrintInfo; -import static org.compiere.model.SystemIDs.*; import org.compiere.process.ProcessInfo; import org.compiere.util.CLogger; import org.compiere.util.Env; @@ -66,6 +75,7 @@ public class ReportCtl /** Static Logger */ private static CLogger s_log = CLogger.getCLogger (ReportCtl.class); + private volatile static ProcessInfo m_pi; /** * Create Report. @@ -113,6 +123,7 @@ public class ReportCtl { if (s_log.isLoggable(Level.INFO)) s_log.info("start - " + pi); + m_pi = pi; /** * Order Print */ @@ -363,6 +374,8 @@ public class ReportCtl private static void createOutput(ReportEngine re, boolean printPreview, String printerName) { + if (m_pi != null) + m_pi.setRowCount(re.getPrintData().getRowCount()); if (printPreview) preview(re); else { From 31c808cf7ccabe916cd62d9ca15b8c26b41962f0 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Sat, 30 Mar 2013 12:24:50 -0500 Subject: [PATCH 2/3] IDEMPIERE-454 Easy import / fix problem with java7 --- .../src/org/adempiere/impexp/GridTabCSVImporter.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java b/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java index 92c100ba96..dea57ca07c 100644 --- a/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java +++ b/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java @@ -219,8 +219,11 @@ public class GridTabCSVImporter implements IGridTabImporter sortedtTabMapIndexes = new TreeMap(bvc); sortedtTabMapIndexes.putAll(tabMapIndexes); }else{ - sortedtTabMapIndexes = new TreeMap(); - sortedtTabMapIndexes.put(gridTab,header.size()-1); + Map localMapIndexes = new HashMap(); + localMapIndexes.put(gridTab, header.size()-1); + ValueComparator bvc = new ValueComparator(localMapIndexes); + sortedtTabMapIndexes = new TreeMap(bvc); + sortedtTabMapIndexes.putAll(localMapIndexes); } CellProcessor[] processors = readProcArray.toArray(new CellProcessor[readProcArray.size()]); From 7ad9d21ef8685788a5d81acc16ac3c5e99e72802 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Sat, 30 Mar 2013 12:34:29 -0500 Subject: [PATCH 3/3] IDEMPIERE-454 Easy import / apply best practices on import mode variables --- .../adempiere/impexp/GridTabCSVImporter.java | 61 ++++++++++++------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java b/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java index dea57ca07c..dc545b4fc1 100644 --- a/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java +++ b/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java @@ -75,11 +75,14 @@ public class GridTabCSVImporter implements IGridTabImporter { private static final String ERROR_HEADER = "_ERROR_"; private static final String LOG_HEADER = "_LOG_"; - private String IMPORT_MODE = null; + private boolean m_isError = false; + private String m_import_mode = null; + private static final String IMPORT_MODE_MERGE = "M"; + private static final String IMPORT_MODE_UPDATE = "U"; + private static final String IMPORT_MODE_INSERT = "I"; /** Logger */ private static CLogger log = CLogger.getCLogger(GridTabCSVImporter.class); - boolean m_isError = false; public File fileImport(GridTab gridTab, List childs, InputStream filestream, Charset charset , String importMode) { ICsvMapReader mapReader = null; @@ -90,9 +93,9 @@ public class GridTabCSVImporter implements IGridTabImporter CsvPreference csvpref = CsvPreference.STANDARD_PREFERENCE; String delimiter = String.valueOf((char) csvpref.getDelimiterChar()); String quoteChar = String.valueOf((char) csvpref.getQuoteChar()); - IMPORT_MODE = importMode; + m_import_mode = importMode; - if(!gridTab.isInsertRecord() && IMPORT_MODE.equals("I")) + if(!gridTab.isInsertRecord() && isInsertMode()) throw new AdempiereException("Insert record disabled for Tab"); try { @@ -143,7 +146,7 @@ public class GridTabCSVImporter implements IGridTabImporter } } - if((IMPORT_MODE.equals("U") || IMPORT_MODE.equals("M")) && !isThereKey) + if(isUpdateOrMergeMode() && !isThereKey) throw new AdempiereException(gridTab.getTableName()+": "+Msg.getMsg(Env.getCtx(), "NoKeyFound")); tabMapIndexes.put(gridTab,indxDetail-1); @@ -161,7 +164,7 @@ public class GridTabCSVImporter implements IGridTabImporter if(currentDetailTab!=null){ //check out key per Tab - if((IMPORT_MODE.equals("U") || IMPORT_MODE.equals("M")) && !isThereKey){ + if(isUpdateOrMergeMode() && !isThereKey){ throw new AdempiereException(currentDetailTab.getTableName()+": "+Msg.getMsg(Env.getCtx(), "NoKeyFound")); }else{ tabMapIndexes.put(currentDetailTab,idx-1); @@ -207,7 +210,7 @@ public class GridTabCSVImporter implements IGridTabImporter } if(currentDetailTab!=null){ - if((IMPORT_MODE.equals("U") || IMPORT_MODE.equals("M")) && !isThereKey) + if(isUpdateOrMergeMode() && !isThereKey) throw new AdempiereException(currentDetailTab.getTableName()+": "+Msg.getMsg(Env.getCtx(), "NoKeyFound")); tabMapIndexes.put(currentDetailTab,header.size()-1); @@ -337,7 +340,7 @@ public class GridTabCSVImporter implements IGridTabImporter logMsg = areValidKeysAndColumns(currentGridTab,map,header,currentColumn,j,masterRecord); if (logMsg == null){ - if (IMPORT_MODE.equals("I")){ + if (isInsertMode()){ if(!currentGridTab.getTableModel().isOpen()) currentGridTab.getTableModel().open(0); //how to read from status since the warning is coming empty ? @@ -350,7 +353,7 @@ public class GridTabCSVImporter implements IGridTabImporter currentColumn = j + 1; if(!(logMsg == null)){ - IMPORT_MODE =importMode; + m_import_mode =importMode; //Ignore row since there is no data if("NO_DATA_TO_IMPORT".equals(logMsg)){ logMsg =""; @@ -370,7 +373,7 @@ public class GridTabCSVImporter implements IGridTabImporter if(currentGridTab.equals(gridTab)) masterRecord = po; - if(IMPORT_MODE.equals("I")) + if(isInsertMode()) logMsg = Msg.getMsg(Env.getCtx(), "Inserted")+" "+ po.toString(); else logMsg = Msg.getMsg(Env.getCtx(), "Updated")+" "+ po.toString(); @@ -420,7 +423,7 @@ public class GridTabCSVImporter implements IGridTabImporter break; } } - IMPORT_MODE = importMode; + m_import_mode = importMode; currentGridTab.getTableModel().setImportingMode(false, null); } } catch (Exception e) { @@ -435,7 +438,7 @@ public class GridTabCSVImporter implements IGridTabImporter trx.close(); trx = null; } - IMPORT_MODE =importMode; + m_import_mode =importMode; } // write rawLine = rawLine + delimiter + quoteChar + rowResult.toString().replaceAll(delimiter, "") + quoteChar + "\n"; @@ -468,7 +471,23 @@ public class GridTabCSVImporter implements IGridTabImporter else return errFile; } + + private boolean isInsertMode() { + return IMPORT_MODE_INSERT.equals(m_import_mode); + } + private boolean isUpdateMode() { + return IMPORT_MODE_UPDATE.equals(m_import_mode); + } + + private boolean isMergeMode() { + return IMPORT_MODE_MERGE.equals(m_import_mode); + } + + private boolean isUpdateOrMergeMode() { + return isUpdateMode() || isMergeMode(); + } + private String getColumnName(boolean isKey ,boolean isForeing ,boolean isDetail , String headName){ if(isKey){ @@ -594,7 +613,7 @@ public class GridTabCSVImporter implements IGridTabImporter if(idS == null && id < 0){ //it could be that record still doesn't exist if import mode is inserting or merging - if(IMPORT_MODE.equals("U")) + if(isUpdateMode()) return new StringBuilder(Msg.getMsg(Env.getCtx(),"ForeignNotResolved",new Object[]{header.get(i),value})); } } else { @@ -692,7 +711,7 @@ public class GridTabCSVImporter implements IGridTabImporter if(header.get(i).contains(MTable.getTableName(Env.getCtx(),MLocation.Table_ID))){ if(address == null){ - if(IMPORT_MODE.equals("I")){ + if(isInsertMode()){ address = new MLocation (Env.getCtx(),0,masterRecord.get_TrxName()); }else{ Object location = gridTab.getValue("C_Location_ID")==null?0:gridTab.getValue("C_Location_ID").toString(); @@ -712,7 +731,7 @@ public class GridTabCSVImporter implements IGridTabImporter } address.set_ValueOfColumn(columnName,setValue); }else{ - if(isKeyColumn && IMPORT_MODE.equals("U")) + if(isKeyColumn && isUpdateMode()) continue; GridField field = gridTab.getField(columnName); @@ -765,7 +784,7 @@ public class GridTabCSVImporter implements IGridTabImporter if(!field.isDisplayed(true)) continue; - if (!IMPORT_MODE.equals("I") && !field.isEditable(true) && value!=null) { + if (!isInsertMode() && !field.isEditable(true) && value!=null) { logMsg = Msg.getMsg(Env.getCtx(), "FieldNotEditable", new Object[] {header.get(i)}) + "{" + value + "}"; break; } @@ -1000,13 +1019,13 @@ public class GridTabCSVImporter implements IGridTabImporter } gridTab.getTableModel().dataRequery(pquery.getWhereClause(),false,0); gridTab.setCurrentRow(0,true); - if (IMPORT_MODE.equals("I")){ + if (isInsertMode()){ if(gridTab.getTableModel().getRowCount()>=1) logMsg = Msg.getMsg(Env.getCtx(), "AlreadyExists")+" "+pquery; else return null; } - if (IMPORT_MODE.equals("U")){ + if (isUpdateMode()){ if(gridTab.getTableModel().getRowCount()==1) return null; else if(gridTab.getTableModel().getRowCount()<=0) @@ -1014,11 +1033,11 @@ public class GridTabCSVImporter implements IGridTabImporter else if(gridTab.getTableModel().getRowCount()>1) logMsg = Msg.getMsg(Env.getCtx(),"TooManyRows")+" "+pquery; } - if (IMPORT_MODE.equals("M")){ + if (isMergeMode()){ if(gridTab.getTableModel().getRowCount()==1) - IMPORT_MODE = "U"; + m_import_mode = IMPORT_MODE_UPDATE; else if(gridTab.getTableModel().getRowCount()<=0) - IMPORT_MODE = "I"; + m_import_mode = IMPORT_MODE_INSERT; else if(gridTab.getTableModel().getRowCount()>1) logMsg = Msg.getMsg(Env.getCtx(),"TooManyRows")+" "+pquery; }