use of org.compiere.model.MProcessPara in project adempiere by adempiere.
the class Process method fillParameter.
// createProcessPage
private static MPInstance fillParameter(CompiereService m_cs, DataRow dr, MProcess process) throws Exception {
MPInstance pInstance = new MPInstance(process, 0);
DataField[] f = dr.getFieldArray();
HashMap fmap = new HashMap();
for (int i = 0; i < f.length; i++) fmap.put(f[i].getColumn(), f[i].getVal());
//
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;
}
int displayType = pPara.getAD_Reference_ID();
String valueString = null;
Object ob = fmap.get(key);
if (ob != null)
valueString = ob.toString();
String valueString2 = null;
if (pPara.isRange()) {
ob = fmap.get(key + "_2");
if (ob != null)
valueString2 = ob.toString();
}
log.fine("fillParameter - " + key + " = " + valueString);
Object value = valueString;
if (valueString != null && valueString.length() == 0)
value = null;
if (value != null && (DisplayType.List == displayType || DisplayType.TableDir == displayType || DisplayType.Table == displayType) && value.equals("-1"))
value = null;
// No Value
if (value == null && DisplayType.YesNo != pPara.getAD_Reference_ID()) {
if (pPara.isMandatory())
throw new Exception(" Parameter " + pPara.getName() + " is required.");
} else {
// Convert to Type
try {
if (DisplayType.isNumeric(displayType) || DisplayType.isID(displayType)) {
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 + "=)");
if (pPara.isRange()) {
bd = null;
bd = new BigDecimal(valueString2.toString());
iPara.setP_Number_To(bd);
}
} else if (DisplayType.isDate(displayType)) {
java.util.Date d;
if (displayType == DisplayType.DateTime)
d = m_cs.dateFormat.parse(value.toString());
else
// TODO: datetime
d = m_cs.dateFormat.parse(value.toString());
//d = m_cs.dateTimeFormat.parse(value.toString());
Timestamp ts = null;
ts = new Timestamp(d.getTime());
iPara.setP_Date(ts);
if (pPara.isRange()) {
if (displayType == DisplayType.DateTime)
d = m_cs.dateFormat.parse(valueString2);
else //d = m_cs.dateTimeFormat.parse(valueString2);
{
if (valueString2 == null || valueString2.length() == 0)
d = new java.util.Date();
else
//TODO: datetime
d = m_cs.dateFormat.parse(valueString2);
}
ts = new Timestamp(d.getTime());
iPara.setP_Date_To(ts);
}
log.fine("fillParameter - " + key + " = " + valueString + " (=" + ts + "=)");
} else if (DisplayType.YesNo == pPara.getAD_Reference_ID()) {
String bv = "N";
if (value == null)
bv = "N";
else //if (value.toString().toLowerCase().charAt(0)=='t')
{
if ("true".equalsIgnoreCase(valueString) || "y".equalsIgnoreCase(valueString))
bv = "Y";
else
bv = "N";
}
//bv ="Y";
iPara.setP_String(bv);
} else {
iPara.setP_String(value.toString());
}
if (// kolec - ustawia wartosc dla parametru Lookup
pPara.isLookup()) {
Lookup lok = pPara.getLookup();
if (lok != null) {
NamePair np = lok.getDirect(value, false, false);
if (np != null) {
iPara.setInfo(np.getName());
}
}
} else {
if (value != null)
iPara.setInfo(value.toString());
if (valueString2 != null)
iPara.setInfo_To(valueString2);
}
//
iPara.save();
} catch (Exception e) {
log.warning("fillParameter - " + key + " = " + valueString + " (" + value + ") " + value.getClass().getName() + " - " + e.getLocalizedMessage());
}
}
// not null
}
// instance parameter loop
// kolec - tego chyba brakowalo
pInstance.save();
return pInstance;
}
use of org.compiere.model.MProcessPara in project adempiere by adempiere.
the class Process method getProcessParams.
public static ProcessParamsDocument getProcessParams(CompiereService cs, GetProcessParamsDocument req) throws XFireFault {
ProcessParamsDocument res = ProcessParamsDocument.Factory.newInstance();
ProcessParams params = res.addNewProcessParams();
ProcessParamList PL = params.addNewParams();
int AD_Menu_ID = req.getGetProcessParams().getADMenuID();
int AD_Process_ID = req.getGetProcessParams().getADProcessID();
MProcess process = null;
if (AD_Menu_ID > 0 && AD_Process_ID == 0)
process = MProcess.getFromMenu(cs.getM_ctx(), AD_Menu_ID);
else if (AD_Menu_ID == 0 && AD_Process_ID > 0)
process = new MProcess(cs.getM_ctx(), AD_Process_ID, null);
if (process != null) {
params.setDescription(process.getDescription());
params.setHelp(process.getHelp());
params.setName(process.getName());
params.setADProcessID(process.getAD_Process_ID());
MProcessPara[] parameter = process.getParameters();
for (int i = 0; i < parameter.length; i++) {
MProcessPara para = parameter[i];
ProcessParam p = PL.addNewParam();
p.setName(para.getName());
p.setDescription(para.getDescription());
p.setDisplayType(para.getAD_Reference_ID());
p.setIsMandatory(para.isMandatory());
p.setFieldLength(para.getFieldLength());
p.setIsRange(para.isRange());
p.setColumnName(para.getColumnName());
p.setDefaultValue(para.getDefaultValue());
p.setDefaultValue2(para.getDefaultValue2());
if (para.getDefaultValue() != null) {
if (DisplayType.isDate(para.getAD_Reference_ID())) {
if (para.getDefaultValue().indexOf("@#Date@") >= 0) {
//Object t = Env.getContextAsDate( cs.getM_ctx(), "#Date" );
//String t = Env.getContext( cs.getM_ctx(), "#Date" );
String t = cs.dateFormat.format(Env.getContextAsDate(cs.getM_ctx(), "#Date"));
//cs.dateFormat.format( t ));
p.setDefaultValue(t);
}
} else if (DisplayType.YesNo == para.getAD_Reference_ID()) {
if ("Y".equalsIgnoreCase(para.getDefaultValue()))
p.setDefaultValue("true");
else
p.setDefaultValue("false");
}
} else {
if (DisplayType.YesNo == para.getAD_Reference_ID())
p.setDefaultValue("false");
}
if (para.getDefaultValue2() != null) {
if (DisplayType.isDate(para.getAD_Reference_ID())) {
if (para.getDefaultValue2().indexOf("@#Date@") >= 0) {
//Object t = Env.getContextAsDate( cs.getM_ctx(), "#Date" );
//String t = Env.getContext( cs.getM_ctx(), "#Date" );
String t = cs.dateFormat.format(Env.getContextAsDate(cs.getM_ctx(), "#Date"));
//cs.dateFormat.format( t ) );
p.setDefaultValue2(t);
}
}
}
if (para.isLookup()) {
LookupValues lvs = p.addNewLookup();
Lookup lookup = para.getLookup();
try {
ADLookup.fillLookupValues(lvs, lookup, para.isMandatory(), false);
} catch (Exception ex) {
System.out.println("getProcessParams exception: " + ex.getMessage());
ex.printStackTrace();
}
}
}
}
return res;
}
use of org.compiere.model.MProcessPara 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 = MobileUtil.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 {
if (pPara.getAD_Reference_ID() == DisplayType.YesNo)
value = "true".equalsIgnoreCase(value.toString()) ? "Y" : "N";
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.MProcessPara in project adempiere by adempiere.
the class ASPGenerateFields method generateProcess.
// doIt
private void generateProcess(int p_AD_Process_ID) {
// Add Process and Parameters
MProcess process = new MProcess(getCtx(), p_AD_Process_ID, get_TrxName());
int asp_process_id = DB.getSQLValueEx(get_TrxName(), "SELECT COUNT(*) FROM ASP_Process WHERE ASP_Level_ID = ? AND AD_Process_ID = ?", p_ASP_Level_ID, process.getAD_Process_ID());
X_ASP_Process aspProcess = null;
if (asp_process_id < 1) {
aspProcess = new X_ASP_Process(getCtx(), 0, get_TrxName());
aspProcess.setASP_Level_ID(p_ASP_Level_ID);
aspProcess.setAD_Process_ID(process.getAD_Process_ID());
aspProcess.setASP_Status(p_ASP_Status);
if (aspProcess.save()) {
noProcesses++;
asp_process_id = aspProcess.getASP_Process_ID();
}
} else {
aspProcess = new X_ASP_Process(getCtx(), asp_process_id, get_TrxName());
}
// parameters
for (MProcessPara processpara : process.getParameters()) {
if (DB.getSQLValueEx(get_TrxName(), "SELECT COUNT(*) FROM ASP_Process_Para WHERE ASP_Process_ID = ? AND AD_Process_Para_ID = ?", asp_process_id, processpara.getAD_Process_Para_ID()) < 1) {
X_ASP_Process_Para aspProcess_Para = new X_ASP_Process_Para(getCtx(), 0, get_TrxName());
aspProcess_Para.setASP_Process_ID(asp_process_id);
aspProcess_Para.setAD_Process_Para_ID(processpara.getAD_Process_Para_ID());
aspProcess_Para.setASP_Status(p_ASP_Status);
if (aspProcess_Para.save())
noParameters++;
}
}
if (process.getAD_Workflow_ID() > 0) {
generateWorkflow(process.getAD_Workflow_ID());
}
}
use of org.compiere.model.MProcessPara in project adempiere by adempiere.
the class ProcessAbstractClassGenerator method createParameters.
/**
* Create Parameters for header
* @return
*/
private void createParameters() {
// Create Name and Values
for (MProcessPara parameter : getParameters()) {
// The information only don't are parameters
if (parameter.isInfoOnly())
continue;
createParameterName(parameter);
createParameterValue(parameter, false);
createParameterFill(parameter, false);
// For Range
if (parameter.isRange()) {
createParameterValue(parameter, true);
createParameterFill(parameter, true);
}
}
}
Aggregations