Search in sources :

Example 6 with MorphiaView

use of io.lumeer.storage.mongodb.model.MorphiaView in project engine by Lumeer.

the class MorphiaViewDaoTest method testGetViewsPagination.

@Test
public void testGetViewsPagination() {
    MorphiaView view = prepareView();
    datastore.save(viewDao.databaseCollection(), view);
    MorphiaView view2 = prepareView();
    view2.setCode(CODE2);
    view2.setName(NAME2);
    datastore.save(viewDao.databaseCollection(), view2);
    SearchQuery query = SearchQuery.createBuilder(USER).page(1).pageSize(1).build();
    List<View> views = viewDao.getViews(query);
    assertThat(views).extracting(View::getCode).containsOnly(CODE2);
}
Also used : SearchQuery(io.lumeer.storage.api.query.SearchQuery) MorphiaView(io.lumeer.storage.mongodb.model.MorphiaView) View(io.lumeer.api.model.View) MorphiaView(io.lumeer.storage.mongodb.model.MorphiaView) Test(org.junit.Test)

Example 7 with MorphiaView

use of io.lumeer.storage.mongodb.model.MorphiaView in project engine by Lumeer.

the class MorphiaViewDao method updateView.

public View updateView(final String id, final View view) {
    MorphiaView morphiaView = new MorphiaView(view);
    morphiaView.setId(id);
    datastore.save(databaseCollection(), morphiaView);
    return morphiaView;
}
Also used : MorphiaView(io.lumeer.storage.mongodb.model.MorphiaView)

Example 8 with MorphiaView

use of io.lumeer.storage.mongodb.model.MorphiaView in project engine by Lumeer.

the class MorphiaViewDaoTest method testCreateViewExistingName.

@Test
public void testCreateViewExistingName() {
    MorphiaView view = prepareView();
    datastore.save(viewDao.databaseCollection(), view);
    MorphiaView view2 = prepareView();
    view2.setCode(CODE2);
    assertThatThrownBy(() -> viewDao.createView(view2)).isInstanceOf(DuplicateKeyException.class);
}
Also used : MorphiaView(io.lumeer.storage.mongodb.model.MorphiaView) Test(org.junit.Test)

Example 9 with MorphiaView

use of io.lumeer.storage.mongodb.model.MorphiaView in project engine by Lumeer.

the class MorphiaViewDaoTest method testGetViewsNoReadRole.

@Test
public void testGetViewsNoReadRole() {
    MorphiaView view = prepareView();
    Permission userPermission = new MorphiaPermission(USER2, Collections.singleton(Role.CLONE.toString()));
    view.getPermissions().updateUserPermissions(userPermission);
    datastore.save(viewDao.databaseCollection(), view);
    MorphiaView view2 = prepareView();
    view2.setCode(CODE2);
    view2.setName(NAME2);
    Permission groupPermission = new MorphiaPermission(GROUP2, Collections.singleton(Role.SHARE.toString()));
    view2.getPermissions().updateGroupPermissions(groupPermission);
    datastore.save(viewDao.databaseCollection(), view2);
    SearchQuery query = SearchQuery.createBuilder(USER2).groups(Collections.singleton(GROUP2)).build();
    List<View> views = viewDao.getViews(query);
    assertThat(views).isEmpty();
}
Also used : SearchQuery(io.lumeer.storage.api.query.SearchQuery) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) MorphiaView(io.lumeer.storage.mongodb.model.MorphiaView) Permission(io.lumeer.api.model.Permission) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) View(io.lumeer.api.model.View) MorphiaView(io.lumeer.storage.mongodb.model.MorphiaView) Test(org.junit.Test)

Example 10 with MorphiaView

use of io.lumeer.storage.mongodb.model.MorphiaView in project engine by Lumeer.

the class MorphiaViewDaoTest method testUpdateViewPermissions.

@Test
public void testUpdateViewPermissions() {
    MorphiaView view = prepareView();
    String id = datastore.save(viewDao.databaseCollection(), view).getId().toString();
    assertThat(id).isNotNull().isNotEmpty();
    view.getPermissions().removeUserPermission(USER);
    view.getPermissions().updateGroupPermissions(GROUP_PERMISSION);
    viewDao.updateView(id, view);
    MorphiaView storedView = datastore.get(viewDao.databaseCollection(), MorphiaView.class, new ObjectId(id));
    assertThat(storedView).isNotNull();
    assertThat(storedView.getPermissions().getUserPermissions()).isEmpty();
    assertThat(storedView.getPermissions().getGroupPermissions()).containsExactly(GROUP_PERMISSION);
}
Also used : ObjectId(org.bson.types.ObjectId) MorphiaView(io.lumeer.storage.mongodb.model.MorphiaView) Test(org.junit.Test)

Aggregations

MorphiaView (io.lumeer.storage.mongodb.model.MorphiaView)17 Test (org.junit.Test)11 View (io.lumeer.api.model.View)4 SearchQuery (io.lumeer.storage.api.query.SearchQuery)4 ObjectId (org.bson.types.ObjectId)3 ArrayList (java.util.ArrayList)2 FindOptions (org.mongodb.morphia.query.FindOptions)2 Permission (io.lumeer.api.model.Permission)1 MorphiaPermission (io.lumeer.storage.mongodb.model.embedded.MorphiaPermission)1 MorphiaPermissions (io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions)1