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.DecimalFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -462,29 +463,41 @@ public class DrillReportCtl {
*/ */
protected void fillParameter(ProcessInfo pi, MProcessDrillRule processDrillRule) protected void fillParameter(ProcessInfo pi, MProcessDrillRule processDrillRule)
{ {
boolean isKeyParameterSet= false; boolean isKeyParameterSet = false;
MProcessDrillRulePara[] sParams = processDrillRule.getParameters (true); MProcessDrillRulePara[] sParams = processDrillRule.getParameters (true);
ArrayList<ProcessInfoParameter> iParams = new ArrayList<ProcessInfoParameter>(); 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) { // Check for key parameter
if(hasMandatoryProcessPara(processDrillRule.getAD_Process_ID())) for(int i = 0; i < sParams.length; i++) {
throw new AdempiereException(Msg.parseTranslation(Env.getCtx(), "@FillMandatoryDrillRulePara@")); if(sParams[i].getAD_Process_Para().getColumnName().equals(m_ColumnName)) {
isKeyParameterSet = true;
}
}
if(!isKeyParameterSet) {
MProcessDrillRulePara keyPara = new MProcessDrillRulePara(Env.getCtx(), 0, null); MProcessDrillRulePara keyPara = new MProcessDrillRulePara(Env.getCtx(), 0, null);
keyPara.setAD_Process_DrillRule_ID(processDrillRule.getAD_Process_DrillRule_ID()); keyPara.setAD_Process_DrillRule_ID(processDrillRule.getAD_Process_DrillRule_ID());
keyPara.setAD_Process_Para_ID(processDrillRule.getAD_Process_Para_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++) for (int p = 0; p < sParams.length; p++)
{ {
MProcessPara processPara = (MProcessPara) sParams[p].getAD_Process_Para(); MProcessPara processPara = (MProcessPara) sParams[p].getAD_Process_Para();
ProcessInfoParameter iPara = new ProcessInfoParameter(processPara.getColumnName(), null, null, null, null); ProcessInfoParameter iPara = new ProcessInfoParameter(processPara.getColumnName(), null, null, null, null);
MProcessDrillRulePara sPara = sParams[p]; MProcessDrillRulePara sPara = sParams[p];
if(processPara. getColumnName().equals(m_ColumnName)) if(processPara.getColumnName().equals(m_ColumnName))
{ {
iPara.setParameter(DisplayType.isID(sPara.getDisplayType()) ? new BigDecimal(String.valueOf(m_Value)) : String.valueOf(m_Value)); 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)); iPara.setInfo(!Util.isEmpty(m_DisplayValue) ? m_DisplayValue : String.valueOf(m_Value));
isKeyParameterSet = true;
iParams.add(iPara); iParams.add(iPara);
continue; continue;
} }
@ -571,6 +584,12 @@ public class DrillReportCtl {
+ " = " + variable + " = " + variable
+ " (=" + value + "=) " + value.getClass().getName()); + " (=" + 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); iParams.add(iPara);
} }
catch (Exception e) catch (Exception e)
@ -581,6 +600,13 @@ public class DrillReportCtl {
+ " - " + e.getLocalizedMessage()); + " - " + e.getLocalizedMessage());
} }
} // Drill Rule Parameter loop } // 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])); pi.setParameter(iParams.toArray(new ProcessInfoParameter[0]));
if(!isKeyParameterSet) { if(!isKeyParameterSet) {
@ -588,15 +614,6 @@ public class DrillReportCtl {
} }
} // fillParameter } // 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) { private Timestamp toTimestamp(Object value) {
Timestamp ts = null; Timestamp ts = null;
if (value instanceof Timestamp) if (value instanceof Timestamp)