use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.
the class FilterSqlService method addJoin.
private void addJoin(MetaField field, List<String> joins, StringBuilder parent) {
MetaModel metaModel = metaModelRepo.findByName(field.getTypeName());
String parentField = getColumn(field);
joins.add("left join " + metaModel.getTableName() + " " + "obj" + joins.size() + " on (" + "obj" + joins.size() + ".id = " + parent.toString() + "." + parentField + ")");
parent.replace(0, parent.length(), "obj" + (joins.size() - 1));
}
use of com.axelor.meta.db.MetaModel 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());
}
use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.
the class FileTabServiceImpl method updateFields.
@Override
public FileTab updateFields(FileTab fileTab) throws ClassNotFoundException {
MetaModel model = fileTab.getMetaModel();
if (model == null || CollectionUtils.isEmpty(fileTab.getFileFieldList())) {
return fileTab;
}
Beans.get(ValidatorService.class).sortFileFieldList(fileTab.getFileFieldList());
for (FileField fileField : fileTab.getFileFieldList()) {
MetaField importField = metaFieldRepo.all().filter("self.label = ?1 AND self.metaModel.id = ?2", fileField.getColumnTitle(), model.getId()).fetchOne();
if (importField != null) {
String relationship = importField.getRelationship();
if (!Strings.isNullOrEmpty(relationship) && relationship.equals("OneToMany")) {
continue;
}
fileField.setImportField(importField);
if (!Strings.isNullOrEmpty(relationship)) {
String subImportField = this.getSubImportField(importField);
fileField.setSubImportField(subImportField);
}
fileField = fileFieldService.fillType(fileField);
if (!Strings.isNullOrEmpty(relationship) && !fileField.getTargetType().equals("MetaFile")) {
fileField.setImportType(FileFieldRepository.IMPORT_TYPE_FIND);
} else {
if (!Strings.isNullOrEmpty(fileField.getTargetType()) && fileField.getTargetType().equals("MetaFile")) {
fileField.setImportType(FileFieldRepository.IMPORT_TYPE_NEW);
}
}
fileField.setFullName(fileFieldService.computeFullName(fileField));
} else {
fileField.setImportField(null);
fileField.setSubImportField(null);
}
}
return fileTab;
}
use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.
the class TemplateService method checkTargetReceptor.
public void checkTargetReceptor(Template template) throws AxelorException {
String target = template.getTarget();
MetaModel metaModel = template.getMetaModel();
if (Strings.isNullOrEmpty(target)) {
return;
}
if (metaModel == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TEMPLATE_SERVICE_1));
}
try {
this.validTarget(target, metaModel);
} catch (Exception e) {
throw new AxelorException(e.getCause(), TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.TEMPLATE_SERVICE_2));
}
}
use of com.axelor.meta.db.MetaModel in project axelor-open-suite by axelor.
the class ChartRecordViewServiceImpl method getTableName.
protected String getTableName(ChartBuilder chartBuilder) throws AxelorException {
Class<?> modelClass = getModelClass(chartBuilder);
MetaModel metaModel = metaModelRepository.findByName(modelClass.getSimpleName());
return metaModel.getTableName();
}
Aggregations