Search in sources :

Example 1 with Operator

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

the class DocumentFilterDescriptorsProviderFactory method createFilterParam.

private final DocumentFilterParamDescriptor.Builder createFilterParam(final DocumentFieldDescriptor field) {
    final ITranslatableString displayName = field.getCaption();
    final String fieldName = field.getFieldName();
    final DocumentFieldWidgetType widgetType = extractFilterWidgetType(field);
    final DocumentFieldDefaultFilterDescriptor filteringInfo = field.getDefaultFilterInfo();
    final LookupDescriptor lookupDescriptor = field.getLookupDescriptor(LookupDescriptorProvider.LookupScope.DocumentFilter);
    final Operator operator;
    if (widgetType.isText()) {
        operator = Operator.LIKE_I;
    } else if (filteringInfo.isRangeFilter()) {
        operator = Operator.BETWEEN;
    } else {
        operator = Operator.EQUAL;
    }
    return DocumentFilterParamDescriptor.builder().setDisplayName(displayName).setFieldName(fieldName).setWidgetType(widgetType).setOperator(operator).setLookupDescriptor(lookupDescriptor).setMandatory(false).setShowIncrementDecrementButtons(filteringInfo.isShowFilterIncrementButtons()).setAutoFilterInitialValue(filteringInfo.getAutoFilterInitialValue());
}
Also used : Operator(de.metas.ui.web.document.filter.DocumentFilterParam.Operator) DocumentFieldDefaultFilterDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDefaultFilterDescriptor) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) ITranslatableString(de.metas.i18n.ITranslatableString) ITranslatableString(de.metas.i18n.ITranslatableString) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor)

Example 2 with Operator

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

the class MQueryDocumentFilterHelper method createDocumentFilterParamFromMQueryRestriction.

private static DocumentFilterParam createDocumentFilterParamFromMQueryRestriction(final MQuery mquery, final int restrictionIndex) {
    try {
        if (mquery.isDirectWhereClause(restrictionIndex)) {
            final boolean joinAnd = mquery.isJoinAnd(restrictionIndex);
            final String sqlWhereClause = mquery.getDirectWhereClause(restrictionIndex);
            return DocumentFilterParam.ofSqlWhereClause(joinAnd, sqlWhereClause);
        }
        final boolean joinAnd = mquery.isJoinAnd(restrictionIndex);
        final String fieldName = mquery.getColumnName(restrictionIndex);
        final Operator operator = MQueryDocumentFilterHelper.fromMQueryOperator(mquery.getOperator(restrictionIndex));
        final Object value = mquery.getCode(restrictionIndex);
        final Object valueTo = mquery.getCodeTo(restrictionIndex);
        return DocumentFilterParam.builder().setJoinAnd(joinAnd).setFieldName(fieldName).setOperator(operator).setValue(value).setValueTo(valueTo).build();
    } catch (final Exception ex) {
        throw new AdempiereException("Failed converting MQuery's restriction to " + DocumentFilterParam.class + "\n MQuery: " + mquery + "\n Restriction index: " + // 
        restrictionIndex, ex);
    }
}
Also used : Operator(de.metas.ui.web.document.filter.DocumentFilterParam.Operator) AdempiereException(org.adempiere.exceptions.AdempiereException) ITranslatableString(de.metas.i18n.ITranslatableString) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 3 with Operator

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

the class UserQueryDocumentFilterDescriptorsProvider method createFilterDescriptor0.

private static final DocumentFilterDescriptor createFilterDescriptor0(@NonNull final IUserQuery userQuery) {
    final DocumentFilterDescriptor.Builder filter = DocumentFilterDescriptor.builder().setFilterId("userquery-" + userQuery.getId()).setDisplayName(userQuery.getCaption()).setFrequentUsed(false);
    if (WindowConstants.isProtocolDebugging()) {
        filter.putDebugProperty("userQuery", userQuery.toString());
    }
    for (final IUserQueryRestriction queryRestriction : userQuery.getRestrictions()) {
        final Join join = queryRestriction.getJoin();
        final UserQueryField searchField = UserQueryField.cast(queryRestriction.getSearchField());
        final String fieldName = searchField.getColumnName();
        final Operator operator = MQueryDocumentFilterHelper.fromMQueryOperator(queryRestriction.getOperator());
        final Object value = queryRestriction.getValue();
        final Object valueTo = queryRestriction.getValueTo();
        final boolean isParameter;
        if (operator.isRangeOperator()) {
            isParameter = value == null || valueTo == null;
        } else {
            isParameter = value == null;
        }
        if (isParameter) {
            final ITranslatableString displayName = searchField.getDisplayName();
            final DocumentFieldWidgetType widgetType = searchField.getWidgetType();
            final LookupDescriptor lookupDescriptor = searchField.getLookupDescriptor();
            filter.addParameter(DocumentFilterParamDescriptor.builder().setJoinAnd(join == Join.AND).setDisplayName(displayName).setFieldName(fieldName).setWidgetType(widgetType).setOperator(operator).setDefaultValue(value).setDefaultValueTo(valueTo).setMandatory(// mandatory if there is no default value
            value == null).setLookupDescriptor(lookupDescriptor));
        } else {
            filter.addInternalParameter(DocumentFilterParam.builder().setJoinAnd(join == Join.AND).setFieldName(fieldName).setOperator(operator).setValue(value).setValueTo(valueTo).build());
        }
    }
    return filter.build();
}
Also used : Operator(de.metas.ui.web.document.filter.DocumentFilterParam.Operator) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) ITranslatableString(de.metas.i18n.ITranslatableString) Join(org.compiere.apps.search.IUserQueryRestriction.Join) IUserQueryField(org.compiere.apps.search.IUserQueryField) ITranslatableString(de.metas.i18n.ITranslatableString) IUserQueryRestriction(org.compiere.apps.search.IUserQueryRestriction) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor)

Example 4 with Operator

use of de.metas.ui.web.document.filter.DocumentFilterParam.Operator 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

Operator (de.metas.ui.web.document.filter.DocumentFilterParam.Operator)4 ITranslatableString (de.metas.i18n.ITranslatableString)3 DocumentFieldWidgetType (de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)3 LookupDescriptor (de.metas.ui.web.window.descriptor.LookupDescriptor)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2 MoreObjects (com.google.common.base.MoreObjects)1 Check (de.metas.printing.esb.base.util.Check)1 DocumentFilter (de.metas.ui.web.document.filter.DocumentFilter)1 DocumentFilterParam (de.metas.ui.web.document.filter.DocumentFilterParam)1 DocumentFilterParamDescriptor (de.metas.ui.web.document.filter.DocumentFilterParamDescriptor)1 LookupValue (de.metas.ui.web.window.datatypes.LookupValue)1 LookupValuesList (de.metas.ui.web.window.datatypes.LookupValuesList)1 DocumentFieldDefaultFilterDescriptor (de.metas.ui.web.window.descriptor.DocumentFieldDefaultFilterDescriptor)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