Search in sources :

Example 11 with JsonView

use of io.lumeer.api.dto.JsonView in project engine by Lumeer.

the class ViewServiceIT method testGetAllViews.

@Test
public void testGetAllViews() {
    createView(CODE);
    createView(CODE2);
    Response response = client.target(VIEWS_URL).request(MediaType.APPLICATION_JSON).buildGet().invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    List<JsonView> views = response.readEntity(new GenericType<List<JsonView>>() {
    });
    assertThat(views).extracting(Resource::getCode).containsOnly(CODE, CODE2);
    Permissions permissions1 = views.get(0).getPermissions();
    assertThat(permissions1).extracting(Permissions::getUserPermissions).containsOnly(Collections.singleton(USER_PERMISSION));
    assertThat(permissions1).extracting(p -> p.getUserPermissions().iterator().next().getRoles()).containsOnly(USER_ROLES);
    assertThat(permissions1).extracting(Permissions::getGroupPermissions).containsOnly(Collections.emptySet());
    Permissions permissions2 = views.get(1).getPermissions();
    assertThat(permissions2).extracting(Permissions::getUserPermissions).containsOnly(Collections.singleton(USER_PERMISSION));
    assertThat(permissions2).extracting(p -> p.getUserPermissions().iterator().next().getRoles()).containsOnly(USER_ROLES);
    assertThat(permissions2).extracting(Permissions::getGroupPermissions).containsOnly(Collections.emptySet());
}
Also used : Response(javax.ws.rs.core.Response) JsonView(io.lumeer.api.dto.JsonView) UserDao(io.lumeer.storage.api.dao.UserDao) Arrays(java.util.Arrays) SoftAssertions(org.assertj.core.api.SoftAssertions) ProjectDao(io.lumeer.storage.api.dao.ProjectDao) Arquillian(org.jboss.arquillian.junit.Arquillian) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JsonPermission(io.lumeer.api.dto.JsonPermission) User(io.lumeer.api.model.User) RunWith(org.junit.runner.RunWith) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) JsonQuery(io.lumeer.api.dto.JsonQuery) Resource(io.lumeer.api.model.Resource) JsonPermissions(io.lumeer.api.dto.JsonPermissions) HashSet(java.util.HashSet) Inject(javax.inject.Inject) OrganizationDao(io.lumeer.storage.api.dao.OrganizationDao) MediaType(javax.ws.rs.core.MediaType) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Role(io.lumeer.api.model.Role) ViewDao(io.lumeer.storage.api.dao.ViewDao) SimplePermission(io.lumeer.core.model.SimplePermission) UriBuilder(javax.ws.rs.core.UriBuilder) MorphiaPermissions(io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions) Organization(io.lumeer.api.model.Organization) Before(org.junit.Before) Permission(io.lumeer.api.model.Permission) View(io.lumeer.api.model.View) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException) Permissions(io.lumeer.api.model.Permissions) MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) AuthenticatedUser(io.lumeer.core.AuthenticatedUser) Set(java.util.Set) Test(org.junit.Test) Entity(javax.ws.rs.client.Entity) GenericType(javax.ws.rs.core.GenericType) Project(io.lumeer.api.model.Project) MorphiaOrganization(io.lumeer.storage.mongodb.model.MorphiaOrganization) List(java.util.List) Response(javax.ws.rs.core.Response) Collections(java.util.Collections) Link(javax.ws.rs.core.Link) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) JsonPermissions(io.lumeer.api.dto.JsonPermissions) MorphiaPermissions(io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions) Permissions(io.lumeer.api.model.Permissions) JsonView(io.lumeer.api.dto.JsonView) List(java.util.List) Test(org.junit.Test)

Example 12 with JsonView

use of io.lumeer.api.dto.JsonView in project engine by Lumeer.

the class ViewService method getViews.

@GET
public List<JsonView> getViews(@QueryParam("page") Integer page, @QueryParam("pageSize") Integer pageSize) {
    Pagination pagination = new Pagination(page, pageSize);
    List<View> views = viewFacade.getViews(pagination);
    return JsonView.convert(views);
}
Also used : Pagination(io.lumeer.api.model.Pagination) JsonView(io.lumeer.api.dto.JsonView) View(io.lumeer.api.model.View) GET(javax.ws.rs.GET)

Example 13 with JsonView

use of io.lumeer.api.dto.JsonView in project engine by Lumeer.

the class ViewService method updateView.

@PUT
@Path("{viewCode}")
public Response updateView(@PathParam("viewCode") String code, JsonView view) {
    View storedView = viewFacade.updateView(code, view);
    JsonView jsonView = new JsonView(storedView);
    return Response.ok(jsonView).build();
}
Also used : JsonView(io.lumeer.api.dto.JsonView) JsonView(io.lumeer.api.dto.JsonView) View(io.lumeer.api.model.View) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 14 with JsonView

use of io.lumeer.api.dto.JsonView in project engine by Lumeer.

the class MongoViewDaoTest method testGetViewsGroupRole.

@Test
public void testGetViewsGroupRole() {
    JsonView view = prepareView();
    viewDao.databaseCollection().insertOne(view);
    JsonView view2 = prepareView();
    view2.setCode(CODE2);
    view2.setName(NAME2);
    viewDao.databaseCollection().insertOne(view2);
    SearchQuery query = SearchQuery.createBuilder(USER2).groups(Collections.singleton(GROUP)).build();
    List<View> views = viewDao.getViews(query);
    assertThat(views).extracting(View::getCode).containsOnly(CODE, CODE2);
}
Also used : SearchQuery(io.lumeer.storage.api.query.SearchQuery) JsonView(io.lumeer.api.dto.JsonView) JsonView(io.lumeer.api.dto.JsonView) View(io.lumeer.api.model.View) Test(org.junit.Test)

Example 15 with JsonView

use of io.lumeer.api.dto.JsonView in project engine by Lumeer.

the class MongoViewDaoTest method testUpdateViewExistingName.

@Test
public void testUpdateViewExistingName() {
    JsonView view = prepareView();
    viewDao.databaseCollection().insertOne(view);
    JsonView view2 = prepareView();
    view2.setCode(CODE2);
    view2.setName(NAME2);
    viewDao.databaseCollection().insertOne(view2);
    view2.setName(NAME);
    assertThatThrownBy(() -> viewDao.updateView(view2.getId(), view2)).isInstanceOf(StorageException.class);
}
Also used : JsonView(io.lumeer.api.dto.JsonView) Test(org.junit.Test)

Aggregations

JsonView (io.lumeer.api.dto.JsonView)22 View (io.lumeer.api.model.View)14 Test (org.junit.Test)14 SearchQuery (io.lumeer.storage.api.query.SearchQuery)4 JsonQuery (io.lumeer.api.dto.JsonQuery)3 MongoException (com.mongodb.MongoException)2 JsonPermissions (io.lumeer.api.dto.JsonPermissions)2 Permission (io.lumeer.api.model.Permission)2 StorageException (io.lumeer.storage.api.exception.StorageException)2 MorphiaPermissions (io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions)2 FindOneAndReplaceOptions (com.mongodb.client.model.FindOneAndReplaceOptions)1 JsonPermission (io.lumeer.api.dto.JsonPermission)1 Organization (io.lumeer.api.model.Organization)1 Pagination (io.lumeer.api.model.Pagination)1 Permissions (io.lumeer.api.model.Permissions)1 Project (io.lumeer.api.model.Project)1 Resource (io.lumeer.api.model.Resource)1 Role (io.lumeer.api.model.Role)1 User (io.lumeer.api.model.User)1 AuthenticatedUser (io.lumeer.core.AuthenticatedUser)1