use of org.compiere.model.Scriptlet in project adempiere by adempiere.
the class MHRProcess method executeScript.
/**
* Execute the script
* @param ruleId
* @param columnType Column Type
* @return Object
*/
private Object executeScript(MHRConcept concept, int ruleId, String columnType) {
MRule rule = MRule.get(getCtx(), ruleId);
Object result = null;
description = null;
try {
if (rule == null) {
logger.log(Level.WARNING, " @AD_Rule_ID@ @NotFound@");
}
if (!(rule.getEventType().equals(MRule.EVENTTYPE_HumanResourcePayroll) && rule.getRuleType().equals(MRule.RULETYPE_JSR223ScriptingAPIs))) {
logger.log(Level.WARNING, " must be of type JSR 223 and event human resource");
}
if (rule.getEngineName() != null)
return executeScriptEngine(concept, rule, columnType);
String text = "";
if (rule.getScript() != null) {
text = rule.getScript().trim().replaceAll("\\bget", "process.get").replace(".process.get", ".get");
}
String resultType = "double";
// Yamel Senih Add DefValue to another Types
String defValue = "0";
if (MHRAttribute.COLUMNTYPE_Date.equals(columnType)) {
resultType = "Timestamp";
defValue = "null";
} else if (MHRAttribute.COLUMNTYPE_Text.equals(columnType)) {
resultType = "String";
defValue = "null";
}
final String script = s_scriptImport.toString() + " " + resultType + " result = " + defValue + ";" + " String description = null;" + text;
Scriptlet engine = new Scriptlet(Scriptlet.VARIABLE, script, scriptCtx);
Exception ex = engine.execute();
if (ex != null) {
throw ex;
}
result = engine.getResult(false);
description = engine.getDescription();
} catch (Exception e) {
throw new AdempiereException("@HR_Employee_ID@ : " + employee.getName() + " " + employee.getName2() + " @HR_Concept_ID@ " + concept.getValue() + " -> " + concept.getName() + " @AD_Rule_ID@=" + rule.getValue() + " Execution error " + e.getLocalizedMessage());
}
return result;
}
use of org.compiere.model.Scriptlet in project adempiere by adempiere.
the class ScriptEditor method start.
/**
* Start ScriptEditor
*
* @param owner
* @param header Title
* @param script ScriptCode
* @param editable
* @return updated Script
*/
public static String start(Frame owner, String header, String script, boolean editable, int WindowNo) {
Scriptlet scr = new Scriptlet(Scriptlet.VARIABLE, script, Env.getCtx(), WindowNo);
String value = Env.getContext(Env.getCtx(), WindowNo, "Value");
//TODO: generic editor for jsr223 script
if (value != null && value.startsWith("groovy:")) {
GroovyEditor gv = new GroovyEditor(owner, header, script, WindowNo);
return gv.getScript();
} else {
BeanShellEditor se = new BeanShellEditor(owner, header, scr, WindowNo);
return scr.getScript();
}
}
Aggregations