use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.
the class DataImportServiceImpl method checkAndWriteData.
private void checkAndWriteData(String dataCell, MetaModel model, FileField fileField, Mapper mapper, List<String> dataList) throws ClassNotFoundException {
Property parentProp = mapper.getProperty(fileField.getImportField().getName());
if (Strings.isNullOrEmpty(fileField.getSubImportField())) {
if (!Strings.isNullOrEmpty(parentProp.getSelection())) {
this.writeSelectionData(parentProp.getSelection(), dataCell, fileField.getForSelectUse(), dataList);
} else {
dataList.add(dataCell);
}
} else {
String[] subFields = fileField.getSubImportField().split("\\.");
this.checkSubFieldAndWriteData(subFields, 0, parentProp, dataCell, fileField.getForSelectUse(), dataList);
}
}
use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.
the class DataImportServiceImpl method createCSVBinding.
private List<CSVBind> createCSVBinding(String column, FileField fileField, Mapper mapper, List<CSVBind> allBindings) throws ClassNotFoundException {
Property prop = mapper.getProperty(fileField.getImportField().getName());
if (prop == null) {
return allBindings;
}
CSVBind dummyBind = null;
if (!fileField.getIsMatchWithFile()) {
dummyBind = this.createCSVBind(null, column, null, null, null, null);
allBindings.add(0, dummyBind);
}
if (Strings.isNullOrEmpty(fileField.getSubImportField())) {
String expression = this.setExpression(column, fileField, prop);
String adapter = null;
String dateFormat = fileField.getDateFormat();
if (Strings.isNullOrEmpty(expression) && !Strings.isNullOrEmpty(dateFormat)) {
adapter = this.getAdapter(prop.getJavaType().getSimpleName(), dateFormat.trim());
}
CSVBind bind = null;
if (!fileField.getIsMatchWithFile()) {
dummyBind.setExpression(expression);
dummyBind.setAdapter(adapter);
bind = this.createCSVBind(column, prop.getName(), null, null, null, null);
this.setImportIf(prop, bind, column);
} else {
bind = this.createCSVBind(column, prop.getName(), null, expression, adapter, null);
this.setImportIf(prop, bind, column);
}
allBindings.add(bind);
} else {
CSVBind parentBind = null;
boolean isSameParentExist = false;
if (parentBindMap.containsKey(prop.getName())) {
parentBind = parentBindMap.get(prop.getName());
isSameParentExist = true;
} else {
parentBind = this.createCSVBind(null, prop.getName(), null, null, null, true);
parentBind.setBindings(new ArrayList<>());
allBindings.add(parentBind);
parentBindMap.put(prop.getName(), parentBind);
}
fullFieldName = prop.getName();
String[] subFields = fileField.getSubImportField().split("\\.");
this.createCSVSubBinding(subFields, 0, column, prop, fileField, parentBind, dummyBind, isSameParentExist);
}
if (!Strings.isNullOrEmpty(fileField.getNoImportIf())) {
String importIf = this.convertExpression(fileField.getNoImportIf().trim(), fileField.getTargetType(), column);
ifList.add(importIf);
}
return allBindings;
}
use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.
the class PrintServiceImpl method saveMetaFileInModel.
protected void saveMetaFileInModel(Class<? extends Model> modelClass, Model objectModel, MetaFile metaFile, String metaFileFieldName) {
Mapper mapper = Mapper.of(modelClass);
Property p = mapper.getProperty(metaFileFieldName);
if (ObjectUtils.notEmpty(p)) {
p.set(objectModel, metaFile);
JPA.save(objectModel);
}
}
use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.
the class ActionServiceImpl method updateBean.
@SuppressWarnings("unchecked")
protected <T extends Model> Object updateBean(Object bean) {
final Class<T> klass = (Class<T>) JPA.model(this.modelName);
T updatedBean = Mapper.toBean(klass, this.context);
for (Property property : JPA.fields(klass)) {
Object oldValue = property.get(bean);
Object newValue = property.get(updatedBean);
if (!ObjectUtils.isEmpty(newValue) && property.valueChanged(updatedBean, oldValue)) {
property.set(bean, this.validate(property, newValue));
}
}
return bean;
}
use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.
the class AdvancedImportServiceImpl method checkSubFields.
private boolean checkSubFields(String[] subFields, int index, Property parentProp, String model) throws AxelorException, ClassNotFoundException {
boolean isValid = true;
if (index < subFields.length) {
if (parentProp.getTarget() != null) {
Mapper mapper = getMapper(parentProp.getTarget().getName());
Property childProp = mapper.getProperty(subFields[index]);
if (childProp == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, String.format(I18n.get(IExceptionMessage.ADVANCED_IMPORT_2), subFields[index], parentProp.getName(), model));
}
if (childProp.getTarget() != null) {
if (childProp.getType().name().equals("ONE_TO_MANY")) {
isValid = false;
return isValid;
}
if (index != subFields.length - 1) {
isValid = this.checkSubFields(subFields, index + 1, childProp, model);
} else {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, String.format(I18n.get(IExceptionMessage.ADVANCED_IMPORT_5), subFields[index], model));
}
}
}
}
return isValid;
}
Aggregations