use of com.axelor.apps.base.db.FileField in project axelor-open-suite by axelor.
the class DataImportServiceImpl method createData.
private String[] createData(String[] dataRow, FileTab fileTab, boolean isConfig, Mapper mapper) throws ClassNotFoundException {
Map<String, Object> map = isConfig ? fieldMap : titleMap;
List<String> dataList = new ArrayList<String>();
for (int fieldIndex = 0; fieldIndex < fileTab.getFileFieldList().size(); fieldIndex++) {
FileField fileField = fileTab.getFileFieldList().get(fieldIndex);
String key = null;
if (isConfig) {
key = validatorService.getField(fileField);
} else {
key = fileField.getColumnTitle();
}
if (!fileField.getIsMatchWithFile() || fileField.getImportType() == FileFieldRepository.IMPORT_TYPE_IGNORE_EMPTY) {
continue;
}
int cell = 0;
if (map.containsKey(key)) {
cell = (int) map.get(key);
}
cell = (!isConfig && !fileTab.getAdvancedImport().getIsHeader()) ? fieldIndex : cell;
if (Strings.isNullOrEmpty(dataRow[cell])) {
dataList.add(!Strings.isNullOrEmpty(fileField.getDefaultIfNotFound()) ? fileField.getDefaultIfNotFound().trim() : "");
continue;
}
String dataCell = dataRow[cell].trim();
this.checkAndWriteData(dataCell, fileTab.getMetaModel(), fileField, mapper, dataList);
}
return dataList.stream().toArray(String[]::new);
}
use of com.axelor.apps.base.db.FileField in project axelor-open-suite by axelor.
the class DataImportServiceImpl method createHeader.
private String[] createHeader(String[] row, FileTab fileTab, boolean isConfig, Mapper mapper) throws ClassNotFoundException {
Map<String, Object> map = isConfig ? fieldMap : titleMap;
int rowCount = row.length;
for (int cell = 0; cell < rowCount; cell++) {
if (Strings.isNullOrEmpty(row[cell])) {
continue;
}
String value = row[cell].trim();
map.put(isConfig ? value.contains("(") ? value.split("\\(")[0] : value : value, cell);
}
validatorService.sortFileFieldList(fileTab.getFileFieldList());
List<String> headers = new ArrayList<>();
List<CSVBind> allBindings = new ArrayList<CSVBind>();
int cnt = 0;
Map<String, Object> searchMap = new HashMap<String, Object>();
for (FileField fileField : fileTab.getFileFieldList()) {
if (fileField.getImportType() == FileFieldRepository.IMPORT_TYPE_IGNORE_EMPTY) {
continue;
}
String key = (isConfig) ? validatorService.getField(fileField) : fileField.getColumnTitle();
String column = ("cell" + (cnt + 1));
if (!CollectionUtils.isEmpty(fileTab.getSearchFieldSet()) && fileTab.getSearchFieldSet().contains(fileField) && fileTab.getImportType() != FileFieldRepository.IMPORT_TYPE_NEW) {
searchMap.put(validatorService.getField(fileField), column);
}
if ((map.containsKey(key) || (!isConfig && !fileTab.getAdvancedImport().getIsHeader())) && fileField.getIsMatchWithFile()) {
headers.add(column);
}
allBindings = this.createCSVBinding(column, fileField, mapper, allBindings);
cnt++;
}
CSVBind fileTabBind = new CSVBind();
fileTabBind.setField("fileTabId");
fileTabBind.setExpression(fileTab.getId().toString());
allBindings.add(fileTabBind);
for (Entry<String, Object> entry : searchMap.entrySet()) {
String field = entry.getKey(), cond1 = "", cond2 = "", condAnd = "";
if (field.contains(".")) {
int index = field.lastIndexOf(46);
cond1 = " (:" + entry.getValue() + " IS NOT NULL AND";
cond2 = " OR self." + field.substring(0, index) + " IS NULL)";
}
if (!Strings.isNullOrEmpty(csvInput.getSearch())) {
condAnd = csvInput.getSearch() + " AND";
}
csvInput.setSearch(condAnd + cond1 + " self." + field + " = :" + entry.getValue() + cond2);
}
csvInput.setBindings(allBindings);
return headers.stream().toArray(String[]::new);
}
Aggregations