Search in sources :

Example 31 with MetaField

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

the class FilterJpqlService method getJpqlFilters.

public String getJpqlFilters(List<Filter> filterList) {
    String filters = null;
    if (filterList == null) {
        return filters;
    }
    for (Filter filter : filterList) {
        MetaField field = filter.getMetaField();
        if (filter.getValue() != null) {
            String value = filter.getValue();
            value = value.replaceAll("\"", "");
            value = value.replaceAll("'", "");
            if (filter.getOperator().contains("like") && !value.contains("%")) {
                value = "%" + value + "%";
            }
            filter.setValue("'" + value + "'");
        }
        String relationship = field.getRelationship();
        String fieldName = relationship != null ? filter.getTargetField() : filter.getMetaField().getName();
        fieldName = "self." + fieldName;
        String fieldValue;
        if (filter.getTargetType().equals("String")) {
            fieldName = "LOWER(" + fieldName + ")";
            fieldValue = "LOWER(" + filter.getValue() + ")";
        } else {
            fieldValue = filter.getValue();
        }
        String condition = filterCommonService.getCondition(fieldName, filter.getOperator(), fieldValue);
        if (filters == null) {
            filters = condition;
        } else {
            String opt = filter.getLogicOp() != null && filter.getLogicOp() == 0 ? " AND " : " OR ";
            filters = filters + opt + condition;
        }
    }
    log.debug("JPQL filter: {}", filters);
    return filters;
}
Also used : Filter(com.axelor.studio.db.Filter) MetaField(com.axelor.meta.db.MetaField)

Example 32 with MetaField

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

Example 33 with MetaField

use of com.axelor.meta.db.MetaField 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 34 with MetaField

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

the class AppLoaderExportServiceImpl method getMetaFieldBinding.

private List<XMLBind> getMetaFieldBinding(Mapper modelMapper, AppDataLoader dataLoader, boolean relationalInput) {
    List<XMLBind> fieldBindings = new ArrayList<XMLBind>();
    for (MetaField field : dataLoader.getMetaFieldSet()) {
        fieldBindings.add(createDummyFieldBinding(field.getName()));
        if (relationalInput && field.getRelationship() == null) {
            continue;
        }
        XMLBind fieldBind = new XMLBind();
        fieldBind.setField(field.getName());
        fieldBind.setNode(field.getName());
        if (field.getRelationship() != null) {
            addRelationalMetaFieldBind(modelMapper, field, fieldBind);
        } else if (field.getTypeName().equals("Boolean")) {
            fieldBind.setAdapter("Boolean");
        }
        fieldBindings.add(fieldBind);
    }
    return fieldBindings;
}
Also used : MetaField(com.axelor.meta.db.MetaField) ArrayList(java.util.ArrayList) XMLBind(com.axelor.data.xml.XMLBind)

Example 35 with MetaField

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

the class AppLoaderExportServiceImpl method getMetaSearchFields.

protected String getMetaSearchFields(Mapper modelMapper, AppDataLoader appDataLoader) throws ClassNotFoundException {
    StringBuilder fields = new StringBuilder();
    for (MetaField field : appDataLoader.getSearchMetaFieldSet()) {
        if (fields.length() != 0) {
            fields.append(" AND ");
        }
        if (field.getRelationship() != null) {
            Property property = modelMapper.getProperty(field.getName());
            fields.append("self." + field.getName() + "." + property.getTargetName() + " =  :_" + field.getName());
        } else {
            fields.append("self." + field.getName() + " =  :_" + field.getName());
        }
    }
    return fields.toString();
}
Also used : MetaField(com.axelor.meta.db.MetaField) Property(com.axelor.db.mapper.Property)

Aggregations

MetaField (com.axelor.meta.db.MetaField)45 MetaJsonField (com.axelor.meta.db.MetaJsonField)15 MetaModel (com.axelor.meta.db.MetaModel)10 Mapper (com.axelor.db.mapper.Mapper)9 AxelorException (com.axelor.exception.AxelorException)8 ArrayList (java.util.ArrayList)6 Property (com.axelor.db.mapper.Property)5 Filter (com.axelor.studio.db.Filter)4 Model (com.axelor.db.Model)3 MetaFieldRepository (com.axelor.meta.db.repo.MetaFieldRepository)3 MetaModelRepository (com.axelor.meta.db.repo.MetaModelRepository)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Company (com.axelor.apps.base.db.Company)2 FileField (com.axelor.apps.base.db.FileField)2 ProductCompany (com.axelor.apps.base.db.ProductCompany)2 Context (com.axelor.rpc.Context)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Transactional (com.google.inject.persist.Transactional)2 BigInteger (java.math.BigInteger)2