Search in sources :

Example 36 with MetaModel

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));
}
Also used : MetaModel(com.axelor.meta.db.MetaModel)

Example 37 with MetaModel

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());
}
Also used : AxelorException(com.axelor.exception.AxelorException) MetaModel(com.axelor.meta.db.MetaModel) MetaField(com.axelor.meta.db.MetaField) MetaJsonField(com.axelor.meta.db.MetaJsonField)

Example 38 with MetaModel

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;
}
Also used : MetaModel(com.axelor.meta.db.MetaModel) MetaField(com.axelor.meta.db.MetaField) FileField(com.axelor.apps.base.db.FileField)

Example 39 with MetaModel

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));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) MetaModel(com.axelor.meta.db.MetaModel) AxelorException(com.axelor.exception.AxelorException)

Example 40 with MetaModel

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();
}
Also used : MetaModel(com.axelor.meta.db.MetaModel)

Aggregations

MetaModel (com.axelor.meta.db.MetaModel)41 MetaModelRepository (com.axelor.meta.db.repo.MetaModelRepository)12 AxelorException (com.axelor.exception.AxelorException)9 MetaField (com.axelor.meta.db.MetaField)9 ArrayList (java.util.ArrayList)8 Model (com.axelor.db.Model)7 Mapper (com.axelor.db.mapper.Mapper)6 IOException (java.io.IOException)6 Transactional (com.google.inject.persist.Transactional)5 List (java.util.List)5 App (com.axelor.apps.base.db.App)4 Property (com.axelor.db.mapper.Property)4 MetaJsonModel (com.axelor.meta.db.MetaJsonModel)4 Context (com.axelor.rpc.Context)4 AuditableModel (com.axelor.auth.db.AuditableModel)3 CSVInput (com.axelor.data.csv.CSVInput)3 MetaFile (com.axelor.meta.db.MetaFile)3 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)3 AppFilter (com.axelor.app.internal.AppFilter)2 AdvancedExport (com.axelor.apps.base.db.AdvancedExport)2