Commit 85b789f1 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

project has obligatory owner field

parent 415845d3
......@@ -21,6 +21,7 @@ import lcsb.mapviewer.model.map.layout.Layout;
import lcsb.mapviewer.model.map.layout.graphics.Glyph;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelData;
import lcsb.mapviewer.model.user.User;
@Entity
public class Project implements Serializable {
......@@ -42,6 +43,9 @@ public class Project implements Serializable {
private String version;
@ManyToOne(optional = false)
private User owner;
private String notifyEmail;
private String directory;
......@@ -388,4 +392,12 @@ public class Project implements Serializable {
parseGlyph.setProject(this);
}
public User getOwner() {
return owner;
}
public void setOwner(User owner) {
this.owner = owner;
}
}
alter table project_table add column owner_id integer;
-- match by email
update project_table set owner_id = (select id from user_table where email = notify_email and email<>'' limit 1) where owner_id is null;
-- assign admin owner to project without owner
update project_table set owner_id = (select id from user_table where id in (select user_id from user_privilege_map_table where privilege_id in (select id from privilege_table where type ='IS_ADMIN')) and removed =False limit 1) where owner_id is null;
-- in case there is no admin assign to any user that is not removed (shouldn't happen at all)
update project_table set owner_id = (select id from user_table where removed =False limit 1) where owner_id is null;
......@@ -32,6 +32,8 @@ import lcsb.mapviewer.persist.dao.user.UserDao;
@RunWith(SpringJUnit4ClassRunner.class)
public abstract class PersistTestFunctions {
protected static String ADMIN_BUILT_IN_LOGIN = "admin";
@Rule
public UnitTestFailedWatcher unitTestFailedWatcher = new UnitTestFailedWatcher();
public double EPSILON = 1e-6;
......
......@@ -37,6 +37,7 @@ public class ProjectDaoTest extends PersistTestFunctions {
public void testGetProjectByName() throws Exception {
Project project = new Project();
project.setProjectId(projectId);
project.setOwner(userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
projectDao.add(project);
projectDao.evict(project);
......@@ -52,6 +53,7 @@ public class ProjectDaoTest extends PersistTestFunctions {
public void testGetProjectForModelId() throws Exception {
Project project = new Project();
project.setProjectId(projectId);
project.setOwner(userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
projectDao.add(project);
Model model = new ModelFullIndexed(null);
project.addModel(model);
......@@ -76,6 +78,7 @@ public class ProjectDaoTest extends PersistTestFunctions {
assertFalse(projectDao.isProjectExistsByName(projectId));
project.setOwner(userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
projectDao.add(project);
projectDao.evict(project);
......@@ -89,6 +92,7 @@ public class ProjectDaoTest extends PersistTestFunctions {
@Test
public void testCheckEqualityAfterReload() throws Exception {
Project project = new Project(projectId);
project.setOwner(userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
projectDao.add(project);
projectDao.flush();
......@@ -110,6 +114,7 @@ public class ProjectDaoTest extends PersistTestFunctions {
@Test
public void testCheckEqualityAfterReload2() throws Exception {
Project project = new Project(projectId);
project.setOwner(userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
Model model = createModel();
project.addModel(model);
......@@ -168,6 +173,7 @@ public class ProjectDaoTest extends PersistTestFunctions {
oi.addLink(oml);
project.addOverviewImage(oi);
project.addModel(model);
project.setOwner(userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
projectDao.add(project);
projectDao.evict(project);
......@@ -198,6 +204,7 @@ public class ProjectDaoTest extends PersistTestFunctions {
Project project = new Project("test_project_id");
project.addWarning("warning A");
project.addWarning("warning B");
project.setOwner(userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
assertEquals(2, project.getWarnings().size());
projectDao.add(project);
......@@ -226,6 +233,7 @@ public class ProjectDaoTest extends PersistTestFunctions {
@Test
public void testLayoutsInProject() throws Exception {
Project project = new Project("test_porject_id");
project.setOwner(userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
Model model = createModel();
project.addModel(model);
projectDao.add(project);
......@@ -252,6 +260,7 @@ public class ProjectDaoTest extends PersistTestFunctions {
public void testGetNextId() throws Exception {
long id = projectDao.getNextId();
Project project = new Project(projectId);
project.setOwner(userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
projectDao.add(project);
long id2 = projectDao.getNextId();
......
......@@ -36,6 +36,7 @@ public class CommentDaoTest extends PersistTestFunctions {
projectDao.delete(project);
}
project = new Project();
project.setOwner(user);
project.setProjectId(projectId);
projectDao.add(project);
}
......
......@@ -50,6 +50,7 @@ public class LayoutDaoTest extends PersistTestFunctions {
Project project = new Project("test_project_id");
project.addModel(model);
project.setOwner(userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
projectDao.add(project);
modelDao.evict(model);
......@@ -91,6 +92,7 @@ public class LayoutDaoTest extends PersistTestFunctions {
Project project = new Project("test_project_id");
project.addModel(model);
project.setOwner(userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
projectDao.add(project);
......@@ -174,6 +176,7 @@ public class LayoutDaoTest extends PersistTestFunctions {
Model model = createModel();
Project project = new Project("test_project_id");
project.setOwner(userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
project.addModel(model);
projectDao.add(project);
......
......@@ -36,6 +36,7 @@ public class ModelDaoTest extends PersistTestFunctions {
}
project = new Project();
project.setProjectId(projectId);
project.setOwner(userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
projectDao.add(project);
}
......@@ -273,6 +274,7 @@ public class ModelDaoTest extends PersistTestFunctions {
Model model = createModel();
Project project = new Project("test_project_id");
project.addModel(model);
project.setOwner(userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
projectDao.add(project);
modelDao.evict(model);
......@@ -299,6 +301,7 @@ public class ModelDaoTest extends PersistTestFunctions {
Model model = createModel();
Project project = new Project("test_project_id");
project.addModel(model);
project.setOwner(userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
projectDao.add(project);
modelDao.evict(model);
......
......@@ -13,17 +13,21 @@ import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.species.AntisenseRna;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.field.CodingRegion;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.persist.PersistTestFunctions;
@Rollback(true)
public class AntisenseRnaTest extends PersistTestFunctions {
Logger logger = LogManager.getLogger(AntisenseRnaTest.class);
User admin;
int identifierCounter = 0;
String projectId = "Some_id";
@Before
public void setUp() throws Exception {
admin = userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN);
Project project = projectDao.getProjectByProjectId(projectId);
if (project != null) {
projectDao.delete(project);
......@@ -38,6 +42,7 @@ public class AntisenseRnaTest extends PersistTestFunctions {
public void testAntisenseRnaRegionInDb() throws Exception {
Project project = new Project();
project.setProjectId(projectId);
project.setOwner(admin);
Model model = createModel();
......
......@@ -46,6 +46,7 @@ public class ElementDaoTest extends PersistTestFunctions {
}
project = new Project();
project.setProjectId(projectId);
project.setOwner(userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
projectDao.add(project);
}
......
......@@ -40,6 +40,7 @@ public class RnaTest extends PersistTestFunctions {
Model model = createModel();
project.setOwner(userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
project.addModel(model);
projectDao.add(project);
projectDao.evict(project);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment