Search in sources :

Example 11 with MorphiaProject

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

the class MorphiaProjectDaoTest method testUpdateProjectPermissions.

@Test
public void testUpdateProjectPermissions() {
    MorphiaProject project = prepareProject(CODE1);
    String id = datastore.save(projectDao.databaseCollection(), project).getId().toString();
    assertThat(id).isNotNull().isNotEmpty();
    project.getPermissions().removeUserPermission(USER);
    project.getPermissions().updateGroupPermissions(GROUP_PERMISSION);
    projectDao.updateProject(id, project);
    MorphiaProject storedProject = datastore.get(projectDao.databaseCollection(), MorphiaProject.class, new ObjectId(id));
    assertThat(storedProject).isNotNull();
    assertThat(storedProject.getPermissions().getUserPermissions()).isEmpty();
    assertThat(storedProject.getPermissions().getGroupPermissions()).containsExactly(GROUP_PERMISSION);
}
Also used : ObjectId(org.bson.types.ObjectId) MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) Test(org.junit.Test)

Example 12 with MorphiaProject

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

the class MorphiaProjectDaoTest method testGetProjectsNoReadRole.

@Test
public void testGetProjectsNoReadRole() {
    MorphiaProject project = prepareProject(CODE1);
    Permission userPermission = new MorphiaPermission(USER2, Collections.singleton(Role.CLONE.toString()));
    project.getPermissions().updateUserPermissions(userPermission);
    datastore.save(projectDao.databaseCollection(), project);
    MorphiaProject project2 = prepareProject(CODE2);
    Permission groupPermission = new MorphiaPermission(GROUP2, Collections.singleton(Role.SHARE.toString()));
    project2.getPermissions().updateGroupPermissions(groupPermission);
    datastore.save(projectDao.databaseCollection(), project2);
    DatabaseQuery query = DatabaseQuery.createBuilder(USER2).groups(Collections.singleton(GROUP2)).build();
    List<Project> projects = projectDao.getProjects(query);
    assertThat(projects).isEmpty();
}
Also used : MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) Project(io.lumeer.api.model.Project) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) DatabaseQuery(io.lumeer.storage.api.query.DatabaseQuery) MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) Permission(io.lumeer.api.model.Permission) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) Test(org.junit.Test)

Example 13 with MorphiaProject

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

the class MorphiaProjectDao method updateProject.

@Override
public Project updateProject(final String projectId, final Project project) {
    MorphiaProject morphiaProject = new MorphiaProject(project);
    morphiaProject.setId(projectId);
    datastore.save(databaseCollection(), morphiaProject);
    return morphiaProject;
}
Also used : MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject)

Example 14 with MorphiaProject

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

the class MorphiaProjectDao method getProjects.

@Override
public List<Project> getProjects(final DatabaseQuery query) {
    Query<MorphiaProject> projectQuery = createProjectQuery(query);
    FindOptions findOptions = createFindOptions(query);
    return new ArrayList<>(projectQuery.asList(findOptions));
}
Also used : FindOptions(org.mongodb.morphia.query.FindOptions) MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) ArrayList(java.util.ArrayList)

Example 15 with MorphiaProject

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

the class ViewServiceIT method configureProject.

@Before
public void configureProject() {
    MorphiaOrganization organization = new MorphiaOrganization();
    organization.setCode(ORGANIZATION_CODE);
    organization.setPermissions(new MorphiaPermissions());
    Organization storedOrganization = organizationDao.createOrganization(organization);
    projectDao.setOrganization(storedOrganization);
    User user = new User(USER);
    userDao.createUser(user);
    MorphiaProject project = new MorphiaProject();
    project.setCode(PROJECT_CODE);
    project.setPermissions(new MorphiaPermissions());
    Project storedProject = projectDao.createProject(project);
    viewDao.setProject(storedProject);
}
Also used : MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) Project(io.lumeer.api.model.Project) Organization(io.lumeer.api.model.Organization) MorphiaOrganization(io.lumeer.storage.mongodb.model.MorphiaOrganization) User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.AuthenticatedUser) MorphiaOrganization(io.lumeer.storage.mongodb.model.MorphiaOrganization) MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) MorphiaPermissions(io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions) Before(org.junit.Before)

Aggregations

MorphiaProject (io.lumeer.storage.mongodb.model.MorphiaProject)15 Test (org.junit.Test)9 Project (io.lumeer.api.model.Project)6 ObjectId (org.bson.types.ObjectId)4 DatabaseQuery (io.lumeer.storage.api.query.DatabaseQuery)3 MorphiaPermissions (io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions)3 Organization (io.lumeer.api.model.Organization)2 User (io.lumeer.api.model.User)2 AuthenticatedUser (io.lumeer.core.AuthenticatedUser)2 MorphiaOrganization (io.lumeer.storage.mongodb.model.MorphiaOrganization)2 SoftAssertions (org.assertj.core.api.SoftAssertions)2 Before (org.junit.Before)2 Permission (io.lumeer.api.model.Permission)1 MorphiaPermission (io.lumeer.storage.mongodb.model.embedded.MorphiaPermission)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 FindOptions (org.mongodb.morphia.query.FindOptions)1