use of com.axelor.db.mapper.Property 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);
}
}
use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.
the class AdvancedImportServiceImpl method resetSubPropertyValue.
@SuppressWarnings("unchecked")
private void resetSubPropertyValue(Class<? extends Model> klass, JsonContext jsonContext) throws ClassNotFoundException {
for (Property prop : Mapper.of(klass).getProperties()) {
if (prop.getTarget() == null || prop.isRequired()) {
continue;
}
String simpleModelName = StringUtils.substringAfterLast(prop.getTarget().getName(), ".");
String field = inflector.camelize(simpleModelName, true) + "Set";
if (!jsonContext.containsKey(field)) {
continue;
}
List<Object> recordList = (List<Object>) jsonContext.get(field);
Class<? extends Model> modelKlass = (Class<? extends Model>) Class.forName(prop.getTarget().getName());
this.resetPropertyValue(modelKlass, recordList);
}
}
use of com.axelor.db.mapper.Property 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.Property 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.Property 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;
}
Aggregations