Search in sources :

Example 41 with MetaField

use of com.axelor.meta.db.MetaField 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 42 with MetaField

use of com.axelor.meta.db.MetaField 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 43 with MetaField

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

the class FileTabServiceImpl method updateFields.

@Override
public FileTab updateFields(FileTab fileTab) throws ClassNotFoundException {
    MetaModel model = fileTab.getMetaModel();
    if (model == null || CollectionUtils.isEmpty(fileTab.getFileFieldList())) {
        return fileTab;
    }
    Beans.get(ValidatorService.class).sortFileFieldList(fileTab.getFileFieldList());
    for (FileField fileField : fileTab.getFileFieldList()) {
        MetaField importField = metaFieldRepo.all().filter("self.label = ?1 AND self.metaModel.id = ?2", fileField.getColumnTitle(), model.getId()).fetchOne();
        if (importField != null) {
            String relationship = importField.getRelationship();
            if (!Strings.isNullOrEmpty(relationship) && relationship.equals("OneToMany")) {
                continue;
            }
            fileField.setImportField(importField);
            if (!Strings.isNullOrEmpty(relationship)) {
                String subImportField = this.getSubImportField(importField);
                fileField.setSubImportField(subImportField);
            }
            fileField = fileFieldService.fillType(fileField);
            if (!Strings.isNullOrEmpty(relationship) && !fileField.getTargetType().equals("MetaFile")) {
                fileField.setImportType(FileFieldRepository.IMPORT_TYPE_FIND);
            } else {
                if (!Strings.isNullOrEmpty(fileField.getTargetType()) && fileField.getTargetType().equals("MetaFile")) {
                    fileField.setImportType(FileFieldRepository.IMPORT_TYPE_NEW);
                }
            }
            fileField.setFullName(fileFieldService.computeFullName(fileField));
        } else {
            fileField.setImportField(null);
            fileField.setSubImportField(null);
        }
    }
    return fileTab;
}
Also used : MetaModel(com.axelor.meta.db.MetaModel) MetaField(com.axelor.meta.db.MetaField) FileField(com.axelor.apps.base.db.FileField)

Example 44 with MetaField

use of com.axelor.meta.db.MetaField 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 45 with MetaField

use of com.axelor.meta.db.MetaField 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

MetaField (com.axelor.meta.db.MetaField)45 MetaJsonField (com.axelor.meta.db.MetaJsonField)15 MetaModel (com.axelor.meta.db.MetaModel)10 Mapper (com.axelor.db.mapper.Mapper)9 AxelorException (com.axelor.exception.AxelorException)8 ArrayList (java.util.ArrayList)6 Property (com.axelor.db.mapper.Property)5 Filter (com.axelor.studio.db.Filter)4 Model (com.axelor.db.Model)3 MetaFieldRepository (com.axelor.meta.db.repo.MetaFieldRepository)3 MetaModelRepository (com.axelor.meta.db.repo.MetaModelRepository)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Company (com.axelor.apps.base.db.Company)2 FileField (com.axelor.apps.base.db.FileField)2 ProductCompany (com.axelor.apps.base.db.ProductCompany)2 Context (com.axelor.rpc.Context)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Transactional (com.google.inject.persist.Transactional)2 BigInteger (java.math.BigInteger)2