Search in sources :

Example 11 with GroovyScriptHelper

use of com.axelor.script.GroovyScriptHelper in project axelor-open-suite by axelor.

the class ConfiguratorServiceImpl method computeFormula.

@Override
public Object computeFormula(String groovyFormula, JsonContext values) {
    User currentUser = AuthUtils.getUser();
    Company company = currentUser != null ? currentUser.getActiveCompany() : null;
    values.put("__user__", currentUser);
    values.put("__date__", appBaseService.getTodayDate(company));
    values.put("__datetime__", appBaseService.getTodayDateTime(company));
    ScriptHelper scriptHelper = new GroovyScriptHelper(values);
    return scriptHelper.eval(groovyFormula);
}
Also used : Company(com.axelor.apps.base.db.Company) User(com.axelor.auth.db.User) GroovyScriptHelper(com.axelor.script.GroovyScriptHelper) ScriptHelper(com.axelor.script.ScriptHelper) GroovyScriptHelper(com.axelor.script.GroovyScriptHelper)

Example 12 with GroovyScriptHelper

use of com.axelor.script.GroovyScriptHelper in project axelor-open-suite by axelor.

the class TestBamlParser method test.

public void test() {
    InputStream is = ResourceUtils.getResourceStream("BamlTest.xml");
    ProcessActionRootNode rootNode = BamlParser.parse(is);
    List<ProcessActionNode> processActionNodes = rootNode.getProcessActions();
    String script = "";
    if (processActionNodes != null) {
        script = processActionNodes.get(0).toCode(true);
    }
    Context ctx = new Context(User.class);
    GroovyScriptHelper helper = new GroovyScriptHelper(ctx);
    helper.eval(script);
}
Also used : Context(com.axelor.rpc.Context) InputStream(java.io.InputStream) ProcessActionNode(com.axelor.apps.baml.xml.ProcessActionNode) ProcessActionRootNode(com.axelor.apps.baml.xml.ProcessActionRootNode) GroovyScriptHelper(com.axelor.script.GroovyScriptHelper)

Aggregations

GroovyScriptHelper (com.axelor.script.GroovyScriptHelper)12 Context (com.axelor.rpc.Context)4 FullContext (com.axelor.apps.tool.context.FullContext)3 Model (com.axelor.db.Model)3 ScriptBindings (com.axelor.script.ScriptBindings)3 ScriptHelper (com.axelor.script.ScriptHelper)3 Bindings (javax.script.Bindings)3 SimpleBindings (javax.script.SimpleBindings)3 BamlModel (com.axelor.apps.bpm.db.BamlModel)2 User (com.axelor.auth.db.User)2 AxelorException (com.axelor.exception.AxelorException)2 Transactional (com.google.inject.persist.Transactional)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ProcessActionNode (com.axelor.apps.baml.xml.ProcessActionNode)1 ProcessActionRootNode (com.axelor.apps.baml.xml.ProcessActionRootNode)1 Company (com.axelor.apps.base.db.Company)1 FileTab (com.axelor.apps.base.db.FileTab)1 GlobalTrackingConfigurationLine (com.axelor.apps.base.db.GlobalTrackingConfigurationLine)1 GlobalTrackingLog (com.axelor.apps.base.db.GlobalTrackingLog)1