Search in sources :

Example 11 with MetaJsonField

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

the class FilterController method updateTargetField.

public void updateTargetField(ActionRequest request, ActionResponse response) {
    Filter filter = request.getContext().asType(Filter.class);
    MetaField metaField = filter.getMetaField();
    MetaJsonField metaJson = filter.getMetaJsonField();
    Boolean isJson = filter.getIsJson() != null ? filter.getIsJson() : false;
    if (!isJson && metaField != null) {
        String type = metaField.getRelationship() != null ? metaField.getRelationship() : metaField.getTypeName();
        response.setValue("targetType", type);
        response.setValue("targetField", metaField.getName());
        response.setValue("targetTitle", metaField.getLabel() != null && !metaField.getLabel().isEmpty() ? metaField.getLabel() : metaField.getName());
    } else if ((isJson || !isJson) && metaJson != null) {
        response.setValue("targetType", Inflector.getInstance().camelize(metaJson.getType()));
        response.setValue("targetField", metaJson.getName());
    } else {
        response.setValue("targetField", null);
        response.setValue("targetType", null);
    }
    response.setValue("operator", null);
}
Also used : Filter(com.axelor.studio.db.Filter) MetaField(com.axelor.meta.db.MetaField) MetaJsonField(com.axelor.meta.db.MetaJsonField)

Example 12 with MetaJsonField

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

the class MetaJsonFieldController method trackJsonField.

public void trackJsonField(ActionRequest request, ActionResponse response) {
    MetaJsonField metaJsonField = request.getContext().asType(MetaJsonField.class);
    MetaJsonField jsonField = Beans.get(MetaJsonFieldRepo.class).all().filter("self.name = ?1 AND self.model = ?2", metaJsonField.getName(), metaJsonField.getModel()).fetchOne();
    if (jsonField != null) {
        return;
    }
    Beans.get(StudioMetaService.class).trackJsonField(metaJsonField);
}
Also used : StudioMetaService(com.axelor.studio.service.StudioMetaService) MetaJsonFieldRepo(com.axelor.studio.db.repo.MetaJsonFieldRepo) MetaJsonField(com.axelor.meta.db.MetaJsonField)

Example 13 with MetaJsonField

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

the class ConfiguratorCreatorServiceImpl method completeSelection.

/**
 * Fill {@link MetaJsonField#selection} searching in java class code.
 *
 * @param metaField a meta field.
 * @param newField a meta json field.
 */
protected void completeSelection(MetaField metaField, MetaJsonField newField) {
    try {
        Field correspondingField = Class.forName(metaField.getMetaModel().getPackageName() + "." + metaField.getMetaModel().getName()).getDeclaredField(metaField.getName());
        Widget widget = correspondingField.getAnnotation(Widget.class);
        if (widget == null) {
            return;
        }
        String selection = widget.selection();
        if (!Strings.isNullOrEmpty(selection)) {
            newField.setSelection(selection);
        }
    } catch (ClassNotFoundException | NoSuchFieldException e) {
        TraceBackService.trace(e);
    }
}
Also used : MetaJsonField(com.axelor.meta.db.MetaJsonField) MetaField(com.axelor.meta.db.MetaField) Field(java.lang.reflect.Field) Widget(com.axelor.db.annotations.Widget)

Example 14 with MetaJsonField

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

the class ConfiguratorCreatorServiceImpl method addIfMissing.

/**
 * Add the {@link ConfiguratorFormula} in {@link ConfiguratorCreator#indicators} if the formula is
 * not represented by an existing indicator.
 *
 * @param formula
 * @param creator
 */
protected void addIfMissing(ConfiguratorFormula formula, ConfiguratorCreator creator) throws AxelorException {
    MetaField formulaMetaField = formula.getMetaField();
    List<MetaJsonField> fields = Optional.ofNullable(creator.getIndicators()).orElse(Collections.emptyList());
    for (MetaJsonField field : fields) {
        if (field.getName().equals(formulaMetaField.getName() + "_" + creator.getId())) {
            return;
        }
    }
    String metaModelName = formulaMetaField.getMetaModel().getName();
    MetaJsonField newField = new MetaJsonField();
    newField.setModel(Configurator.class.getName());
    newField.setModelField("indicators");
    MetaField metaField = Beans.get(MetaFieldRepository.class).all().filter("self.metaModel.name = :metaModelName AND self.name = :name").bind("metaModelName", metaModelName).bind("name", formulaMetaField.getName()).fetchOne();
    String typeName;
    if (!Strings.isNullOrEmpty(metaField.getRelationship())) {
        typeName = metaField.getRelationship();
        completeDefaultGridAndForm(metaField, newField);
    } else {
        typeName = metaField.getTypeName();
    }
    completeSelection(metaField, newField);
    newField.setType(MetaTool.typeToJsonType(typeName));
    newField.setName(formulaMetaField.getName() + "_" + creator.getId());
    newField.setTitle(formulaMetaField.getLabel());
    creator.addIndicator(newField);
}
Also used : MetaField(com.axelor.meta.db.MetaField) Configurator(com.axelor.apps.sale.db.Configurator) MetaJsonField(com.axelor.meta.db.MetaJsonField) MetaFieldRepository(com.axelor.meta.db.repo.MetaFieldRepository)

Example 15 with MetaJsonField

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

the class ConfiguratorCreatorImportServiceImpl method fixAttributesName.

@Override
public void fixAttributesName(ConfiguratorCreator creator) throws AxelorException {
    List<MetaJsonField> attributes = creator.getAttributes();
    if (attributes == null) {
        return;
    }
    for (MetaJsonField attribute : attributes) {
        String name = attribute.getName();
        if (name != null && name.contains("_")) {
            attribute.setName(name.substring(0, name.lastIndexOf('_')) + '_' + creator.getId());
        }
        updateOtherFieldsInAttribute(creator, attribute);
        updateAttributeNameInFormulas(creator, name, attribute.getName());
    }
}
Also used : 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