use of org.compiere.model.MSchedulerPara in project adempiere by adempiere.
the class Scheduler method fillParameter.
/**
* Fill Parameter
* @param pInstance process instance
*/
private void fillParameter(MPInstance pInstance) {
MSchedulerPara[] sParams = m_model.getParameters(false);
MPInstancePara[] iParams = pInstance.getParameters();
for (int pi = 0; pi < iParams.length; pi++) {
MPInstancePara iPara = iParams[pi];
for (int np = 0; np < sParams.length; np++) {
MSchedulerPara sPara = sParams[np];
if (iPara.getParameterName().equals(sPara.getColumnName())) {
String paraDesc = sPara.getDescription();
if (paraDesc != null && paraDesc.trim().length() > 0)
iPara.setInfo(sPara.getDescription());
String variable = sPara.getParameterDefault();
log.fine(sPara.getColumnName() + " = " + variable);
// Value - Constant/Variable
Object value = variable;
if (variable == null || (variable != null && variable.length() == 0))
value = null;
else if (variable.indexOf('@') != -1 && // we have a variable / BF [1926032]
variable.indexOf('@') != variable.lastIndexOf('@')) {
// Strip
int index = variable.indexOf('@');
String columnName = variable.substring(index + 1);
index = columnName.indexOf('@');
if (index == -1) {
log.warning(sPara.getColumnName() + " - cannot evaluate=" + variable);
break;
}
columnName = columnName.substring(0, index);
// try Env
String env = Env.getContext(m_schedulerctx, columnName);
if (env == null || env.length() == 0)
env = Env.getContext(getCtx(), columnName);
if (env.length() == 0) {
log.warning(sPara.getColumnName() + " - not in environment =" + columnName + "(" + variable + ")");
break;
} else
value = env;
}
// No Value
if (value == null) {
log.fine(sPara.getColumnName() + " - empty");
break;
}
// Convert to Type
try {
if (DisplayType.isNumeric(sPara.getDisplayType()) || DisplayType.isID(sPara.getDisplayType())) {
BigDecimal bd = null;
if (value instanceof BigDecimal)
bd = (BigDecimal) value;
else if (value instanceof Integer)
bd = new BigDecimal(((Integer) value).intValue());
else
bd = new BigDecimal(value.toString());
iPara.setP_Number(bd);
log.fine(sPara.getColumnName() + " = " + variable + " (=" + bd + "=)");
} else if (DisplayType.isDate(sPara.getDisplayType())) {
Timestamp ts = null;
if (value instanceof Timestamp)
ts = (Timestamp) value;
else
ts = Timestamp.valueOf(value.toString());
iPara.setP_Date(ts);
log.fine(sPara.getColumnName() + " = " + variable + " (=" + ts + "=)");
} else {
iPara.setP_String(value.toString());
log.fine(sPara.getColumnName() + " = " + variable + " (=" + value + "=) " + value.getClass().getName());
}
if (!iPara.save())
log.warning("Not Saved - " + sPara.getColumnName());
} catch (Exception e) {
log.warning(sPara.getColumnName() + " = " + variable + " (" + value + ") " + value.getClass().getName() + " - " + e.getLocalizedMessage());
}
break;
}
// parameter match
}
// scheduler parameter loop
}
// instance parameter loop
}
Aggregations