Search in sources :

Example 6 with JsonView

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

the class MongoViewDaoTest method createView.

private JsonView createView(String code, String name, Set<String> collections) {
    JsonView jsonView = prepareView();
    jsonView.setCode(code);
    jsonView.setName(name);
    jsonView.setQuery(new JsonQuery(collections, null, null));
    viewDao.databaseCollection().insertOne(jsonView);
    return jsonView;
}
Also used : JsonQuery(io.lumeer.api.dto.JsonQuery) JsonView(io.lumeer.api.dto.JsonView)

Example 7 with JsonView

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

the class MongoViewDaoTest method testGetViews.

@Test
public void testGetViews() {
    JsonView view = prepareView();
    viewDao.databaseCollection().insertOne(view);
    JsonView view2 = prepareView();
    view2.setCode(CODE2);
    view2.setName(NAME2);
    viewDao.databaseCollection().insertOne(view2);
    SearchQuery query = SearchQuery.createBuilder(USER).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 8 with JsonView

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

the class MongoViewDaoTest method testGetViewsPagination.

@Test
public void testGetViewsPagination() {
    JsonView view = prepareView();
    viewDao.databaseCollection().insertOne(view);
    JsonView view2 = prepareView();
    view2.setCode(CODE2);
    view2.setName(NAME2);
    viewDao.databaseCollection().insertOne(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) JsonView(io.lumeer.api.dto.JsonView) JsonView(io.lumeer.api.dto.JsonView) View(io.lumeer.api.model.View) Test(org.junit.Test)

Example 9 with JsonView

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

the class MongoViewDao method createView.

@Override
public View createView(final View view) {
    try {
        JsonView jsonView = new JsonView(view);
        databaseCollection().insertOne(jsonView);
        return jsonView;
    } catch (MongoException ex) {
        throw new StorageException("Cannot create view: " + view, ex);
    }
}
Also used : MongoException(com.mongodb.MongoException) JsonView(io.lumeer.api.dto.JsonView) StorageException(io.lumeer.storage.api.exception.StorageException)

Example 10 with JsonView

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

the class ViewCodec method decode.

@Override
public JsonView decode(final BsonReader reader, final DecoderContext decoderContext) {
    Document bson = documentCodec.decode(reader, decoderContext);
    String id = bson.getObjectId(ID).toHexString();
    String code = bson.getString(CODE);
    String name = bson.getString(NAME);
    String icon = bson.getString(ICON);
    String color = bson.getString(COLOR);
    String description = bson.getString(DESCRIPTION);
    // TODO try to use better approach
    JsonPermissions permissions = PermissionsCodec.convertFromDocument(bson.get(PERMISSIONS, Document.class));
    JsonQuery query = QueryCodec.convertFromDocument(bson.get(QUERY, Document.class));
    String perspective = bson.getString(PERSPECTIVE);
    Object config = bson.get(CONFIG);
    JsonView view = new JsonView(code, name, icon, color, description, permissions, query, perspective, config);
    view.setId(id);
    return view;
}
Also used : JsonPermissions(io.lumeer.api.dto.JsonPermissions) JsonQuery(io.lumeer.api.dto.JsonQuery) JsonView(io.lumeer.api.dto.JsonView) Document(org.bson.Document)

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