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