Search in sources :

Example 11 with MetaField

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

the class AdvancedExportController method getModelAllFields.

public void getModelAllFields(ActionRequest request, ActionResponse response) throws ClassNotFoundException {
    AdvancedExport advancedExport = request.getContext().asType(AdvancedExport.class);
    inflector = Inflector.getInstance();
    if (advancedExport.getMetaModel() != null) {
        List<Map<String, Object>> allFieldList = new ArrayList<>();
        MetaModelRepository metaModelRepository = Beans.get(MetaModelRepository.class);
        MetaFieldRepository metaFieldRepository = Beans.get(MetaFieldRepository.class);
        for (MetaField field : advancedExport.getMetaModel().getMetaFields()) {
            Map<String, Object> allFieldMap = new HashMap<>();
            allFieldMap.put("currentDomain", advancedExport.getMetaModel().getName());
            Class<?> modelClass = Class.forName(advancedExport.getMetaModel().getFullName());
            Mapper modelMapper = Mapper.of(modelClass);
            if (modelMapper.getProperty(field.getName()) == null || modelMapper.getProperty(field.getName()).isTransient()) {
                continue;
            }
            if (!Strings.isNullOrEmpty(field.getRelationship())) {
                MetaModel metaModel = metaModelRepository.all().filter("self.name = ?", field.getTypeName()).fetchOne();
                Class<?> klass = Class.forName(metaModel.getFullName());
                Mapper mapper = Mapper.of(klass);
                String fieldName = mapper.getNameField() == null ? "id" : mapper.getNameField().getName();
                MetaField metaField = metaFieldRepository.all().filter("self.name = ?1 AND self.metaModel = ?2", fieldName, metaModel).fetchOne();
                allFieldMap.put("metaField", metaField);
                allFieldMap.put("targetField", field.getName() + "." + metaField.getName());
            } else {
                allFieldMap.put("metaField", field);
                allFieldMap.put("targetField", field.getName());
            }
            if (Strings.isNullOrEmpty(field.getLabel())) {
                allFieldMap.put("title", this.getFieldTitle(inflector, field.getName()));
            } else {
                allFieldMap.put("title", field.getLabel());
            }
            allFieldList.add(allFieldMap);
        }
        response.setAttr("advancedExportLineList", "value", allFieldList);
    }
}
Also used : MetaModelRepository(com.axelor.meta.db.repo.MetaModelRepository) MetaField(com.axelor.meta.db.MetaField) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MetaFieldRepository(com.axelor.meta.db.repo.MetaFieldRepository) Mapper(com.axelor.db.mapper.Mapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MetaModel(com.axelor.meta.db.MetaModel) AdvancedExport(com.axelor.apps.base.db.AdvancedExport) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with MetaField

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

the class AdvancedExportController method metaFieldDomain.

public void metaFieldDomain(ActionRequest request, ActionResponse response) throws ClassNotFoundException {
    AdvancedExportLine adv = request.getContext().asType(AdvancedExportLine.class);
    MetaModel metaModel = Beans.get(MetaModelRepository.class).findByName(adv.getCurrentDomain());
    List<MetaField> metaFields = metaModel.getMetaFields();
    List<Long> metaFieldList = new ArrayList<>();
    if (metaFields != null) {
        Class<?> klass = Class.forName(metaModel.getFullName());
        Mapper mapper = Mapper.of(klass);
        for (MetaField field : metaFields) {
            if (!mapper.getProperty(field.getName()).isTransient()) {
                metaFieldList.add(field.getId());
            }
        }
    }
    metaFieldList.add(0L);
    response.setAttr("metaField", "domain", "self.id in (" + Joiner.on(",").join(metaFieldList) + ")");
}
Also used : Mapper(com.axelor.db.mapper.Mapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MetaModel(com.axelor.meta.db.MetaModel) MetaModelRepository(com.axelor.meta.db.repo.MetaModelRepository) AdvancedExportLine(com.axelor.apps.base.db.AdvancedExportLine) MetaField(com.axelor.meta.db.MetaField) ArrayList(java.util.ArrayList)

Example 13 with MetaField

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

the class AdvancedExportController method fillTitle.

public void fillTitle(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    MetaField metaField = (MetaField) context.get("metaField");
    if (metaField != null) {
        if (Strings.isNullOrEmpty(metaField.getLabel())) {
            inflector = Inflector.getInstance();
            response.setValue("title", I18n.get(this.getFieldTitle(inflector, metaField.getName())));
        } else {
            response.setValue("title", I18n.get(metaField.getLabel()));
        }
    } else {
        response.setValue("title", null);
    }
}
Also used : Context(com.axelor.rpc.Context) MetaField(com.axelor.meta.db.MetaField)

Example 14 with MetaField

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

the class AdvancedExportController method fillTargetField.

public void fillTargetField(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    MetaField metaField = (MetaField) context.get("metaField");
    if (metaField != null) {
        String targetField = "";
        if (context.get("targetField") == null) {
            targetField = metaField.getName();
        } else {
            targetField = context.get("targetField").toString();
            targetField += "." + metaField.getName();
        }
        response.setValue("targetField", targetField);
        if (metaField.getRelationship() != null) {
            response.setValue("currentDomain", metaField.getTypeName());
            response.setValue("metaField", null);
        } else {
            response.setAttr("metaField", "readonly", true);
            response.setAttr("validateFieldSelectionBtn", "readonly", true);
            response.setAttr("$viewerMessage", "hidden", false);
            response.setAttr("$isValidate", "value", true);
        }
    }
}
Also used : Context(com.axelor.rpc.Context) MetaField(com.axelor.meta.db.MetaField)

Example 15 with MetaField

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

the class ConfiguratorCreatorServiceImpl method completeFormula.

/**
 * Complete the given configurator formula with correct metafields.
 *
 * @param configuratorFormula a configurator formula.
 * @param name the meta field name.
 * @param metaFieldType the name of the model owning the meta field.
 */
protected void completeFormula(ConfiguratorFormula configuratorFormula, String name, String metaFieldType) {
    configuratorFormula.setShowOnConfigurator(true);
    configuratorFormula.setFormula("");
    Long modelId = JPA.all(MetaModel.class).filter("self.name = ?", metaFieldType).fetchOne().getId();
    MetaField metaField = JPA.all(MetaField.class).filter("self.name = ? AND self.metaModel.id = ?", name, modelId).fetchOne();
    configuratorFormula.setMetaField(metaField);
}
Also used : MetaModel(com.axelor.meta.db.MetaModel) MetaField(com.axelor.meta.db.MetaField)

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