Search in sources :

Example 1 with BamlModel

use of com.axelor.apps.bpm.db.BamlModel in project axelor-open-suite by axelor.

the class WkfBamlService method executeBaml.

private void executeBaml(DelegateExecution execution, BamlModel bamlModel) {
    Map<String, Object> context = createContext(execution);
    Model record = Beans.get(BamlService.class).execute(bamlModel, context);
    log.debug("Record created from BAML: {}", record);
    if (record != null) {
        String varName = Beans.get(WkfCommonService.class).getVarName(record);
        Map<String, Object> modelMap = new HashMap<String, Object>();
        modelMap.put(varName, record);
        execution.getProcessInstance().setVariables(Beans.get(WkfCommonService.class).createVariables(modelMap));
    }
}
Also used : HashMap(java.util.HashMap) Model(com.axelor.db.Model) BamlModel(com.axelor.apps.bpm.db.BamlModel) BamlService(com.axelor.apps.baml.service.BamlService)

Example 2 with BamlModel

use of com.axelor.apps.bpm.db.BamlModel in project axelor-open-suite by axelor.

the class WkfBamlService method execute.

@Override
public void execute(DelegateExecution execution) throws Exception {
    BpmnModelElementInstance bpmnModelElementInstance = execution.getBpmnModelElementInstance();
    String baml = bpmnModelElementInstance.getAttributeValueNs(BpmnParse.CAMUNDA_BPMN_EXTENSIONS_NS.getNamespaceUri(), "baml");
    if (baml != null && Boolean.parseBoolean(baml)) {
        String model = bpmnModelElementInstance.getAttributeValueNs(BpmnParse.CAMUNDA_BPMN_EXTENSIONS_NS.getNamespaceUri(), "bamlModel");
        BamlModel bamlModel = Beans.get(BamlModelRepository.class).findByName(model);
        if (bamlModel != null) {
            executeBaml(execution, bamlModel);
        }
    }
}
Also used : BamlModel(com.axelor.apps.bpm.db.BamlModel) BpmnModelElementInstance(org.camunda.bpm.model.bpmn.instance.BpmnModelElementInstance) BamlModelRepository(com.axelor.apps.bpm.db.repo.BamlModelRepository)

Example 3 with BamlModel

use of com.axelor.apps.bpm.db.BamlModel in project axelor-open-suite by axelor.

the class BamlModelController method generateCode.

public void generateCode(ActionRequest request, ActionResponse response) throws AxelorException {
    BamlModel model = request.getContext().asType(BamlModel.class);
    String xml = bamlService.extractBamlXml(model.getBamlXml());
    if (xml != null) {
        String resultScript = Beans.get(BamlService.class).generateGroovyCode(xml);
        response.setValue("resultScript", resultScript);
    }
}
Also used : BamlModel(com.axelor.apps.bpm.db.BamlModel) BamlService(com.axelor.apps.baml.service.BamlService)

Example 4 with BamlModel

use of com.axelor.apps.bpm.db.BamlModel in project axelor-open-suite by axelor.

the class BamlServiceImpl method execute.

@Override
@Transactional
public Model execute(BamlModel bamlModel, Model entity) {
    Bindings bindings = new SimpleBindings();
    if (entity != null) {
        String varName = Beans.get(WkfCommonService.class).getVarName(entity);
        bindings.put(varName, entity);
    }
    bindings.put("$ctx", WkfContextHelper.class);
    GroovyScriptHelper helper = new GroovyScriptHelper(bindings);
    Object object = helper.eval(bamlModel.getResultScript());
    if (object != null && object instanceof Model) {
        return JpaRepository.of(EntityHelper.getEntityClass((Model) object)).save((Model) object);
    }
    return null;
}
Also used : SimpleBindings(javax.script.SimpleBindings) Model(com.axelor.db.Model) BamlModel(com.axelor.apps.bpm.db.BamlModel) Bindings(javax.script.Bindings) SimpleBindings(javax.script.SimpleBindings) GroovyScriptHelper(com.axelor.script.GroovyScriptHelper) WkfCommonService(com.axelor.apps.bpm.service.WkfCommonService) Transactional(com.google.inject.persist.Transactional)

Example 5 with BamlModel

use of com.axelor.apps.bpm.db.BamlModel in project axelor-open-suite by axelor.

the class BamlServiceImpl method execute.

@Override
@Transactional
public Model execute(BamlModel bamlModel, Map<String, Object> context) {
    Bindings bindings = new SimpleBindings();
    if (context != null) {
        bindings.putAll(context);
    }
    GroovyScriptHelper helper = new GroovyScriptHelper(bindings);
    Object object = helper.eval(bamlModel.getResultScript());
    if (object != null && object instanceof Model) {
        return JpaRepository.of(EntityHelper.getEntityClass((Model) object)).save((Model) object);
    }
    return null;
}
Also used : SimpleBindings(javax.script.SimpleBindings) Model(com.axelor.db.Model) BamlModel(com.axelor.apps.bpm.db.BamlModel) Bindings(javax.script.Bindings) SimpleBindings(javax.script.SimpleBindings) GroovyScriptHelper(com.axelor.script.GroovyScriptHelper) Transactional(com.google.inject.persist.Transactional)

Aggregations

BamlModel (com.axelor.apps.bpm.db.BamlModel)6 Model (com.axelor.db.Model)4 BamlService (com.axelor.apps.baml.service.BamlService)3 BamlModelRepository (com.axelor.apps.bpm.db.repo.BamlModelRepository)2 GroovyScriptHelper (com.axelor.script.GroovyScriptHelper)2 Transactional (com.google.inject.persist.Transactional)2 Bindings (javax.script.Bindings)2 SimpleBindings (javax.script.SimpleBindings)2 WkfCommonService (com.axelor.apps.bpm.service.WkfCommonService)1 MetaJsonRecord (com.axelor.meta.db.MetaJsonRecord)1 MetaJsonModelRepository (com.axelor.meta.db.repo.MetaJsonModelRepository)1 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)1 Context (com.axelor.rpc.Context)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BpmnModelElementInstance (org.camunda.bpm.model.bpmn.instance.BpmnModelElementInstance)1