Search in sources :

Example 6 with BamlModel

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

the class BamlModelController method execute.

public void execute(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    String model = (String) context.get("modelName");
    Model entity = null;
    if (context.get("recordId") != null && model != null) {
        Long recordId = Long.parseLong(context.get("recordId").toString());
        entity = WkfContextHelper.getRepository(model).find(recordId);
    }
    Map<String, Object> bamlModelMap = (Map<String, Object>) context.get("bamlModel");
    BamlModel bamlModel = Beans.get(BamlModelRepository.class).find(Long.parseLong(bamlModelMap.get("id").toString()));
    Model object = Beans.get(BamlService.class).execute(bamlModel, entity);
    String modelName = object.getClass().getSimpleName();
    String dasherizeModel = Inflector.getInstance().dasherize(modelName);
    String title = object.getClass().getSimpleName();
    String formView = dasherizeModel + "-form";
    String gridView = dasherizeModel + "-grid";
    String jsonModel = null;
    if (object instanceof MetaJsonRecord) {
        jsonModel = ((MetaJsonRecord) object).getJsonModel();
        title = Beans.get(MetaJsonModelRepository.class).findByName(jsonModel).getTitle();
        if (Strings.isNullOrEmpty(title)) {
            title = jsonModel;
        }
        formView = "custom-model-" + jsonModel + "-form";
        gridView = "custom-model-" + jsonModel + "-grid";
    }
    response.setCanClose(true);
    ActionViewBuilder builder = ActionView.define(I18n.get(title)).model(object.getClass().getName()).add("form", formView).add("grid", gridView).context("_showRecord", object.getId());
    if (jsonModel != null) {
        builder.context("jsonModel", jsonModel);
        builder.domain("self.jsonModel = :jsonModel");
    }
    response.setView(builder.map());
}
Also used : Context(com.axelor.rpc.Context) BamlModelRepository(com.axelor.apps.bpm.db.repo.BamlModelRepository) MetaJsonModelRepository(com.axelor.meta.db.repo.MetaJsonModelRepository) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) BamlModel(com.axelor.apps.bpm.db.BamlModel) Model(com.axelor.db.Model) BamlModel(com.axelor.apps.bpm.db.BamlModel) Map(java.util.Map) BamlService(com.axelor.apps.baml.service.BamlService) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord)

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