Commit 524b696b authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge remote-tracking branch 'origin/master' into 840-replace-e-printstacktrace-in-unit-tests

parents f5a3ad90 9cdd17f3
Pipeline #12033 passed with stage
in 11 minutes and 45 seconds
......@@ -621,7 +621,7 @@ public class CellDesignerXmlParser extends Converter {
result.append(functionCollectionXmlParser.toXml(model.getFunctions()));
result.append(unitCollectionXmlParser.toXml(model.getUnits()));
//notes must be inserted here, but we don't know the warnings yet
// notes must be inserted here, but we don't know the warnings yet
int notesPosition = result.length();
result.append(annotationToXml(model, elements));
......@@ -633,7 +633,7 @@ public class CellDesignerXmlParser extends Converter {
result.append(parameterCollectionXmlParser.toXml(model.getParameters()));
result.append(reactionCollectionXmlParser.reactionCollectionToXmlString(model.getReactions()));
if (model.getNotes() != null || !appender.getWarnings().isEmpty()) {
StringBuilder notes = new StringBuilder();
notes.append("<notes>");
......@@ -676,8 +676,8 @@ public class CellDesignerXmlParser extends Converter {
result.append("<annotation>\n");
result.append("<celldesigner:extension>\n");
result.append("<celldesigner:modelVersion>4.0</celldesigner:modelVersion>\n");
result.append("<celldesigner:modelDisplay sizeX=\"" + model.getWidth().intValue() + "\" sizeY=\""
+ model.getHeight().intValue() + "\"/>\n");
result.append("<celldesigner:modelDisplay sizeX=\"" + (int) (model.getWidth()) + "\" sizeY=\""
+ (int) (model.getHeight()) + "\"/>\n");
result.append(speciesCollectionXmlParser.speciesCollectionToXmlIncludedString(model.getSpeciesList()));
......
......@@ -99,7 +99,8 @@ public class SbmlExporter {
compartmentExporter.setProvideDefaults(provideDefaults);
XmlAnnotationParser parser = new XmlAnnotationParser();
String rdf = parser.dataSetToXmlString(model.getMiriamData(), model.getAuthors(), model.getCreationDate(), model.getModificationDates(), model.getIdModel());
String rdf = parser.dataSetToXmlString(model.getMiriamData(), model.getAuthors(), model.getCreationDate(),
model.getModificationDates(), model.getIdModel());
try {
result.setAnnotation(rdf);
} catch (XMLStreamException e1) {
......@@ -141,12 +142,12 @@ public class SbmlExporter {
Layout layout = new Layout();
layout.setId("minerva_layout");
Dimensions dimensions = new Dimensions();
if (model.getHeight() != null) {
if (model.getHeight() > 0) {
dimensions.setHeight(model.getHeight());
} else {
dimensions.setHeight(640);
}
if (model.getWidth() != null) {
if (model.getWidth() > 0) {
dimensions.setWidth(model.getWidth());
} else {
dimensions.setWidth(480);
......
package lcsb.mapviewer.converter.model.sbml;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.*;
import javax.xml.stream.XMLStreamException;
......@@ -18,12 +16,9 @@ import org.sbml.jsbml.ext.multi.MultiModelPlugin;
import lcsb.mapviewer.commands.CommandExecutionException;
import lcsb.mapviewer.commands.layout.ApplySimpleLayoutModelCommand;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.MimeType;
import lcsb.mapviewer.converter.Converter;
import lcsb.mapviewer.converter.ConverterException;
import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.InvalidInputDataExecption;
import lcsb.mapviewer.converter.ZIndexPopulator;
import lcsb.mapviewer.converter.*;
import lcsb.mapviewer.converter.model.sbml.compartment.SbmlCompartmentParser;
import lcsb.mapviewer.converter.model.sbml.reaction.SbmlReactionParser;
import lcsb.mapviewer.converter.model.sbml.species.SbmlSpeciesParser;
......@@ -33,12 +28,8 @@ import lcsb.mapviewer.model.map.InconsistentModelException;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.modifier.Modulation;
import lcsb.mapviewer.model.map.reaction.AbstractNode;
import lcsb.mapviewer.model.map.reaction.Modifier;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.reaction.*;
import lcsb.mapviewer.model.map.species.*;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.SpeciesWithModificationResidue;
......@@ -165,7 +156,7 @@ public class SbmlParser extends Converter {
private void createLayout(Model model, Layout layout, boolean resize, SbmlReactionParser parser)
throws InvalidInputDataExecption {
if (model.getWidth() == null) {
if (model.getWidth() <= Configuration.EPSILON) {
double maxY = 1;
double maxX = 1;
for (Element element : model.getElements()) {
......
......@@ -139,7 +139,7 @@ public class SbmlCompartmentExporter extends SbmlElementExporter<Compartment, or
boundingBox.setPosition(new Point(element.getX(), element.getY(), 0));
Dimensions dimensions = new Dimensions();
if (getMinervaModel().getWidth() != null) {
if (getMinervaModel().getWidth() > 0) {
dimensions.setWidth(getMinervaModel().getWidth());
dimensions.setHeight(getMinervaModel().getHeight());
}
......
......@@ -126,8 +126,8 @@ public class SbmlExporterTest extends SbmlTestFunctions {
model.setHeight(300);
Model deserializedModel = getModelAfterSerializing(model);
assertEquals(model.getWidth(), deserializedModel.getWidth());
assertEquals(model.getHeight(), deserializedModel.getHeight());
assertEquals(model.getWidth(), deserializedModel.getWidth(), Configuration.EPSILON);
assertEquals(model.getHeight(), deserializedModel.getHeight(), Configuration.EPSILON);
}
@Test
......
......@@ -58,12 +58,12 @@ public class SbmlReactionExporterTest {
Layout layout = new Layout();
Dimensions dimensions = new Dimensions();
if (model.getHeight() != null) {
if (model.getHeight() > 0) {
dimensions.setHeight(model.getHeight());
} else {
dimensions.setHeight(640);
}
if (model.getWidth() != null) {
if (model.getWidth() > 0) {
dimensions.setWidth(model.getWidth());
} else {
dimensions.setWidth(480);
......
package lcsb.mapviewer.commands.layout;
import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.awt.geom.*;
import java.util.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -27,23 +18,9 @@ import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.reaction.AbstractNode;
import lcsb.mapviewer.model.map.reaction.AndOperator;
import lcsb.mapviewer.model.map.reaction.AssociationOperator;
import lcsb.mapviewer.model.map.reaction.DissociationOperator;
import lcsb.mapviewer.model.map.reaction.Modifier;
import lcsb.mapviewer.model.map.reaction.NodeOperator;
import lcsb.mapviewer.model.map.reaction.Product;
import lcsb.mapviewer.model.map.reaction.Reactant;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.reaction.SplitOperator;
import lcsb.mapviewer.model.map.reaction.TruncationOperator;
import lcsb.mapviewer.model.map.reaction.type.DissociationReaction;
import lcsb.mapviewer.model.map.reaction.type.HeterodimerAssociationReaction;
import lcsb.mapviewer.model.map.reaction.type.TruncationReaction;
import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.reaction.*;
import lcsb.mapviewer.model.map.reaction.type.*;
import lcsb.mapviewer.model.map.species.*;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.SpeciesWithModificationResidue;
......@@ -448,14 +425,8 @@ public class ApplySimpleLayoutModelCommand extends ApplyLayoutModelCommand {
}
protected void modifyModelSize(Model model, Point2D minPoint, Dimension2D dimension) {
double width = 0;
double height = 0;
if (model.getWidth() != null) {
width = model.getWidth();
}
if (model.getHeight() != null) {
height = model.getHeight();
}
double width = model.getWidth();
double height = model.getHeight();
width = Math.max(width, minPoint.getX() + dimension.getWidth());
height = Math.max(height, minPoint.getY() + dimension.getHeight());
model.setWidth(width);
......
......@@ -53,7 +53,7 @@ public interface Model {
*
* @return model width
*/
Double getWidth();
double getWidth();
/**
* Sets model width.
......@@ -61,13 +61,13 @@ public interface Model {
* @param width
* new model width
*/
void setWidth(Double width);
void setWidth(double width);
/**
*
* @return model height
*/
Double getHeight();
double getHeight();
/**
* Sets model height.
......@@ -75,7 +75,7 @@ public interface Model {
* @param height
* new model height
*/
void setHeight(Double height);
void setHeight(double height);
/**
* Sets model width.
......
......@@ -129,12 +129,12 @@ public class ModelData implements Serializable {
/**
* Width of the map.
*/
private Double width;
private double width;
/**
* Height of the map.
*/
private Double height;
private double height;
/**
* X coordinate that should be used when initially showing map.
......@@ -550,7 +550,7 @@ public class ModelData implements Serializable {
* @return the width
* @see #width
*/
public Double getWidth() {
public double getWidth() {
return width;
}
......@@ -559,7 +559,7 @@ public class ModelData implements Serializable {
* the width to set
* @see #width
*/
public void setWidth(Double width) {
public void setWidth(double width) {
this.width = width;
}
......@@ -567,7 +567,7 @@ public class ModelData implements Serializable {
* @return the height
* @see #height
*/
public Double getHeight() {
public double getHeight() {
return height;
}
......@@ -576,7 +576,7 @@ public class ModelData implements Serializable {
* the height to set
* @see #height
*/
public void setHeight(Double height) {
public void setHeight(double height) {
this.height = height;
}
......
......@@ -122,22 +122,22 @@ public class ModelFullIndexed implements Model {
}
@Override
public Double getWidth() {
public double getWidth() {
return modelData.getWidth();
}
@Override
public void setWidth(Double width) {
public void setWidth(double width) {
modelData.setWidth(width);
}
@Override
public Double getHeight() {
public double getHeight() {
return modelData.getHeight();
}
@Override
public void setHeight(Double height) {
public void setHeight(double height) {
modelData.setHeight(height);
}
......
......@@ -2,15 +2,14 @@ package lcsb.mapviewer.model.user;
import java.awt.Color;
import java.io.Serializable;
import java.util.Calendar;
import java.util.HashSet;
import java.util.Set;
import java.util.*;
import javax.persistence.*;
import lcsb.mapviewer.model.security.Privilege;
import org.hibernate.annotations.Cascade;
import lcsb.mapviewer.model.security.Privilege;
@Entity
public class User implements Serializable {
......@@ -20,8 +19,10 @@ public class User implements Serializable {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(unique = true, nullable = false)
private String login;
@Column(nullable = false)
private String cryptedPassword;
private String name;
......@@ -32,25 +33,29 @@ public class User implements Serializable {
/**
* User defined color overriding system
* {@link ConfigurationElementType#MIN_COLOR_VAL}. Used for coloring minimum values in overlays.
* {@link ConfigurationElementType#MIN_COLOR_VAL}. Used for coloring minimum
* values in overlays.
*/
private Color minColor;
/**
* User defined color overriding system
* {@link ConfigurationElementType#MAX_COLOR_VAL}. Used for coloring maximum values in overlays.
* {@link ConfigurationElementType#MAX_COLOR_VAL}. Used for coloring maximum
* values in overlays.
*/
private Color maxColor;
/**
* User defined color overriding system
* {@link ConfigurationElementType#NEUTRAL_COLOR_VAL}. Used for coloring neutral values (0) in overlays.
* {@link ConfigurationElementType#NEUTRAL_COLOR_VAL}. Used for coloring neutral
* values (0) in overlays.
*/
private Color neutralColor;
/**
* User defined color overriding system
* {@link ConfigurationElementType#SIMPLE_COLOR_VAL}. Used for coloring overlays without values and colors.
* {@link ConfigurationElementType#SIMPLE_COLOR_VAL}. Used for coloring overlays
* without values and colors.
*/
private Color simpleColor;
......@@ -67,11 +72,7 @@ public class User implements Serializable {
private Set<Calendar> termsOfUseConsentDates = new HashSet<>();
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(
name = "user_privilege_map_table",
joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "privilege_id")
)
@JoinTable(name = "user_privilege_map_table", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "privilege_id"))
private Set<Privilege> privileges = new HashSet<>();
@OneToOne(cascade = CascadeType.ALL)
......
......@@ -471,38 +471,34 @@ public class ModelFullIndexedTest extends ModelTestFunctions {
public void testGetters() {
Model model = new ModelFullIndexed(null);
Double width = 12.0;
int widthInt = 12;
String widthStr = "12.0";
Double height = 13.0;
String heightStr = "13.0";
int heightInt = 13;
Set<Element> elements = new HashSet<>();
int zoomLevels = 98;
int tileSize = 1024;
String idModel = "model_ID";
model.setWidth(widthStr);
assertEquals(width, model.getWidth());
model.setWidth((Double) null);
assertNull(model.getWidth());
model.setWidth(width);
assertEquals(width, model.getWidth());
model.setWidth((Double) null);
assertNull(model.getWidth());
model.setWidth(widthInt);
assertEquals(width, model.getWidth());
model.setHeight(heightStr);
assertEquals(height, model.getHeight());
model.setHeight((Double) null);
assertNull(model.getHeight());
model.setHeight(height);
assertEquals(height, model.getHeight());
model.setHeight((Double) null);
assertNull(model.getHeight());
model.setHeight(heightInt);
assertEquals(height, model.getHeight());
double width = 12.0;
int widthInt = 12;
String widthStr = "12.0";
double height = 13.0;
String heightStr = "13.0";
int heightInt = 13;
Set<Element> elements = new HashSet<>();
int zoomLevels = 98;
int tileSize = 1024;
String idModel = "model_ID";
model.setWidth(widthStr);
assertEquals(width, model.getWidth(), Configuration.EPSILON);
model.setWidth(0.0);
model.setWidth(width);
assertEquals(width, model.getWidth(), Configuration.EPSILON);
model.setWidth(0.0);
model.setWidth(widthInt);
assertEquals(width, model.getWidth(), Configuration.EPSILON);
model.setHeight(heightStr);
assertEquals(height, model.getHeight(), Configuration.EPSILON);
model.setHeight(0.0);
model.setHeight(height);
assertEquals(height, model.getHeight(), Configuration.EPSILON);
model.setHeight(0.0);
model.setHeight(heightInt);
assertEquals(height, model.getHeight(), Configuration.EPSILON);
model.setElements(elements);
assertEquals(elements, model.getElements());
......
update model_data_table set width = 800 where width is null;
update model_data_table set height = 600 where height is null;
ALTER TABLE model_data_table ALTER COLUMN width SET NOT NULL;
ALTER TABLE model_data_table ALTER COLUMN height SET NOT NULL;
update user_table set crypted_password = '' where crypted_password is null;
ALTER TABLE user_table ALTER COLUMN crypted_password SET NOT NULL;
package lcsb.mapviewer.persist.dao.user;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import java.util.ArrayList;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.PropertyValueException;
import org.hibernate.exception.ConstraintViolationException;
import org.junit.*;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.security.Privilege;
import lcsb.mapviewer.model.security.PrivilegeType;
import lcsb.mapviewer.model.user.AnnotatorParamDefinition;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.model.user.UserAnnotationSchema;
import lcsb.mapviewer.model.user.UserClassAnnotators;
import lcsb.mapviewer.model.user.UserClassRequiredAnnotations;
import lcsb.mapviewer.model.user.UserClassValidAnnotations;
import lcsb.mapviewer.model.user.UserGuiPreference;
import lcsb.mapviewer.model.user.*;
import lcsb.mapviewer.model.user.annotator.AnnotatorConfigParameter;
import lcsb.mapviewer.model.user.annotator.AnnotatorData;
import lcsb.mapviewer.persist.PersistTestFunctions;
......@@ -54,6 +45,7 @@ public class UserDaoTest extends PersistTestFunctions {
long counter = userDao.getCount();
user = new User();
user.setCryptedPassword("");
user.setLogin(testLogin);
user.addPrivilege(new Privilege(PrivilegeType.CAN_CREATE_OVERLAYS));
userDao.add(user);
......@@ -80,6 +72,52 @@ public class UserDaoTest extends PersistTestFunctions {
}
}
@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;
}
}
@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;
}
}
@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;
}
}
@Test
public void testAddDeleteAdd() {
try {
......@@ -90,6 +128,7 @@ public class UserDaoTest extends PersistTestFunctions {
user = new User();
user.setLogin(testLogin);
user.setCryptedPassword("");
userDao.add(user);
long counter2 = userDao.getCount();
......@@ -101,6 +140,7 @@ public class UserDaoTest extends PersistTestFunctions {
assertNull(user2);
user2 = new User();
user2.setCryptedPassword("");