IDEMPIERE-3294 - check empty String parameter (#1336)

* IDEMPIERE-3294 - check empty String parameter
This commit is contained in:
PeterTakacs300 2022-05-25 08:48:37 +02:00 committed by GitHub
parent 9f1eeb07f3
commit b2b31fb087
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 87 additions and 19 deletions

View File

@ -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 <MProcessPara> 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

View File

@ -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();

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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(),

View File

@ -104,6 +104,9 @@ import org.zkoss.zul.Vlayout;
*/
public class DashboardController implements EventListener<Event> {
/** 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<Event> {
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<Event> {
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<Event> {
{
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()))

View File

@ -482,17 +482,20 @@ public class Process {
private static MPInstance fillParameter(CompiereService m_cs, DataRow dr, MProcess process, Map<String, Object> 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<String,DataField> fmap = new HashMap<String,DataField>();
for (int i=0; i<f.length; i++)
fmap.put(f[i].getColumn(), f[i]);
//
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());
String key = iPara.getParameterName();
MProcessPara pPara = process.getParameter(key);
if (pPara == null)
@ -541,6 +544,7 @@ public class Process {
if (log.isLoggable(Level.FINE)) log.fine("fillParameter - " + key + " = " + valueString);
Object value = valueString;
Object toValue = valueString2;
if (valueString != null && valueString.length() == 0)
value = null;
if (value != null && (DisplayType.isList(displayType) ||
@ -555,6 +559,12 @@ public class Process {
}
else
{
if( DisplayType.isText(displayType)
&& Util.isEmpty(String.valueOf(value))
&& Util.isEmpty(String.valueOf(toValue))) {
if (log.isLoggable(Level.FINE)) log.fine(pPara.getColumnName() + " - empty string");
break;
}
// Convert to Type
try
{