use of com.axelor.studio.db.Filter in project axelor-open-suite by axelor.
the class FilterController method updateTargetMetaField.
public void updateTargetMetaField(ActionRequest request, ActionResponse response) {
Filter filter = request.getContext().asType(Filter.class);
if (request.getContext().get("targetMetaField") != null) {
Integer id = (Integer) ((Map) request.getContext().get("targetMetaField")).get("id");
MetaField targetMetaField = Beans.get(MetaFieldRepository.class).find(Long.valueOf(id));
String targetTitle = targetMetaField.getLabel() != null && !targetMetaField.getLabel().isEmpty() ? targetMetaField.getLabel() : targetMetaField.getName();
response.setValue("targetField", filter.getTargetField() + "." + targetMetaField.getName());
response.setValue("targetTitle", filter.getTargetTitle() + "." + targetTitle);
response.setValue("targetType", targetMetaField.getRelationship() != null ? targetMetaField.getRelationship() : targetMetaField.getTypeName());
if (targetMetaField.getRelationship() != null) {
response.setValue("metaTargetFieldDomain", targetMetaField.getTypeName());
response.setValue("targetMetaField", null);
}
}
response.setValue("operator", null);
}
use of com.axelor.studio.db.Filter 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.studio.db.Filter in project axelor-open-suite by axelor.
the class FilterController method clearSelection.
public void clearSelection(ActionRequest request, ActionResponse response) {
Filter filter = request.getContext().asType(Filter.class);
if (filter.getMetaField() != null) {
response.setValue("targetField", filter.getMetaField().getName());
response.setValue("targetTitle", filter.getMetaField().getLabel() != null && !filter.getMetaField().getLabel().isEmpty() ? filter.getMetaField().getLabel() : filter.getMetaField().getName());
response.setValue("targetType", filter.getMetaField().getRelationship());
}
response.setValue("metaTargetFieldDomain", null);
response.setValue("targetMetaField", null);
response.setValue("operator", null);
}
use of com.axelor.studio.db.Filter in project axelor-open-suite by axelor.
the class FilterController method updateTargetType.
public void updateTargetType(ActionRequest request, ActionResponse response) throws AxelorException {
Filter filter = request.getContext().asType(Filter.class);
FilterSqlService filterSqlService = Beans.get(FilterSqlService.class);
if (filter.getTargetField() == null)
return;
StringBuilder parent = new StringBuilder("self");
String targetType = filterSqlService.getTargetType(filterSqlService.getTargetField(parent, filter, null, false));
response.setValue("targetType", targetType);
response.setValue("filterOperator", null);
}
use of com.axelor.studio.db.Filter in project axelor-open-suite by axelor.
the class ChartRecordViewServiceImpl method getFilters.
protected List<Filter> getFilters(ChartBuilder chartBuilder, Map<String, Object> params, boolean isForGroup) throws AxelorException {
String paramKey = isForGroup ? PARAM_GROUP : PARAM_AGG;
if (!isForGroup && isAggregationAllowed(chartBuilder)) {
params.remove(paramKey);
return new ArrayList<>();
}
String targetType = isForGroup ? chartBuilder.getGroupOnTargetType() : chartBuilder.getAggregateOnTargetType();
Object paramObj = params.get(paramKey);
boolean isNull = ObjectUtils.isEmpty(paramObj);
Filter filter = createFilter(chartBuilder, isNull, isForGroup);
if (!TARGET_DATE_TYPES.contains(targetType.toUpperCase()) || isNull) {
if (isNull) {
params.remove(paramKey);
} else {
Object value = getSelectionFieldValue(chartBuilder, paramObj, isForGroup);
if (value != null) {
params.put(paramKey, value);
}
}
return Arrays.asList(filter);
}
List<Filter> dateFilters = getFiltersForDateType(chartBuilder, params, filter, false);
return dateFilters;
}
Aggregations