use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.
the class FilterJpqlService method getJpqlFilters.
public String getJpqlFilters(List<Filter> filterList) {
String filters = null;
if (filterList == null) {
return filters;
}
for (Filter filter : filterList) {
MetaField field = filter.getMetaField();
if (filter.getValue() != null) {
String value = filter.getValue();
value = value.replaceAll("\"", "");
value = value.replaceAll("'", "");
if (filter.getOperator().contains("like") && !value.contains("%")) {
value = "%" + value + "%";
}
filter.setValue("'" + value + "'");
}
String relationship = field.getRelationship();
String fieldName = relationship != null ? filter.getTargetField() : filter.getMetaField().getName();
fieldName = "self." + fieldName;
String fieldValue;
if (filter.getTargetType().equals("String")) {
fieldName = "LOWER(" + fieldName + ")";
fieldValue = "LOWER(" + filter.getValue() + ")";
} else {
fieldValue = filter.getValue();
}
String condition = filterCommonService.getCondition(fieldName, filter.getOperator(), fieldValue);
if (filters == null) {
filters = condition;
} else {
String opt = filter.getLogicOp() != null && filter.getLogicOp() == 0 ? " AND " : " OR ";
filters = filters + opt + condition;
}
}
log.debug("JPQL filter: {}", filters);
return filters;
}
use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.
the class FilterSqlService method getTargetType.
public String getTargetType(Object target) {
String targetType = null;
if (target instanceof MetaField) {
MetaField metaField = (MetaField) target;
String relationship = metaField.getRelationship();
if (relationship != null) {
targetType = relationship;
} else {
targetType = metaField.getTypeName();
}
} else if (target instanceof MetaJsonField) {
targetType = ((MetaJsonField) target).getType();
log.debug("Target json type:", targetType);
targetType = Inflector.getInstance().camelize(targetType);
}
log.debug("Target type: {}, field: {}", targetType, target);
return targetType;
}
use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.
the class FilterSqlService method parseMetaField.
public Object parseMetaField(MetaField field, String target, List<String> joins, StringBuilder parent, boolean checkJson) throws AxelorException {
if (target == null || !target.contains(".")) {
if (field.getRelationship() != null && joins != null) {
target = getDefaultTarget(field.getName(), field.getTypeName())[0];
} else {
return field;
}
}
target = target.substring(target.indexOf(".") + 1);
String targetName = target.contains(".") ? target.substring(0, target.indexOf(".")) : target;
if (field.getRelationship() == null) {
return field;
}
MetaModel model = metaModelRepo.findByName(field.getTypeName());
MetaField subMeta = findMetaField(targetName, model.getFullName());
if (subMeta != null) {
if (joins != null) {
addJoin(field, joins, parent);
}
return parseMetaField(subMeta, target, joins, parent, checkJson);
} else if (checkJson) {
MetaJsonField subJson = findJsonField(targetName, model.getName());
if (subJson != null) {
if (joins != null) {
addJoin(field, joins, parent);
}
return parseJsonField(subJson, target, joins, parent);
}
}
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, "No sub field found field: %s model: %s ", targetName, model.getFullName());
}
use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.
the class AppLoaderExportServiceImpl method getMetaFieldBinding.
private List<XMLBind> getMetaFieldBinding(Mapper modelMapper, AppDataLoader dataLoader, boolean relationalInput) {
List<XMLBind> fieldBindings = new ArrayList<XMLBind>();
for (MetaField field : dataLoader.getMetaFieldSet()) {
fieldBindings.add(createDummyFieldBinding(field.getName()));
if (relationalInput && field.getRelationship() == null) {
continue;
}
XMLBind fieldBind = new XMLBind();
fieldBind.setField(field.getName());
fieldBind.setNode(field.getName());
if (field.getRelationship() != null) {
addRelationalMetaFieldBind(modelMapper, field, fieldBind);
} else if (field.getTypeName().equals("Boolean")) {
fieldBind.setAdapter("Boolean");
}
fieldBindings.add(fieldBind);
}
return fieldBindings;
}
use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.
the class AppLoaderExportServiceImpl method getMetaSearchFields.
protected String getMetaSearchFields(Mapper modelMapper, AppDataLoader appDataLoader) throws ClassNotFoundException {
StringBuilder fields = new StringBuilder();
for (MetaField field : appDataLoader.getSearchMetaFieldSet()) {
if (fields.length() != 0) {
fields.append(" AND ");
}
if (field.getRelationship() != null) {
Property property = modelMapper.getProperty(field.getName());
fields.append("self." + field.getName() + "." + property.getTargetName() + " = :_" + field.getName());
} else {
fields.append("self." + field.getName() + " = :_" + field.getName());
}
}
return fields.toString();
}
Aggregations