Search in sources :

Example 1 with Page

use of io.gravitee.am.model.common.Page in project gravitee-access-management by gravitee-io.

the class RolesResourceTest method shouldSearchRoles.

@Test
public void shouldSearchRoles() {
    final String domainId = "domain-1";
    final Domain mockDomain = new Domain();
    mockDomain.setId(domainId);
    final Role mockRole = new Role();
    mockRole.setId("role-1-id");
    mockRole.setName("role-1-name");
    mockRole.setReferenceId(domainId);
    final Role mockRole2 = new Role();
    mockRole2.setId("role-2-id");
    mockRole2.setName("role-2-name");
    mockRole2.setReferenceId(domainId);
    final Set<Role> roles = new HashSet<>(Arrays.asList(mockRole, mockRole2));
    final Page<Role> pagedRoles = new Page<>(roles, 0, 2);
    doReturn(Maybe.just(mockDomain)).when(domainService).findById(domainId);
    doReturn(Single.just(roles)).when(roleService).findByDomain(domainId);
    doReturn(Single.just(pagedRoles)).when(roleService).searchByDomain(domainId, "*role-2-name*", 0, 50);
    final Response response = target("domains").path(domainId).path("roles").queryParam("q", "*role-2-name*").request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    JsonArray pageArray = new JsonObject(readEntity(response, String.class)).getJsonArray("data");
    assertTrue(pageArray.size() == 2);
}
Also used : Role(io.gravitee.am.model.Role) NewRole(io.gravitee.am.service.model.NewRole) Response(javax.ws.rs.core.Response) JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) Page(io.gravitee.am.model.common.Page) Domain(io.gravitee.am.model.Domain) HashSet(java.util.HashSet) Test(org.junit.Test) JerseySpringTest(io.gravitee.am.management.handlers.management.api.JerseySpringTest)

Example 2 with Page

use of io.gravitee.am.model.common.Page in project gravitee-access-management by gravitee-io.

the class RolesResourceTest method shouldGetRoles.

@Test
public void shouldGetRoles() {
    final String domainId = "domain-1";
    final Domain mockDomain = new Domain();
    mockDomain.setId(domainId);
    final Role mockRole = new Role();
    mockRole.setId("role-1-id");
    mockRole.setName("role-1-name");
    mockRole.setReferenceId(domainId);
    final Role mockRole2 = new Role();
    mockRole2.setId("role-2-id");
    mockRole2.setName("role-2-name");
    mockRole2.setReferenceId(domainId);
    final Set<Role> roles = new HashSet<>(Arrays.asList(mockRole, mockRole2));
    final Page<Role> pagedRoles = new Page<>(roles, 0, 2);
    doReturn(Maybe.just(mockDomain)).when(domainService).findById(domainId);
    doReturn(Single.just(pagedRoles)).when(roleService).findByDomain(domainId, 0, 50);
    final Response response = target("domains").path(domainId).path("roles").request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    JsonArray pageArray = new JsonObject(readEntity(response, String.class)).getJsonArray("data");
    assertTrue(pageArray.size() == 2);
}
Also used : Role(io.gravitee.am.model.Role) NewRole(io.gravitee.am.service.model.NewRole) Response(javax.ws.rs.core.Response) JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) Page(io.gravitee.am.model.common.Page) Domain(io.gravitee.am.model.Domain) HashSet(java.util.HashSet) Test(org.junit.Test) JerseySpringTest(io.gravitee.am.management.handlers.management.api.JerseySpringTest)

Example 3 with Page

use of io.gravitee.am.model.common.Page in project gravitee-access-management by gravitee-io.

the class ScopesResourceTest method shouldGetScopes.

@Test
public void shouldGetScopes() {
    final String domainId = "domain-1";
    final Scope mockScope = new Scope();
    mockScope.setId("scope-1-id");
    mockScope.setKey("scope-1-id");
    mockScope.setName("scope-1-name");
    mockScope.setDomain(domainId);
    final Scope mockScope2 = new Scope();
    mockScope2.setId("scope-2-id");
    mockScope2.setKey("scope-2-id");
    mockScope2.setName("scope-2-name");
    mockScope2.setDomain(domainId);
    final Set<Scope> scopes = new HashSet<>(Arrays.asList(mockScope, mockScope2));
    doReturn(Single.just(new Page<>(scopes, 0, 2))).when(scopeService).findByDomain(domainId, 0, 50);
    final Response response = target("domains").path(domainId).path("scopes").request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    String body = response.readEntity(String.class);
    JsonArray data = new JsonObject(body).getJsonArray("data");
    assertTrue(data.size() == 2);
}
Also used : Response(javax.ws.rs.core.Response) JsonArray(io.vertx.core.json.JsonArray) NewScope(io.gravitee.am.service.model.NewScope) Scope(io.gravitee.am.model.oauth2.Scope) JsonObject(io.vertx.core.json.JsonObject) Page(io.gravitee.am.model.common.Page) HashSet(java.util.HashSet) Test(org.junit.Test) JerseySpringTest(io.gravitee.am.management.handlers.management.api.JerseySpringTest)

Example 4 with Page

use of io.gravitee.am.model.common.Page in project gravitee-access-management by gravitee-io.

the class UsersResourceTest method shouldGetUsers.

@Test
public void shouldGetUsers() {
    final String domainId = "domain-1";
    final Domain mockDomain = new Domain();
    mockDomain.setId(domainId);
    final User mockUser = new User();
    mockUser.setId("user-id-1");
    mockUser.setUsername("username-1");
    mockUser.setReferenceType(ReferenceType.DOMAIN);
    mockUser.setReferenceId(domainId);
    final User mockUser2 = new User();
    mockUser2.setId("domain-id-2");
    mockUser2.setUsername("username-2");
    mockUser2.setReferenceType(ReferenceType.DOMAIN);
    mockUser2.setReferenceId(domainId);
    final Set<User> users = new HashSet<>(Arrays.asList(mockUser, mockUser2));
    final Page<User> pagedUsers = new Page<>(users, 0, 2);
    doReturn(Maybe.just(mockDomain)).when(domainService).findById(domainId);
    doReturn(Single.just(pagedUsers)).when(userService).findAll(ReferenceType.DOMAIN, domainId, 0, 10);
    final Response response = target("domains").path(domainId).path("users").queryParam("page", 0).queryParam("size", 10).request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) NewUser(io.gravitee.am.service.model.NewUser) Page(io.gravitee.am.model.common.Page) HashSet(java.util.HashSet) Test(org.junit.Test) JerseySpringTest(io.gravitee.am.management.handlers.management.api.JerseySpringTest)

Example 5 with Page

use of io.gravitee.am.model.common.Page 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)

Aggregations

Page (io.gravitee.am.model.common.Page)68 Test (org.junit.Test)51 User (io.gravitee.am.model.User)29 AbstractManagementTest (io.gravitee.am.repository.management.AbstractManagementTest)26 FilterCriteria (io.gravitee.am.repository.management.api.search.FilterCriteria)16 Autowired (org.springframework.beans.factory.annotation.Autowired)14 Maybe (io.reactivex.Maybe)12 Single (io.reactivex.Single)12 ReferenceType (io.gravitee.am.model.ReferenceType)11 Flowable (io.reactivex.Flowable)11 Response (javax.ws.rs.core.Response)11 Domain (io.gravitee.am.model.Domain)10 List (java.util.List)10 Application (io.gravitee.am.model.Application)9 Scope (io.gravitee.am.model.oauth2.Scope)8 Completable (io.reactivex.Completable)8 LocalDateTime (java.time.LocalDateTime)8 InitializingBean (org.springframework.beans.factory.InitializingBean)8 Criteria.where (org.springframework.data.relational.core.query.Criteria.where)8 Query (org.springframework.data.relational.core.query.Query)8