Search in sources :

Example 36 with Property

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

the class ValidatorService method validateObjectRequiredFields.

private void validateObjectRequiredFields(FileTab fileTab) throws ClassNotFoundException, IOException, AxelorException {
    if (CollectionUtils.isEmpty(fileTab.getFileFieldList())) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, String.format(I18n.get(IExceptionMessage.ADVANCED_IMPORT_NO_FIELDS), fileTab.getName()));
    }
    List<String> fieldList = new ArrayList<String>();
    for (FileField fileField : fileTab.getFileFieldList()) {
        if (fileField.getImportField() != null) {
            fieldList.add(fileField.getImportField().getName());
        } else {
            logService.addLog(IExceptionMessage.ADVANCED_IMPORT_LOG_2, fileField.getColumnTitle(), null);
        }
    }
    if (fileTab.getImportType() == FileFieldRepository.IMPORT_TYPE_FIND) {
        return;
    }
    if (fileTab.getMetaModel() != null) {
        Mapper mapper = advancedImportService.getMapper(fileTab.getMetaModel().getFullName());
        Model obj = null;
        try {
            obj = (Model) Class.forName(fileTab.getMetaModel().getFullName()).newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            TraceBackService.trace(e);
        }
        for (Property prop : mapper.getProperties()) {
            if (prop.isRequired() && !fieldList.contains(prop.getName())) {
                if (obj != null && mapper.get(obj, prop.getName()) != null) {
                    continue;
                }
                logService.addLog(IExceptionMessage.ADVANCED_IMPORT_LOG_3, prop.getName(), null);
            }
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Mapper(com.axelor.db.mapper.Mapper) ArrayList(java.util.ArrayList) Model(com.axelor.db.Model) FileField(com.axelor.apps.base.db.FileField) Property(com.axelor.db.mapper.Property)

Example 37 with Property

use of com.axelor.db.mapper.Property 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 38 with Property

use of com.axelor.db.mapper.Property 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 39 with Property

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

the class TemplateService method validTarget.

private void validTarget(String target, MetaModel metaModel) throws ClassNotFoundException {
    Iterator<String> iter = Splitter.on(".").split(target).iterator();
    Property p = Mapper.of(Class.forName(metaModel.getFullName())).getProperty(iter.next());
    while (iter.hasNext() && p != null) {
        p = Mapper.of(p.getTarget()).getProperty(iter.next());
    }
    if (p == null) {
        throw new IllegalArgumentException();
    }
}
Also used : Property(com.axelor.db.mapper.Property)

Example 40 with Property

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

Property (com.axelor.db.mapper.Property)40 Mapper (com.axelor.db.mapper.Mapper)21 Model (com.axelor.db.Model)12 ArrayList (java.util.ArrayList)11 AxelorException (com.axelor.exception.AxelorException)10 MetaModel (com.axelor.meta.db.MetaModel)8 List (java.util.List)8 Transactional (com.google.inject.persist.Transactional)7 MetaField (com.axelor.meta.db.MetaField)6 FileField (com.axelor.apps.base.db.FileField)5 FileTab (com.axelor.apps.base.db.FileTab)4 Inflector (com.axelor.common.Inflector)4 TraceBackRepository (com.axelor.exception.db.repo.TraceBackRepository)4 I18n (com.axelor.i18n.I18n)4 Inject (com.google.inject.Inject)4 Arrays (java.util.Arrays)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 AdvancedImport (com.axelor.apps.base.db.AdvancedImport)3 FileFieldRepository (com.axelor.apps.base.db.repo.FileFieldRepository)3