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));
}
}
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);
}
}
}
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);
}
}
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;
}
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;
}
Aggregations