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();
}
Aggregations