use of com.axelor.db.mapper.Property 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);
}
}
}
}
use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.
the class DataImportServiceImpl method checkSubFieldAndWriteData.
private void checkSubFieldAndWriteData(String[] subFields, int index, Property parentProp, String dataCell, int forSelectUse, List<String> dataList) throws ClassNotFoundException {
if (index < subFields.length) {
if (parentProp.getTarget() != null) {
Mapper mapper = advancedImportService.getMapper(parentProp.getTarget().getName());
Property childProp = mapper.getProperty(subFields[index]);
if (childProp != null && childProp.getTarget() != null) {
this.checkSubFieldAndWriteData(subFields, index + 1, childProp, dataCell, forSelectUse, dataList);
} else {
if (!Strings.isNullOrEmpty(childProp.getSelection())) {
this.writeSelectionData(childProp.getSelection(), dataCell, forSelectUse, dataList);
} else {
dataList.add(dataCell);
}
}
}
}
}
use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.
the class DataImportServiceImpl method createCSVSubBinding.
private void createCSVSubBinding(String[] subFields, int index, String column, Property parentProp, FileField fileField, CSVBind parentBind, CSVBind dummyBind, boolean isSameParentExist) throws ClassNotFoundException {
if (index < subFields.length) {
if (parentProp.getTarget() == null) {
return;
}
int importType = fileField.getImportType();
String relationship = fileField.getRelationship();
fullFieldName += "." + subFields[index];
Mapper mapper = advancedImportService.getMapper(parentProp.getTarget().getName());
Property childProp = mapper.getProperty(subFields[index]);
if (childProp != null && childProp.getTarget() != null) {
CSVBind subBind = null;
if (subBindMap.containsKey(fullFieldName)) {
subBind = subBindMap.get(fullFieldName);
} else if (importType != FileFieldRepository.IMPORT_TYPE_FIND) {
subBind = this.createCSVBind(null, childProp.getName(), null, null, null, true);
subBind.setBindings(new ArrayList<>());
parentBind.getBindings().add(subBind);
subBindMap.put(fullFieldName, subBind);
}
if (importType == FileFieldRepository.IMPORT_TYPE_FIND_NEW && subBind != null) {
String fieldName = (isSameParentExist ? fullFieldName.replaceFirst(fileField.getImportField().getName() + ".", "") : fullFieldName) + "." + subFields[index + 1];
this.setSearch(column, fieldName, fileField, parentBind, isSameParentExist);
}
this.createCSVSubBinding(subFields, index + 1, column, childProp, fileField, isSameParentExist && importType == FileFieldRepository.IMPORT_TYPE_FIND ? parentBind : subBind, dummyBind, isSameParentExist);
} else {
String expression = this.setExpression(column, fileField, childProp);
String adapter = null;
String dateFormat = fileField.getDateFormat();
if (Strings.isNullOrEmpty(expression) && !Strings.isNullOrEmpty(dateFormat)) {
adapter = this.getAdapter(childProp.getJavaType().getSimpleName(), dateFormat.trim());
}
if (!fileField.getIsMatchWithFile()) {
this.createBindForNotMatchWithFile(column, importType, dummyBind, expression, adapter, parentBind, childProp);
} else {
this.createBindForMatchWithFile(column, importType, expression, adapter, relationship, parentBind, childProp);
}
String fieldName = isSameParentExist && importType == FileFieldRepository.IMPORT_TYPE_FIND ? fullFieldName.replaceFirst(fileField.getImportField().getName() + ".", "") : childProp.getName();
this.setSearch(column, fieldName, fileField, parentBind, isSameParentExist);
if (importType != FileFieldRepository.IMPORT_TYPE_FIND) {
parentBind.setUpdate(false);
}
}
}
}
use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.
the class TemplateService method validTarget.
private void validTarget(String target, MetaModel metaModel) throws ClassNotFoundException {
Iterator<String> iter = Splitter.on(".").split(target).iterator();
Property p = Mapper.of(Class.forName(metaModel.getFullName())).getProperty(iter.next());
while (iter.hasNext() && p != null) {
p = Mapper.of(p.getTarget()).getProperty(iter.next());
}
if (p == null) {
throw new IllegalArgumentException();
}
}
use of com.axelor.db.mapper.Property in project axelor-open-suite by axelor.
the class ChartRecordViewServiceImpl method getSelectionFieldValue.
protected Object getSelectionFieldValue(ChartBuilder chartBuilder, Object titleParam, Boolean isForGroup) throws AxelorException {
Object value = null;
String selection = null;
Class<?> targetType = String.class;
Boolean isJson = chartBuilder.getIsJson() || (isForGroup ? chartBuilder.getIsJsonGroupOn() : chartBuilder.getIsJsonAggregateOn());
MetaField target = chartBuilder.getGroupOn();
MetaJsonField jsonField = chartBuilder.getGroupOnJson();
if (!isForGroup) {
target = chartBuilder.getAggregateOn();
jsonField = chartBuilder.getAggregateOnJson();
}
if (isJson && ObjectUtils.notEmpty(jsonField.getSelection()) && (Integer.class.getSimpleName().toLowerCase().equals(jsonField.getType()) || String.class.getSimpleName().toLowerCase().equals(jsonField.getType()))) {
selection = jsonField.getSelection();
if (Integer.class.getSimpleName().toLowerCase().equals(jsonField.getType())) {
targetType = Integer.class;
}
} else {
try {
Mapper mapper = Mapper.of(Class.forName(chartBuilder.getModel()));
Property p = mapper.getProperty(target.getName());
if (ObjectUtils.notEmpty(p.getSelection())) {
selection = p.getSelection();
targetType = p.getJavaType();
}
} catch (ClassNotFoundException e) {
throw new AxelorException(e, TraceBackRepository.CATEGORY_INCONSISTENCY);
}
}
if (ObjectUtils.isEmpty(selection)) {
return value;
}
List<Option> selectionList = MetaStore.getSelectionList(selection);
for (Option option : selectionList) {
if (option.getLocalizedTitle().equals(titleParam)) {
return ConvertUtils.convert(option.getValue(), targetType);
}
}
return value;
}
Aggregations