use of org.compiere.model.MPInstancePara in project adempiere by adempiere.
the class ProcessController method updateInstance.
/**
* Update a instance from Name
* @param saveName
* @return
*/
public String updateInstance(String saveName) {
// Validate Instance List
if (savedParams == null || saveName == null)
return null;
//
String errorMsg = null;
try {
for (MPInstance instance : savedParams) {
if (instance.getName().equals(saveName)) {
processInfo.setAD_PInstance_ID(instance.getAD_PInstance_ID());
for (MPInstancePara para : instance.getParameters()) {
para.deleteEx(true);
}
// Save
errorMsg = saveParameters();
if (errorMsg != null)
throw new AdempiereException(errorMsg);
}
}
} catch (Exception ex) {
errorMsg = ex.getLocalizedMessage();
log.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
// Default Return
return errorMsg;
}
use of org.compiere.model.MPInstancePara in project adempiere by adempiere.
the class WProcess method fillParameter.
/**
* Fill Parameter
* @param request request
* @param process process
* @return process instance
*/
private MPInstance fillParameter(HttpServletRequest request, MProcess process) {
MPInstance pInstance = new MPInstance(process, 0);
//
MPInstancePara[] iParams = pInstance.getParameters();
for (int pi = 0; pi < iParams.length; pi++) {
MPInstancePara iPara = iParams[pi];
String key = iPara.getParameterName();
MProcessPara pPara = process.getParameter(key);
if (pPara == null) {
log.log(Level.SEVERE, "Parameter not found: " + key);
continue;
}
String valueString = WebUtil.getParameter(request, key);
log.fine("fillParameter - " + key + " = " + valueString);
Object value = valueString;
if (valueString != null && valueString.length() == 0)
value = null;
// No Value
if (value == null) {
// if (pPara.isMandatory())
// log.log(Level.WARNING,"fillParameter - " + key
// + " - empty - mandatory!");
} else {
// Convert to Type
try {
if (DisplayType.isNumeric(pPara.getAD_Reference_ID()) || DisplayType.isID(pPara.getAD_Reference_ID())) {
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("fillParameter - " + key + " = " + valueString + " (=" + bd + "=)");
} else if (DisplayType.isDate(pPara.getAD_Reference_ID())) {
Timestamp ts = null;
if (value instanceof Timestamp)
ts = (Timestamp) value;
else
ts = Timestamp.valueOf(value.toString());
iPara.setP_Date(ts);
log.fine("fillParameter - " + key + " = " + valueString + " (=" + ts + "=)");
} else {
iPara.setP_String(value.toString());
}
//
iPara.saveEx();
} catch (Exception e) {
log.warning("fillParameter - " + key + " = " + valueString + " (" + value + ") " + value.getClass().getName() + " - " + e.getLocalizedMessage());
}
}
// not null
}
return pInstance;
}
use of org.compiere.model.MPInstancePara in project adempiere by adempiere.
the class OrderDistribution method generate.
// saveSelection
public String generate(IStatusBar statusBar, String docActionSelected) {
String info = "";
log.info("M_Locator_ID=" + m_M_Locator_ID);
String trxName = Trx.createTrxName("IMG");
Trx trx = Trx.get(trxName, true);
// prevents from being called twice
setSelectionActive(false);
statusBar.setStatusLine(Msg.translate(Env.getCtx(), "M_Movement_ID"));
statusBar.setStatusDB(String.valueOf(getSelection().size()));
// Prepare Process
int AD_Process_ID = MProcess.getProcess_ID("M_Generate Movement", trxName);
MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
if (!instance.save()) {
info = Msg.getMsg(Env.getCtx(), "ProcessNoInstance");
return info;
}
DB.createT_Selection(instance.getAD_PInstance_ID(), getSelection(), null);
//call process
ProcessInfo pi = new ProcessInfo("VOrderDistribution", AD_Process_ID);
pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
// Add Parameter - Selection=Y
MPInstancePara ip = new MPInstancePara(instance, 10);
ip.setParameter("Selection", "Y");
ip.saveEx();
MLocator locator = MLocator.get(Env.getCtx(), Integer.parseInt(m_M_Locator_ID.toString()));
// Add Parameter - M_Warehouse_ID=x
ip = new MPInstancePara(instance, 20);
ip.setParameter("M_Warehouse_ID", locator.getM_Warehouse_ID());
ip.saveEx();
setTrx(trx);
setProcessInfo(pi);
return info;
}
use of org.compiere.model.MPInstancePara in project adempiere by adempiere.
the class MPInstanceTest method testQuery.
public void testQuery() throws Exception {
lines = new MPInstance(getCtx(), 1000000, getTrxName());
MPInstancePara[] params = lines.getParameters();
assertTrue("There should be params", params.length > 0);
}
use of org.compiere.model.MPInstancePara in project adempiere by adempiere.
the class PayrollViaEMail method CreatePDF.
// sendIndividualMail
private File CreatePDF(int bPartnerId) {
File attachment = null;
int AD_Process_ID = reportProcessId;
MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, bPartnerId);
instance.saveEx();
ProcessInfo pi = new ProcessInfo("PH_SendEmail", AD_Process_ID);
pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
// Add Parameter - Selection=Y
MPInstancePara ip = new MPInstancePara(instance, 10);
ip.setParameter(X_HR_Process.COLUMNNAME_HR_Process_ID, payrollProcessId);
ip.saveEx();
pi.setRecord_ID(bPartnerId);
pi.setIsBatch(true);
MProcess worker = new MProcess(getCtx(), AD_Process_ID, get_TrxName());
worker.processIt(pi, Trx.get(get_TrxName(), true));
attachment = pi.getPDFReport();
return attachment;
}
Aggregations