Search in sources :

Example 11 with MorphiaCollection

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

the class MorphiaCollectionDaoTest method testGetCollectionsByCollectionIds.

@Test
public void testGetCollectionsByCollectionIds() {
    MorphiaCollection collection = prepareCollection(CODE, NAME);
    collection.getPermissions().removeUserPermission(USER);
    Permission userPermission = new MorphiaPermission(USER2, Collections.singleton(Role.READ.toString()));
    collection.getPermissions().updateUserPermissions(userPermission);
    datastore.save(collectionDao.databaseCollection(), collection);
    MorphiaCollection collection2 = prepareCollection(CODE2, NAME2);
    datastore.save(collectionDao.databaseCollection(), collection2);
    MorphiaCollection collection3 = prepareCollection(CODE3, NAME3);
    datastore.save(collectionDao.databaseCollection(), collection3);
    SearchQuery query = SearchQuery.createBuilder(USER).collectionIds(new HashSet<>(Arrays.asList(collection.getId(), collection3.getId()))).build();
    List<Collection> views = collectionDao.getCollections(query);
    assertThat(views).extracting(Collection::getId).containsOnly(collection3.getId());
}
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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with MorphiaCollection

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

the class MorphiaCollectionDaoTest method testCreateCollection.

@Test
public void testCreateCollection() {
    MorphiaCollection collection = prepareCollection(CODE, NAME);
    String id = collectionDao.createCollection(collection).getId();
    assertThat(id).isNotNull().isNotEmpty();
    assertThat(ObjectId.isValid(id)).isTrue();
    MorphiaCollection storedCollection = datastore.get(collectionDao.databaseCollection(), MorphiaCollection.class, new ObjectId(id));
    assertThat(storedCollection).isNotNull();
    assertThat(storedCollection.getCode()).isEqualTo(CODE);
    assertThat(storedCollection.getName()).isEqualTo(NAME);
    assertThat(storedCollection.getColor()).isEqualTo(COLOR);
    assertThat(storedCollection.getIcon()).isEqualTo(ICON);
    assertThat(storedCollection.getPermissions()).isEqualTo(PERMISSIONS);
    assertThat(storedCollection.getAttributes()).isEqualTo(ATTRIBUTES);
    assertThat(storedCollection.getDocumentsCount()).isEqualTo(DOCUMENTS_COUNT);
    assertThat(storedCollection.getLastTimeUsed()).isEqualTo(LAST_TIME_USED);
}
Also used : MorphiaCollection(io.lumeer.storage.mongodb.model.MorphiaCollection) ObjectId(org.bson.types.ObjectId) Test(org.junit.Test)

Example 13 with MorphiaCollection

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

the class MorphiaCollectionDaoTest method testGetCollectionsGroupsRole.

@Test
public void testGetCollectionsGroupsRole() {
    MorphiaCollection collection = prepareCollection(CODE, NAME);
    datastore.save(collectionDao.databaseCollection(), collection);
    MorphiaCollection collection2 = prepareCollection(CODE2, NAME2);
    datastore.save(collectionDao.databaseCollection(), collection2);
    SearchQuery query = SearchQuery.createBuilder(USER2).groups(Collections.singleton(GROUP)).build();
    List<Collection> collections = collectionDao.getCollections(query);
    assertThat(collections).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 14 with MorphiaCollection

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

the class MorphiaCollectionDaoTest method prepareCollection.

private MorphiaCollection prepareCollection(String code, String name) {
    MorphiaCollection collection = new MorphiaCollection();
    collection.setCode(code);
    collection.setName(name);
    collection.setColor(COLOR);
    collection.setIcon(ICON);
    collection.setPermissions(new MorphiaPermissions(PERMISSIONS));
    collection.setAttributes(ATTRIBUTES);
    collection.setDocumentsCount(DOCUMENTS_COUNT);
    collection.setLastTimeUsed(LAST_TIME_USED);
    return collection;
}
Also used : MorphiaCollection(io.lumeer.storage.mongodb.model.MorphiaCollection) MorphiaPermissions(io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions)

Example 15 with MorphiaCollection

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

the class MorphiaCollectionDao method updateCollection.

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

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