use of com.axelor.db.mapper.Mapper in project axelor-open-suite by axelor.
the class AdvancedImportServiceImpl method applyWithConfig.
private void applyWithConfig(String[] row, int line, List<FileField> fileFieldList, List<Integer> ignoreFields, FileTab fileTab, Boolean isTabConfig, int tabConfigRowCount) throws AxelorException, ClassNotFoundException {
Mapper mapper = getMapper(fileTab.getMetaModel().getFullName());
FileField fileField = null;
int index = 0;
for (int i = 0; i < row.length; i++) {
if (Strings.isNullOrEmpty(row[i])) {
continue;
}
index = line;
String value = row[i].trim();
if (line == 1) {
this.readFields(value, i, fileFieldList, ignoreFields, mapper, fileTab);
continue;
}
if (ignoreFields.contains(i)) {
continue;
}
if (fileFieldList.size() < i) {
break;
} else if (!isTabConfig && fileFieldList.size() <= i) {
break;
}
if (row[0] == null) {
fileField = fileFieldList.get(i - 1);
} else if (!isTabConfig && row[0] != null) {
fileField = fileFieldList.get(i);
}
if (isTabWithoutConfig) {
fileField = fileFieldList.get(i);
}
if (line == 2) {
fileField.setColumnTitle(value);
continue;
}
if (isTabConfig && i > 0 && row[0] != null && line >= 3 && line <= 11) {
fileField = fileFieldList.get(i - 1);
this.setFileFieldConfig(row, i, fileField);
}
if (isTabConfig && i > 0 && row[0] == null) {
line += -(tabConfigRowCount + 2);
this.setSampleLines(line, value, fileField);
line = index;
} else if (!isTabConfig) {
line += -2;
this.setSampleLines(line, value, fileField);
line = index;
}
}
}
use of com.axelor.db.mapper.Mapper 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;
}
use of com.axelor.db.mapper.Mapper 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);
}
}
}
}
use of com.axelor.db.mapper.Mapper 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;
}
use of com.axelor.db.mapper.Mapper in project axelor-open-suite by axelor.
the class ValidatorService method validateObjectRequiredFields.
private void validateObjectRequiredFields(FileTab fileTab) throws ClassNotFoundException, IOException, AxelorException {
if (CollectionUtils.isEmpty(fileTab.getFileFieldList())) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, String.format(I18n.get(IExceptionMessage.ADVANCED_IMPORT_NO_FIELDS), fileTab.getName()));
}
List<String> fieldList = new ArrayList<String>();
for (FileField fileField : fileTab.getFileFieldList()) {
if (fileField.getImportField() != null) {
fieldList.add(fileField.getImportField().getName());
} else {
logService.addLog(IExceptionMessage.ADVANCED_IMPORT_LOG_2, fileField.getColumnTitle(), null);
}
}
if (fileTab.getImportType() == FileFieldRepository.IMPORT_TYPE_FIND) {
return;
}
if (fileTab.getMetaModel() != null) {
Mapper mapper = advancedImportService.getMapper(fileTab.getMetaModel().getFullName());
Model obj = null;
try {
obj = (Model) Class.forName(fileTab.getMetaModel().getFullName()).newInstance();
} catch (InstantiationException | IllegalAccessException e) {
TraceBackService.trace(e);
}
for (Property prop : mapper.getProperties()) {
if (prop.isRequired() && !fieldList.contains(prop.getName())) {
if (obj != null && mapper.get(obj, prop.getName()) != null) {
continue;
}
logService.addLog(IExceptionMessage.ADVANCED_IMPORT_LOG_3, prop.getName(), null);
}
}
}
}
Aggregations