use of com.axelor.meta.db.MetaJsonField in project axelor-open-suite by axelor.
the class DmnServiceImpl method processMetaModelJson.
private Object processMetaModelJson(String fieldName, String subField, Object value, Class<Model> entityClass) throws AxelorException {
MetaJsonField jsonField = Beans.get(MetaJsonFieldRepository.class).all().filter("self.name = ?1 and self.model = ?2", fieldName, entityClass.getName()).fetchOne();
log.debug("Meta model json field search for field: {}, class: {}, found: {}", fieldName, entityClass.getName(), jsonField);
if (jsonField == null) {
return null;
}
return processMetaJsonField(value, subField, jsonField);
}
use of com.axelor.meta.db.MetaJsonField in project axelor-open-suite by axelor.
the class DmnServiceImpl method mapToMetaCustomModelFields.
private String mapToMetaCustomModelFields(List<String> fields, String modelName, String searchOperator, boolean multiple, String resultVar) throws ClassNotFoundException {
StringBuilder scriptBuilder = new StringBuilder();
scriptBuilder.append("def _query = null\n");
String varName = Beans.get(WkfCommonService.class).getVarName(modelName);
List<MetaJsonField> metaJsonFields = Beans.get(MetaJsonFieldRepository.class).all().filter("self.name in (?1) and self.jsonModel.name = ?2", fields, modelName).fetch();
log.debug("Json fields founds: {}", metaJsonFields);
for (MetaJsonField field : metaJsonFields) {
addJsonField(searchOperator, multiple, resultVar, scriptBuilder, varName, field);
scriptBuilder.append("\n");
}
return scriptBuilder.toString();
}
use of com.axelor.meta.db.MetaJsonField in project axelor-open-suite by axelor.
the class DmnServiceImpl method mapToMetaModelFields.
private String mapToMetaModelFields(List<String> fields, String modelName, String searchOperator, boolean multiple, String resultVar) throws ClassNotFoundException {
StringBuilder scriptBuilder = new StringBuilder();
Mapper mapper = Mapper.of(EntityHelper.getEntityClass(Class.forName(modelName)));
String varName = Beans.get(WkfCommonService.class).getVarName(modelName);
scriptBuilder.append("def _query = null\n");
for (String field : fields) {
String resultField = resultVar + "?." + field;
String targetField = varName + "." + field;
Property property = mapper.getProperty(field);
if (property == null) {
MetaJsonField jsonField = Beans.get(MetaJsonFieldRepository.class).all().filter("self.model = ?1 and self.name = ?2", modelName, field).fetchOne();
if (jsonField != null) {
addJsonField(searchOperator, multiple, resultVar, scriptBuilder, varName, jsonField);
}
continue;
}
if (property.getTarget() != null) {
addRelationalField(searchOperator, multiple, scriptBuilder, targetField, resultField, property.getTarget().getSimpleName(), property.getTargetName());
} else {
scriptBuilder.append(targetField + " = " + resultField);
}
scriptBuilder.append("\n");
}
return scriptBuilder.toString();
}
use of com.axelor.meta.db.MetaJsonField in project axelor-open-suite by axelor.
the class FilterSqlService method getTargetType.
public String getTargetType(Object target) {
String targetType = null;
if (target instanceof MetaField) {
MetaField metaField = (MetaField) target;
String relationship = metaField.getRelationship();
if (relationship != null) {
targetType = relationship;
} else {
targetType = metaField.getTypeName();
}
} else if (target instanceof MetaJsonField) {
targetType = ((MetaJsonField) target).getType();
log.debug("Target json type:", targetType);
targetType = Inflector.getInstance().camelize(targetType);
}
log.debug("Target type: {}, field: {}", targetType, target);
return targetType;
}
use of com.axelor.meta.db.MetaJsonField in project axelor-open-suite by axelor.
the class FilterSqlService method parseMetaField.
public Object parseMetaField(MetaField field, String target, List<String> joins, StringBuilder parent, boolean checkJson) throws AxelorException {
if (target == null || !target.contains(".")) {
if (field.getRelationship() != null && joins != null) {
target = getDefaultTarget(field.getName(), field.getTypeName())[0];
} else {
return field;
}
}
target = target.substring(target.indexOf(".") + 1);
String targetName = target.contains(".") ? target.substring(0, target.indexOf(".")) : target;
if (field.getRelationship() == null) {
return field;
}
MetaModel model = metaModelRepo.findByName(field.getTypeName());
MetaField subMeta = findMetaField(targetName, model.getFullName());
if (subMeta != null) {
if (joins != null) {
addJoin(field, joins, parent);
}
return parseMetaField(subMeta, target, joins, parent, checkJson);
} else if (checkJson) {
MetaJsonField subJson = findJsonField(targetName, model.getName());
if (subJson != null) {
if (joins != null) {
addJoin(field, joins, parent);
}
return parseJsonField(subJson, target, joins, parent);
}
}
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, "No sub field found field: %s model: %s ", targetName, model.getFullName());
}
Aggregations