Search in sources :

Example 1 with ScimUserSearch

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)));
}
Also used : ScimUserSearch(io.gravitee.am.repository.jdbc.common.dialect.ScimUserSearch) Address(io.gravitee.am.model.scim.Address) FilterCriteria(io.gravitee.am.repository.management.api.search.FilterCriteria) Completable(io.reactivex.Completable) Maybe(io.reactivex.Maybe) Query(org.springframework.data.relational.core.query.Query) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) Criteria.where(org.springframework.data.relational.core.query.Criteria.where) Single(io.reactivex.Single) InitializingBean(org.springframework.beans.factory.InitializingBean) DatabaseClient(org.springframework.r2dbc.core.DatabaseClient) OrganizationUserRepository(io.gravitee.am.repository.management.api.OrganizationUserRepository) AbstractJdbcRepository(io.gravitee.am.repository.jdbc.management.AbstractJdbcRepository) io.gravitee.am.repository.jdbc.management.api.spring.user(io.gravitee.am.repository.jdbc.management.api.spring.user) Attribute(io.gravitee.am.model.scim.Attribute) Flowable(io.reactivex.Flowable) Map(java.util.Map) ReferenceType(io.gravitee.am.model.ReferenceType) Sort(org.springframework.data.domain.Sort) Stream.concat(java.util.stream.Stream.concat) User(io.gravitee.am.model.User) Repository(org.springframework.stereotype.Repository) StreamUtils(org.springframework.data.util.StreamUtils) Page(io.gravitee.am.model.common.Page) TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) PageRequest(org.springframework.data.domain.PageRequest) Mono(reactor.core.publisher.Mono) RandomString(io.gravitee.am.common.utils.RandomString) Flux(reactor.core.publisher.Flux) List(java.util.List) Stream(java.util.stream.Stream) RxJava2Adapter(reactor.adapter.rxjava.RxJava2Adapter) JdbcOrganizationUser(io.gravitee.am.repository.jdbc.management.api.model.JdbcOrganizationUser) Optional(java.util.Optional) ScimUserSearch(io.gravitee.am.repository.jdbc.common.dialect.ScimUserSearch) Page(io.gravitee.am.model.common.Page) RandomString(io.gravitee.am.common.utils.RandomString) DatabaseClient(org.springframework.r2dbc.core.DatabaseClient) JdbcOrganizationUser(io.gravitee.am.repository.jdbc.management.api.model.JdbcOrganizationUser) Map(java.util.Map)

Example 2 with ScimUserSearch

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)));
}
Also used : DOMAIN(io.gravitee.am.model.ReferenceType.DOMAIN) ScimUserSearch(io.gravitee.am.repository.jdbc.common.dialect.ScimUserSearch) java.util(java.util) Address(io.gravitee.am.model.scim.Address) UserRepository(io.gravitee.am.repository.management.api.UserRepository) FilterCriteria(io.gravitee.am.repository.management.api.search.FilterCriteria) Completable(io.reactivex.Completable) Maybe(io.reactivex.Maybe) Query(org.springframework.data.relational.core.query.Query) LocalDateTime(java.time.LocalDateTime) JdbcUser(io.gravitee.am.repository.jdbc.management.api.model.JdbcUser) Autowired(org.springframework.beans.factory.annotation.Autowired) Criteria.where(org.springframework.data.relational.core.query.Criteria.where) Field(io.gravitee.am.common.analytics.Field) AnalyticsQuery(io.gravitee.am.model.analytics.AnalyticsQuery) AbstractRole(io.gravitee.am.repository.jdbc.management.api.model.JdbcUser.AbstractRole) Single(io.reactivex.Single) InitializingBean(org.springframework.beans.factory.InitializingBean) DatabaseClient(org.springframework.r2dbc.core.DatabaseClient) AbstractJdbcRepository(io.gravitee.am.repository.jdbc.management.AbstractJdbcRepository) io.gravitee.am.repository.jdbc.management.api.spring.user(io.gravitee.am.repository.jdbc.management.api.spring.user) Attribute(io.gravitee.am.model.scim.Attribute) Flowable(io.reactivex.Flowable) ReferenceType(io.gravitee.am.model.ReferenceType) Sort(org.springframework.data.domain.Sort) Stream.concat(java.util.stream.Stream.concat) User(io.gravitee.am.model.User) Repository(org.springframework.stereotype.Repository) StreamUtils(org.springframework.data.util.StreamUtils) Page(io.gravitee.am.model.common.Page) TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) PageRequest(org.springframework.data.domain.PageRequest) Mono(reactor.core.publisher.Mono) RandomString(io.gravitee.am.common.utils.RandomString) Flux(reactor.core.publisher.Flux) ChronoUnit(java.time.temporal.ChronoUnit) Stream(java.util.stream.Stream) RxJava2Adapter(reactor.adapter.rxjava.RxJava2Adapter) UTC(java.time.ZoneOffset.UTC) ScimUserSearch(io.gravitee.am.repository.jdbc.common.dialect.ScimUserSearch) Page(io.gravitee.am.model.common.Page) RandomString(io.gravitee.am.common.utils.RandomString) DatabaseClient(org.springframework.r2dbc.core.DatabaseClient) JdbcUser(io.gravitee.am.repository.jdbc.management.api.model.JdbcUser)

Aggregations

RandomString (io.gravitee.am.common.utils.RandomString)2 ReferenceType (io.gravitee.am.model.ReferenceType)2 User (io.gravitee.am.model.User)2 Page (io.gravitee.am.model.common.Page)2 Address (io.gravitee.am.model.scim.Address)2 Attribute (io.gravitee.am.model.scim.Attribute)2 ScimUserSearch (io.gravitee.am.repository.jdbc.common.dialect.ScimUserSearch)2 AbstractJdbcRepository (io.gravitee.am.repository.jdbc.management.AbstractJdbcRepository)2 io.gravitee.am.repository.jdbc.management.api.spring.user (io.gravitee.am.repository.jdbc.management.api.spring.user)2 FilterCriteria (io.gravitee.am.repository.management.api.search.FilterCriteria)2 Completable (io.reactivex.Completable)2 Flowable (io.reactivex.Flowable)2 Maybe (io.reactivex.Maybe)2 Single (io.reactivex.Single)2 LocalDateTime (java.time.LocalDateTime)2 Stream (java.util.stream.Stream)2 Stream.concat (java.util.stream.Stream.concat)2 InitializingBean (org.springframework.beans.factory.InitializingBean)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 PageRequest (org.springframework.data.domain.PageRequest)2