Java Code Examples for org.springframework.data.querydsl.binding.QuerydslPredicate

The following examples show how to use org.springframework.data.querydsl.binding.QuerydslPredicate. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Obtains the domain type information from the given method parameter. Will
 * favor an explicitly registered on through
 * {@link QuerydslPredicate#root()} but use the actual type of the method's
 * return type as fallback.
 * 
 * @param parameter
 *            must not be {@literal null}.
 * @return
 */
static TypeInformation<?> extractTypeInfo(MethodParameter parameter) {

	QuerydslPredicate annotation = parameter.getParameterAnnotation(QuerydslPredicate.class);

	if (annotation != null && !Object.class.equals(annotation.root())) {
		return ClassTypeInformation.from(annotation.root());
	}

	Class<?> containingClass = parameter.getContainingClass();
	if (ClassUtils.isAssignable(EntityController.class, containingClass)) {
		ResolvableType resolvableType = ResolvableType.forClass(containingClass);
		return ClassTypeInformation.from(resolvableType.as(EntityController.class).getGeneric(0).resolve());
	}

	return detectDomainType(ClassTypeInformation.fromReturnTypeOf(parameter.getMethod()));
}
 
Example 2
Source Project: flair-engine   Source File: ConnectionResource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * GET  /connections/all : get all the connections.
 *
 * @param predicate predicate
 * @return the ResponseEntity with status 200 (OK) and the list of connections in body
 */
@GetMapping("/connections/all")
@Timed
public ResponseEntity<List<ConnectionDTO>> getAllConnections(@QuerydslPredicate(root = Connection.class) Predicate predicate) {
    log.debug("REST request to get a page of Connections");
    return new ResponseEntity<>(connectionService.findAll(predicate), HttpStatus.OK);
}
 
Example 3
Source Project: blog-tutorials   Source File: PersonController.java    License: MIT License 5 votes vote down vote up
@GetMapping("/simplified")
public Page<Person> getPersonsSimplified(
		@QuerydslPredicate(root = Person.class) Predicate predicate, 
		@RequestParam(name = "page", defaultValue = "0") int page,
		@RequestParam(name = "size", defaultValue = "500") int size) {

	return personRepository.findAll(predicate, PageRequest.of(page, size, Sort.by(Sort.Direction.ASC, "id")));
}
 
Example 4
Source Project: SuperBoot   Source File: SysMenuController.java    License: MIT License 5 votes vote down vote up
@ApiOperation(value = "获取全部菜单", notes = "获取全部菜单,系统管理员默认可以访问")
@RequestMapping(value = "/", method = RequestMethod.GET)
public BaseResponse<List<ResMenu>> getItems(@RequestParam(value = "page", defaultValue = "0") Integer page,
                                            @RequestParam(value = "size", defaultValue = "15") Integer size,
                                            @QuerydslPredicate(root = SuperbootMenu.class) Predicate predicate) throws BaseException {
    Pageable pageable = new PageRequest(page, size);
    return menuService.getMenus(-1, pageable, predicate);
}
 
Example 5
Source Project: SuperBoot   Source File: SysMenuController.java    License: MIT License 5 votes vote down vote up
@ApiOperation(value = "获取角色未授权菜单", notes = "获取角色未授权菜单,系统管理员默认可以访问")
@RequestMapping(value = "/getRoleNoMenu/{role_id}", method = RequestMethod.GET)
public BaseResponse<List<ResMenu>> getRoleNoMenu(@PathVariable("role_id") Long pkRole,
                                                 @RequestParam(value = "page", defaultValue = "0") Integer page,
                                                 @RequestParam(value = "size", defaultValue = "15") Integer size,
                                                 @QuerydslPredicate(root = SuperbootMenu.class) Predicate predicate) throws BaseException {
    Pageable pageable = new PageRequest(page, size);
    return menuService.getRoleNoMenu(pkRole, -1L, pageable, predicate);
}
 
Example 6
Source Project: SuperBoot   Source File: SysRoleController.java    License: MIT License 5 votes vote down vote up
@ApiOperation(value = "获取全部角色,分页查询", notes = "获取全部角色,系统管理员默认可以访问")
@RequestMapping(value = "/", method = RequestMethod.GET)
public BaseResponse<List<ResRole>> getItems(@RequestParam(value = "page", defaultValue = "0") Integer page,
                                            @RequestParam(value = "size", defaultValue = "15") Integer size,
                                            @QuerydslPredicate(root = SuperbootRole.class) Predicate predicate) throws BaseException {
    Pageable pageable = new PageRequest(page, size);
    return roleService.getRoles(-1, pageable, predicate);
}
 
Example 7
Source Project: SuperBoot   Source File: SysGroupController.java    License: MIT License 5 votes vote down vote up
@ApiOperation(value = "获取组织信息", notes = "获取组织基本信息,系统管理员默认可以访问")
@RequestMapping(value = "/", method = RequestMethod.GET)
public BaseResponse<List<ResGroup>> getGroupList(@RequestParam(value = "page", defaultValue = "0") Integer page,
                                                 @RequestParam(value = "size", defaultValue = "15") Integer size,
                                                 @QuerydslPredicate(root = SuperbootGroup.class) Predicate predicate) throws BaseException {
    Pageable pageable = new PageRequest(page, size);
    return groupService.getGroupList(pageable, predicate);
}
 
Example 8
Source Project: SuperBoot   Source File: SysUserController.java    License: MIT License 5 votes vote down vote up
@ApiOperation(value = "获取用户信息", notes = "获取系统用户信息,系统管理员默认可以访问")
@RequestMapping(value = "/", method = RequestMethod.GET)
public BaseResponse<List<ResUser>> getUser(@RequestParam(value = "page", defaultValue = "0") Integer page,
                                           @RequestParam(value = "size", defaultValue = "15") Integer size,
                                           @QuerydslPredicate(root = SuperbootUser.class) Predicate user, @QuerydslPredicate(root = SuperbootRole.class) Predicate role, @QuerydslPredicate(root = SuperbootGroup.class) Predicate group) throws BaseException {
    Pageable pageable = new PageRequest(page, size);
    return userService.getUserList(pageable, false, user, role, group);
}
 
Example 9
Source Project: SuperBoot   Source File: SysLogController.java    License: MIT License 5 votes vote down vote up
@ApiOperation(value = "获取日志列表信息", notes = "获取日志列表信息,系统管理员默认可以访问")
@RequestMapping(value = "/", method = RequestMethod.GET)
public BaseResponse<List<ResLog>> getLogList(@QuerydslPredicate(root = DataInfo.class) Predicate predicate, @RequestParam(value = "page", defaultValue = "0") Integer page,
                                             @RequestParam(value = "size", defaultValue = "15") Integer size) throws BaseException {
    //添加排序 默认按照最后访问时间进行倒排
    Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "execTime"));
    Pageable pageable = new PageRequest(page, size, sort);
    return service.getLogList(pageable, predicate);
}
 
Example 10
Source Project: SuperBoot   Source File: SysErrLogController.java    License: MIT License 5 votes vote down vote up
@ApiOperation(value = "获取日志列表信息", notes = "获取日志列表信息,系统管理员默认可以访问")
@RequestMapping(value = "/", method = RequestMethod.GET)
public BaseResponse<List<ResErrLog>> getErrorLogList(@QuerydslPredicate(root = ErrorInfo.class) Predicate predicate, @RequestParam(value = "page", defaultValue = "0") Integer page,
                                                     @RequestParam(value = "size", defaultValue = "15") Integer size) throws BaseException {
    //添加排序 默认按照最后访问时间进行倒排
    Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "execTime"));
    Pageable pageable = new PageRequest(page, size, sort);
    return service.getErrorLogList(pageable, predicate);
}
 
Example 11
Source Project: spring-boot-jpa   Source File: PatientController.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Another alternative to QBE via QueryDsl Predicates.
 *
 * @param predicate the Predicate to use to query with
 * @param pageable a Pageable to restrict results
 * @return A paged result of matching Patients
 */
@GetMapping("/search/predicate")
public Page<Patient> getPatientsByPredicate(
		@QuerydslPredicate(root = Patient.class) final Predicate predicate, final Pageable pageable) {
	Page<Patient> pagedResults = this.patientRepository.findAll(predicate, pageable);

	if (!pagedResults.hasContent()) {
		throw new NotFoundException(Patient.RESOURCE_PATH,
				"No Patients found matching predicate " + predicate);
	}

	return pagedResults;
}
 
Example 12
@Override
public boolean supportsParameter(MethodParameter parameter) {

	if (Predicate.class.equals(parameter.getParameterType())) {
		return true;
	}

	if (parameter.hasParameterAnnotation(QuerydslPredicate.class)) {
		throw new IllegalArgumentException(
				String.format("Parameter at position %s must be of type Predicate but was %s.",
						parameter.getParameterIndex(), parameter.getParameterType()));
	}

	return false;
}
 
Example 13
Source Project: spring-data-examples   Source File: UserController.java    License: Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/", method = RequestMethod.GET)
String index(Model model, //
		@QuerydslPredicate(root = User.class) Predicate predicate, //
		@PageableDefault(sort = { "lastname", "firstname" }) Pageable pageable, //
		@RequestParam MultiValueMap<String, String> parameters) {

	ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentRequest();
	builder.replaceQueryParam("page", new Object[0]);

	model.addAttribute("baseUri", builder.build().toUri());
	model.addAttribute("users", repository.findAll(predicate, pageable));

	return "index";
}
 
Example 14
@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()).map(Field::getName).collect(Collectors.toSet());

		Map<String, Object> pathSpecMap = getPathSpec(bindings, "pathSpecs");
		//remove blacklisted fields
		Set<String> blacklist = getFieldValues(bindings, "blackList");
		fieldsToAdd.removeIf(blacklist::contains);

		Set<String> whiteList = getFieldValues(bindings, "whiteList");
		Set<String> aliases = getFieldValues(bindings, "aliases");

		fieldsToAdd.addAll(aliases);
		fieldsToAdd.addAll(whiteList);
		for (String fieldName : fieldsToAdd) {
			Type type = getFieldType(fieldName, pathSpecMap, predicate.root());
			io.swagger.v3.oas.models.parameters.Parameter newParameter = buildParam(type, fieldName);

			parametersToAddToOperation.add(newParameter);
		}
	}
	operation.getParameters().addAll(parametersToAddToOperation);
	return operation;
}
 
Example 15
/**
 * Extract qdsl bindings querydsl bindings.
 *
 * @param predicate the predicate
 * @return the querydsl bindings
 */
private QuerydslBindings extractQdslBindings(QuerydslPredicate predicate) {
	ClassTypeInformation<?> classTypeInformation = ClassTypeInformation.from(predicate.root());
	TypeInformation<?> domainType = classTypeInformation.getRequiredActualType();

	Optional<Class<? extends QuerydslBinderCustomizer<?>>> bindingsAnnotation = Optional.of(predicate)
			.map(QuerydslPredicate::bindings)
			.map(CastUtils::cast);

	return bindingsAnnotation
			.map(it -> querydslBindingsFactory.createBindingsFor(domainType, it))
			.orElseGet(() -> querydslBindingsFactory.createBindingsFor(domainType));
}
 
Example 16
Source Project: springdoc-openapi   Source File: GreetingController.java    License: Apache License 2.0 4 votes vote down vote up
@GetMapping("/test")
public ResponseEntity<?> sayHello2(@QuerydslPredicate(bindings = CountryPredicate.class, root = Country.class) Predicate predicate,
		@RequestParam List<Status> statuses) {
	return ResponseEntity.ok().build();
}
 
Example 17
Source Project: SuperBoot   Source File: BaseController.java    License: MIT License 4 votes vote down vote up
@ApiOperation(value = "获取全部组织信息", notes = "获取全部组织信息,主要用于下拉使用")
@RequestMapping(value = "/group/all", method = RequestMethod.GET)
public BaseResponse<List<ResGroup>> getGroupAll(@QuerydslPredicate(root = SuperbootGroup.class) Predicate predicate) throws BaseException {
    return pubService.getGroupAll(predicate);
}
 
Example 18
Source Project: SuperBoot   Source File: BaseController.java    License: MIT License 4 votes vote down vote up
@ApiOperation(value = "获取组织树", notes = "获取组织树,主要用于构造菜单使用")
@RequestMapping(value = "/group/tree", method = RequestMethod.GET)
public BaseResponse<List<ResTree>> getGroupTree(@QuerydslPredicate(root = SuperbootGroup.class) Predicate predicate) throws BaseException {
    return pubService.getGroupTree(predicate);
}
 
Example 19
Source Project: SuperBoot   Source File: SysMenuController.java    License: MIT License 4 votes vote down vote up
@ApiOperation(value = "获取菜单总数", notes = "获取菜单总数,系统管理员默认可以访问")
@RequestMapping(value = "/count", method = RequestMethod.GET)
public BaseResponse<ResCount> getCount(@QuerydslPredicate(root = SuperbootMenu.class) Predicate predicate) throws BaseException {
    return menuService.getCount(-1, predicate);
}
 
Example 20
Source Project: SuperBoot   Source File: SysRoleController.java    License: MIT License 4 votes vote down vote up
@ApiOperation(value = "获取记录总数", notes = "获取全部角色,系统管理员默认可以访问")
@RequestMapping(value = "/count", method = RequestMethod.GET)
public BaseResponse<ResCount> getCount(@QuerydslPredicate(root = SuperbootRole.class) Predicate predicate) throws BaseException {
    return roleService.getCount(-1, predicate);
}
 
Example 21
Source Project: SuperBoot   Source File: SysRoleController.java    License: MIT License 4 votes vote down vote up
@ApiOperation(value = "获取全部角色", notes = "获取全部角色多用于下拉,系统管理员默认可以访问")
@RequestMapping(value = "/all", method = RequestMethod.GET)
public BaseResponse<List<ResRole>> getAll(@QuerydslPredicate(root = SuperbootRole.class) Predicate predicate) throws BaseException {
    return roleService.getRoleAll(-1, predicate);
}
 
Example 22
Source Project: SuperBoot   Source File: SysGroupController.java    License: MIT License 4 votes vote down vote up
@ApiOperation(value = "获取组织记录总数", notes = "获取组织记录总数,系统管理员默认可以访问")
@RequestMapping(value = "/count", method = RequestMethod.GET)
public BaseResponse<ResCount> getGroupCount(@QuerydslPredicate(root = SuperbootGroup.class) Predicate predicate) throws BaseException {
    return groupService.getGroupCount(predicate);
}
 
Example 23
Source Project: SuperBoot   Source File: SysUserController.java    License: MIT License 4 votes vote down vote up
@ApiOperation(value = "获取用户信息", notes = "获取系统用户信息,系统管理员默认可以访问")
@RequestMapping(value = "/count", method = RequestMethod.GET)
public BaseResponse<ResCount> getCount(@QuerydslPredicate(root = SuperbootUser.class) Predicate user, @QuerydslPredicate(root = SuperbootRole.class) Predicate role, @QuerydslPredicate(root = SuperbootGroup.class) Predicate group) throws BaseException {
    return userService.getUserCount(user, role, group);
}
 
Example 24
Source Project: SuperBoot   Source File: SysLogController.java    License: MIT License 4 votes vote down vote up
@ApiOperation(value = "获取日志记录数", notes = "获取日志记录数,系统管理员默认可以访问")
@RequestMapping(value = "/count", method = RequestMethod.GET)
public BaseResponse<ResCount> getLogCount(@QuerydslPredicate(root = DataInfo.class) Predicate predicate) throws BaseException {
    return service.getLogCount(predicate);
}
 
Example 25
Source Project: SuperBoot   Source File: SysErrLogController.java    License: MIT License 4 votes vote down vote up
@ApiOperation(value = "获取日志记录数", notes = "获取日志记录数,系统管理员默认可以访问")
@RequestMapping(value = "/count", method = RequestMethod.GET)
public BaseResponse<ResCount> getErrorLogCount(@QuerydslPredicate(root = ErrorInfo.class) Predicate predicate) throws BaseException {
    return service.getErrorLogCount(predicate);
}
 
Example 26
Source Project: tutorials   Source File: QueryController.java    License: MIT License 4 votes vote down vote up
@GetMapping(value = "/users", produces = MediaType.APPLICATION_JSON_VALUE)
public Iterable<User> queryOverUser(@QuerydslPredicate(root = User.class) Predicate predicate) {
    final BooleanBuilder builder = new BooleanBuilder();
    return personRepository.findAll(builder.and(predicate));
}
 
Example 27
Source Project: tutorials   Source File: QueryController.java    License: MIT License 4 votes vote down vote up
@GetMapping(value = "/addresses", produces = MediaType.APPLICATION_JSON_VALUE)
public Iterable<Address> queryOverAddress(@QuerydslPredicate(root = Address.class) Predicate predicate) {
    final BooleanBuilder builder = new BooleanBuilder();
    return addressRepository.findAll(builder.and(predicate));
}
 
Example 28
Source Project: tutorials   Source File: UserController.java    License: MIT License 4 votes vote down vote up
@RequestMapping(method = RequestMethod.GET, value = "/api/myusers")
@ResponseBody
public Iterable<MyUser> findAllByWebQuerydsl(@QuerydslPredicate(root = MyUser.class) Predicate predicate) {
    return myUserRepository.findAll(predicate);
}
 
Example 29
Source Project: tutorials   Source File: UserController.java    License: MIT License 4 votes vote down vote up
@GetMapping("/filteredusers")
public Iterable<User> getUsersByQuerydslPredicate(@QuerydslPredicate(root = User.class) Predicate predicate) {
    return userRepository.findAll(predicate);
}