Commit 77526774 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '859-comment-table-changes' into 'master'

Resolve "Comment table changes"

Closes #859

See merge request !860
parents 7720b265 82f53276
Pipeline #12116 passed with stage
in 11 minutes and 51 seconds
......@@ -50,15 +50,9 @@ public class Comment implements Serializable {
/**
* The model that was commented.
*/
@ManyToOne(fetch = FetchType.LAZY)
@ManyToOne(fetch = FetchType.LAZY, optional=false)
private ModelData model;
/**
* The model that was commented.
*/
@ManyToOne(fetch = FetchType.LAZY)
private ModelData submodel;
/**
* User who gave the feedback (if logged in).
*/
......@@ -314,38 +308,4 @@ public class Comment implements Serializable {
this.model = model2;
}
/**
* @return the submodel
* @see #submodel
*/
public ModelData getSubmodelData() {
return submodel;
}
/**
* @param submodel
* the submodel to set
* @see #submodel
*/
public void setSubmodelData(ModelData submodel) {
this.submodel = submodel;
}
/**
* @return the submodel
* @see #submodel
*/
public Model getSubmodel() {
return this.submodel.getModel();
}
/**
* @param submodel
* the submodel to set
* @see #submodel
*/
public void setSubmodel(Model submodel) {
this.submodel = submodel.getModelData();
}
}
......@@ -64,10 +64,6 @@ public class CommentTest extends ModelTestFunctions {
assertEquals(pinned, comment.isPinned());
comment.setRemoveReason(removeReason);
assertEquals(removeReason, comment.getRemoveReason());
comment.setSubmodel(submodel);
assertEquals(submodel, comment.getSubmodel());
comment.setSubmodelData(submodel.getModelData());
assertEquals(submodel.getModelData(), comment.getSubmodelData());
comment.setTableId(tableId);
assertEquals(tableId, comment.getTableId());
comment.setTableName(tableName);
......
--remove submodel_id column
update comment_table set model_id = submodel_id where submodel_id is not null;
ALTER TABLE comment_table drop COLUMN submodel_id;
--comment must be attached to a model
delete from comment_table where model_id is null;
ALTER TABLE comment_table ALTER COLUMN model_id SET NOT NULL;
-- pinned should be not null
update comment_table set pinned = false where pinned is null;
ALTER TABLE comment_table ALTER COLUMN pinned SET NOT NULL;
......@@ -2,7 +2,7 @@ package lcsb.mapviewer.persist.dao.graphics;
import static org.junit.Assert.*;
import java.awt.*;
import java.awt.Color;
import java.awt.geom.Point2D;
import org.junit.*;
......@@ -26,40 +26,34 @@ public class PolylineDataTest extends PersistTestFunctions {
@Test
public void test() {
try {
PolylineData pd = new PolylineData();
pd.getBeginAtd().setArrowType(ArrowType.BLANK_CROSSBAR);
pd.getBeginAtd().setArrowLineType(LineType.DASHED);
pd.getBeginAtd().setLen(102);
pd.setColor(Color.CYAN);
pd.setType(LineType.SOLID_BOLD);
pd.setWidth(2);
pd.getPoints().add(new Point2D.Double(1, 1));
pd.getPoints().add(new Point2D.Double(2, 3));
pd.getPoints().add(new Point2D.Double(10, 11));
polylineDao.add(pd);
assertNotNull(pd.getId());
PolylineData pd2 = polylineDao.getById(pd.getId());
assertNotNull(pd2);
assertEquals(ArrowType.BLANK_CROSSBAR, pd2.getBeginAtd().getArrowType());
assertEquals(LineType.DASHED, pd2.getBeginAtd().getArrowLineType());
assertEquals(102, pd2.getBeginAtd().getLen(), EPSILON);
assertEquals(Color.CYAN, pd2.getColor());
assertEquals(LineType.SOLID_BOLD, pd2.getType());
assertEquals(2, pd2.getWidth(), EPSILON);
assertEquals(0, pd2.getPoints().get(0).distance(new Point2D.Double(1, 1)), EPSILON);
assertEquals(0, pd2.getPoints().get(1).distance(new Point2D.Double(2, 3)), EPSILON);
assertEquals(0, pd2.getPoints().get(2).distance(new Point2D.Double(10, 11)), EPSILON);
polylineDao.delete(pd);
pd2 = polylineDao.getById(pd.getId());
assertNull(pd2);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
PolylineData pd = new PolylineData();
pd.getBeginAtd().setArrowType(ArrowType.BLANK_CROSSBAR);
pd.getBeginAtd().setArrowLineType(LineType.DASHED);
pd.getBeginAtd().setLen(102);
pd.setColor(Color.CYAN);
pd.setType(LineType.SOLID_BOLD);
pd.setWidth(2);
pd.getPoints().add(new Point2D.Double(1, 1));
pd.getPoints().add(new Point2D.Double(2, 3));
pd.getPoints().add(new Point2D.Double(10, 11));
polylineDao.add(pd);
assertNotNull(pd.getId());
PolylineData pd2 = polylineDao.getById(pd.getId());
assertNotNull(pd2);
assertEquals(ArrowType.BLANK_CROSSBAR, pd2.getBeginAtd().getArrowType());
assertEquals(LineType.DASHED, pd2.getBeginAtd().getArrowLineType());
assertEquals(102, pd2.getBeginAtd().getLen(), EPSILON);
assertEquals(Color.CYAN, pd2.getColor());
assertEquals(LineType.SOLID_BOLD, pd2.getType());
assertEquals(2, pd2.getWidth(), EPSILON);
assertEquals(0, pd2.getPoints().get(0).distance(new Point2D.Double(1, 1)), EPSILON);
assertEquals(0, pd2.getPoints().get(1).distance(new Point2D.Double(2, 3)), EPSILON);
assertEquals(0, pd2.getPoints().get(2).distance(new Point2D.Double(10, 11)), EPSILON);
polylineDao.delete(pd);
pd2 = polylineDao.getById(pd.getId());
assertNull(pd2);
}
}
......@@ -48,9 +48,15 @@ public class CommentDaoTest extends PersistTestFunctions {
@Test
public void testGetById() throws Exception {
Model model = createModel();
project.addModel(model);
modelDao.add(model);
projectDao.update(project);
int counter = (int) commentDao.getCount();
Comment comment = new Comment();
comment.setUser(user);
comment.setModel(model);
commentDao.add(comment);
int counter2 = (int) commentDao.getCount();
assertEquals(counter + 1, counter2);
......
......@@ -38,298 +38,233 @@ public class UserDaoTest extends PersistTestFunctions {
@Test
public void testAddUpdateDelete() {
try {
User user = userDao.getUserByLogin(testLogin);
assertNull(user);
User user = userDao.getUserByLogin(testLogin);
assertNull(user);
long counter = userDao.getCount();
long counter = userDao.getCount();
user = new User();
user.setCryptedPassword("");
user.setLogin(testLogin);
user.addPrivilege(new Privilege(PrivilegeType.CAN_CREATE_OVERLAYS));
userDao.add(user);
user = new User();
user.setCryptedPassword("");
user.setLogin(testLogin);
user.addPrivilege(new Privilege(PrivilegeType.CAN_CREATE_OVERLAYS));
userDao.add(user);
long counter2 = userDao.getCount();
assertEquals(counter + 1, counter2);
long counter2 = userDao.getCount();
assertEquals(counter + 1, counter2);
user.setLogin(testLogin2);
userDao.update(user);
user.setLogin(testLogin2);
userDao.update(user);
User user2 = userDao.getUserByLogin(testLogin2);
assertNotNull(user2);
User user2 = userDao.getUserByLogin(testLogin2);
assertNotNull(user2);
userDao.delete(user);
userDao.delete(user);
user2 = userDao.getUserByLogin(testLogin2);
assertNull(user2);
counter2 = userDao.getCount();
assertEquals(counter, counter2);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
user2 = userDao.getUserByLogin(testLogin2);
assertNull(user2);
counter2 = userDao.getCount();
assertEquals(counter, counter2);
}
@Test(expected = PropertyValueException.class)
public void testTryUserWithNullPassword() {
try {
User user = new User();
user.setLogin(testLogin);
userDao.add(user);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
User user = new User();
user.setLogin(testLogin);
userDao.add(user);
}
@Test(expected = PropertyValueException.class)
public void testTryUserWithNullLogin() {
try {
User user = new User();
user.setCryptedPassword("ZX");
userDao.add(user);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
User user = new User();
user.setCryptedPassword("ZX");
userDao.add(user);
}
@Test(expected = ConstraintViolationException.class)
public void testTryUserWithExistingLogin() {
try {
User user = new User();
user.setLogin(testLogin);
user.setCryptedPassword("");
userDao.add(user);
User user2 = new User();
user2.setLogin(testLogin);
user2.setCryptedPassword("");
userDao.add(user2);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
User user = new User();
user.setLogin(testLogin);
user.setCryptedPassword("");
userDao.add(user);
User user2 = new User();
user2.setLogin(testLogin);
user2.setCryptedPassword("");
userDao.add(user2);
}
@Test
public void testAddDeleteAdd() {
try {
User user = userDao.getUserByLogin(testLogin);
assertNull(user);
long counter = userDao.getCount();
User user = userDao.getUserByLogin(testLogin);
assertNull(user);
user = new User();
user.setLogin(testLogin);
user.setCryptedPassword("");
userDao.add(user);
long counter = userDao.getCount();
long counter2 = userDao.getCount();
assertEquals(counter + 1, counter2);
user = new User();
user.setLogin(testLogin);
user.setCryptedPassword("");
userDao.add(user);
userDao.delete(user);
long counter2 = userDao.getCount();
assertEquals(counter + 1, counter2);
User user2 = userDao.getUserByLogin(testLogin);
assertNull(user2);
userDao.delete(user);
user2 = new User();
user2.setCryptedPassword("");
user2.setLogin(testLogin);
userDao.add(user2);
User user2 = userDao.getUserByLogin(testLogin);
assertNull(user2);
assertNotNull(userDao.getUserByLogin(testLogin));
user2 = new User();
user2.setCryptedPassword("");
user2.setLogin(testLogin);
userDao.add(user2);
userDao.delete(user2);
assertNotNull(userDao.getUserByLogin(testLogin));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
userDao.delete(user2);
}
@Test
public void testGetUserByLogin() throws Exception {
try {
User user = new User();
user.setCryptedPassword(testPasswd);
user.setLogin(testLogin);
userDao.add(user);
User user2 = userDao.getUserByLogin(testLogin);
assertNotNull(user2);
assertEquals(user2.getId(), user.getId());
assertEquals(user2.getLogin(), user.getLogin());
assertEquals(user2.getCryptedPassword(), user.getCryptedPassword());
user2 = userDao.getUserByLogin(testLogin2);
assertNull(user2);
userDao.delete(user);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
User user = new User();
user.setCryptedPassword(testPasswd);
user.setLogin(testLogin);
userDao.add(user);
User user2 = userDao.getUserByLogin(testLogin);
assertNotNull(user2);
assertEquals(user2.getId(), user.getId());
assertEquals(user2.getLogin(), user.getLogin());
assertEquals(user2.getCryptedPassword(), user.getCryptedPassword());
user2 = userDao.getUserByLogin(testLogin2);
assertNull(user2);
userDao.delete(user);
}
@Test
public void testGetUserByEmail() throws Exception {
try {
User user = new User();
user.setCryptedPassword(testPasswd);
user.setLogin(testLogin);
user.setEmail(testEmail);
user.addPrivilege(new Privilege(PrivilegeType.CAN_CREATE_OVERLAYS));
userDao.add(user);
User user2 = userDao.getUserByEmail(testEmail);
assertNotNull(user2);
assertEquals(user2.getId(), user.getId());
assertEquals(user2.getLogin(), user.getLogin());
assertEquals(user2.getCryptedPassword(), user.getCryptedPassword());
user2 = userDao.getUserByEmail(testEmail + "sadas");
assertNull(user2);
userDao.delete(user);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
User user = new User();
user.setCryptedPassword(testPasswd);
user.setLogin(testLogin);
user.setEmail(testEmail);
user.addPrivilege(new Privilege(PrivilegeType.CAN_CREATE_OVERLAYS));
userDao.add(user);
User user2 = userDao.getUserByEmail(testEmail);
assertNotNull(user2);
assertEquals(user2.getId(), user.getId());
assertEquals(user2.getLogin(), user.getLogin());
assertEquals(user2.getCryptedPassword(), user.getCryptedPassword());
user2 = userDao.getUserByEmail(testEmail + "sadas");
assertNull(user2);
userDao.delete(user);
}
@Test
public void testGetAll() throws Exception {
try {
assertTrue(userDao.getAll().size() > 0);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
assertTrue(userDao.getAll().size() > 0);
}
@Test
public void testUserWithAnnotatorSchema() throws Exception {
try {
User user = new User();
user.setLogin(testLogin);
user.setCryptedPassword("");
UserAnnotationSchema uas = new UserAnnotationSchema();
uas.setValidateMiriamTypes(true);
UserClassAnnotators ca = new UserClassAnnotators();
ca.setClassName(Species.class);
AnnotatorData annotatorData = new AnnotatorData(String.class);
ca.addAnnotator(annotatorData);
uas.addClassAnnotator(ca);
uas.addClassAnnotator(new UserClassAnnotators(String.class, new ArrayList<>()));
UserClassValidAnnotations cva = new UserClassValidAnnotations();
cva.setClassName(Reaction.class);
cva.addValidMiriamType(MiriamType.HGNC);
cva.addValidMiriamType(MiriamType.HGNC_SYMBOL);
uas.addClassValidAnnotations(cva);
uas.addClassValidAnnotations(new UserClassValidAnnotations(String.class, new ArrayList<>()));
uas.addClassValidAnnotations(new UserClassValidAnnotations(Integer.class, new ArrayList<>()));
user.setAnnotationSchema(uas);
userDao.add(user);
userDao.evict(user);
User user2 = userDao.getById(user.getId());
assertNotNull(user2);
UserAnnotationSchema uas2 = user2.getAnnotationSchema();
assertNotNull(uas2);
assertEquals(2, uas2.getClassAnnotators().size());
assertEquals(3, uas2.getClassValidAnnotators().size());
assertEquals(Species.class.getCanonicalName(), uas.getClassAnnotators().get(0).getClassName());
assertEquals(annotatorData, uas.getClassAnnotators().get(0).getAnnotators().get(0));
assertEquals(Reaction.class.getCanonicalName(), uas.getClassValidAnnotators().get(0).getClassName());
assertEquals(MiriamType.HGNC, uas.getClassValidAnnotators().get(0).getValidMiriamTypes().get(0));
assertEquals(MiriamType.HGNC_SYMBOL, uas.getClassValidAnnotators().get(0).getValidMiriamTypes().get(1));
userDao.delete(user2);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
User user = new User();
user.setLogin(testLogin);
user.setCryptedPassword("");
UserAnnotationSchema uas = new UserAnnotationSchema();
uas.setValidateMiriamTypes(true);
UserClassAnnotators ca = new UserClassAnnotators();
ca.setClassName(Species.class);
AnnotatorData annotatorData = new AnnotatorData(String.class);
ca.addAnnotator(annotatorData);
uas.addClassAnnotator(ca);
uas.addClassAnnotator(new UserClassAnnotators(String.class, new ArrayList<>()));
UserClassValidAnnotations cva = new UserClassValidAnnotations();
cva.setClassName(Reaction.class);
cva.addValidMiriamType(MiriamType.HGNC);
cva.addValidMiriamType(MiriamType.HGNC_SYMBOL);
uas.addClassValidAnnotations(cva);
uas.addClassValidAnnotations(new UserClassValidAnnotations(String.class, new ArrayList<>()));
uas.addClassValidAnnotations(new UserClassValidAnnotations(Integer.class, new ArrayList<>()));
user.setAnnotationSchema(uas);
userDao.add(user);
userDao.evict(user);
User user2 = userDao.getById(user.getId());
assertNotNull(user2);
UserAnnotationSchema uas2 = user2.getAnnotationSchema();
assertNotNull(uas2);
assertEquals(2, uas2.getClassAnnotators().size());
assertEquals(3, uas2.getClassValidAnnotators().size());
assertEquals(Species.class.getCanonicalName(), uas.getClassAnnotators().get(0).getClassName());
assertEquals(annotatorData, uas.getClassAnnotators().get(0).getAnnotators().get(0));
assertEquals(Reaction.class.getCanonicalName(), uas.getClassValidAnnotators().get(0).getClassName());
assertEquals(MiriamType.HGNC, uas.getClassValidAnnotators().get(0).getValidMiriamTypes().get(0));
assertEquals(MiriamType.HGNC_SYMBOL, uas.getClassValidAnnotators().get(0).getValidMiriamTypes().get(1));
userDao.delete(user2);
}
@Test
public void testUserWithAnnotatorSchemaGuiPreferences() throws Exception {
try {
User user = new User();
user.setLogin(testLogin);
user.setCryptedPassword("");
UserAnnotationSchema uas = new UserAnnotationSchema();
user.setAnnotationSchema(uas);
UserGuiPreference option = new UserGuiPreference();
option.setKey("key");
option.setValue("val");
uas.addGuiPreference(option);
userDao.add(user);
userDao.evict(user);
User user2 = userDao.getById(user.getId());
assertNotNull(user2);
UserAnnotationSchema uas2 = user2.getAnnotationSchema();
assertNotNull(uas2);
assertEquals(1, uas2.getGuiPreferences().size());
userDao.delete(user2);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
User user = new User();
user.setLogin(testLogin);
user.setCryptedPassword("");
UserAnnotationSchema uas = new UserAnnotationSchema();
user.setAnnotationSchema(uas);
UserGuiPreference option = new UserGuiPreference();
option.setKey("key");
option.setValue("val");
uas.addGuiPreference(option);
userDao.add(user);
userDao.evict(user);
User user2 = userDao.getById(user.getId());
assertNotNull(user2);
UserAnnotationSchema uas2 = user2.getAnnotationSchema();
assertNotNull(uas2);
assertEquals(1, uas2.getGuiPreferences().size());
userDao.delete(user2);
}
@Test
public void testUserWithAnnotatorSchemaRequiredAnnotations() throws Exception {
try {
User user = new User();
user.setLogin(testLogin);
user.setCryptedPassword("");
UserAnnotationSchema uas = new UserAnnotationSchema();
user.setAnnotationSchema(uas);
uas.addClassRequiredAnnotations(
new UserClassRequiredAnnotations(String.class, new MiriamType[] { MiriamType.WIKIPEDIA }));
userDao.add(user);
userDao.evict(user);
User user2 = userDao.getById(user.getId());
assertNotNull(user2);