use of de.metas.ui.web.document.filter.DocumentFilterParamDescriptor in project metasfresh-webui-api by metasfresh.
the class SqlDefaultDocumentFilterConverter method buildSqlWhereClause.
/**
* Build document filter parameter where clause
*/
private String buildSqlWhereClause(final SqlParamsCollector sqlParams, final String filterId, final DocumentFilterParam filterParam, final SqlOptions sqlOpts) {
// SQL filter
if (filterParam.isSqlFilter()) {
String sqlWhereClause = filterParam.getSqlWhereClause();
if (sqlOpts.isUseTableAlias()) {
sqlWhereClause = replaceTableNameWithTableAlias(sqlWhereClause, sqlOpts.getTableAlias());
}
final List<Object> sqlWhereClauseParams = filterParam.getSqlWhereClauseParams();
sqlParams.collectAll(sqlWhereClauseParams);
return sqlWhereClause;
}
//
// Labels filter
final String parameterName = filterParam.getFieldName();
final DocumentFieldWidgetType widgetType = getParameterWidgetType(parameterName);
if (widgetType == DocumentFieldWidgetType.Labels) {
final DocumentFilterParamDescriptor paramDescriptor = getParameterDescriptor(filterId, parameterName);
return buildSqlWhereClause_LabelsWidget(filterParam, paramDescriptor, sqlParams, sqlOpts);
} else //
// Standard filter
{
return buildSqlWhereClause_StandardWidget(sqlParams, filterParam, sqlOpts);
}
}
use of de.metas.ui.web.document.filter.DocumentFilterParamDescriptor 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();
}
use of de.metas.ui.web.document.filter.DocumentFilterParamDescriptor in project metasfresh-webui-api by metasfresh.
the class SqlViewFactory method createAutoFilter.
private static DocumentFilter createAutoFilter(final DocumentFilterDescriptor filterDescriptor) {
if (!filterDescriptor.isAutoFilter()) {
throw new AdempiereException("Not an auto filter: " + filterDescriptor);
}
final Builder filterBuilder = DocumentFilter.builder().setFilterId(filterDescriptor.getFilterId());
filterDescriptor.getParameters().stream().filter(DocumentFilterParamDescriptor::isAutoFilter).map(SqlViewFactory::createAutoFilterParam).forEach(filterBuilder::addParameter);
return filterBuilder.build();
}
Aggregations