Search in sources :

Example 41 with Mapper

use of com.axelor.db.mapper.Mapper in project axelor-open-suite by axelor.

the class DataImportServiceImpl method checkSubFieldAndWriteData.

private void checkSubFieldAndWriteData(String[] subFields, int index, Property parentProp, String dataCell, int forSelectUse, List<String> dataList) throws ClassNotFoundException {
    if (index < subFields.length) {
        if (parentProp.getTarget() != null) {
            Mapper mapper = advancedImportService.getMapper(parentProp.getTarget().getName());
            Property childProp = mapper.getProperty(subFields[index]);
            if (childProp != null && childProp.getTarget() != null) {
                this.checkSubFieldAndWriteData(subFields, index + 1, childProp, dataCell, forSelectUse, dataList);
            } else {
                if (!Strings.isNullOrEmpty(childProp.getSelection())) {
                    this.writeSelectionData(childProp.getSelection(), dataCell, forSelectUse, dataList);
                } else {
                    dataList.add(dataCell);
                }
            }
        }
    }
}
Also used : Mapper(com.axelor.db.mapper.Mapper) Property(com.axelor.db.mapper.Property)

Example 42 with Mapper

use of com.axelor.db.mapper.Mapper in project axelor-open-suite by axelor.

the class DataImportServiceImpl method createCSVSubBinding.

private void createCSVSubBinding(String[] subFields, int index, String column, Property parentProp, FileField fileField, CSVBind parentBind, CSVBind dummyBind, boolean isSameParentExist) throws ClassNotFoundException {
    if (index < subFields.length) {
        if (parentProp.getTarget() == null) {
            return;
        }
        int importType = fileField.getImportType();
        String relationship = fileField.getRelationship();
        fullFieldName += "." + subFields[index];
        Mapper mapper = advancedImportService.getMapper(parentProp.getTarget().getName());
        Property childProp = mapper.getProperty(subFields[index]);
        if (childProp != null && childProp.getTarget() != null) {
            CSVBind subBind = null;
            if (subBindMap.containsKey(fullFieldName)) {
                subBind = subBindMap.get(fullFieldName);
            } else if (importType != FileFieldRepository.IMPORT_TYPE_FIND) {
                subBind = this.createCSVBind(null, childProp.getName(), null, null, null, true);
                subBind.setBindings(new ArrayList<>());
                parentBind.getBindings().add(subBind);
                subBindMap.put(fullFieldName, subBind);
            }
            if (importType == FileFieldRepository.IMPORT_TYPE_FIND_NEW && subBind != null) {
                String fieldName = (isSameParentExist ? fullFieldName.replaceFirst(fileField.getImportField().getName() + ".", "") : fullFieldName) + "." + subFields[index + 1];
                this.setSearch(column, fieldName, fileField, parentBind, isSameParentExist);
            }
            this.createCSVSubBinding(subFields, index + 1, column, childProp, fileField, isSameParentExist && importType == FileFieldRepository.IMPORT_TYPE_FIND ? parentBind : subBind, dummyBind, isSameParentExist);
        } else {
            String expression = this.setExpression(column, fileField, childProp);
            String adapter = null;
            String dateFormat = fileField.getDateFormat();
            if (Strings.isNullOrEmpty(expression) && !Strings.isNullOrEmpty(dateFormat)) {
                adapter = this.getAdapter(childProp.getJavaType().getSimpleName(), dateFormat.trim());
            }
            if (!fileField.getIsMatchWithFile()) {
                this.createBindForNotMatchWithFile(column, importType, dummyBind, expression, adapter, parentBind, childProp);
            } else {
                this.createBindForMatchWithFile(column, importType, expression, adapter, relationship, parentBind, childProp);
            }
            String fieldName = isSameParentExist && importType == FileFieldRepository.IMPORT_TYPE_FIND ? fullFieldName.replaceFirst(fileField.getImportField().getName() + ".", "") : childProp.getName();
            this.setSearch(column, fieldName, fileField, parentBind, isSameParentExist);
            if (importType != FileFieldRepository.IMPORT_TYPE_FIND) {
                parentBind.setUpdate(false);
            }
        }
    }
}
Also used : Mapper(com.axelor.db.mapper.Mapper) ArrayList(java.util.ArrayList) CSVBind(com.axelor.data.csv.CSVBind) Property(com.axelor.db.mapper.Property)

Example 43 with Mapper

use of com.axelor.db.mapper.Mapper in project axelor-open-suite by axelor.

the class AdvancedExportServiceImpl method checkSelectionField.

private void checkSelectionField(String[] fieldName, int index, MetaModel metaModel) throws ClassNotFoundException {
    Class<?> klass = Class.forName(metaModel.getFullName());
    Mapper mapper = Mapper.of(klass);
    List<MetaSelect> metaSelectList = metaSelectRepo.all().filter("self.name = ?", mapper.getProperty(fieldName[index]).getSelection()).fetch();
    if (CollectionUtils.isNotEmpty(metaSelectList)) {
        isSelectionField = true;
        String alias = "self";
        msi++;
        mt++;
        if (!isNormalField && index != 0) {
            alias = aliasName;
        }
        addSelectionField(fieldName[index], alias, StringTool.getIdListString(metaSelectList));
    }
}
Also used : Mapper(com.axelor.db.mapper.Mapper) MetaSelect(com.axelor.meta.db.MetaSelect)

Example 44 with Mapper

use of com.axelor.db.mapper.Mapper 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

Mapper (com.axelor.db.mapper.Mapper)44 Property (com.axelor.db.mapper.Property)19 AxelorException (com.axelor.exception.AxelorException)13 Model (com.axelor.db.Model)12 MetaField (com.axelor.meta.db.MetaField)10 ArrayList (java.util.ArrayList)10 MetaModel (com.axelor.meta.db.MetaModel)7 File (java.io.File)6 IOException (java.io.IOException)6 FileField (com.axelor.apps.base.db.FileField)5 Transactional (com.google.inject.persist.Transactional)5 TraceBackService (com.axelor.exception.service.TraceBackService)4 MetaFiles (com.axelor.meta.MetaFiles)4 MetaModelRepository (com.axelor.meta.db.repo.MetaModelRepository)4 List (java.util.List)4 Inflector (com.axelor.common.Inflector)3 MetaFile (com.axelor.meta.db.MetaFile)3 MetaJsonField (com.axelor.meta.db.MetaJsonField)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Strings (com.google.common.base.Strings)3