Search in sources :

Example 6 with MorphiaCollection

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

the class MorphiaCollectionDaoTest method createCollection.

private MorphiaCollection createCollection(String code, String name, Set<Attribute> attributes) {
    MorphiaCollection collection = prepareCollection(code, name);
    collection.setAttributes(attributes);
    datastore.insert(collectionDao.databaseCollection(), collection);
    return collection;
}
Also used : MorphiaCollection(io.lumeer.storage.mongodb.model.MorphiaCollection)

Example 7 with MorphiaCollection

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

the class MorphiaCollectionDaoTest method testGetCollections.

@Test
public void testGetCollections() {
    MorphiaCollection collection = prepareCollection(CODE, NAME);
    datastore.save(collectionDao.databaseCollection(), collection);
    MorphiaCollection collection2 = prepareCollection(CODE2, NAME2);
    datastore.save(collectionDao.databaseCollection(), collection2);
    SearchQuery query = SearchQuery.createBuilder(USER).build();
    List<Collection> views = collectionDao.getCollections(query);
    assertThat(views).extracting(Collection::getCode).containsOnly(CODE, CODE2);
}
Also used : SearchQuery(io.lumeer.storage.api.query.SearchQuery) MorphiaCollection(io.lumeer.storage.mongodb.model.MorphiaCollection) MorphiaCollection(io.lumeer.storage.mongodb.model.MorphiaCollection) Collection(io.lumeer.api.model.Collection) Test(org.junit.Test)

Example 8 with MorphiaCollection

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

the class MorphiaCollectionDaoTest method testGetCollectionsByIds.

@Test
public void testGetCollectionsByIds() {
    MorphiaCollection collection = prepareCollection(CODE, NAME);
    String id = collectionDao.createCollection(collection).getId();
    MorphiaCollection collection2 = prepareCollection(CODE2, NAME2);
    String id2 = collectionDao.createCollection(collection2).getId();
    MorphiaCollection collection3 = prepareCollection(CODE3, NAME3);
    String id3 = collectionDao.createCollection(collection3).getId();
    MorphiaCollection collection4 = prepareCollection(CODE4, NAME4);
    String id4 = collectionDao.createCollection(collection4).getId();
    List<Collection> collections = collectionDao.getCollectionsByIds(Arrays.asList(id, id3));
    assertThat(collections).hasSize(2).extracting("id").containsOnlyElementsOf(Arrays.asList(id, id3));
    collections = collectionDao.getCollectionsByIds(Arrays.asList(id, id2, id4));
    assertThat(collections).hasSize(3).extracting("id").containsOnlyElementsOf(Arrays.asList(id, id2, id4));
}
Also used : MorphiaCollection(io.lumeer.storage.mongodb.model.MorphiaCollection) MorphiaCollection(io.lumeer.storage.mongodb.model.MorphiaCollection) Collection(io.lumeer.api.model.Collection) Test(org.junit.Test)

Example 9 with MorphiaCollection

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

the class MorphiaCollectionDao method createCollection.

@Override
public Collection createCollection(final Collection collection) {
    MorphiaCollection morphiaCollection = new MorphiaCollection(collection);
    datastore.insert(databaseCollection(), morphiaCollection);
    return morphiaCollection;
}
Also used : MorphiaCollection(io.lumeer.storage.mongodb.model.MorphiaCollection)

Example 10 with MorphiaCollection

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

the class MorphiaCollectionDaoTest method testGetCollectionsNoReadRole.

@Test
public void testGetCollectionsNoReadRole() {
    MorphiaCollection collection = prepareCollection(CODE, NAME);
    Permission userPermission = new MorphiaPermission(USER2, Collections.singleton(Role.CLONE.toString()));
    collection.getPermissions().updateUserPermissions(userPermission);
    datastore.save(collectionDao.databaseCollection(), collection);
    MorphiaCollection collection2 = prepareCollection(CODE2, NAME2);
    Permission groupPermission = new MorphiaPermission(GROUP2, Collections.singleton(Role.SHARE.toString()));
    collection2.getPermissions().updateGroupPermissions(groupPermission);
    datastore.save(collectionDao.databaseCollection(), collection2);
    SearchQuery query = SearchQuery.createBuilder(USER2).groups(Collections.singleton(GROUP2)).build();
    List<Collection> collections = collectionDao.getCollections(query);
    assertThat(collections).isEmpty();
}
Also used : SearchQuery(io.lumeer.storage.api.query.SearchQuery) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) MorphiaCollection(io.lumeer.storage.mongodb.model.MorphiaCollection) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) Permission(io.lumeer.api.model.Permission) MorphiaCollection(io.lumeer.storage.mongodb.model.MorphiaCollection) Collection(io.lumeer.api.model.Collection) Test(org.junit.Test)

Aggregations

MorphiaCollection (io.lumeer.storage.mongodb.model.MorphiaCollection)15 Test (org.junit.Test)10 Collection (io.lumeer.api.model.Collection)6 SearchQuery (io.lumeer.storage.api.query.SearchQuery)4 Permission (io.lumeer.api.model.Permission)2 MorphiaPermission (io.lumeer.storage.mongodb.model.embedded.MorphiaPermission)2 ObjectId (org.bson.types.ObjectId)2 MorphiaPermissions (io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions)1 HashSet (java.util.HashSet)1 Ignore (org.junit.Ignore)1