Search in sources :

Example 1 with FileField

use of com.axelor.apps.base.db.FileField in project axelor-open-suite by axelor.

the class AdvancedImportServiceImpl method applyWithoutConfig.

@Transactional
public void applyWithoutConfig(String[] row, int line, List<FileField> fileFieldList, FileTab fileTab, boolean isHeader) throws AxelorException {
    int index = 0;
    for (int i = 0; i < row.length; i++) {
        if (Strings.isNullOrEmpty(row[i])) {
            continue;
        }
        index = line;
        String value = row[i].trim();
        FileField fileField = null;
        if (line == 0) {
            fileField = new FileField();
            fileField.setIsMatchWithFile(true);
            fileFieldList.add(fileField);
            fileField.setFileTab(fileTab);
            if (isHeader) {
                fileField.setColumnTitle(value);
            } else {
                fileField.setFirstLine(value);
            }
            fileField.setSequence(i);
            fileField.setFullName(fileFieldService.computeFullName(fileField));
            fileField = fileFieldRepository.save(fileField);
            continue;
        }
        if (fileFieldList.size() <= i) {
            break;
        }
        if (!isHeader) {
            line += 1;
        }
        if (fileField == null) {
            fileField = fileFieldList.get(i);
        }
        setSampleLines(line, value, fileField);
        line = index;
    }
}
Also used : FileField(com.axelor.apps.base.db.FileField) Transactional(com.google.inject.persist.Transactional)

Example 2 with FileField

use of com.axelor.apps.base.db.FileField in project axelor-open-suite by axelor.

the class AdvancedImportServiceImpl method setSearchField.

protected FileTab setSearchField(FileTab fileTab, List<String> searchFieldList, List<FileField> fileFieldList) {
    Set<FileField> searchFieldSet = new HashSet<FileField>();
    for (String searchField : searchFieldList) {
        for (FileField fileField : fileFieldList) {
            if (fileField.getFullName().endsWith("- " + searchField)) {
                searchFieldSet.add(fileField);
            }
        }
    }
    fileTab.setSearchFieldSet(searchFieldSet);
    return fileTab;
}
Also used : FileField(com.axelor.apps.base.db.FileField) HashSet(java.util.HashSet)

Example 3 with FileField

use of com.axelor.apps.base.db.FileField in project axelor-open-suite by axelor.

the class ValidatorService method validateData.

private void validateData(String[] dataRow, int line, boolean isConfig, FileTab fileTab) throws IOException, ClassNotFoundException {
    Map<String, Object> map = isConfig ? fieldMap : titleMap;
    for (int fieldIndex = 0; fieldIndex < fileTab.getFileFieldList().size(); fieldIndex++) {
        FileField fileField = fileTab.getFileFieldList().get(fieldIndex);
        if (!fileField.getIsMatchWithFile() || !Strings.isNullOrEmpty(fileField.getExpression())) {
            continue;
        }
        Mapper mapper = null;
        Property property = null;
        String key = null;
        if (isConfig) {
            key = this.getField(fileField);
        } else {
            key = fileField.getColumnTitle();
        }
        int cellIndex = 0;
        if (map.containsKey(key)) {
            cellIndex = (int) map.get(key);
        }
        cellIndex = (!isConfig && !fileTab.getAdvancedImport().getIsHeader()) ? fieldIndex : cellIndex;
        if (fileField.getImportField() != null) {
            mapper = advancedImportService.getMapper(fileField.getImportField().getMetaModel().getFullName());
            property = mapper.getProperty(fileField.getImportField().getName());
        }
        if (property != null && Strings.isNullOrEmpty(fileField.getSubImportField())) {
            if (this.validateDataRequiredField(dataRow, cellIndex, line, Class.forName(fileTab.getMetaModel().getFullName()), property.getName(), fileField)) {
                continue;
            }
            if (!Strings.isNullOrEmpty(property.getSelection()) && fileField.getForSelectUse() != FileFieldRepository.SELECT_USE_VALUES) {
                continue;
            }
            this.validateDataType(dataRow, cellIndex, line, property.getJavaType().getSimpleName(), fileField);
        } else if (!Strings.isNullOrEmpty(fileField.getSubImportField())) {
            Property subProperty = this.getAndValidateSubField(line, property, fileField, true);
            if (subProperty != null) {
                if (this.validateDataRequiredField(dataRow, cellIndex, line, subProperty.getEntity(), subProperty.getName(), fileField)) {
                    continue;
                }
                if (!Strings.isNullOrEmpty(subProperty.getSelection()) && fileField.getForSelectUse() != FileFieldRepository.SELECT_USE_VALUES) {
                    continue;
                }
                this.validateDataType(dataRow, cellIndex, line, subProperty.getJavaType().getSimpleName(), fileField);
            }
        }
    }
}
Also used : Mapper(com.axelor.db.mapper.Mapper) FileField(com.axelor.apps.base.db.FileField) Property(com.axelor.db.mapper.Property)

Example 4 with FileField

use of com.axelor.apps.base.db.FileField in project axelor-open-suite by axelor.

the class FileFieldController method fillType.

public void fillType(ActionRequest request, ActionResponse response) {
    try {
        FileField fileField = request.getContext().asType(FileField.class);
        fileField = Beans.get(FileFieldService.class).fillType(fileField);
        response.setValues(fileField);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : FileField(com.axelor.apps.base.db.FileField)

Example 5 with FileField

use of com.axelor.apps.base.db.FileField in project axelor-open-suite by axelor.

the class AdvancedImportServiceImpl method readFields.

@Transactional
public void readFields(String value, int index, List<FileField> fileFieldList, List<Integer> ignoreFields, Mapper mapper, FileTab fileTab) throws AxelorException, ClassNotFoundException {
    FileField fileField = new FileField();
    fileField.setSequence(index);
    if (Strings.isNullOrEmpty(value)) {
        return;
    }
    String importType = StringUtils.substringBetween(value, "(", ")");
    if (!Strings.isNullOrEmpty(importType) && (importType.equalsIgnoreCase(forSelectUseValues) || importType.equalsIgnoreCase(forSelectUseTitles) || importType.equalsIgnoreCase(forSelectUseTranslatedTitles))) {
        fileField.setForSelectUse(this.getForStatusSelect(importType));
    } else {
        fileField.setImportType(this.getImportType(value, importType));
    }
    value = value.split("\\(")[0];
    String importField = null;
    String subImportField = null;
    if (value.contains(".")) {
        importField = value.substring(0, value.indexOf("."));
        subImportField = value.substring(value.indexOf(".") + 1, value.length());
    } else {
        importField = value;
    }
    boolean isValid = this.checkFields(mapper, importField, subImportField);
    if (isValid) {
        this.setImportFields(mapper, fileField, importField, subImportField);
    } else {
        ignoreFields.add(index);
    }
    fileFieldList.add(fileField);
    fileField = fileFieldRepository.save(fileField);
    fileTab.addFileFieldListItem(fileField);
}
Also used : FileField(com.axelor.apps.base.db.FileField) Transactional(com.google.inject.persist.Transactional)

Aggregations

FileField (com.axelor.apps.base.db.FileField)12 ArrayList (java.util.ArrayList)5 Mapper (com.axelor.db.mapper.Mapper)4 Transactional (com.google.inject.persist.Transactional)4 Property (com.axelor.db.mapper.Property)3 FileTab (com.axelor.apps.base.db.FileTab)2 Model (com.axelor.db.Model)2 AxelorException (com.axelor.exception.AxelorException)2 MetaField (com.axelor.meta.db.MetaField)2 HashMap (java.util.HashMap)2 AdvancedImport (com.axelor.apps.base.db.AdvancedImport)1 FileFieldRepository (com.axelor.apps.base.db.repo.FileFieldRepository)1 FileTabRepository (com.axelor.apps.base.db.repo.FileTabRepository)1 IExceptionMessage (com.axelor.apps.base.exceptions.IExceptionMessage)1 DataReaderFactory (com.axelor.apps.tool.reader.DataReaderFactory)1 DataReaderService (com.axelor.apps.tool.reader.DataReaderService)1 Inflector (com.axelor.common.Inflector)1 CSVBind (com.axelor.data.csv.CSVBind)1 TraceBackRepository (com.axelor.exception.db.repo.TraceBackRepository)1 TraceBackService (com.axelor.exception.service.TraceBackService)1