Search in sources :

Example 1 with DatabaseQuery

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

the class ProjectFacade method getProjects.

public List<Project> getProjects() {
    User user = authenticatedUser.getCurrentUser();
    Set<String> groups = authenticatedUser.getCurrentUserGroups();
    DatabaseQuery query = DatabaseQuery.createBuilder(user.getEmail()).groups(groups).build();
    return projectDao.getProjects(query).stream().map(this::keepOnlyActualUserRoles).collect(Collectors.toList());
}
Also used : User(io.lumeer.api.model.User) DatabaseQuery(io.lumeer.storage.api.query.DatabaseQuery)

Example 2 with DatabaseQuery

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

the class MorphiaProjectDaoTest method testGetProjectsGroupRole.

@Test
public void testGetProjectsGroupRole() {
    MorphiaProject project = prepareProject(CODE1);
    datastore.save(projectDao.databaseCollection(), project);
    MorphiaProject project2 = prepareProject(CODE2);
    datastore.save(projectDao.databaseCollection(), project2);
    DatabaseQuery query = DatabaseQuery.createBuilder(USER2).groups(Collections.singleton(GROUP)).build();
    List<Project> projects = projectDao.getProjects(query);
    assertThat(projects).extracting(Project::getCode).containsOnly(CODE1, CODE2);
}
Also used : MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) Project(io.lumeer.api.model.Project) DatabaseQuery(io.lumeer.storage.api.query.DatabaseQuery) MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) Test(org.junit.Test)

Example 3 with DatabaseQuery

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

the class MorphiaProjectDaoTest method testGetProjects.

@Test
public void testGetProjects() {
    MorphiaProject project = prepareProject(CODE1);
    datastore.save(projectDao.databaseCollection(), project);
    MorphiaProject project2 = prepareProject(CODE2);
    datastore.save(projectDao.databaseCollection(), project2);
    DatabaseQuery query = DatabaseQuery.createBuilder(USER).build();
    List<MorphiaProject> projects = (List<MorphiaProject>) (List<?>) projectDao.getProjects(query);
    assertThat(projects).extracting(Project::getCode).containsOnly(CODE1, CODE2);
}
Also used : DatabaseQuery(io.lumeer.storage.api.query.DatabaseQuery) MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) List(java.util.List) Test(org.junit.Test)

Example 4 with DatabaseQuery

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

the class MorphiaOrganizationDaoTest method testGetOrganizationsNoReadRole.

@Test
public void testGetOrganizationsNoReadRole() {
    Organization organization = prepareOrganization(CODE1);
    Permission userPermission = new MorphiaPermission(USER2, Collections.singleton(Role.CLONE.toString()));
    organization.getPermissions().updateUserPermissions(userPermission);
    datastore.save(organization);
    Organization organization2 = prepareOrganization(CODE2);
    Permission groupPermission = new MorphiaPermission(GROUP2, Collections.singleton(Role.SHARE.toString()));
    organization2.getPermissions().updateGroupPermissions(groupPermission);
    datastore.save(organization2);
    DatabaseQuery query = DatabaseQuery.createBuilder(USER2).groups(Collections.singleton(GROUP2)).build();
    List<Organization> organizations = organizationDao.getOrganizations(query);
    assertThat(organizations).isEmpty();
}
Also used : MorphiaOrganization(io.lumeer.storage.mongodb.model.MorphiaOrganization) Organization(io.lumeer.api.model.Organization) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) DatabaseQuery(io.lumeer.storage.api.query.DatabaseQuery) Permission(io.lumeer.api.model.Permission) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) Test(org.junit.Test)

Example 5 with DatabaseQuery

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

the class MorphiaOrganizationDaoTest method testGetOrganizations.

@Test
public void testGetOrganizations() {
    Organization organization = prepareOrganization(CODE1);
    datastore.save(organization);
    Organization organization2 = prepareOrganization(CODE2);
    datastore.save(organization2);
    DatabaseQuery query = DatabaseQuery.createBuilder(USER).build();
    List<Organization> organizations = organizationDao.getOrganizations(query);
    assertThat(organizations).extracting(Organization::getCode).containsOnly(CODE1, CODE2);
}
Also used : MorphiaOrganization(io.lumeer.storage.mongodb.model.MorphiaOrganization) Organization(io.lumeer.api.model.Organization) DatabaseQuery(io.lumeer.storage.api.query.DatabaseQuery) Test(org.junit.Test)

Aggregations

DatabaseQuery (io.lumeer.storage.api.query.DatabaseQuery)8 Test (org.junit.Test)6 Organization (io.lumeer.api.model.Organization)3 MorphiaOrganization (io.lumeer.storage.mongodb.model.MorphiaOrganization)3 MorphiaProject (io.lumeer.storage.mongodb.model.MorphiaProject)3 Permission (io.lumeer.api.model.Permission)2 Project (io.lumeer.api.model.Project)2 MorphiaPermission (io.lumeer.storage.mongodb.model.embedded.MorphiaPermission)2 User (io.lumeer.api.model.User)1 List (java.util.List)1