Search in sources :

Example 1 with IUserQueryRestriction

use of org.compiere.apps.search.IUserQueryRestriction 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)

Aggregations

ITranslatableString (de.metas.i18n.ITranslatableString)1 Operator (de.metas.ui.web.document.filter.DocumentFilterParam.Operator)1 DocumentFieldWidgetType (de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)1 LookupDescriptor (de.metas.ui.web.window.descriptor.LookupDescriptor)1 IUserQueryField (org.compiere.apps.search.IUserQueryField)1 IUserQueryRestriction (org.compiere.apps.search.IUserQueryRestriction)1 Join (org.compiere.apps.search.IUserQueryRestriction.Join)1