Search in sources :

Example 1 with MetaJsonModel

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

the class ImportService method importAppMetaJsonModel.

public Object importAppMetaJsonModel(Object bean, Map<String, Object> values) {
    assert bean instanceof MetaJsonModel;
    MetaJsonModel model = (MetaJsonModel) bean;
    JPA.flush();
    JPA.refresh(model);
    return metaJsonModelRepo.save(model);
}
Also used : MetaJsonModel(com.axelor.meta.db.MetaJsonModel)

Example 2 with MetaJsonModel

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

the class ActionEmailBuilderService method build.

public MetaAction build(ActionBuilder builder) {
    String name = builder.getName();
    Object model = builder.getIsJson() ? metaJsonModelRepo.all().filter("self.name = ?", builder.getModel()).fetchOne() : metaModelRepo.all().filter("self.fullName = ?", builder.getModel()).fetchOne();
    int sendOption = builder.getEmailSendOptionSelect();
    Template template = builder.getEmailTemplate();
    String xml = "<action-method name=\"" + name + "\" id=\"" + builder.getXmlId() + "\">\n\t" + "<call class=\"com.axelor.studio.service.builder.ActionEmailBuilderService\" method=\"sendEmail(id, '" + (builder.getIsJson() ? ((MetaJsonModel) model).getName() : ((MetaModel) model).getFullName()) + "', '" + (builder.getIsJson() ? ((MetaJsonModel) model).getName() : ((MetaModel) model).getName()) + "', '" + template.getId() + "', '" + sendOption + "')\" " + "if=\"id != null\"/>\n" + "</action-method>";
    return studioMetaService.updateMetaAction(name, "action-method", xml, null, builder.getXmlId());
}
Also used : MetaJsonModel(com.axelor.meta.db.MetaJsonModel) MetaModel(com.axelor.meta.db.MetaModel) Template(com.axelor.apps.message.db.Template)

Example 3 with MetaJsonModel

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

the class WkfModelController method showRecord.

@SuppressWarnings("unchecked")
public void showRecord(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        String status = context.get("status").toString();
        String tableName = null;
        String jsonModel = null;
        ActionViewBuilder actionViewBuilder = null;
        if (context.get("metaModel") != null) {
            Long id = Long.parseLong(((Map<String, Object>) context.get("metaModel")).get("id").toString());
            MetaModel metaModel = Beans.get(MetaModelRepository.class).find(id);
            tableName = metaModel.getTableName();
            actionViewBuilder = createActionBuilder(status, metaModel);
        } else if (context.get("metaJsonModel") != null) {
            Long id = Long.parseLong(((Map<String, Object>) context.get("metaJsonModel")).get("id").toString());
            MetaJsonModel metaJsonModel = Beans.get(MetaJsonModelRepository.class).find(id);
            jsonModel = metaJsonModel.getName();
            tableName = MetaJsonRecord.class.getAnnotation(Table.class).name();
            actionViewBuilder = createActionBuilder(status, metaJsonModel);
        }
        List<Long> idList = getRecordIds(context, tableName, jsonModel);
        response.setView(actionViewBuilder.context("ids", !idList.isEmpty() ? idList : 0).map());
        response.setCanClose(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) MetaJsonModel(com.axelor.meta.db.MetaJsonModel) MetaModelRepository(com.axelor.meta.db.repo.MetaModelRepository) Table(javax.persistence.Table) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) AxelorException(com.axelor.exception.AxelorException) MetaModel(com.axelor.meta.db.MetaModel) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord)

Example 4 with MetaJsonModel

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

the class WkfModelController method viewNewRecord.

private ActionViewBuilder viewNewRecord(String modelName, boolean isMetaModel) {
    ActionViewBuilder actionViewBuilder = null;
    if (isMetaModel) {
        MetaModel metaModel = Beans.get(MetaModelRepository.class).findByName(modelName);
        String viewPrefix = Inflector.getInstance().dasherize(metaModel.getName());
        actionViewBuilder = ActionView.define(metaModel.getName()).model(metaModel.getFullName()).add("form", viewPrefix + "-form");
    } else {
        MetaJsonModel metaJsonModel = Beans.get(MetaJsonModelRepository.class).findByName(modelName);
        actionViewBuilder = ActionView.define(metaJsonModel.getTitle()).model(MetaJsonRecord.class.getName()).add("form", metaJsonModel.getFormView().getName()).domain("self.jsonModel = :jsonModel").context("jsonModel", modelName);
    }
    return actionViewBuilder;
}
Also used : MetaJsonModel(com.axelor.meta.db.MetaJsonModel) MetaModel(com.axelor.meta.db.MetaModel) MetaModelRepository(com.axelor.meta.db.repo.MetaModelRepository) MetaJsonModelRepository(com.axelor.meta.db.repo.MetaJsonModelRepository) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord)

Example 5 with MetaJsonModel

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

the class DmnServiceImpl method addJsonField.

private void addJsonField(String searchOperator, boolean multiple, String resultVar, StringBuilder scriptBuilder, String varName, MetaJsonField field) throws ClassNotFoundException {
    String resultField = resultVar + "?." + field.getName();
    String targetField = varName + "." + field.getName();
    String type = field.getType();
    switch(type) {
        case ("many-to-one"):
        case ("one-to-many"):
        case ("many-to-many"):
            Class<?> klass = Class.forName(field.getTargetModel());
            Mapper mapper = Mapper.of(EntityHelper.getEntityClass(klass));
            addRelationalField(searchOperator, multiple, scriptBuilder, targetField, resultField, klass.getSimpleName(), mapper.getNameField().getName());
            break;
        case ("json-many-to-one"):
        case ("json-many-to-many"):
        case ("json-one-to-many"):
            MetaJsonModel targetModel = field.getTargetJsonModel();
            String nameField = targetModel.getNameField() != null ? targetModel.getNameField() : "id";
            String targetName = "jsonModel = '" + targetModel.getName() + "' AND json_extract(self." + field.getModelField() + ", '" + nameField + "')";
            addRelationalField(searchOperator, multiple, scriptBuilder, targetField, resultField, MetaJsonRecord.class.getSimpleName(), targetName);
            break;
        default:
            scriptBuilder.append(targetField + " = " + resultField);
            break;
    }
}
Also used : Mapper(com.axelor.db.mapper.Mapper) MetaJsonModel(com.axelor.meta.db.MetaJsonModel) MetaJsonRecord(com.axelor.meta.db.MetaJsonRecord)

Aggregations

MetaJsonModel (com.axelor.meta.db.MetaJsonModel)8 MetaJsonRecord (com.axelor.meta.db.MetaJsonRecord)4 MetaModel (com.axelor.meta.db.MetaModel)4 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)4 MetaModelRepository (com.axelor.meta.db.repo.MetaModelRepository)3 MetaJsonModelRepository (com.axelor.meta.db.repo.MetaJsonModelRepository)2 LinkedHashMap (java.util.LinkedHashMap)2 Template (com.axelor.apps.message.db.Template)1 Mapper (com.axelor.db.mapper.Mapper)1 AxelorException (com.axelor.exception.AxelorException)1 Context (com.axelor.rpc.Context)1 MenuBuilder (com.axelor.studio.db.MenuBuilder)1 MenuBuilderRepo (com.axelor.studio.db.repo.MenuBuilderRepo)1 MenuBuilderRepository (com.axelor.studio.db.repo.MenuBuilderRepository)1 MetaJsonModelRepo (com.axelor.studio.db.repo.MetaJsonModelRepo)1 Transactional (com.google.inject.persist.Transactional)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Table (javax.persistence.Table)1