Search in sources :

Example 26 with MetaJsonField

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

the class ActionScriptBuilderService method addFieldsBinding.

private String addFieldsBinding(String target, List<ActionBuilderLine> lines, int level) {
    StringBuilder stb = new StringBuilder();
    lines.sort((l1, l2) -> {
        if (l1.getDummy() && !l2.getDummy()) {
            return -1;
        }
        if (!l1.getDummy() && l2.getDummy()) {
            return 1;
        }
        return 0;
    });
    for (ActionBuilderLine line : lines) {
        String name = line.getName();
        String value = line.getValue();
        if (value != null && value.contains(".sum(")) {
            value = getSum(value, line.getFilter());
        }
        if (line.getDummy()) {
            stb.append(format("_$." + name + " = " + value + ";", level));
            continue;
        }
        MetaJsonField jsonField = line.getMetaJsonField();
        MetaField metaField = line.getMetaField();
        if (jsonField != null && (jsonField.getTargetJsonModel() != null || jsonField.getTargetModel() != null)) {
            value = addRelationalBinding(line, target, true);
        } else if (metaField != null && metaField.getRelationship() != null) {
            value = addRelationalBinding(line, target, false);
        }
        if (value != null && metaField != null && metaField.getTypeName().equals(BigDecimal.class.getSimpleName())) {
            value = "new BigDecimal(" + value + ")";
        }
        String condition = line.getConditionText();
        if (condition != null) {
            stb.append(format("if(" + condition + "){" + target + "." + name + " = " + value + ";}", level));
        } else {
            stb.append(format(target + "." + name + " = " + value + ";", level));
        }
    }
    return stb.toString();
}
Also used : ActionBuilderLine(com.axelor.studio.db.ActionBuilderLine) MetaField(com.axelor.meta.db.MetaField) MetaJsonField(com.axelor.meta.db.MetaJsonField)

Example 27 with MetaJsonField

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

the class ActionScriptBuilderService method getTargetModel.

private String getTargetModel(ActionBuilderLine line) {
    MetaJsonField jsonField = line.getMetaJsonField();
    String targetModel = "";
    if (jsonField != null && jsonField.getTargetModel() != null) {
        targetModel = jsonField.getTargetModel();
    }
    MetaField field = line.getMetaField();
    if (field != null && field.getTypeName() != null) {
        targetModel = field.getTypeName();
    }
    return targetModel;
}
Also used : MetaField(com.axelor.meta.db.MetaField) MetaJsonField(com.axelor.meta.db.MetaJsonField)

Example 28 with MetaJsonField

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

the class ActionScriptBuilderService method getSourceModel.

private String getSourceModel(ActionBuilderLine line) {
    MetaJsonField jsonField = line.getValueJson();
    String sourceModel = null;
    Object targetObject = null;
    try {
        if (jsonField != null && jsonField.getTargetModel() != null) {
            if (line.getValue() != null && !line.getValue().contentEquals("$." + jsonField.getName())) {
                targetObject = filterSqlService.parseJsonField(jsonField, line.getValue().replace("$.", ""), null, null);
            } else {
                sourceModel = jsonField.getTargetModel();
            }
        }
        MetaField field = line.getValueField();
        if (field != null && field.getTypeName() != null) {
            if (line.getValue() != null && !line.getValue().contentEquals("$." + field.getName())) {
                targetObject = filterSqlService.parseMetaField(field, line.getValue().replace("$.", ""), null, null, false);
            } else {
                sourceModel = field.getTypeName();
            }
        }
    } catch (AxelorException e) {
        TraceBackService.trace(e);
    }
    if (sourceModel == null && line.getValue() != null && line.getValue().equals("$")) {
        sourceModel = getRootSourceModel(line);
    }
    if (sourceModel == null && line.getValue() != null && line.getValue().equals("$$")) {
        sourceModel = getRootSourceModel(line);
    }
    if (targetObject != null) {
        if (targetObject instanceof MetaJsonField) {
            sourceModel = ((MetaJsonField) targetObject).getTargetModel();
        } else if (targetObject instanceof MetaField) {
            sourceModel = ((MetaField) targetObject).getTypeName();
        }
    }
    return sourceModel;
}
Also used : AxelorException(com.axelor.exception.AxelorException) MetaField(com.axelor.meta.db.MetaField) MetaJsonField(com.axelor.meta.db.MetaJsonField)

Example 29 with MetaJsonField

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

the class ValidatorService method createCustomButton.

@Transactional(rollbackOn = { Exception.class })
public void createCustomButton(String modelName, String targetModelName, int sequence) {
    String simpleModelName = StringUtils.substringAfterLast(targetModelName, ".");
    String fieldName = Inflector.getInstance().camelize(simpleModelName, true) + "Set";
    String buttonName = "show" + fieldName + "Btn";
    if (metaJsonFieldRepo.all().filter("self.name = ?1 AND self.type = ?2 AND self.model = ?3", buttonName, "button", modelName).count() > 0) {
        return;
    }
    MetaJsonField jsonField = new MetaJsonField();
    jsonField.setName(buttonName);
    jsonField.setType("button");
    jsonField.setTitle("Show " + Inflector.getInstance().titleize(simpleModelName));
    jsonField.setSequence(sequence);
    jsonField.setModel(modelName);
    jsonField.setModelField("attrs");
    jsonField.setOnClick("action-file-tab-method-show-record,close");
    jsonField.setWidgetAttrs("{\"colSpan\": \"4\"}");
    jsonField.setShowIf(fieldName + " != null && $record.advancedImport.statusSelect > 0");
    metaJsonFieldRepo.save(jsonField);
}
Also used : MetaJsonField(com.axelor.meta.db.MetaJsonField) Transactional(com.google.inject.persist.Transactional)

Example 30 with MetaJsonField

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

the class ChartRecordViewServiceImpl method getSelectionFieldValue.

protected Object getSelectionFieldValue(ChartBuilder chartBuilder, Object titleParam, Boolean isForGroup) throws AxelorException {
    Object value = null;
    String selection = null;
    Class<?> targetType = String.class;
    Boolean isJson = chartBuilder.getIsJson() || (isForGroup ? chartBuilder.getIsJsonGroupOn() : chartBuilder.getIsJsonAggregateOn());
    MetaField target = chartBuilder.getGroupOn();
    MetaJsonField jsonField = chartBuilder.getGroupOnJson();
    if (!isForGroup) {
        target = chartBuilder.getAggregateOn();
        jsonField = chartBuilder.getAggregateOnJson();
    }
    if (isJson && ObjectUtils.notEmpty(jsonField.getSelection()) && (Integer.class.getSimpleName().toLowerCase().equals(jsonField.getType()) || String.class.getSimpleName().toLowerCase().equals(jsonField.getType()))) {
        selection = jsonField.getSelection();
        if (Integer.class.getSimpleName().toLowerCase().equals(jsonField.getType())) {
            targetType = Integer.class;
        }
    } else {
        try {
            Mapper mapper = Mapper.of(Class.forName(chartBuilder.getModel()));
            Property p = mapper.getProperty(target.getName());
            if (ObjectUtils.notEmpty(p.getSelection())) {
                selection = p.getSelection();
                targetType = p.getJavaType();
            }
        } catch (ClassNotFoundException e) {
            throw new AxelorException(e, TraceBackRepository.CATEGORY_INCONSISTENCY);
        }
    }
    if (ObjectUtils.isEmpty(selection)) {
        return value;
    }
    List<Option> selectionList = MetaStore.getSelectionList(selection);
    for (Option option : selectionList) {
        if (option.getLocalizedTitle().equals(titleParam)) {
            return ConvertUtils.convert(option.getValue(), targetType);
        }
    }
    return value;
}
Also used : AxelorException(com.axelor.exception.AxelorException) MetaField(com.axelor.meta.db.MetaField) BigInteger(java.math.BigInteger) Mapper(com.axelor.db.mapper.Mapper) MetaJsonField(com.axelor.meta.db.MetaJsonField) Option(com.axelor.meta.schema.views.Selection.Option) Property(com.axelor.db.mapper.Property)

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