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;
}
}
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;
}
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);
}
}
}
}
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);
}
}
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);
}
Aggregations