Search in sources :

Example 1 with MetaJsonRecord

use of com.axelor.meta.db.MetaJsonRecord in project axelor-open-suite by axelor.

the class WkfEmailServiceImpl method createUrl.

@Override
public String createUrl(FullContext wkfContext, String formName) {
    if (wkfContext == null) {
        return "";
    }
    String url = AppSettings.get().getBaseURL();
    Model model = (Model) EntityHelper.getEntity(wkfContext.getTarget());
    if (formName == null) {
        if (model instanceof MetaJsonRecord) {
            formName = "custom-model-" + ((MetaJsonRecord) model).getJsonModel() + "-form";
        } else {
            formName = inflector.dasherize(model.getClass().getSimpleName());
        }
    }
    String action = getAction(formName);
    if (action == null) {
        url += "/#ds/form::" + model.getClass().getName() + "/edit/" + wkfContext.get("id");
    } else {
        url += "/#ds/" + action + "/edit/" + wkfContext.get("id");
    }
    return url;
}
Also used : Model(com.axelor.db.Model) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord)

Example 2 with MetaJsonRecord

use of com.axelor.meta.db.MetaJsonRecord in project axelor-open-suite by axelor.

the class WkfInstanceServiceImpl method checkSubProcess.

protected void checkSubProcess(Model model) {
    String chldModel = model instanceof MetaJsonRecord ? ((MetaJsonRecord) model).getJsonModel() : model.getClass().getSimpleName();
    List<WkfTaskConfig> taskConfigs = wkfTaskConfigRepository.all().filter("self.callModel = ?1 AND self.callLink IS NOT NULL", chldModel).fetch();
    if (taskConfigs.isEmpty()) {
        return;
    }
    FullContext modelCtx = WkfContextHelper.create(model);
    Map<String, Object> ctxMap = ImmutableMap.of(wkfService.getVarName(model), modelCtx);
    for (WkfTaskConfig taskConfig : taskConfigs) {
        if (!evalCondition(ctxMap, taskConfig.getCallLinkCondition())) {
            continue;
        }
        Object parentModel = modelCtx.get(taskConfig.getCallLink());
        if (parentModel != null && parentModel instanceof FullContext) {
            Model parent = (Model) ((FullContext) parentModel).getTarget();
            if (parent.getProcessInstanceId() != null) {
                addChildProcessInstanceId(parent.getProcessInstanceId(), modelCtx, ctxMap);
                break;
            }
        }
    }
}
Also used : FullContext(com.axelor.apps.tool.context.FullContext) Model(com.axelor.db.Model) WkfTaskConfig(com.axelor.apps.bpm.db.WkfTaskConfig) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord)

Example 3 with MetaJsonRecord

use of com.axelor.meta.db.MetaJsonRecord in project axelor-open-suite by axelor.

the class WkfDisplayServiceImpl method getWkfStatus.

@Override
public List<Map<String, Object>> getWkfStatus(Class<?> klass, Long id) {
    List<Map<String, Object>> statusList = new ArrayList<>();
    if (klass == null || id == null) {
        return statusList;
    }
    Model model = (Model) JPA.em().find(klass, id);
    if (model == null) {
        return statusList;
    }
    String processInstanceId = model.getProcessInstanceId();
    log.debug("Display wkf nodes of processInstanceId: {}", processInstanceId);
    if (processInstanceId != null) {
        WkfInstance wkfInstance = Beans.get(WkfInstanceRepository.class).findByInstnaceId(processInstanceId);
        if (wkfInstance == null) {
            return statusList;
        }
        String klassName = klass.getSimpleName();
        if (model instanceof MetaJsonRecord) {
            klassName = ((MetaJsonRecord) model).getJsonModel();
        }
        boolean valid = isValidDisplayModel(klassName, wkfInstance);
        log.debug("Is valid model to display wkf nodes : {}", valid);
        if (!valid) {
            return statusList;
        }
        addActiveNodes(statusList, wkfInstance, klassName);
    }
    return statusList;
}
Also used : WkfInstance(com.axelor.apps.bpm.db.WkfInstance) ArrayList(java.util.ArrayList) WkfModel(com.axelor.apps.bpm.db.WkfModel) Model(com.axelor.db.Model) WkfInstanceRepository(com.axelor.apps.bpm.db.repo.WkfInstanceRepository) HashMap(java.util.HashMap) Map(java.util.Map) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord)

Example 4 with MetaJsonRecord

use of com.axelor.meta.db.MetaJsonRecord 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)

Example 5 with MetaJsonRecord

use of com.axelor.meta.db.MetaJsonRecord in project axelor-open-suite by axelor.

the class ValueMapperController method execute.

public void execute(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    Map<String, Object> valueMapperMap = (Map<String, Object>) context.get("valueMapper");
    ValueMapper mapper = Beans.get(ValueMapperRepository.class).find(Long.parseLong(valueMapperMap.get("id").toString()));
    if (mapper == null || mapper.getScript() == null) {
        return;
    }
    String modelName = (String) context.get("modelName");
    Model model = null;
    if (context.get("recordId") != null && modelName != null) {
        Long recordId = Long.parseLong(context.get("recordId").toString());
        model = FullContextHelper.getRepository(modelName).find(recordId);
    }
    Object result = Beans.get(ValueMapperService.class).execute(mapper, model);
    if (result != null && result instanceof FullContext && mapper.getScript().startsWith("def rec = $ctx.create(")) {
        FullContext fullContext = (FullContext) result;
        Object object = fullContext.getTarget();
        String title = object.getClass().getSimpleName();
        if (object instanceof MetaJsonRecord) {
            title = ((MetaJsonRecord) object).getJsonModel();
        }
        response.setView(ActionView.define(I18n.get(title)).model(object.getClass().getName()).add("form").add("grid").context("_showRecord", fullContext.get("id")).map());
    }
    response.setCanClose(true);
}
Also used : FullContext(com.axelor.apps.tool.context.FullContext) Context(com.axelor.rpc.Context) ValueMapper(com.axelor.studio.db.ValueMapper) ValueMapperRepository(com.axelor.studio.db.repo.ValueMapperRepository) FullContext(com.axelor.apps.tool.context.FullContext) Model(com.axelor.db.Model) ValueMapperService(com.axelor.studio.service.mapper.ValueMapperService) Map(java.util.Map) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord)

Aggregations

Model (com.axelor.db.Model)5 MetaJsonRecord (com.axelor.meta.db.MetaJsonRecord)5 Map (java.util.Map)3 FullContext (com.axelor.apps.tool.context.FullContext)2 Context (com.axelor.rpc.Context)2 BamlService (com.axelor.apps.baml.service.BamlService)1 BamlModel (com.axelor.apps.bpm.db.BamlModel)1 WkfInstance (com.axelor.apps.bpm.db.WkfInstance)1 WkfModel (com.axelor.apps.bpm.db.WkfModel)1 WkfTaskConfig (com.axelor.apps.bpm.db.WkfTaskConfig)1 BamlModelRepository (com.axelor.apps.bpm.db.repo.BamlModelRepository)1 WkfInstanceRepository (com.axelor.apps.bpm.db.repo.WkfInstanceRepository)1 MetaJsonModelRepository (com.axelor.meta.db.repo.MetaJsonModelRepository)1 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)1 ValueMapper (com.axelor.studio.db.ValueMapper)1 ValueMapperRepository (com.axelor.studio.db.repo.ValueMapperRepository)1 ValueMapperService (com.axelor.studio.service.mapper.ValueMapperService)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1