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,141 +463,157 @@ 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();
if(sParams.length <= 0) { ArrayList<MProcessPara> processParasExclDrillRuleParas = new ArrayList<MProcessPara>(Arrays.asList(process.getParameters()));
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); 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();
ProcessInfoParameter iPara = new ProcessInfoParameter(processPara.getColumnName(), null, null, null, null);
MProcessDrillRulePara sPara = sParams[p];
if(processPara.getColumnName().equals(m_ColumnName))
{ {
MProcessPara processPara = (MProcessPara) sParams[p].getAD_Process_Para(); iPara.setParameter(DisplayType.isID(sPara.getDisplayType()) ? new BigDecimal(String.valueOf(m_Value)) : String.valueOf(m_Value));
ProcessInfoParameter iPara = new ProcessInfoParameter(processPara.getColumnName(), null, null, null, null); iPara.setInfo(!Util.isEmpty(m_DisplayValue) ? m_DisplayValue : String.valueOf(m_Value));
MProcessDrillRulePara sPara = sParams[p]; iParams.add(iPara);
if(processPara. getColumnName().equals(m_ColumnName)) continue;
}
String paraDesc = sPara.getDescription();
if (paraDesc != null && paraDesc.trim().length() > 0)
iPara.setInfo(sPara.getDescription());
String variable = sPara.getParameterDefault();
String toVariable = sPara.getParameterToDefault();
if (log.isLoggable(Level.FINE)) log.fine(sPara.getColumnName() + " = " + variable);
// Value - Constant/Variable
Object value = parseVariable(sPara, variable);
Object toValue = toVariable != null ? parseVariable(sPara, toVariable) : null;
// No Value
if (value == null && toValue == null)
{
if (log.isLoggable(Level.FINE)) log.fine(sPara.getColumnName() + " - empty");
continue;
}
// Convert to Type
try
{
if (DisplayType.isNumeric(sPara.getDisplayType())
|| DisplayType.isID(sPara.getDisplayType()))
{ {
iPara.setParameter(DisplayType.isID(sPara.getDisplayType()) ? new BigDecimal(String.valueOf(m_Value)) : String.valueOf(m_Value)); DecimalFormat decimalFormat = DisplayType.getNumberFormat(sPara.getDisplayType());
iPara.setInfo(!Util.isEmpty(m_DisplayValue) ? m_DisplayValue : String.valueOf(m_Value)); BigDecimal bd = toBigDecimal(value);
isKeyParameterSet = true; iPara.setParameter(bd);
iParams.add(iPara); if (toValue != null)
continue; {
bd = toBigDecimal(toValue);
iPara.setParameter_To(bd);
}
if (Util.isEmpty(paraDesc))
{
String info = decimalFormat.format(iPara.getParameterAsBigDecimal());
if (iPara.getParameter_ToAsBigDecimal() != null)
info = info + " - " + decimalFormat.format(iPara.getParameter_ToAsBigDecimal());
iPara.setInfo(info);
}
if (log.isLoggable(Level.FINE)) log.fine(sPara.getColumnName()
+ " = " + variable + " (=" + bd + "=)");
} }
else if (DisplayType.isDate(sPara.getDisplayType()))
String paraDesc = sPara.getDescription(); {
if (paraDesc != null && paraDesc.trim().length() > 0) SimpleDateFormat dateFormat = DisplayType.getDateFormat(sPara.getDisplayType());
iPara.setInfo(sPara.getDescription()); Timestamp ts = toTimestamp(value);
String variable = sPara.getParameterDefault(); iPara.setParameter(ts);
String toVariable = sPara.getParameterToDefault(); if (toValue != null) {
if (log.isLoggable(Level.FINE)) log.fine(sPara.getColumnName() + " = " + variable); ts = toTimestamp(toValue);
// Value - Constant/Variable iPara.setParameter_To(ts);
Object value = parseVariable(sPara, variable);
Object toValue = toVariable != null ? parseVariable(sPara, toVariable) : null;
// No Value
if (value == null && toValue == null)
{
if (log.isLoggable(Level.FINE)) log.fine(sPara.getColumnName() + " - empty");
continue;
} }
if (Util.isEmpty(paraDesc))
// Convert to Type
try
{ {
if (DisplayType.isNumeric(sPara.getDisplayType()) String info = dateFormat.format(iPara.getParameterAsTimestamp());
|| DisplayType.isID(sPara.getDisplayType())) if (iPara.getParameter_ToAsTimestamp() != null)
{ {
DecimalFormat decimalFormat = DisplayType.getNumberFormat(sPara.getDisplayType()); info = info + " - " + dateFormat.format(iPara.getParameter_ToAsTimestamp());
BigDecimal bd = toBigDecimal(value);
iPara.setParameter(bd);
if (toValue != null)
{
bd = toBigDecimal(toValue);
iPara.setParameter_To(bd);
}
if (Util.isEmpty(paraDesc))
{
String info = decimalFormat.format(iPara.getParameterAsBigDecimal());
if (iPara.getParameter_ToAsBigDecimal() != null)
info = info + " - " + decimalFormat.format(iPara.getParameter_ToAsBigDecimal());
iPara.setInfo(info);
}
if (log.isLoggable(Level.FINE)) log.fine(sPara.getColumnName()
+ " = " + variable + " (=" + bd + "=)");
} }
else if (DisplayType.isDate(sPara.getDisplayType())) iPara.setInfo(info);
{
SimpleDateFormat dateFormat = DisplayType.getDateFormat(sPara.getDisplayType());
Timestamp ts = toTimestamp(value);
iPara.setParameter(ts);
if (toValue != null) {
ts = toTimestamp(toValue);
iPara.setParameter_To(ts);
}
if (Util.isEmpty(paraDesc))
{
String info = dateFormat.format(iPara.getParameterAsTimestamp());
if (iPara.getParameter_ToAsTimestamp() != null)
{
info = info + " - " + dateFormat.format(iPara.getParameter_ToAsTimestamp());
}
iPara.setInfo(info);
}
if (log.isLoggable(Level.FINE)) log.fine(sPara.getColumnName()
+ " = " + variable + " (=" + ts + "=)");
}
else
{
iPara.setParameter(value.toString());
if (toValue != null)
{
iPara.setParameter_To(toValue.toString());
}
if (Util.isEmpty(paraDesc))
{
String info = iPara.getParameterAsString();
if (iPara.getParameter_ToAsString() != null)
{
info = info + " - " + iPara.getParameter_ToAsString();
}
iPara.setInfo(info);
}
if (log.isLoggable(Level.FINE)) log.fine(sPara.getColumnName()
+ " = " + variable
+ " (=" + value + "=) " + value.getClass().getName());
}
iParams.add(iPara);
} }
catch (Exception e) if (log.isLoggable(Level.FINE)) log.fine(sPara.getColumnName()
+ " = " + variable + " (=" + ts + "=)");
}
else
{
iPara.setParameter(value.toString());
if (toValue != null)
{ {
log.warning(sPara.getColumnName() iPara.setParameter_To(toValue.toString());
+ " = " + variable + " (" + value
+ ") " + value.getClass().getName()
+ " - " + e.getLocalizedMessage());
} }
} // Drill Rule Parameter loop if (Util.isEmpty(paraDesc))
pi.setParameter(iParams.toArray(new ProcessInfoParameter[0])); {
String info = iPara.getParameterAsString();
if (iPara.getParameter_ToAsString() != null)
{
info = info + " - " + iPara.getParameter_ToAsString();
}
iPara.setInfo(info);
}
if (log.isLoggable(Level.FINE)) log.fine(sPara.getColumnName()
+ " = " + 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)
{
log.warning(sPara.getColumnName()
+ " = " + variable + " (" + value
+ ") " + value.getClass().getName()
+ " - " + 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) { if(!isKeyParameterSet) {
throw new AdempiereException(Msg.parseTranslation(Env.getCtx(), "@NoDrillKeyParameterSet@")); throw new AdempiereException(Msg.parseTranslation(Env.getCtx(), "@NoDrillKeyParameterSet@"));
} }
} // 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)