Skip to content

#925: Correct behavior for QuerydslPredicateOperationCustomizer#excludeUnlistedProperties #926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,13 @@ public Operation customize(Operation operation, HandlerMethod handlerMethod) {
fieldsToAdd.addAll(aliases);
fieldsToAdd.addAll(whiteList);

boolean excludeUnlistedProperties = getFieldValueOfBoolean(bindings, "excludeUnlistedProperties");
// if only listed properties should be included, remove all other fields from fieldsToAdd
if (getFieldValueOfBoolean(bindings, "excludeUnlistedProperties")) {
fieldsToAdd.removeIf(s -> !whiteList.contains(s));
}

for (String fieldName : fieldsToAdd) {
Type type = getFieldType(fieldName, pathSpecMap, predicate.root(), excludeUnlistedProperties);
Type type = getFieldType(fieldName, pathSpecMap, predicate.root());
if (type != null) {
Parameter newParameter = buildParam(type, fieldName);
parametersToAddToOperation.add(newParameter);
Expand Down Expand Up @@ -232,19 +235,18 @@ private Optional<Path<?>> getPathFromPathSpec(Object instance) {
* Tries to figure out the Type of the field. It first checks the Qdsl pathSpecMap before checking the root class. Defaults to String.class
* @param fieldName The name of the field used as reference to get the type
* @param pathSpecMap The Qdsl path specifications as defined in the resolved bindings
* @param root The root type where the paths are gotten
* @param excludeUnlistedProperties the exclude unlisted properties
* @param root The root type where the paths are gotten
* @return The type of the field. Returns
*/
private Type getFieldType(String fieldName, Map<String, Object> pathSpecMap, Class<?> root, boolean excludeUnlistedProperties) {
private Type getFieldType(String fieldName, Map<String, Object> pathSpecMap, Class<?> root) {
Type genericType = null;
try {
Object pathAndBinding = pathSpecMap.get(fieldName);
Optional<Path<?>> path = getPathFromPathSpec(pathAndBinding);
Field declaredField;
if (path.isPresent()) {
genericType = path.get().getType();
} else if (!excludeUnlistedProperties) {
} else {
declaredField = root.getDeclaredField(fieldName);
genericType = declaredField.getGenericType();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class ApplicationPredicate implements QuerydslBinderCustomizer<QApplicati
public void customize(QuerydslBindings bindings, QApplication root) {
bindings.excludeUnlistedProperties(true);
bindings.bind(root.name).first(StringExpression::containsIgnoreCase);
bindings.including(root.icon);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
"schema": {
"type": "string"
}
},
{
"name": "icon",
"in": "query",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
Expand Down