From b2b31fb087fb8b81f4cab7b765be423d38d7f3e9 Mon Sep 17 00:00:00 2001 From: PeterTakacs300 <93127072+PeterTakacs300@users.noreply.github.com> Date: Wed, 25 May 2022 08:48:37 +0200 Subject: [PATCH] IDEMPIERE-3294 - check empty String parameter (#1336) * IDEMPIERE-3294 - check empty String parameter --- .../src/org/compiere/model/MPInstance.java | 19 ++++++++++++++++ .../src/org/compiere/model/MProcess.java | 4 ++-- .../org/compiere/report/FinReportJasper.java | 2 +- .../src/org/compiere/wf/MWFActivity.java | 22 ++++++++++++++----- .../server/org/compiere/server/Scheduler.java | 18 +++++++++++---- .../webui/apps/ProcessParameterPanel.java | 4 ++++ .../webui/desktop/DashboardController.java | 19 +++++++++++++--- .../org/idempiere/adinterface/Process.java | 18 +++++++++++---- 8 files changed, 87 insertions(+), 19 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MPInstance.java b/org.adempiere.base/src/org/compiere/model/MPInstance.java index 81b7e3aa11..6987d4b594 100644 --- a/org.adempiere.base/src/org/compiere/model/MPInstance.java +++ b/org.adempiere.base/src/org/compiere/model/MPInstance.java @@ -151,6 +151,25 @@ public class MPInstance extends X_AD_PInstance return m_parameters; } // getParameters + /** + * Get Process Parameters + * @return processParameters array + */ + public MProcessPara[] getProcessParameters() + { + final String whereClause = "AD_Process_ID=?"; + List list = new Query(getCtx(), MProcessPara.Table_Name, whereClause, get_TrxName()) + .setParameters(getAD_Process_ID()) + .setOnlyActiveRecords(true) + .setOrderBy("SeqNo") + .list(); + + // + MProcessPara[] processParameters = new MProcessPara[list.size()]; + list.toArray(processParameters); + return processParameters; + } // getParameters + /** * Validate that a set of process instance parameters are equal or not * to the current instance parameter diff --git a/org.adempiere.base/src/org/compiere/model/MProcess.java b/org.adempiere.base/src/org/compiere/model/MProcess.java index a957d515e4..8edf1d552d 100644 --- a/org.adempiere.base/src/org/compiere/model/MProcess.java +++ b/org.adempiere.base/src/org/compiere/model/MProcess.java @@ -297,7 +297,7 @@ public class MProcess extends X_AD_Process implements ImmutablePOSupport */ public MPInstance processIt (int Record_ID, Trx trx, boolean managedTrx) { - MPInstance pInstance = new MPInstance (this, Record_ID); + MPInstance pInstance = new MPInstance (getCtx(), this.getAD_Process_ID(), Record_ID); // Lock pInstance.setIsProcessing(true); pInstance.saveEx(); @@ -340,7 +340,7 @@ public class MProcess extends X_AD_Process implements ImmutablePOSupport { if (pi.getAD_PInstance_ID() == 0) { - MPInstance pInstance = new MPInstance (this, pi.getRecord_ID()); + MPInstance pInstance = new MPInstance (getCtx(), this.getAD_Process_ID(), pi.getRecord_ID()); // Lock pInstance.setIsProcessing(true); pInstance.saveEx(); diff --git a/org.adempiere.base/src/org/compiere/report/FinReportJasper.java b/org.adempiere.base/src/org/compiere/report/FinReportJasper.java index 44221cfc72..173c3e3de2 100644 --- a/org.adempiere.base/src/org/compiere/report/FinReportJasper.java +++ b/org.adempiere.base/src/org/compiere/report/FinReportJasper.java @@ -70,7 +70,7 @@ public class FinReportJasper extends FinReport m_report = new MReport (getCtx(), getRecord_ID(), get_TrxName()); MProcess proc = new MProcess(getCtx(), m_report.getJasperProcess_ID(), get_TrxName()); - MPInstance instance = new MPInstance(proc, getRecord_ID()); + MPInstance instance = new MPInstance(getCtx(), proc.getAD_Process_ID(), getRecord_ID()); instance.saveEx(); ProcessInfo poInfo = new ProcessInfo(proc.getName(), proc.getAD_Process_ID()); poInfo.setParameter(pars); diff --git a/org.adempiere.base/src/org/compiere/wf/MWFActivity.java b/org.adempiere.base/src/org/compiere/wf/MWFActivity.java index 7110e50995..bf383e332f 100644 --- a/org.adempiere.base/src/org/compiere/wf/MWFActivity.java +++ b/org.adempiere.base/src/org/compiere/wf/MWFActivity.java @@ -46,6 +46,7 @@ import org.compiere.model.MOrgInfo; import org.compiere.model.MPInstance; import org.compiere.model.MPInstancePara; import org.compiere.model.MProcess; +import org.compiere.model.MProcessPara; import org.compiere.model.MRefList; import org.compiere.model.MRole; import org.compiere.model.MTable; @@ -1127,8 +1128,9 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable getAD_Table_ID(), getRecord_ID()); pi.setAD_User_ID(getAD_User_ID()); pi.setAD_Client_ID(getAD_Client_ID()); - MPInstance pInstance = new MPInstance(process, getRecord_ID()); + MPInstance pInstance = new MPInstance(getCtx(), process.getAD_Process_ID(), getRecord_ID()); pInstance.set_TrxName(trx != null ? trx.getTrxName() : null); + pInstance.saveEx(); fillParameter(pInstance, trx); pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID()); // Report @@ -1157,7 +1159,8 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable if (log.isLoggable(Level.FINE)) log.fine("Process:AD_Process_ID=" + m_node.getAD_Process_ID()); // Process MProcess process = MProcess.get(getCtx(), m_node.getAD_Process_ID()); - MPInstance pInstance = new MPInstance(process, getRecord_ID()); + MPInstance pInstance = new MPInstance(getCtx(), process.getAD_Process_ID(), getRecord_ID()); + pInstance.saveEx(); fillParameter(pInstance, trx); // ProcessInfo pi = new ProcessInfo (m_node.getName(true), m_node.getAD_Process_ID(), @@ -1649,10 +1652,14 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable getPO(trx); // MWFNodePara[] nParams = m_node.getParameters(); - MPInstancePara[] iParams = pInstance.getParameters(); - for (int pi = 0; pi < iParams.length; pi++) + MProcessPara[] processParams = pInstance.getProcessParameters(); + for (int pi = 0; pi < processParams.length; pi++) { - MPInstancePara iPara = iParams[pi]; + MPInstancePara iPara = new MPInstancePara (pInstance, processParams[pi].getSeqNo()); + iPara.setParameterName(processParams[pi].getColumnName()); + iPara.setInfo(processParams[pi].getName()); + iPara.setParameterName(processParams[pi].getColumnName()); + iPara.setInfo(processParams[pi].getName()); for (int np = 0; np < nParams.length; np++) { MWFNodePara nPara = nParams[np]; @@ -1674,6 +1681,11 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable + " - empty"); break; } + if( DisplayType.isText(nPara.getDisplayType()) + && Util.isEmpty(String.valueOf(value))) { + if (log.isLoggable(Level.FINE)) log.fine(nPara.getAttributeName() + " - empty string"); + break; + } // Convert to Type try diff --git a/org.adempiere.server/src/main/server/org/compiere/server/Scheduler.java b/org.adempiere.server/src/main/server/org/compiere/server/Scheduler.java index 1ff636d865..47585c1980 100644 --- a/org.adempiere.server/src/main/server/org/compiere/server/Scheduler.java +++ b/org.adempiere.server/src/main/server/org/compiere/server/Scheduler.java @@ -45,6 +45,7 @@ import org.compiere.model.MOrgInfo; import org.compiere.model.MPInstance; import org.compiere.model.MPInstancePara; import org.compiere.model.MProcess; +import org.compiere.model.MProcessPara; import org.compiere.model.MRole; import org.compiere.model.MScheduler; import org.compiere.model.MSchedulerLog; @@ -192,7 +193,8 @@ public class Scheduler extends AdempiereServer int AD_Table_ID = scheduler.getAD_Table_ID(); int Record_ID = scheduler.getRecord_ID(); // - MPInstance pInstance = new MPInstance(process, Record_ID); + MPInstance pInstance = new MPInstance(getCtx(), process.getAD_Process_ID(), Record_ID); + pInstance.saveEx(); fillParameter(pInstance); // pi = new ProcessInfo (process.getName(), process.getAD_Process_ID(), AD_Table_ID, Record_ID); @@ -512,10 +514,12 @@ public class Scheduler extends AdempiereServer protected void fillParameter(MPInstance pInstance) { MSchedulerPara[] sParams = get(getCtx(), AD_Scheduler_ID).getParameters (false); - MPInstancePara[] iParams = pInstance.getParameters(); - for (int pi = 0; pi < iParams.length; pi++) + MProcessPara[] processParams = pInstance.getProcessParameters(); + for (int pi = 0; pi < processParams.length; pi++) { - MPInstancePara iPara = iParams[pi]; + MPInstancePara iPara = new MPInstancePara (pInstance, processParams[pi].getSeqNo()); + iPara.setParameterName(processParams[pi].getColumnName()); + iPara.setInfo(processParams[pi].getName()); for (int np = 0; np < sParams.length; np++) { MSchedulerPara sPara = sParams[np]; @@ -537,6 +541,12 @@ public class Scheduler extends AdempiereServer if (log.isLoggable(Level.FINE)) log.fine(sPara.getColumnName() + " - empty"); break; } + if( DisplayType.isText(sPara.getDisplayType()) + && Util.isEmpty(String.valueOf(value)) + && Util.isEmpty(String.valueOf(toValue))) { + if (log.isLoggable(Level.FINE)) log.fine(sPara.getColumnName() + " - empty string"); + break; + } // Convert to Type try diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessParameterPanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessParameterPanel.java index 7a4a2ea098..ce2696dff6 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessParameterPanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessParameterPanel.java @@ -655,6 +655,10 @@ public class ProcessParameterPanel extends Panel implements //Save only parameters which are set if((result == null) && (result2 == null)) continue; + if(result instanceof String) { + if (Util.isEmpty((String)result) && (result2 == null || Util.isEmpty((String)result2))) + continue; + } // Create Parameter MPInstancePara para = MPInstancePara.getOrCreate(Env.getCtx(), diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java index a7c915411e..a6ce17e1f4 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java @@ -104,6 +104,9 @@ import org.zkoss.zul.Vlayout; */ public class DashboardController implements EventListener { + /** Logger */ + protected transient CLogger log = CLogger.getCLogger (getClass()); + private static final String PANEL_EMPTY_ATTR = "panel.empty"; private final static CLogger logger = CLogger.getCLogger(DashboardController.class); private Component prevParent; @@ -866,7 +869,8 @@ public class DashboardController implements EventListener { int AD_Table_ID = 0; int Record_ID = 0; // - MPInstance pInstance = new MPInstance(process, Record_ID); + MPInstance pInstance = new MPInstance(Env.getCtx(), process.getAD_Process_ID(), Record_ID); + pInstance.saveEx(); fillParameter(pInstance, parameters); // ProcessInfo pi = new ProcessInfo (process.getName(), process.getAD_Process_ID(), @@ -911,9 +915,13 @@ public class DashboardController implements EventListener { String value = s.substring(pos + 1); paramMap.put(key, value); } - MPInstancePara[] iParams = pInstance.getParameters(); - for (MPInstancePara iPara : iParams) + MProcessPara[] processParams = pInstance.getProcessParameters(); + for (int pi = 0; pi < processParams.length; pi++) { + MPInstancePara iPara = new MPInstancePara (pInstance, processParams[pi].getSeqNo()); + iPara.setParameterName(processParams[pi].getColumnName()); + iPara.setInfo(processParams[pi].getName()); + String variable = paramMap.get(iPara.getParameterName()); if (Util.isEmpty(variable)) @@ -970,6 +978,11 @@ public class DashboardController implements EventListener { { continue; } + if( DisplayType.isText(iPara.getDisplayType()) + && Util.isEmpty(String.valueOf(value))) { + if (log.isLoggable(Level.FINE)) log.fine(iPara.getParameterName() + " - empty string"); + break; + } // Convert to Type if (DisplayType.isNumeric(iPara.getDisplayType())) diff --git a/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/Process.java b/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/Process.java index 7e4d4fa1ed..57801ce181 100644 --- a/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/Process.java +++ b/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/Process.java @@ -482,17 +482,20 @@ public class Process { private static MPInstance fillParameter(CompiereService m_cs, DataRow dr, MProcess process, Map requestCtx) throws Exception { - MPInstance pInstance = new MPInstance (process, 0); + MPInstance pInstance = new MPInstance(Env.getCtx(), process.getAD_Process_ID(), 0); + pInstance.saveEx(); DataField f[] = dr.getFieldArray(); HashMap fmap = new HashMap(); for (int i=0; i