Search in sources :

Example 31 with SearchQuery

use of io.lumeer.storage.api.query.SearchQuery 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)

Example 32 with SearchQuery

use of io.lumeer.storage.api.query.SearchQuery 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 33 with SearchQuery

use of io.lumeer.storage.api.query.SearchQuery 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 34 with SearchQuery

use of io.lumeer.storage.api.query.SearchQuery in project engine by Lumeer.

the class MorphiaCollectionDaoTest method testGetCollectionsByFulltextWithAttributes.

@Test
@Ignore("Fulltext index on attribute names does not work at the moment")
public void testGetCollectionsByFulltextWithAttributes() {
    createCollection(CODE, NAME, ATTRIBUTES);
    createCollection(CODE2, NAME_FULLTEXT, ATTRIBUTES);
    createCollection(CODE3, NAME, ATTRIBUTES);
    createCollection(CODE4, NAME, ATTRIBUTES_FULLTEXT);
    SearchQuery searchQuery = SearchQuery.createBuilder(USER).fulltext("fulltext").build();
    List<Collection> collections = collectionDao.getCollections(searchQuery);
    assertThat(collections).extracting(Resource::getCode).containsOnly(CODE2, CODE3, CODE4);
}
Also used : SearchQuery(io.lumeer.storage.api.query.SearchQuery) MorphiaCollection(io.lumeer.storage.mongodb.model.MorphiaCollection) Collection(io.lumeer.api.model.Collection) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 35 with SearchQuery

use of io.lumeer.storage.api.query.SearchQuery in project engine by Lumeer.

the class MorphiaCollectionDaoTest method testGetCollectionsByFulltextDifferentUser.

@Test
public void testGetCollectionsByFulltextDifferentUser() {
    createCollection(CODE, NAME, ATTRIBUTES);
    createCollection(CODE2, NAME_FULLTEXT, ATTRIBUTES);
    createCollection(CODE3, NAME3, ATTRIBUTES);
    SearchQuery searchQuery = SearchQuery.createBuilder(USER2).fulltext("fulltext").build();
    List<Collection> collections = collectionDao.getCollections(searchQuery);
    assertThat(collections).isEmpty();
}
Also used : SearchQuery(io.lumeer.storage.api.query.SearchQuery) MorphiaCollection(io.lumeer.storage.mongodb.model.MorphiaCollection) Collection(io.lumeer.api.model.Collection) Test(org.junit.Test)

Aggregations

SearchQuery (io.lumeer.storage.api.query.SearchQuery)39 Test (org.junit.Test)37 View (io.lumeer.api.model.View)15 Collection (io.lumeer.api.model.Collection)11 MorphiaCollection (io.lumeer.storage.mongodb.model.MorphiaCollection)9 JsonView (io.lumeer.api.dto.JsonView)8 HashSet (java.util.HashSet)8 MorphiaView (io.lumeer.storage.mongodb.model.MorphiaView)7 LinkType (io.lumeer.api.model.LinkType)5 DataDocument (io.lumeer.engine.api.data.DataDocument)5 LinkInstance (io.lumeer.api.model.LinkInstance)4 Permission (io.lumeer.api.model.Permission)4 MorphiaPermission (io.lumeer.storage.mongodb.model.embedded.MorphiaPermission)4 ArrayList (java.util.ArrayList)4 Ignore (org.junit.Ignore)2 HashMap (java.util.HashMap)1