use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.
the class ActionScriptBuilderService method getSourceModel.
private String getSourceModel(ActionBuilderLine line) {
MetaJsonField jsonField = line.getValueJson();
String sourceModel = null;
Object targetObject = null;
try {
if (jsonField != null && jsonField.getTargetModel() != null) {
if (line.getValue() != null && !line.getValue().contentEquals("$." + jsonField.getName())) {
targetObject = filterSqlService.parseJsonField(jsonField, line.getValue().replace("$.", ""), null, null);
} else {
sourceModel = jsonField.getTargetModel();
}
}
MetaField field = line.getValueField();
if (field != null && field.getTypeName() != null) {
if (line.getValue() != null && !line.getValue().contentEquals("$." + field.getName())) {
targetObject = filterSqlService.parseMetaField(field, line.getValue().replace("$.", ""), null, null, false);
} else {
sourceModel = field.getTypeName();
}
}
} catch (AxelorException e) {
TraceBackService.trace(e);
}
if (sourceModel == null && line.getValue() != null && line.getValue().equals("$")) {
sourceModel = getRootSourceModel(line);
}
if (sourceModel == null && line.getValue() != null && line.getValue().equals("$$")) {
sourceModel = getRootSourceModel(line);
}
if (targetObject != null) {
if (targetObject instanceof MetaJsonField) {
sourceModel = ((MetaJsonField) targetObject).getTargetModel();
} else if (targetObject instanceof MetaField) {
sourceModel = ((MetaField) targetObject).getTypeName();
}
}
return sourceModel;
}
use of com.axelor.meta.db.MetaField 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.meta.db.MetaField in project axelor-open-suite by axelor.
the class FileTabServiceImpl method updateFields.
@Override
public FileTab updateFields(FileTab fileTab) throws ClassNotFoundException {
MetaModel model = fileTab.getMetaModel();
if (model == null || CollectionUtils.isEmpty(fileTab.getFileFieldList())) {
return fileTab;
}
Beans.get(ValidatorService.class).sortFileFieldList(fileTab.getFileFieldList());
for (FileField fileField : fileTab.getFileFieldList()) {
MetaField importField = metaFieldRepo.all().filter("self.label = ?1 AND self.metaModel.id = ?2", fileField.getColumnTitle(), model.getId()).fetchOne();
if (importField != null) {
String relationship = importField.getRelationship();
if (!Strings.isNullOrEmpty(relationship) && relationship.equals("OneToMany")) {
continue;
}
fileField.setImportField(importField);
if (!Strings.isNullOrEmpty(relationship)) {
String subImportField = this.getSubImportField(importField);
fileField.setSubImportField(subImportField);
}
fileField = fileFieldService.fillType(fileField);
if (!Strings.isNullOrEmpty(relationship) && !fileField.getTargetType().equals("MetaFile")) {
fileField.setImportType(FileFieldRepository.IMPORT_TYPE_FIND);
} else {
if (!Strings.isNullOrEmpty(fileField.getTargetType()) && fileField.getTargetType().equals("MetaFile")) {
fileField.setImportType(FileFieldRepository.IMPORT_TYPE_NEW);
}
}
fileField.setFullName(fileFieldService.computeFullName(fileField));
} else {
fileField.setImportField(null);
fileField.setSubImportField(null);
}
}
return fileTab;
}
use of com.axelor.meta.db.MetaField 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.meta.db.MetaField 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