Java Code Examples for com.querydsl.core.BooleanBuilder#or()

The following examples show how to use com.querydsl.core.BooleanBuilder#or() . 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
Source File: QueryDslRepositorySupportExt.java    From springlets with Apache License 2.0 6 votes vote down vote up
/**
 * Adds a global contains text filter on the provided attributes.
 * WARNING: this creates a very inefficient query. If you have many entity
 * instances to query, use instead an indexed text search solution for better
 * performance.
 * @param text the text to look for
 * @param query
 * @param globalSearchAttributes the list of attributes to perform the
 *        filter on
 * @return the updated query
 */
protected JPQLQuery<T> applyGlobalSearch(String text, JPQLQuery<T> query,
    Path<?>... globalSearchAttributes) {
  if (text != null && !StringUtils.isEmpty(text) && globalSearchAttributes.length > 0) {
    BooleanBuilder searchCondition = new BooleanBuilder();
    for (int i = 0; i < globalSearchAttributes.length; i++) {
      Path<?> path = globalSearchAttributes[i];
      if (path instanceof StringPath) {
        StringPath stringPath = (StringPath) path;
        searchCondition.or(stringPath.containsIgnoreCase(text));
      } else if (path instanceof NumberExpression) {
        searchCondition.or(((NumberExpression<?>) path).like("%".concat(text).concat("%")));
      }
    }
    return query.where(searchCondition);
  }
  return query;
}
 
Example 2
Source File: UserService.java    From eds-starter6-jpa with Apache License 2.0 6 votes vote down vote up
@ExtDirectMethod(STORE_READ)
@Transactional(readOnly = true)
public ExtDirectStoreResult<User> read(ExtDirectStoreReadRequest request) {

	JPQLQuery<User> query = this.jpaQueryFactory.selectFrom(QUser.user);
	if (!request.getFilters().isEmpty()) {
		StringFilter filter = (StringFilter) request.getFilters().iterator().next();

		BooleanBuilder bb = new BooleanBuilder();
		bb.or(QUser.user.loginName.containsIgnoreCase(filter.getValue()));
		bb.or(QUser.user.lastName.containsIgnoreCase(filter.getValue()));
		bb.or(QUser.user.firstName.containsIgnoreCase(filter.getValue()));
		bb.or(QUser.user.email.containsIgnoreCase(filter.getValue()));

		query.where(bb);
	}
	query.where(QUser.user.deleted.isFalse());

	QuerydslUtil.addPagingAndSorting(query, request, User.class, QUser.user);
	QueryResults<User> searchResult = query.fetchResults();

	return new ExtDirectStoreResult<>(searchResult.getTotal(),
			searchResult.getResults());
}
 
Example 3
Source File: UserService.java    From eds-starter6-jpa with Apache License 2.0 6 votes vote down vote up
private boolean isLastAdmin(Long id) {
	JPAQuery<Integer> query = this.jpaQueryFactory.select(Expressions.ONE)
			.from(QUser.user);
	BooleanBuilder bb = new BooleanBuilder();
	bb.or(QUser.user.authorities.eq(Authority.ADMIN.name()));
	bb.or(QUser.user.authorities.endsWith("," + Authority.ADMIN.name()));
	bb.or(QUser.user.authorities.contains("," + Authority.ADMIN.name() + ","));
	bb.or(QUser.user.authorities.startsWith(Authority.ADMIN.name() + ","));

	query.where(QUser.user.id.ne(id).and(QUser.user.deleted.isFalse())
			.and(QUser.user.enabled.isTrue()).and(bb));
	return query.fetchFirst() == null;
}
 
Example 4
Source File: NasService.java    From radman with MIT License 5 votes vote down vote up
private Predicate buildNasSearchPredicate(@Nullable String searchText) {
    BooleanBuilder booleanBuilder = new BooleanBuilder();
    if (!StringUtils.isEmpty(searchText)) {
        booleanBuilder.or(QNas.nas.nasName.contains(searchText));
        booleanBuilder.or(QNas.nas.shortName.contains(searchText));
        booleanBuilder.or(QNas.nas.description.contains(searchText));
        booleanBuilder.or(QNas.nas.ports.like(searchText));
        booleanBuilder.or(QNas.nas.secret.contains(searchText));
        booleanBuilder.or(QNas.nas.server.contains(searchText));
        booleanBuilder.or(QNas.nas.type.contains(searchText));
    }
    return booleanBuilder.getValue();
}
 
Example 5
Source File: NasService.java    From radman with MIT License 5 votes vote down vote up
private Predicate buildNasGroupSearchPredicate(@Nullable String searchText) {
    BooleanBuilder booleanBuilder = new BooleanBuilder();
    if (!StringUtils.isEmpty(searchText)) {
        booleanBuilder.or(QRadHuntGroup.radHuntGroup.groupName.contains(searchText));
        booleanBuilder.or(QRadHuntGroup.radHuntGroup.nasIpAddress.contains(searchText));
        booleanBuilder.or(QRadHuntGroup.radHuntGroup.nasPortId.contains(searchText));
    }
    return booleanBuilder;
}
 
Example 6
Source File: AttributeService.java    From radman with MIT License 5 votes vote down vote up
private Predicate buildAuthenticationAttributeSearchPredicate(AttributeFilter filter) {
    BooleanBuilder booleanBuilder = new BooleanBuilder();
    if (!StringUtils.isEmpty(filter.getSearchText())) {
        if (filter.isSearchByName()) {
            booleanBuilder.or(QRadCheckAttribute.radCheckAttribute.name.contains(filter.getSearchText()));
        }
        if (filter.isSearchByDescription()) {
            booleanBuilder.or(QRadCheckAttribute.radCheckAttribute.description.contains(filter.getSearchText()));
        }
    }
    return booleanBuilder;
}
 
Example 7
Source File: AttributeService.java    From radman with MIT License 5 votes vote down vote up
private Predicate buildAuthorizationAttributeSearchPredicate(AttributeFilter filter) {
    BooleanBuilder booleanBuilder = new BooleanBuilder();
    if (!StringUtils.isEmpty(filter.getSearchText())) {
        if (filter.isSearchByName()) {
            booleanBuilder.or(QRadReplyAttribute.radReplyAttribute.name.contains(filter.getSearchText()));
        }
        if (filter.isSearchByDescription()) {
            booleanBuilder.or(QRadReplyAttribute.radReplyAttribute.description.contains(filter.getSearchText()));
        }
    }
    return booleanBuilder;
}
 
Example 8
Source File: RadiusUserService.java    From radman with MIT License 5 votes vote down vote up
private Predicate buildRadiusUserSearchPredicate(RadiusUserFilter filter) {
    BooleanBuilder booleanBuilder = new BooleanBuilder();
    if (!StringUtils.isEmpty(filter.getSearchText())) {
        if (filter.isSearchByName()) {
            booleanBuilder.or(QRadiusUser.radiusUser.username.contains(filter.getSearchText()));
        }
        if (filter.isSearchByDescription()) {
            booleanBuilder.or(QRadiusUser.radiusUser.description.contains(filter.getSearchText()));
        }
    }
    return booleanBuilder;
}
 
Example 9
Source File: RadiusUserService.java    From radman with MIT License 5 votes vote down vote up
private Predicate buildRadiusGroupSearchPredicate(RadiusGroupFilter filter) {
    BooleanBuilder booleanBuilder = new BooleanBuilder();
    if (!StringUtils.isEmpty(filter.getSearchText())) {
        if (filter.isSearchByGroupName()) {
            booleanBuilder.or(QRadiusGroup.radiusGroup.name.contains(filter.getSearchText()));
        }
        if (filter.isSearchByDescription()) {
            booleanBuilder.or(QRadiusGroup.radiusGroup.description.contains(filter.getSearchText()));
        }
    }
    return booleanBuilder;
}
 
Example 10
Source File: RadiusUserService.java    From radman with MIT License 5 votes vote down vote up
private Predicate buildRadiusUserToGroupSearchPredicate(Filter filter) {
    BooleanBuilder booleanBuilder = new BooleanBuilder();
    if (!StringUtils.isEmpty(filter.getSearchText())) {
        booleanBuilder.or(QRadUserGroup.radUserGroup.username.contains(filter.getSearchText()));
        booleanBuilder.or(QRadUserGroup.radUserGroup.groupName.contains(filter.getSearchText()));
    }
    return booleanBuilder;
}
 
Example 11
Source File: SystemUserService.java    From radman with MIT License 5 votes vote down vote up
private Predicate buildSystemUserSearchPredicate(@Nullable String searchText) {
    BooleanBuilder booleanBuilder = new BooleanBuilder();
    if (!StringUtils.isEmpty(searchText)) {
        booleanBuilder.or(QSystemUser.systemUser.username.contains(searchText));
        booleanBuilder.or(QSystemUser.systemUser.role.stringValue().contains(searchText));
    }
    return booleanBuilder;
}
 
Example 12
Source File: AccountingService.java    From radman with MIT License 5 votes vote down vote up
private Predicate buildAccountingSearchPredicate(@NonNull AccountingFilter filter) {
    BooleanBuilder booleanBuilder = new BooleanBuilder();
    if (!(StringUtils.isEmpty(filter.getSearchText()))) {
        booleanBuilder.or(QRadAcct.radAcct.acctSessionId.contains(filter.getSearchText()));
        booleanBuilder.or(QRadAcct.radAcct.acctUniqueId.contains(filter.getSearchText()));
        booleanBuilder.or(QRadAcct.radAcct.username.contains(filter.getSearchText()));
        booleanBuilder.or(QRadAcct.radAcct.realm.contains(filter.getSearchText()));
        booleanBuilder.or(QRadAcct.radAcct.nasIpAddress.contains(filter.getSearchText()));
        booleanBuilder.or(QRadAcct.radAcct.nasPortId.contains(filter.getSearchText()));
        booleanBuilder.or(QRadAcct.radAcct.nasPortType.contains(filter.getSearchText()));
        booleanBuilder.or(QRadAcct.radAcct.acctInterval.stringValue().contains(filter.getSearchText()));
        booleanBuilder.or(QRadAcct.radAcct.acctSessionTime.stringValue().contains(filter.getSearchText()));
        booleanBuilder.or(QRadAcct.radAcct.acctAuthentic.contains(filter.getSearchText()));
        booleanBuilder.or(QRadAcct.radAcct.connectInfoStart.contains(filter.getSearchText()));
        booleanBuilder.or(QRadAcct.radAcct.connectInfoStop.contains(filter.getSearchText()));
        booleanBuilder.or(QRadAcct.radAcct.acctInputOctets.stringValue().contains(filter.getSearchText()));
        booleanBuilder.or(QRadAcct.radAcct.acctOutputOctets.stringValue().contains(filter.getSearchText()));
        booleanBuilder.or(QRadAcct.radAcct.calledStationId.contains(filter.getSearchText()));
        booleanBuilder.or(QRadAcct.radAcct.callingStationId.contains(filter.getSearchText()));
        booleanBuilder.or(QRadAcct.radAcct.acctTerminateCause.contains(filter.getSearchText()));
        booleanBuilder.or(QRadAcct.radAcct.serviceType.contains(filter.getSearchText()));
        booleanBuilder.or(QRadAcct.radAcct.framedProtocol.contains(filter.getSearchText()));
        booleanBuilder.or(QRadAcct.radAcct.framedIpAddress.contains(filter.getSearchText()));
    }
    if (filter.isSearchOnlyActiveSessions()) {
        booleanBuilder.and(QRadAcct.radAcct.acctStartTime.isNotNull());
        booleanBuilder.and(QRadAcct.radAcct.acctStopTime.isNull());
    }
    return booleanBuilder.getValue();
}