Better error handling of invalid values in faceted search

This commit is contained in:
Francesco
2023-09-30 10:16:06 +02:00
parent fd2728083b
commit e72fcda5fe
6 changed files with 39 additions and 10 deletions

View File

@@ -7,6 +7,7 @@ import java.util.Set;
import org.springframework.util.MultiValueMap;
import tech.ailef.dbadmin.external.dbmapping.DbField;
import tech.ailef.dbadmin.external.dbmapping.DbObjectSchema;
import tech.ailef.dbadmin.external.dto.CompareOperator;
import tech.ailef.dbadmin.external.dto.QueryFilter;
@@ -81,9 +82,16 @@ public interface Utils {
String op = ops.get(i);
String field = fields.get(i);
String value = values.get(i);
QueryFilter queryFilter = new QueryFilter(schema.getFieldByJavaName(field), CompareOperator.valueOf(op.toUpperCase()), value);
filters.add(queryFilter);
// Check if the field can actually be found before creating the filter
// This shouldn't normally happen because this parameter is not provided
// by the user; but there's the chance of a stale bookmarked link referring
// to a non-existing schema or the user fiddling with the URL
DbField dbField = schema.getFieldByJavaName(field);
if (dbField != null) {
QueryFilter queryFilter = new QueryFilter(dbField, CompareOperator.valueOf(op.toUpperCase()), value);
filters.add(queryFilter);
}
}
return filters;