use of org.springframework.data.querydsl.binding.QuerydslBindings in project spring-data-commons by spring-projects.
the class QuerydslPredicateArgumentResolverSupport method getPredicate.
Predicate getPredicate(MethodParameter parameter, MultiValueMap<String, String> queryParameters) {
MergedAnnotations annotations = MergedAnnotations.from(parameter.getParameter());
MergedAnnotation<QuerydslPredicate> predicateAnnotation = annotations.get(QuerydslPredicate.class);
TypeInformation<?> domainType = extractTypeInfo(parameter, predicateAnnotation).getRequiredActualType();
Optional<Class<? extends QuerydslBinderCustomizer<?>>> bindingsAnnotation = //
predicateAnnotation.getValue("bindings").map(CastUtils::cast);
QuerydslBindings bindings = //
bindingsAnnotation.map(//
it -> bindingsFactory.createBindingsFor(domainType, it)).orElseGet(() -> bindingsFactory.createBindingsFor(domainType));
return predicateBuilder.getPredicate(domainType, queryParameters, bindings);
}
use of org.springframework.data.querydsl.binding.QuerydslBindings in project spring-graphql by spring-projects.
the class QuerydslDataFetcher method buildPredicate.
/**
* Prepare a {@link Predicate} from GraphQL request arguments, also applying
* any {@link QuerydslBinderCustomizer} that may have been configured.
* @param environment contextual info for the GraphQL request
* @return the resulting predicate
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Predicate buildPredicate(DataFetchingEnvironment environment) {
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>();
QuerydslBindings bindings = new QuerydslBindings();
EntityPath<?> path = SimpleEntityPathResolver.INSTANCE.createPath(this.domainType.getType());
this.customizer.customize(bindings, path);
for (Map.Entry<String, Object> entry : environment.getArguments().entrySet()) {
Object value = entry.getValue();
List<Object> values = (value instanceof List ? (List<Object>) value : Collections.singletonList(value));
parameters.put(entry.getKey(), values);
}
return BUILDER.getPredicate(this.domainType, (MultiValueMap) parameters, bindings);
}
use of org.springframework.data.querydsl.binding.QuerydslBindings in project springdoc-openapi by springdoc.
the class QuerydslPredicateOperationCustomizer method customize.
@Override
public Operation customize(Operation operation, HandlerMethod handlerMethod) {
if (operation.getParameters() == null) {
return operation;
}
MethodParameter[] methodParameters = handlerMethod.getMethodParameters();
int parametersLength = methodParameters.length;
List<Parameter> parametersToAddToOperation = new ArrayList<>();
for (int i = 0; i < parametersLength; i++) {
MethodParameter parameter = methodParameters[i];
QuerydslPredicate predicate = parameter.getParameterAnnotation(QuerydslPredicate.class);
if (predicate == null)
continue;
QuerydslBindings bindings = extractQdslBindings(predicate);
Set<String> fieldsToAdd = Arrays.stream(predicate.root().getDeclaredFields()).filter(field -> !Modifier.isStatic(field.getModifiers())).map(Field::getName).collect(Collectors.toSet());
Map<String, Object> pathSpecMap = getPathSpec(bindings, "pathSpecs");
// remove blacklisted fields
Set<String> blacklist = getFieldValues(bindings, "denyList", "blackList");
fieldsToAdd.removeIf(blacklist::contains);
Set<String> whiteList = getFieldValues(bindings, "allowList", "whiteList");
Set<String> aliases = getFieldValues(bindings, "aliases", null);
fieldsToAdd.addAll(aliases);
fieldsToAdd.addAll(whiteList);
// if only listed properties should be included, remove all other fields from fieldsToAdd
if (getFieldValueOfBoolean(bindings, "excludeUnlistedProperties")) {
fieldsToAdd.removeIf(s -> !whiteList.contains(s) && !aliases.contains(s));
}
for (String fieldName : fieldsToAdd) {
Type type = getFieldType(fieldName, pathSpecMap, predicate.root());
if (type != null) {
Parameter newParameter = buildParam(type, fieldName);
parametersToAddToOperation.add(newParameter);
}
}
}
operation.getParameters().addAll(parametersToAddToOperation);
return operation;
}
Aggregations