Search in sources :

Example 1 with Filter

use of com.axelor.studio.db.Filter in project axelor-open-suite by axelor.

the class ChartBuilderService method addSearchField.

/**
 * Method set default value for search-fields(parameters). It will add field and expression in
 * onNew for chart.
 *
 * @param fieldName Name of field of search-field.
 * @param typeName Type of field.
 * @param defaultValue Default value input in chart filter.
 * @param modelField It is for relational field. String array with first element as Model name and
 *     second as its field.
 */
// private void setDefaultValue(String fieldName, String typeName,
// String defaultValue, String[] modelField) {
// 
// if (defaultValue == null) {
// return;
// }
// 
// RecordField field = new RecordField();
// field.setName(fieldName);
// 
// defaultValue = filterCommonService.getTagValue(defaultValue, false);
// 
// if (modelField != null) {
// if (typeName.equals("STRING")) {
// defaultValue = "__repo__(" + modelField[0]
// + ").all().filter(\"LOWER(" + modelField[1] + ") LIKE "
// + defaultValue + "\").fetchOne()";
// } else {
// defaultValue = "__repo__(" + modelField[0]
// + ").all().filter(\"" + modelField[1] + " = "
// + defaultValue + "\").fetchOne()";
// }
// 
// }
// 
// log.debug("Default value: {}", defaultValue);
// 
// field.setExpression("eval:" + defaultValue);
// 
// onNewFields.add(field);
// }
/**
 * It will create onNew action from onNew fields.
 *
 * @param viewBuilder ViewBuilder use to get model name also used in onNew action name creation.
 */
// private void setOnNewAction(ChartBuilder chartBuilder) {
// 
// if (!onNewFields.isEmpty()) {
// onNewAction = new ActionRecord();
// onNewAction.setName("action-" + chartBuilder.getName() + "-default");
// onNewAction.setModel(chartBuilder.getModel());
// onNewAction.setFields(onNewFields);
// }
// 
// }
private void addSearchField(List<Filter> filters) throws AxelorException {
    if (filters == null) {
        return;
    }
    for (Filter filter : filters) {
        if (!filter.getIsParameter()) {
            continue;
        }
        String fieldStr = "param" + filter.getId();
        Object object = null;
        StringBuilder parent = new StringBuilder("self");
        if (filter.getIsJson()) {
            object = filterSqlService.parseJsonField(filter.getMetaJsonField(), filter.getTargetField(), null, parent);
        } else {
            object = filterSqlService.parseMetaField(filter.getMetaField(), filter.getTargetField(), null, parent, true);
        }
        if (object instanceof MetaField) {
            fieldStr = getMetaSearchField(fieldStr, (MetaField) object);
        } else {
            fieldStr = getJsonSearchField(fieldStr, (MetaJsonField) object);
        }
        searchFields.add(fieldStr + "\" x-required=\"true\" />");
    }
}
Also used : Filter(com.axelor.studio.db.Filter) MetaField(com.axelor.meta.db.MetaField) MetaJsonField(com.axelor.meta.db.MetaJsonField)

Example 2 with Filter

use of com.axelor.studio.db.Filter in project axelor-open-suite by axelor.

the class ChartRecordViewServiceImpl method createFilter.

protected Filter createFilter(ChartBuilder chartBuilder, boolean isNull, Boolean isForGroup) {
    Boolean isJson = chartBuilder.getIsJson();
    Filter filter = isForGroup ? createFilter(0l, isJson, chartBuilder.getIsJsonGroupOn(), chartBuilder.getGroupOnJson(), chartBuilder.getGroupOn(), chartBuilder.getGroupOnTarget(), chartBuilder.getGroupOnTargetType(), isNull, "=") : createFilter(Long.MAX_VALUE, isJson, chartBuilder.getIsJsonAggregateOn(), chartBuilder.getAggregateOnJson(), chartBuilder.getAggregateOn(), chartBuilder.getAggregateOnTarget(), chartBuilder.getAggregateOnTargetType(), isNull, "=");
    return filter;
}
Also used : Filter(com.axelor.studio.db.Filter)

Example 3 with Filter

use of com.axelor.studio.db.Filter in project axelor-open-suite by axelor.

the class FilterGroovyService method getGroovyFilters.

/**
 * Method to convert chart filter list to groovy expression string. Each filter of list will be
 * joined by logical operator(logicalOp) selected.
 *
 * @param conditions List for chart filters.
 * @param parentField Field that represent parent.
 * @return Groovy expression string.
 * @throws AxelorException
 */
public String getGroovyFilters(List<Filter> conditions, String parentField, boolean isButton, boolean isField) throws AxelorException {
    String condition = null;
    if (conditions == null) {
        return null;
    }
    for (Filter filter : conditions) {
        String activeFilter = createGroovyFilter(filter, parentField, isButton, isField);
        log.debug("Active filter: {}", filter);
        if (condition == null) {
            condition = "(" + activeFilter;
        } else if (filter.getLogicOp() > 0) {
            condition += ") || (" + activeFilter;
        } else {
            condition += " && " + activeFilter;
        }
    }
    if (condition == null) {
        return null;
    }
    return condition + ")";
}
Also used : Filter(com.axelor.studio.db.Filter)

Example 4 with Filter

use of com.axelor.studio.db.Filter in project axelor-open-suite by axelor.

the class FilterSqlService method getSqlFilters.

public String getSqlFilters(List<Filter> filterList, List<String> joins, boolean checkJson) throws AxelorException {
    String filters = null;
    if (filterList == null) {
        return filters;
    }
    for (Filter filter : filterList) {
        StringBuilder parent = new StringBuilder("self");
        Object target = getTargetField(parent, filter, joins, checkJson);
        if (target == null) {
            continue;
        }
        String[] fields = getSqlField(target, parent.toString(), null);
        String field = checkDateTime(fields);
        String value = getParam(filter.getIsParameter(), filter.getValue(), filter.getId(), fields[1]);
        String condition = filterCommonService.getCondition(field, filter.getOperator(), value);
        if (filters == null) {
            filters = condition;
        } else {
            String opt = filter.getLogicOp() == 0 ? " AND " : " OR ";
            filters = filters + opt + condition;
        }
    }
    return filters;
}
Also used : Filter(com.axelor.studio.db.Filter)

Example 5 with Filter

use of com.axelor.studio.db.Filter in project axelor-open-suite by axelor.

the class FilterController method updateTargetField.

public void updateTargetField(ActionRequest request, ActionResponse response) {
    Filter filter = request.getContext().asType(Filter.class);
    MetaField metaField = filter.getMetaField();
    MetaJsonField metaJson = filter.getMetaJsonField();
    Boolean isJson = filter.getIsJson() != null ? filter.getIsJson() : false;
    if (!isJson && metaField != null) {
        String type = metaField.getRelationship() != null ? metaField.getRelationship() : metaField.getTypeName();
        response.setValue("targetType", type);
        response.setValue("targetField", metaField.getName());
        response.setValue("targetTitle", metaField.getLabel() != null && !metaField.getLabel().isEmpty() ? metaField.getLabel() : metaField.getName());
    } else if ((isJson || !isJson) && metaJson != null) {
        response.setValue("targetType", Inflector.getInstance().camelize(metaJson.getType()));
        response.setValue("targetField", metaJson.getName());
    } else {
        response.setValue("targetField", null);
        response.setValue("targetType", null);
    }
    response.setValue("operator", null);
}
Also used : Filter(com.axelor.studio.db.Filter) MetaField(com.axelor.meta.db.MetaField) MetaJsonField(com.axelor.meta.db.MetaJsonField)

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