Search in sources :

Example 31 with Property

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

the class AdvancedImportServiceImpl method setImportFields.

private void setImportFields(Mapper mapper, FileField fileField, String importField, String subImportField) {
    Property prop = mapper.getProperty(importField);
    MetaField field = metaFieldRepo.all().filter("self.name = ?1 AND self.metaModel.name = ?2", prop.getName(), prop.getEntity().getSimpleName()).fetchOne();
    fileField.setImportField(field);
    fileField.setIsMatchWithFile(true);
    if (!Strings.isNullOrEmpty(subImportField)) {
        fileField.setSubImportField(subImportField);
    }
    fileField.setFullName(fileFieldService.computeFullName(fileField));
    fileField = fileFieldService.fillType(fileField);
    if (fileField.getTargetType().equals("MetaFile")) {
        fileField.setImportType(FileFieldRepository.IMPORT_TYPE_NEW);
    }
}
Also used : MetaField(com.axelor.meta.db.MetaField) Property(com.axelor.db.mapper.Property)

Example 32 with Property

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

the class AdvancedImportServiceImpl method resetSubPropertyValue.

@SuppressWarnings("unchecked")
private void resetSubPropertyValue(Class<? extends Model> klass, JsonContext jsonContext) throws ClassNotFoundException {
    for (Property prop : Mapper.of(klass).getProperties()) {
        if (prop.getTarget() == null || prop.isRequired()) {
            continue;
        }
        String simpleModelName = StringUtils.substringAfterLast(prop.getTarget().getName(), ".");
        String field = inflector.camelize(simpleModelName, true) + "Set";
        if (!jsonContext.containsKey(field)) {
            continue;
        }
        List<Object> recordList = (List<Object>) jsonContext.get(field);
        Class<? extends Model> modelKlass = (Class<? extends Model>) Class.forName(prop.getTarget().getName());
        this.resetPropertyValue(modelKlass, recordList);
    }
}
Also used : Model(com.axelor.db.Model) MetaModel(com.axelor.meta.db.MetaModel) ArrayList(java.util.ArrayList) List(java.util.List) Property(com.axelor.db.mapper.Property)

Example 33 with Property

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

the class ValidatorService method getAndValidateSubField.

public Property getAndValidateSubField(String[] subFields, int index, Integer rowNum, Property parentProp, String field, boolean isLog) throws IOException, ClassNotFoundException {
    Property subProperty = null;
    if (parentProp.getTarget() != null) {
        Mapper mapper = advancedImportService.getMapper(parentProp.getTarget().getName());
        Property childProp = mapper.getProperty(subFields[index]);
        if (childProp == null) {
            if (!isLog) {
                logService.addLog(IExceptionMessage.ADVANCED_IMPORT_LOG_7, field, rowNum);
            }
        }
        if (childProp != null && childProp.getTarget() != null) {
            if (index != subFields.length - 1) {
                subProperty = this.getAndValidateSubField(subFields, index + 1, rowNum, childProp, field, isLog);
            } else {
                subProperty = childProp;
                if (!isLog) {
                    logService.addLog(IExceptionMessage.ADVANCED_IMPORT_LOG_4, field, rowNum);
                }
            }
        } else {
            subProperty = childProp;
        }
    }
    return subProperty;
}
Also used : Mapper(com.axelor.db.mapper.Mapper) Property(com.axelor.db.mapper.Property)

Example 34 with Property

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

the class ValidatorService method validateFields.

private void validateFields(int line, boolean isConfig, FileTab fileTab) throws IOException, ClassNotFoundException {
    List<String> relationalFieldList = fileTab.getFileFieldList().stream().filter(field -> !Strings.isNullOrEmpty(field.getSubImportField())).map(field -> field.getImportField().getName() + "." + field.getSubImportField()).collect(Collectors.toList());
    for (FileField fileField : fileTab.getFileFieldList()) {
        MetaField importField = fileField.getImportField();
        if (importField != null && Strings.isNullOrEmpty(fileField.getSubImportField())) {
            if (importField.getRelationship() != null) {
                logService.addLog(IExceptionMessage.ADVANCED_IMPORT_LOG_4, importField.getName(), line);
            }
            this.validateImportRequiredField(line, Class.forName(fileTab.getMetaModel().getFullName()), importField.getName(), fileField, null);
            this.validateDateField(line, fileField);
        } else if (!Strings.isNullOrEmpty(fileField.getSubImportField())) {
            Mapper mapper = advancedImportService.getMapper(importField.getMetaModel().getFullName());
            Property parentProp = mapper.getProperty(importField.getName());
            if (parentProp == null) {
                return;
            }
            Property subProperty = this.getAndValidateSubField(line, parentProp, fileField, false);
            if (subProperty != null) {
                this.validateImportRequiredField(line, subProperty.getEntity(), subProperty.getName(), fileField, relationalFieldList);
                this.validateDateField(line, fileField);
            }
        }
    }
}
Also used : MetaJsonFieldRepository(com.axelor.meta.db.repo.MetaJsonFieldRepository) Arrays(java.util.Arrays) Inject(com.google.inject.Inject) ZonedDateTime(java.time.ZonedDateTime) LocalDateTime(java.time.LocalDateTime) Property(com.axelor.db.mapper.Property) HashMap(java.util.HashMap) Mapper(com.axelor.db.mapper.Mapper) StringUtils(org.apache.commons.lang3.StringUtils) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) FileField(com.axelor.apps.base.db.FileField) Strings(com.google.common.base.Strings) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) Files(com.google.common.io.Files) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) LocalTime(java.time.LocalTime) I18n(com.axelor.i18n.I18n) BigInteger(java.math.BigInteger) Inflector(com.axelor.common.Inflector) MetaJsonField(com.axelor.meta.db.MetaJsonField) DataReaderFactory(com.axelor.apps.tool.reader.DataReaderFactory) MetaFiles(com.axelor.meta.MetaFiles) Model(com.axelor.db.Model) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) MetaField(com.axelor.meta.db.MetaField) BufferedWriter(java.io.BufferedWriter) TraceBackService(com.axelor.exception.service.TraceBackService) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Collectors(java.util.stream.Collectors) FileTabRepository(com.axelor.apps.base.db.repo.FileTabRepository) File(java.io.File) DataReaderService(com.axelor.apps.tool.reader.DataReaderService) DateTimeParseException(java.time.format.DateTimeParseException) List(java.util.List) FileFieldRepository(com.axelor.apps.base.db.repo.FileFieldRepository) IExceptionMessage(com.axelor.apps.base.exceptions.IExceptionMessage) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) FileTab(com.axelor.apps.base.db.FileTab) AdvancedImport(com.axelor.apps.base.db.AdvancedImport) Mapper(com.axelor.db.mapper.Mapper) MetaField(com.axelor.meta.db.MetaField) FileField(com.axelor.apps.base.db.FileField) Property(com.axelor.db.mapper.Property)

Example 35 with Property

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

the class ValidatorService method validateDataRequiredField.

private boolean validateDataRequiredField(String[] row, int cell, int line, Class<?> model, String fieldName, FileField fileField) throws IOException, ClassNotFoundException {
    boolean flag = false;
    String field = getField(fileField);
    int importType = fileField.getImportType();
    Mapper mapper = advancedImportService.getMapper(model.getName());
    Property prop = mapper.getProperty(fieldName);
    if (prop != null) {
        if (prop.isRequired() && Strings.isNullOrEmpty(row[cell]) && importType != FileFieldRepository.IMPORT_TYPE_FIND) {
            logService.addLog(IExceptionMessage.ADVANCED_IMPORT_LOG_8, field, line);
        } else if (importType == FileFieldRepository.IMPORT_TYPE_IGNORE_EMPTY) {
            flag = true;
            return flag;
        }
    }
    return flag;
}
Also used : Mapper(com.axelor.db.mapper.Mapper) 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