Search in sources :

Example 6 with Filter

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);
}
Also used : Filter(com.axelor.studio.db.Filter) MetaField(com.axelor.meta.db.MetaField) MetaFieldRepository(com.axelor.meta.db.repo.MetaFieldRepository)

Example 7 with Filter

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;
}
Also used : Filter(com.axelor.studio.db.Filter) MetaField(com.axelor.meta.db.MetaField)

Example 8 with Filter

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);
}
Also used : Filter(com.axelor.studio.db.Filter)

Example 9 with Filter

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);
}
Also used : FilterSqlService(com.axelor.studio.service.filter.FilterSqlService) Filter(com.axelor.studio.db.Filter)

Example 10 with Filter

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;
}
Also used : Filter(com.axelor.studio.db.Filter) ArrayList(java.util.ArrayList)

Aggregations

Filter (com.axelor.studio.db.Filter)12 MetaField (com.axelor.meta.db.MetaField)4 MetaJsonField (com.axelor.meta.db.MetaJsonField)2 ArrayList (java.util.ArrayList)2 MetaFieldRepository (com.axelor.meta.db.repo.MetaFieldRepository)1 FilterSqlService (com.axelor.studio.service.filter.FilterSqlService)1