IDEMPIERE-5514 - Drill Assistant Error - Drill key parameter is not set (#1607)

This commit is contained in:
Peter Takács 2022-12-22 14:26:59 +01:00 committed by GitHub
parent 6e90caeb39
commit 54980d9a6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 129 additions and 112 deletions

View File

@ -33,6 +33,7 @@ import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map.Entry;
@ -465,15 +466,28 @@ public class DrillReportCtl {
boolean isKeyParameterSet = false;
MProcessDrillRulePara[] sParams = processDrillRule.getParameters (true);
ArrayList<ProcessInfoParameter> iParams = new ArrayList<ProcessInfoParameter>();
MProcess process = (MProcess) processDrillRule.getAD_Process();
ArrayList<MProcessPara> processParasExclDrillRuleParas = new ArrayList<MProcessPara>(Arrays.asList(process.getParameters()));
if(sParams.length <= 0) {
if(hasMandatoryProcessPara(processDrillRule.getAD_Process_ID()))
throw new AdempiereException(Msg.parseTranslation(Env.getCtx(), "@FillMandatoryDrillRulePara@"));
// Check for key parameter
for(int i = 0; i < sParams.length; i++) {
if(sParams[i].getAD_Process_Para().getColumnName().equals(m_ColumnName)) {
isKeyParameterSet = true;
}
}
if(!isKeyParameterSet) {
MProcessDrillRulePara keyPara = new MProcessDrillRulePara(Env.getCtx(), 0, null);
keyPara.setAD_Process_DrillRule_ID(processDrillRule.getAD_Process_DrillRule_ID());
keyPara.setAD_Process_Para_ID(processDrillRule.getAD_Process_Para_ID());
sParams = new MProcessDrillRulePara[] {keyPara};
MProcessDrillRulePara[] sParamsTmp = Arrays.stream(sParams).toArray(MProcessDrillRulePara[]::new);;
sParams = new MProcessDrillRulePara[sParamsTmp.length+1];
int idx = 0;
for(idx = 0; idx < sParamsTmp.length; idx++) {
sParams[idx] = sParamsTmp[idx];
}
sParams[idx] = keyPara;
isKeyParameterSet = true;
}
for (int p = 0; p < sParams.length; p++)
{
@ -484,7 +498,6 @@ public class DrillReportCtl {
{
iPara.setParameter(DisplayType.isID(sPara.getDisplayType()) ? new BigDecimal(String.valueOf(m_Value)) : String.valueOf(m_Value));
iPara.setInfo(!Util.isEmpty(m_DisplayValue) ? m_DisplayValue : String.valueOf(m_Value));
isKeyParameterSet = true;
iParams.add(iPara);
continue;
}
@ -571,6 +584,12 @@ public class DrillReportCtl {
+ " = " + variable
+ " (=" + value + "=) " + value.getClass().getName());
}
// Mandatory check
if(processPara.isMandatory() && Util.isEmpty(sPara.getParameterDefault())) {
if((!processPara.isRange()) || (processPara.isRange() && Util.isEmpty(sPara.getParameterToDefault())))
throw new AdempiereException(Msg.parseTranslation(Env.getCtx(), "@FillMandatoryDrillRulePara@"));
}
processParasExclDrillRuleParas.remove(processPara);
iParams.add(iPara);
}
catch (Exception e)
@ -581,6 +600,13 @@ public class DrillReportCtl {
+ " - " + e.getLocalizedMessage());
}
} // Drill Rule Parameter loop
// Mandatory check
for(MProcessPara unsetProcessPara : processParasExclDrillRuleParas) {
if(unsetProcessPara.isMandatory()) {
throw new AdempiereException(Msg.parseTranslation(Env.getCtx(), "@FillMandatoryDrillRulePara@"));
}
}
pi.setParameter(iParams.toArray(new ProcessInfoParameter[0]));
if(!isKeyParameterSet) {
@ -588,15 +614,6 @@ public class DrillReportCtl {
}
} // fillParameter
private boolean hasMandatoryProcessPara(int processID) {
MProcess process = new MProcess(Env.getCtx(), processID, null);
for(MProcessPara processPara : process.getParameters()) {
if(processPara.isMandatory())
return true;
}
return false;
}
private Timestamp toTimestamp(Object value) {
Timestamp ts = null;
if (value instanceof Timestamp)