Search in sources :

Example 16 with MetaJsonField

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

Example 17 with MetaJsonField

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();
}
Also used : MetaJsonFieldRepository(com.axelor.meta.db.repo.MetaJsonFieldRepository) MetaJsonField(com.axelor.meta.db.MetaJsonField) WkfCommonService(com.axelor.apps.bpm.service.WkfCommonService)

Example 18 with MetaJsonField

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();
}
Also used : Mapper(com.axelor.db.mapper.Mapper) MetaJsonFieldRepository(com.axelor.meta.db.repo.MetaJsonFieldRepository) MetaJsonField(com.axelor.meta.db.MetaJsonField) Property(com.axelor.db.mapper.Property) WkfCommonService(com.axelor.apps.bpm.service.WkfCommonService)

Example 19 with MetaJsonField

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

Example 20 with MetaJsonField

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

Aggregations

MetaJsonField (com.axelor.meta.db.MetaJsonField)30 MetaField (com.axelor.meta.db.MetaField)14 AxelorException (com.axelor.exception.AxelorException)7 HashMap (java.util.HashMap)5 MetaJsonFieldRepository (com.axelor.meta.db.repo.MetaJsonFieldRepository)4 Transactional (com.google.inject.persist.Transactional)4 Map (java.util.Map)4 Mapper (com.axelor.db.mapper.Mapper)3 WkfCommonService (com.axelor.apps.bpm.service.WkfCommonService)2 ConfiguratorFormula (com.axelor.apps.sale.db.ConfiguratorFormula)2 Property (com.axelor.db.mapper.Property)2 MetaModel (com.axelor.meta.db.MetaModel)2 Filter (com.axelor.studio.db.Filter)2 File (java.io.File)2 IOException (java.io.IOException)2 Field (java.lang.reflect.Field)2 ArrayList (java.util.ArrayList)2 FileTab (com.axelor.apps.base.db.FileTab)1 FileTabService (com.axelor.apps.base.service.advanced.imports.FileTabService)1 Configurator (com.axelor.apps.sale.db.Configurator)1