use of io.gravitee.am.repository.jdbc.common.dialect.ScimUserSearch in project gravitee-access-management by gravitee-io.
the class JdbcOrganizationUserRepository method search.
@Override
public Single<Page<User>> search(ReferenceType referenceType, String referenceId, FilterCriteria criteria, int page, int size) {
LOGGER.debug("search({}, {}, {}, {}, {})", referenceType, referenceId, criteria, page, size);
StringBuilder queryBuilder = new StringBuilder();
queryBuilder.append(" FROM organization_users WHERE reference_id = :refId AND reference_type = :refType AND ");
ScimUserSearch search = this.databaseDialectHelper.prepareScimSearchUserQuery(queryBuilder, criteria, page, size);
// execute query
org.springframework.r2dbc.core.DatabaseClient.GenericExecuteSpec executeSelect = template.getDatabaseClient().sql(search.getSelectQuery()).bind("refType", referenceType.name()).bind("refId", referenceId);
for (Map.Entry<String, Object> entry : search.getBinding().entrySet()) {
executeSelect = executeSelect.bind(entry.getKey(), entry.getValue());
}
Flux<JdbcOrganizationUser> userFlux = executeSelect.map(row -> rowMapper.read(JdbcOrganizationUser.class, row)).all();
// execute count to provide total in the Page
org.springframework.r2dbc.core.DatabaseClient.GenericExecuteSpec executeCount = template.getDatabaseClient().sql(search.getCountQuery());
executeCount = executeCount.bind("refType", referenceType.name()).bind("refId", referenceId);
for (Map.Entry<String, Object> entry : search.getBinding().entrySet()) {
executeCount = executeCount.bind(entry.getKey(), entry.getValue());
}
Mono<Long> userCount = executeCount.map(row -> row.get(0, Long.class)).first();
return fluxToFlowable(userFlux).map(this::toEntity).flatMap(user -> completeUser(user).toFlowable()).toList().flatMap(list -> monoToSingle(userCount).map(total -> new Page<User>(list, page, total)));
}
use of io.gravitee.am.repository.jdbc.common.dialect.ScimUserSearch in project gravitee-access-management by gravitee-io.
the class JdbcUserRepository method search.
@Override
public Single<Page<User>> search(ReferenceType referenceType, String referenceId, FilterCriteria criteria, int page, int size) {
LOGGER.debug("search({}, {}, {}, {}, {})", referenceType, referenceId, criteria, page, size);
StringBuilder queryBuilder = new StringBuilder();
queryBuilder.append(" FROM users WHERE reference_id = :refId AND reference_type = :refType AND ");
ScimUserSearch search = this.databaseDialectHelper.prepareScimSearchUserQuery(queryBuilder, criteria, page, size);
// execute query
org.springframework.r2dbc.core.DatabaseClient.GenericExecuteSpec executeSelect = template.getDatabaseClient().sql(search.getSelectQuery());
executeSelect = executeSelect.bind("refType", referenceType.name()).bind("refId", referenceId);
for (Map.Entry<String, Object> entry : search.getBinding().entrySet()) {
executeSelect = executeSelect.bind(entry.getKey(), entry.getValue());
}
Flux<JdbcUser> userFlux = executeSelect.map(row -> rowMapper.read(JdbcUser.class, row)).all();
// execute count to provide total in the Page
org.springframework.r2dbc.core.DatabaseClient.GenericExecuteSpec executeCount = template.getDatabaseClient().sql(search.getCountQuery());
executeCount = executeCount.bind("refType", referenceType.name()).bind("refId", referenceId);
for (Map.Entry<String, Object> entry : search.getBinding().entrySet()) {
executeCount = executeCount.bind(entry.getKey(), entry.getValue());
}
Mono<Long> userCount = executeCount.map(row -> row.get(0, Long.class)).first();
return fluxToFlowable(userFlux).map(this::toEntity).flatMap(user -> completeUser(user).toFlowable()).toList().flatMap(list -> monoToSingle(userCount).map(total -> new Page<User>(list, page, total)));
}
Aggregations