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