Search in sources :

Example 1 with DocumentFilterParam

use of de.metas.ui.web.document.filter.DocumentFilterParam in project metasfresh-webui-api by metasfresh.

the class HuTraceQueryCreator method getUpdateMethodForParameterOrThrowException.

private static BiFunction<HUTraceEventQuery, DocumentFilterParam, HUTraceEventQuery> getUpdateMethodForParameterOrThrowException(@NonNull final DocumentFilterParam parameter) {
    final String paramName = parameter.getFieldName();
    final // 
    BiFunction<HUTraceEventQuery, DocumentFilterParam, HUTraceEventQuery> queryUpdateFunction = FIELD_NAME_2_UPDATE_METHOD.get(paramName);
    if (queryUpdateFunction == null) {
        final String message = StringUtils.formatMessage("The given filterparam has an unexpected fieldName={}", paramName);
        throw new AdempiereException(message).setParameter("documentFilterParam", parameter);
    }
    return queryUpdateFunction;
}
Also used : DocumentFilterParam(de.metas.ui.web.document.filter.DocumentFilterParam) HUTraceEventQuery(de.metas.handlingunits.trace.HUTraceEventQuery) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 2 with DocumentFilterParam

use of de.metas.ui.web.document.filter.DocumentFilterParam in project metasfresh-webui-api by metasfresh.

the class JSONDocumentFilter method unwrapUsingDescriptor.

private static DocumentFilter unwrapUsingDescriptor(final JSONDocumentFilter jsonFilter, final DocumentFilterDescriptor filterDescriptor) {
    final DocumentFilter.Builder filter = DocumentFilter.builder().setFilterId(jsonFilter.getFilterId());
    final Map<String, JSONDocumentFilterParam> jsonParams = Maps.uniqueIndex(jsonFilter.getParameters(), JSONDocumentFilterParam::getParameterName);
    for (final DocumentFilterParamDescriptor paramDescriptor : filterDescriptor.getParameters()) {
        final String parameterName = paramDescriptor.getParameterName();
        final JSONDocumentFilterParam jsonParam = jsonParams.get(parameterName);
        // If parameter is missing: skip it if no required, else throw exception
        if (jsonParam == null) {
            if (paramDescriptor.isMandatory()) {
                throw new IllegalArgumentException("Parameter '" + parameterName + "' was not provided");
            }
            continue;
        }
        final Object value = paramDescriptor.convertValueFromJson(jsonParam.getValue());
        final Object valueTo = paramDescriptor.convertValueFromJson(jsonParam.getValueTo());
        // If there was no value/valueTo provided: skip it if no required, else throw exception
        if (value == null && valueTo == null) {
            if (paramDescriptor.isMandatory()) {
                throw new IllegalArgumentException("Parameter '" + parameterName + "' has no value");
            }
            continue;
        }
        filter.addParameter(DocumentFilterParam.builder().setFieldName(paramDescriptor.getFieldName()).setOperator(paramDescriptor.getOperator()).setValue(value).setValueTo(valueTo).build());
    }
    for (final DocumentFilterParam internalParam : filterDescriptor.getInternalParameters()) {
        filter.addParameter(internalParam);
    }
    return filter.build();
}
Also used : DocumentFilterParam(de.metas.ui.web.document.filter.DocumentFilterParam) DocumentFilterParamDescriptor(de.metas.ui.web.document.filter.DocumentFilterParamDescriptor) DocumentFilter(de.metas.ui.web.document.filter.DocumentFilter)

Example 3 with DocumentFilterParam

use of de.metas.ui.web.document.filter.DocumentFilterParam in project metasfresh-webui-api by metasfresh.

the class SqlDefaultDocumentFilterConverter method getSql.

/**
 * Build document filter where clause
 */
@Override
public String getSql(@NonNull final SqlParamsCollector sqlParams, @NonNull final DocumentFilter filter, @NonNull final SqlOptions sqlOpts) {
    final String filterId = filter.getFilterId();
    final StringBuilder sql = new StringBuilder();
    for (final DocumentFilterParam filterParam : filter.getParameters()) {
        final String sqlFilterParam = buildSqlWhereClause(sqlParams, filterId, filterParam, sqlOpts);
        if (Check.isEmpty(sqlFilterParam, true)) {
            continue;
        }
        if (sql.length() > 0) {
            sql.append(filterParam.isJoinAnd() ? " AND " : " OR ");
        }
        sql.append("(").append(sqlFilterParam).append(")");
    }
    return sql.toString();
}
Also used : DocumentFilterParam(de.metas.ui.web.document.filter.DocumentFilterParam)

Example 4 with DocumentFilterParam

use of de.metas.ui.web.document.filter.DocumentFilterParam in project metasfresh-webui-api by metasfresh.

the class SqlDefaultDocumentFilterConverter method buildSqlWhereClause_StandardWidget.

private final String buildSqlWhereClause_StandardWidget(final SqlParamsCollector sqlParams, final DocumentFilterParam filterParam, final SqlOptions sqlOpts) {
    final SqlEntityFieldBinding paramBinding = getParameterBinding(filterParam.getFieldName());
    final DocumentFieldWidgetType widgetType = paramBinding.getWidgetType();
    // 
    // Regular filter
    final IQueryFilterModifier fieldModifier = extractFieldModifier(widgetType);
    final IQueryFilterModifier valueModifier = extractValueModifier(widgetType);
    final String columnSql = extractColumnSql(paramBinding, fieldModifier, sqlOpts);
    final Operator operator = filterParam.getOperator();
    switch(operator) {
        case EQUAL:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                final boolean negate = false;
                return buildSqlWhereClause_Equals(columnSql, sqlValue, negate, sqlParams);
            }
        case NOT_EQUAL:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                final boolean negate = true;
                return buildSqlWhereClause_Equals(columnSql, sqlValue, negate, sqlParams);
            }
        case IN_ARRAY:
            {
                final List<Object> sqlValuesList = filterParam.getValueAsList(itemObj -> convertToSqlValue(itemObj, paramBinding, valueModifier));
                return buildSqlWhereClause_InArray(columnSql, sqlValuesList, sqlParams);
            }
        case GREATER:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                return buildSqlWhereClause_Compare(columnSql, ">", sqlValue, sqlParams);
            }
        case GREATER_OR_EQUAL:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                return buildSqlWhereClause_Compare(columnSql, ">=", sqlValue, sqlParams);
            }
        case LESS:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                return buildSqlWhereClause_Compare(columnSql, "<", sqlValue, sqlParams);
            }
        case LESS_OR_EQUAL:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                return buildSqlWhereClause_Compare(columnSql, "<=", sqlValue, sqlParams);
            }
        case LIKE:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                final boolean negate = false;
                final boolean ignoreCase = false;
                return buildSqlWhereClause_Like(columnSql, negate, ignoreCase, sqlValue, sqlParams);
            }
        case NOT_LIKE:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                final boolean negate = true;
                final boolean ignoreCase = false;
                return buildSqlWhereClause_Like(columnSql, negate, ignoreCase, sqlValue, sqlParams);
            }
        case LIKE_I:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                final boolean negate = false;
                final boolean ignoreCase = true;
                return buildSqlWhereClause_Like(columnSql, negate, ignoreCase, sqlValue, sqlParams);
            }
        case NOT_LIKE_I:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                final boolean negate = true;
                final boolean ignoreCase = true;
                return buildSqlWhereClause_Like(columnSql, negate, ignoreCase, sqlValue, sqlParams);
            }
        case BETWEEN:
            {
                final Object sqlValue = convertToSqlValue(filterParam.getValue(), paramBinding, valueModifier);
                final Object sqlValueTo = convertToSqlValue(filterParam.getValueTo(), paramBinding, valueModifier);
                return buildSqlWhereClause_Between(columnSql, sqlValue, sqlValueTo, sqlParams);
            }
        default:
            {
                throw new IllegalArgumentException("Operator not supported: " + operator);
            }
    }
}
Also used : Operator(de.metas.ui.web.document.filter.DocumentFilterParam.Operator) LookupValue(de.metas.ui.web.window.datatypes.LookupValue) DateTruncQueryFilterModifier(org.adempiere.ad.dao.impl.DateTruncQueryFilterModifier) NonNull(lombok.NonNull) DocumentFilterParamDescriptor(de.metas.ui.web.document.filter.DocumentFilterParamDescriptor) SqlDocumentsRepository(de.metas.ui.web.window.model.sql.SqlDocumentsRepository) DocumentFilterParam(de.metas.ui.web.document.filter.DocumentFilterParam) IQueryFilterModifier(org.adempiere.ad.dao.IQueryFilterModifier) MoreObjects(com.google.common.base.MoreObjects) SqlOptions(de.metas.ui.web.window.model.sql.SqlOptions) ArrayList(java.util.ArrayList) List(java.util.List) DB(org.compiere.util.DB) Operator(de.metas.ui.web.document.filter.DocumentFilterParam.Operator) LabelsLookup(de.metas.ui.web.window.model.lookup.LabelsLookup) AdempiereException(org.adempiere.exceptions.AdempiereException) SqlEntityFieldBinding(de.metas.ui.web.window.descriptor.sql.SqlEntityFieldBinding) Check(de.metas.printing.esb.base.util.Check) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) SqlEntityBinding(de.metas.ui.web.window.descriptor.sql.SqlEntityBinding) DBConstants(org.adempiere.db.DBConstants) DocumentFilter(de.metas.ui.web.document.filter.DocumentFilter) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) NullQueryFilterModifier(org.adempiere.ad.dao.impl.NullQueryFilterModifier) IQueryFilterModifier(org.adempiere.ad.dao.IQueryFilterModifier) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) ArrayList(java.util.ArrayList) List(java.util.List) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) SqlEntityFieldBinding(de.metas.ui.web.window.descriptor.sql.SqlEntityFieldBinding)

Aggregations

DocumentFilterParam (de.metas.ui.web.document.filter.DocumentFilterParam)4 DocumentFilter (de.metas.ui.web.document.filter.DocumentFilter)2 DocumentFilterParamDescriptor (de.metas.ui.web.document.filter.DocumentFilterParamDescriptor)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2 MoreObjects (com.google.common.base.MoreObjects)1 HUTraceEventQuery (de.metas.handlingunits.trace.HUTraceEventQuery)1 Check (de.metas.printing.esb.base.util.Check)1 Operator (de.metas.ui.web.document.filter.DocumentFilterParam.Operator)1 LookupValue (de.metas.ui.web.window.datatypes.LookupValue)1 LookupValuesList (de.metas.ui.web.window.datatypes.LookupValuesList)1 DocumentFieldWidgetType (de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)1 SqlEntityBinding (de.metas.ui.web.window.descriptor.sql.SqlEntityBinding)1 SqlEntityFieldBinding (de.metas.ui.web.window.descriptor.sql.SqlEntityFieldBinding)1 LabelsLookup (de.metas.ui.web.window.model.lookup.LabelsLookup)1 SqlDocumentsRepository (de.metas.ui.web.window.model.sql.SqlDocumentsRepository)1 SqlOptions (de.metas.ui.web.window.model.sql.SqlOptions)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 NonNull (lombok.NonNull)1 IQueryFilterModifier (org.adempiere.ad.dao.IQueryFilterModifier)1