Search in sources :

Example 21 with JsonView

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

the class MongoViewDaoTest method testUpdateViewPermissions.

@Test
public void testUpdateViewPermissions() {
    JsonView view = prepareView();
    viewDao.databaseCollection().insertOne(view);
    String id = view.getId();
    assertThat(id).isNotNull().isNotEmpty();
    view.getPermissions().removeUserPermission(USER);
    view.getPermissions().updateGroupPermissions(GROUP_PERMISSION);
    viewDao.updateView(id, view);
    View storedView = viewDao.databaseCollection().find(MongoFilters.idFilter(id)).first();
    assertThat(storedView).isNotNull();
    assertThat(storedView.getPermissions().getUserPermissions()).isEmpty();
    assertThat(storedView.getPermissions().getGroupPermissions()).containsExactly(GROUP_PERMISSION);
}
Also used : JsonView(io.lumeer.api.dto.JsonView) JsonView(io.lumeer.api.dto.JsonView) View(io.lumeer.api.model.View) Test(org.junit.Test)

Example 22 with JsonView

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

the class MongoViewDao method updateView.

@Override
public View updateView(final String id, final View view) {
    JsonView jsonView = new JsonView(view);
    FindOneAndReplaceOptions options = new FindOneAndReplaceOptions().returnDocument(ReturnDocument.AFTER);
    try {
        View updatedView = databaseCollection().findOneAndReplace(idFilter(id), jsonView, options);
        if (updatedView == null) {
            throw new StorageException("View '" + view.getId() + "' has not been updated.");
        }
        return updatedView;
    } catch (MongoException ex) {
        throw new StorageException("Cannot update view: " + view, ex);
    }
}
Also used : FindOneAndReplaceOptions(com.mongodb.client.model.FindOneAndReplaceOptions) MongoException(com.mongodb.MongoException) JsonView(io.lumeer.api.dto.JsonView) JsonView(io.lumeer.api.dto.JsonView) View(io.lumeer.api.model.View) StorageException(io.lumeer.storage.api.exception.StorageException)

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