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());
}
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);
}
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);
}
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;
}
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;
}
Aggregations