diff --git a/CHANGELOG b/CHANGELOG index 6cb73ed408253580a902451e1da882ef33b90e1e..f27a7bc28207ddf045d46d604301709bb912c1cf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,9 @@ minerva (18.0.8) stable; urgency=medium * Bug fix: don't create duplicated refresh jobs (#2165) * Bug fix: performance issues with caching suggested query list for chemicals (#2168) + * Bug fix: information about species pathway/compartment has not been + separated. This caused to export the model into incorrect SBML - species are + separated using compartment (#2169) -- Piotr Gawron <piotr.gawron@uni.lu> Thu, 19 Dec 2024 13:00:00 +0200 diff --git a/model-command/src/main/java/lcsb/mapviewer/commands/CreateHierarchyCommand.java b/model-command/src/main/java/lcsb/mapviewer/commands/CreateHierarchyCommand.java index 305c7a799ccb661e230ff59555bdb2faa684f9ad..9db57b4061672e6de5512e362c745ed4468d6409 100644 --- a/model-command/src/main/java/lcsb/mapviewer/commands/CreateHierarchyCommand.java +++ b/model-command/src/main/java/lcsb/mapviewer/commands/CreateHierarchyCommand.java @@ -1,15 +1,5 @@ package lcsb.mapviewer.commands; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Set; - -import org.apache.commons.lang3.math.NumberUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - import lcsb.mapviewer.common.Configuration; import lcsb.mapviewer.common.exception.InvalidStateException; import lcsb.mapviewer.common.exception.NotImplementedException; @@ -25,14 +15,21 @@ import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.species.Complex; import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.Species; +import org.apache.commons.lang3.math.NumberUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Objects; +import java.util.Set; /** * This {@link ModelCommand command} class allows to transform model into * multilevel (nested) component structure. Some artificial compartments will * appear. All compartments have information about children compartments. All * objects have information about parents. - * - * */ public class CreateHierarchyCommand extends ModelCommand { @@ -54,25 +51,22 @@ public class CreateHierarchyCommand extends ModelCommand { * Default class logger. */ @SuppressWarnings("unused") - private static Logger logger = LogManager.getLogger(); + private static final Logger logger = LogManager.getLogger(); /** * How many levels are possible. */ - private int zoomLevels; + private final int zoomLevels; /** * What is the maximum zoom factor in the view. */ - private double maxZoomFactor; + private final double maxZoomFactor; /** * Default constructor that initializes data. * - * @param model - * model on which command will be executed - * @param maxZoomFactor - * what is the maximum zoom out factor - * @param zoomLevels - * how many levels are possible + * @param model model on which command will be executed + * @param maxZoomFactor what is the maximum zoom out factor + * @param zoomLevels how many levels are possible */ public CreateHierarchyCommand(final Model model, final int zoomLevels, final double maxZoomFactor) { super(model); @@ -229,7 +223,7 @@ public class CreateHierarchyCommand extends ModelCommand { } private String extractNotesFromText(final String notes) { - if (notes.indexOf("\n") >= 0) { + if (notes.contains("\n")) { return notes.substring(notes.indexOf("\n")); } else { return ""; @@ -237,7 +231,7 @@ public class CreateHierarchyCommand extends ModelCommand { } private String extractNameFromText(final String notes) { - if (notes.indexOf("\n") >= 0) { + if (notes.contains("\n")) { return notes.substring(0, notes.indexOf("\n")); } else { return notes; @@ -272,15 +266,14 @@ public class CreateHierarchyCommand extends ModelCommand { } return logValue; } else { - return Integer.valueOf(alias.getVisibilityLevel()); + return Integer.parseInt(alias.getVisibilityLevel()); } } /** * Sets transparency level in hierarchical view for compartment alias. * - * @param compartment - * compartment alias + * @param compartment compartment alias */ private void settingTransparencyLevelForCompartment(final Compartment compartment) { if (compartment.getTransparencyLevel() == null || compartment.getTransparencyLevel().isEmpty()) { @@ -288,7 +281,7 @@ public class CreateHierarchyCommand extends ModelCommand { double rate = computeRate(compartment, Configuration.MAX_VISIBLE_OBJECT_SIZE); maxVisibilityLevel = (int) ((int) Math.ceil(Math.log(rate)) / LOG_4); for (final Element child : compartment.getElements()) { - maxVisibilityLevel = Math.min(maxVisibilityLevel, Integer.valueOf(computeVisibility(child))); + maxVisibilityLevel = Math.min(maxVisibilityLevel, computeVisibility(child)); } if (maxVisibilityLevel >= zoomLevels) { maxVisibilityLevel = zoomLevels; @@ -308,8 +301,7 @@ public class CreateHierarchyCommand extends ModelCommand { /** * Sets transparency level in hierarchical view for complex alias. * - * @param complex - * complex alias + * @param complex complex alias */ private void settingTransparencyLevelForComplex(final Complex complex) { if (complex.getTransparencyLevel() == null || complex.getTransparencyLevel().isEmpty()) { @@ -317,7 +309,7 @@ public class CreateHierarchyCommand extends ModelCommand { double rate = computeRate(complex, Configuration.MAX_VISIBLE_OBJECT_SIZE); maxVisibilityLevel = (int) ((int) Math.ceil(Math.log(rate)) / LOG_4); for (final Element child : complex.getElements()) { - maxVisibilityLevel = Math.min(maxVisibilityLevel, Integer.valueOf(computeVisibility(child))); + maxVisibilityLevel = Math.min(maxVisibilityLevel, computeVisibility(child)); } if (maxVisibilityLevel >= zoomLevels) { maxVisibilityLevel = zoomLevels; @@ -337,8 +329,7 @@ public class CreateHierarchyCommand extends ModelCommand { /** * Sets transparency level in hierarchical view for all elements. * - * @param sortedAliases - * list of aliases + * @param sortedAliases list of aliases */ private void settingOfTransparencyLevel(final List<Element> sortedAliases) { for (final Element alias : sortedAliases) { @@ -357,8 +348,7 @@ public class CreateHierarchyCommand extends ModelCommand { /** * Removes invalid compartment children. * - * @param sortedAliases - * list of aliases + * @param sortedAliases list of aliases */ private void setChildrening(final List<Element> sortedAliases) { for (final Element compartment : sortedAliases) { @@ -377,8 +367,7 @@ public class CreateHierarchyCommand extends ModelCommand { /** * Sets parent for elements. * - * @param sortedAliases - * list of aliases + * @param sortedAliases list of aliases */ private void setParentingOfNonComplexChildrens(final List<Element> sortedAliases) { for (final Element element : getModel().getElements()) { @@ -410,8 +399,7 @@ public class CreateHierarchyCommand extends ModelCommand { /** * Set parents for the elements in hierarchical view. * - * @param sortedAliases - * list of aliases + * @param sortedAliases list of aliases */ private void setParentingAndChildreningOfNonComplexChildrens(final List<Element> sortedAliases) { setParentingOfNonComplexChildrens(sortedAliases); @@ -427,14 +415,22 @@ public class CreateHierarchyCommand extends ModelCommand { nullCompartment.setHeight(Double.MAX_VALUE); for (final Element element : getModel().getElements()) { Compartment supposedParent = nullCompartment; - for (final Compartment alias : getModel().getCompartments()) { - if (alias.contains(element) && alias.getSize() < supposedParent.getSize()) { - supposedParent = alias; + PathwayCompartment supposedPathway = null; + for (final Compartment compartment : getModel().getCompartments()) { + if (compartment instanceof PathwayCompartment) { + if (compartment.contains(element)) { + if (supposedPathway == null || compartment.getSize() < supposedPathway.getSize()) { + supposedPathway = (PathwayCompartment) compartment; + } + } + } else if (compartment.contains(element) && compartment.getSize() < supposedParent.getSize()) { + supposedParent = compartment; } } if (supposedParent != nullCompartment) { supposedParent.addElement(element); } + element.setPathway(supposedPathway); } } @@ -442,12 +438,9 @@ public class CreateHierarchyCommand extends ModelCommand { * Computes the ratio between the minimal object that should be visible, and * alias visible on the top level. * - * @param alias - * alias for which computation is done - * @param limit - * size of the minimal visible object - * @return ratio between the minimal object that should be visible, and alias - * visible on the top level + * @param alias alias for which computation is done + * @param limit size of the minimal visible object + * @return ratio between the minimal object that should be visible, and alias visible on the top level */ private double computeRate(final Element alias, final double limit) { double length = alias.getWidth() / maxZoomFactor; diff --git a/model-command/src/test/java/lcsb/mapviewer/commands/CopyCommandTest.java b/model-command/src/test/java/lcsb/mapviewer/commands/CopyCommandTest.java index 438e274b013dca6908805c65d0720409da449480..c9d4eeb036f26bd1da4cddec937eb61797703b1d 100644 --- a/model-command/src/test/java/lcsb/mapviewer/commands/CopyCommandTest.java +++ b/model-command/src/test/java/lcsb/mapviewer/commands/CopyCommandTest.java @@ -1,21 +1,5 @@ package lcsb.mapviewer.commands; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.awt.geom.Point2D; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; - -import org.apache.commons.lang3.mutable.MutableBoolean; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.graphics.PolylineData; import lcsb.mapviewer.model.map.MiriamData; @@ -40,10 +24,25 @@ import lcsb.mapviewer.model.map.reaction.type.TransportReaction; import lcsb.mapviewer.model.map.species.Complex; import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.GenericProtein; +import org.apache.commons.lang3.mutable.MutableBoolean; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class CopyCommandTest extends CommandTestFunctions { - private ModelComparator comparator = new ModelComparator(); + private final ModelComparator comparator = new ModelComparator(); @Before public void setUp() throws Exception { @@ -148,7 +147,7 @@ public class CopyCommandTest extends CommandTestFunctions { } @Test - public void testCopyModelWithArtifitialAliases() throws Exception { + public void testCopyModelWithArtificialAliases() throws Exception { Model model = getModelForFile("testFiles/artifitial_compartments.xml", false); new CreateHierarchyCommand(model, 2, 2).execute(); @@ -292,17 +291,17 @@ public class CopyCommandTest extends CommandTestFunctions { model.addReaction(reaction); - assertTrue(s1.equals(reaction.getReactants().get(0).getElement())); - assertTrue(s2.equals(reaction.getProducts().get(0).getElement())); + assertEquals(s1, reaction.getReactants().get(0).getElement()); + assertEquals(s2, reaction.getProducts().get(0).getElement()); Model model2 = new CopyCommand(model).execute(); Reaction reaction2 = model2.getReactions().iterator().next(); - assertTrue(s1.equals(reaction.getReactants().get(0).getElement())); - assertTrue(s2.equals(reaction.getProducts().get(0).getElement())); + assertEquals(s1, reaction.getReactants().get(0).getElement()); + assertEquals(s2, reaction.getProducts().get(0).getElement()); - assertFalse(s1.equals(reaction2.getReactants().get(0).getElement())); - assertFalse(s2.equals(reaction2.getProducts().get(0).getElement())); + assertNotEquals(s1, reaction2.getReactants().get(0).getElement()); + assertNotEquals(s2, reaction2.getProducts().get(0).getElement()); assertNotNull(reaction2.getReactants().get(0).getElement().getCompartment()); assertNotNull(reaction2.getProducts().get(0).getElement().getCompartment()); diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/Element.java b/model/src/main/java/lcsb/mapviewer/model/map/species/Element.java index 6de2dcc99e1079a9ce32cfa5b1f7b467e14f78ba..8f06c45f1471fd924cae31d1696bad2370b0902f 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/Element.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/Element.java @@ -1,15 +1,31 @@ package lcsb.mapviewer.model.map.species; -import java.awt.Color; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import lcsb.mapviewer.common.exception.InvalidArgumentException; +import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.graphics.HorizontalAlign; +import lcsb.mapviewer.model.graphics.VerticalAlign; +import lcsb.mapviewer.model.map.BioEntity; +import lcsb.mapviewer.model.map.MiriamData; +import lcsb.mapviewer.model.map.compartment.Compartment; +import lcsb.mapviewer.model.map.compartment.PathwayCompartment; +import lcsb.mapviewer.model.map.kinetics.SbmlArgument; +import lcsb.mapviewer.model.map.layout.graphics.Glyph; +import lcsb.mapviewer.model.map.layout.graphics.LayerText; +import lcsb.mapviewer.model.map.model.ElementSubmodelConnection; +import lcsb.mapviewer.model.map.model.Model; +import lcsb.mapviewer.model.map.model.ModelData; +import lcsb.mapviewer.modelutils.serializer.model.map.ElementAsIdSerializer; +import lcsb.mapviewer.modelutils.serializer.model.map.ModelAsIdSerializer; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.hibernate.annotations.Cascade; +import org.hibernate.annotations.CascadeType; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; +import org.hibernate.annotations.Type; import javax.persistence.CollectionTable; import javax.persistence.Column; @@ -32,34 +48,16 @@ import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.OrderColumn; import javax.xml.bind.annotation.XmlTransient; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.hibernate.annotations.Cascade; -import org.hibernate.annotations.CascadeType; -import org.hibernate.annotations.Fetch; -import org.hibernate.annotations.FetchMode; -import org.hibernate.annotations.Type; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -import lcsb.mapviewer.common.exception.InvalidArgumentException; -import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.model.graphics.HorizontalAlign; -import lcsb.mapviewer.model.graphics.VerticalAlign; -import lcsb.mapviewer.model.map.BioEntity; -import lcsb.mapviewer.model.map.MiriamData; -import lcsb.mapviewer.model.map.compartment.Compartment; -import lcsb.mapviewer.model.map.kinetics.SbmlArgument; -import lcsb.mapviewer.model.map.layout.graphics.Glyph; -import lcsb.mapviewer.model.map.layout.graphics.LayerText; -import lcsb.mapviewer.model.map.model.ElementSubmodelConnection; -import lcsb.mapviewer.model.map.model.Model; -import lcsb.mapviewer.model.map.model.ModelData; -import lcsb.mapviewer.modelutils.serializer.model.map.ElementAsIdSerializer; -import lcsb.mapviewer.modelutils.serializer.model.map.ModelAsIdSerializer; +import java.awt.Color; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; /** * Abstract class representing objects in the model. Elements are objects that @@ -67,7 +65,6 @@ import lcsb.mapviewer.modelutils.serializer.model.map.ModelAsIdSerializer; * element (like symbol, name, etc.). * * @author Piotr Gawron - * */ @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @@ -137,14 +134,19 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { private ElementSubmodelConnection submodel; /** - * {@link Compartment} where element is located. When element lies outside of + * {@link Compartment} where element is located. When element lies outside * every compartment then null value is assigned. */ @ManyToOne(fetch = FetchType.LAZY) - @Cascade({ CascadeType.SAVE_UPDATE }) + @Cascade({CascadeType.SAVE_UPDATE}) @JsonSerialize(using = ElementAsIdSerializer.class) private Compartment compartment; + @ManyToOne(fetch = FetchType.LAZY) + @Cascade({CascadeType.SAVE_UPDATE}) + @JsonSerialize(using = ElementAsIdSerializer.class) + private PathwayCompartment pathway; + /** * Unique string identifier within one model object (usually imported from * external source from which map was imported). @@ -206,8 +208,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { * From which level element should be visible. * * @see #transparencyLevel - * @see lcsb.mapviewer.converter.graphics.AbstractImageGenerator.Params#level - * AbstractImageGenerator.Params#level + * @see lcsb.mapviewer.converter.graphics.AbstractImageGenerator.Params#level AbstractImageGenerator.Params#level */ private String visibilityLevel = ""; @@ -283,7 +284,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { @CollectionTable(name = "element_synonyms", joinColumns = @JoinColumn(name = "id")) @Column(name = "synonym", length = 512) @OrderColumn(name = "idx") - @Cascade({ org.hibernate.annotations.CascadeType.ALL }) + @Cascade({org.hibernate.annotations.CascadeType.ALL}) private List<String> synonyms = new ArrayList<>(); /** @@ -294,27 +295,26 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { @CollectionTable(name = "element_former_symbols", joinColumns = @JoinColumn(name = "id")) @Column(name = "symbol", length = 255) @OrderColumn(name = "idx") - @Cascade({ org.hibernate.annotations.CascadeType.ALL }) + @Cascade({org.hibernate.annotations.CascadeType.ALL}) private List<String> formerSymbols = new ArrayList<>(); /** * Set of miriam annotations for this element. */ - @Cascade({ CascadeType.ALL }) + @Cascade({CascadeType.ALL}) @Fetch(FetchMode.SUBSELECT) @ManyToMany(fetch = FetchType.EAGER) @JoinTable(name = "element_miriam", joinColumns = { - @JoinColumn(name = "element_id", referencedColumnName = "id", nullable = false, updatable = false) }, + @JoinColumn(name = "element_id", referencedColumnName = "id", nullable = false, updatable = false)}, inverseJoinColumns = { - @JoinColumn(name = "miriam_id", referencedColumnName = "id", nullable = true, updatable = true) }) + @JoinColumn(name = "miriam_id", referencedColumnName = "id", nullable = true, updatable = true)}) @JsonProperty(value = "references") private Set<MiriamData> miriamData = new HashSet<>(); /** * Constructor that creates a copy of the element given in the parameter. * - * @param original - * original object that will be used for creating copy + * @param original original object that will be used for creating copy */ protected Element(final Element original) { this.id = original.id; @@ -373,8 +373,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { /** * Adds list of former symbol to the object. * - * @param formerSymbols - * list of former symbols to add + * @param formerSymbols list of former symbols to add */ public void addFormerSymbols(final List<String> formerSymbols) { this.formerSymbols.addAll(formerSymbols); @@ -414,8 +413,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { * Methods that increase size of the element by increaseSize. It influence x, y, * width and height fields of the element. * - * @param increaseSize - * by how many units we want to increase size of the element + * @param increaseSize by how many units we want to increase size of the element */ public void increaseBorder(final double increaseSize) { x -= increaseSize; @@ -428,8 +426,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { * This method computes the distance between point and the element. It assumes * that element is a rectangle. * - * @param point - * point from which we are looking for a distance + * @param point point from which we are looking for a distance * @return distance between point and this element */ public double getDistanceFromPoint(final Point2D point) { @@ -451,25 +448,19 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { /** * Checks if element contains a point. It assumes that element is a rectangle. * - * @param point - * point to check + * @param point point to check * @return <i>true</i> if point belongs to the element, <i>false</i> otherwise */ public boolean contains(final Point2D point) { - if (getX() <= point.getX() && getY() <= point.getY() && getX() + getWidth() >= point.getX() - && getY() + getHeight() >= point.getY()) { - return true; - } - return false; + return getX() <= point.getX() && getY() <= point.getY() && getX() + getWidth() >= point.getX() + && getY() + getHeight() >= point.getY(); } /** * Checks if element contains a {@link LayerText}. * - * @param lt - * text to check - * @return <i>true</i> if {@link LayerText} belongs to the element, <i>false</i> - * otherwise + * @param lt text to check + * @return <i>true</i> if {@link LayerText} belongs to the element, <i>false</i> otherwise */ public boolean contains(final LayerText lt) { return getX() < lt.getX() && getY() < lt.getY() && getX() + getWidth() > lt.getX() + lt.getWidth() @@ -481,8 +472,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { * This method should be overridden by all inheriting classes - it should * properly handle other shapes than rectangle. * - * @param element2 - * object to be checked + * @param element2 object to be checked * @return true if element2 lies in this object, false otherwise */ public boolean contains(final Element element2) { @@ -492,12 +482,11 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { Point2D p3 = new Point2D.Double(element2.getX() + element2.getWidth(), element2.getY()); Point2D p4 = new Point2D.Double(element2.getX() + element2.getWidth(), element2.getY() + element2.getHeight()); return contains(p1) || contains(p2) || contains(p3) || contains(p4); - } else if (getX() < element2.getX() && getY() < element2.getY() - && getX() + getWidth() > element2.getX() + element2.getWidth() - && getY() + getHeight() > element2.getY() + element2.getHeight()) { - return true; + } else { + return getX() < element2.getX() && getY() < element2.getY() + && getX() + getWidth() > element2.getX() + element2.getWidth() + && getY() + getHeight() > element2.getY() + element2.getHeight(); } - return false; } /** @@ -545,79 +534,34 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { return x; } - /** - * Parse and set x coordinate from string. - * - * @param string - * text representing x coordinate - * @see x - */ public void setX(final String string) { setX(Double.parseDouble(string)); } - /** - * - * @param x - * the x value to set - * @see x - */ public void setX(final int x) { setX((double) x); } - /** - * @param x - * the x to set - * @see #x - */ public void setX(final Double x) { this.x = x; } - /** - * @return the y - * @see #y - */ public Double getY() { return y; } - /** - * Parse and set y coordinate from string. - * - * @param string - * text representing y coordinate - * @see y - */ public void setY(final String string) { this.y = Double.parseDouble(string); } - /** - * - * @param y - * the y value to set - * @see y - */ public void setY(final int y) { setY((double) y); } - /** - * @param y - * the y to set - * @see #y - */ public void setY(final Double y) { this.y = y; } - /** - * Makes a copy of the element. - * - * @return copy of the element - */ @Override public abstract Element copy(); @@ -632,9 +576,8 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { /** * Parse and set width. * - * @param string - * text representing width - * @see width + * @param string text representing width + * @see #width */ public void setWidth(final String string) { try { @@ -645,9 +588,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { } /** - * - * @param width - * the width value to set + * @param width the width value to set * @see #width */ public void setWidth(final int width) { @@ -655,8 +596,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { } /** - * @param width - * the width to set + * @param width the width to set * @see #width */ public void setWidth(final Double width) { @@ -674,9 +614,8 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { /** * Parse and set height. * - * @param string - * text representing height - * @see height + * @param string text representing height + * @see #height */ public void setHeight(final String string) { try { @@ -687,9 +626,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { } /** - * - * @param height - * the height value to set + * @param height the height value to set * @see #height */ public void setHeight(final int height) { @@ -697,8 +634,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { } /** - * @param height - * the height to set + * @param height the height to set * @see #height */ public void setHeight(final Double height) { @@ -716,17 +652,15 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { /** * Parse and set font size. * - * @param string - * text representing font size - * @see fontSize + * @param string text representing font size + * @see #fontSize */ public void setFontSize(final String string) { this.fontSize = Double.parseDouble(string); } /** - * @param fontSize - * the fontSize to set + * @param fontSize the fontSize to set * @see #fontSize */ public void setFontSize(final Double fontSize) { @@ -734,8 +668,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { } /** - * @param fontSize - * the fontSize to set + * @param fontSize the fontSize to set * @see #fontSize */ public void setFontSize(final int fontSize) { @@ -753,8 +686,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { } /** - * @param model - * the model to set + * @param model the model to set * @see #model */ public void setModelData(final ModelData model) { @@ -769,17 +701,23 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { return compartment; } + public PathwayCompartment getPathway() { + return pathway; + } + @Override public String getVisibilityLevel() { return visibilityLevel; } /** - * @param compartment - * the compartment to set + * @param compartment the compartment to set * @see #compartment */ public void setCompartment(final Compartment compartment) { + if (compartment instanceof PathwayCompartment) { + throw new InvalidArgumentException("Pathway cannot be set as a parent compartment"); + } if (this.compartment != null && compartment != this.compartment) { Compartment formerCompartment = this.compartment; this.compartment = null; @@ -788,6 +726,10 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { this.compartment = compartment; } + public void setPathway(final PathwayCompartment pathway) { + this.pathway = pathway; + } + @Override public void setVisibilityLevel(final Integer visibilityLevel) { if (visibilityLevel == null) { @@ -811,8 +753,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { } /** - * @param color - * the color to set + * @param color the color to set * @see #fillColor */ public void setFillColor(final Color color) { @@ -828,8 +769,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { } /** - * @param transparencyLevel - * the transparencyLevel to set + * @param transparencyLevel the transparencyLevel to set * @see #transparencyLevel */ public void setTransparencyLevel(final String transparencyLevel) { @@ -845,8 +785,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { } /** - * @param submodel - * the submodel to set + * @param submodel the submodel to set * @see #submodel */ public void setSubmodel(final ElementSubmodelConnection submodel) { @@ -865,8 +804,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { } /** - * @param fullName - * the fullName to set + * @param fullName the fullName to set * @see #fullName */ public void setFullName(final String fullName) { @@ -892,8 +830,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { } /** - * @param model - * the model to set + * @param model the model to set * @see #model */ public void setModel(final Model model) { @@ -901,8 +838,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { } /** - * @param formerSymbols - * the formerSymbols to set + * @param formerSymbols the formerSymbols to set * @see #formerSymbols */ public void setFormerSymbols(final List<String> formerSymbols) { @@ -919,8 +855,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { } /** - * @param miriamData - * the miriamData to set + * @param miriamData the miriamData to set * @see #miriamData */ public void setMiriamData(final Set<MiriamData> miriamData) { @@ -964,8 +899,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { } /** - * @param id - * the id to set + * @param id the id to set * @see #id */ public void setId(final int id) { @@ -997,8 +931,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { } /** - * @param symbol - * the symbol to set + * @param symbol the symbol to set * @see #symbol */ @Override @@ -1025,8 +958,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { } /** - * @param synonyms - * the synonyms to set + * @param synonyms the synonyms to set * @see #synonyms */ @Override @@ -1035,8 +967,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { } /** - * @param formula - * the formula to set + * @param formula the formula to set * @see #formula */ @Override @@ -1054,8 +985,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { } /** - * @param abbreviation - * the abbreviation to set + * @param abbreviation the abbreviation to set * @see #abbreviation */ @Override @@ -1066,8 +996,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { /** * Adds synonyms to the element. * - * @param synonyms - * list of synonyms to be added + * @param synonyms list of synonyms to be added */ public void addSynonyms(final List<String> synonyms) { for (final String string : synonyms) { @@ -1084,8 +1013,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { /** * Adds former symbol to the object. * - * @param formerSymbol - * former symbol to add + * @param formerSymbol former symbol to add */ public void addFormerSymbol(final String formerSymbol) { formerSymbols.add(formerSymbol); @@ -1094,8 +1022,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { /** * Adds synonym to object. * - * @param synonym - * synonym to be added + * @param synonym synonym to be added */ public void addSynonym(final String synonym) { synonyms.add(synonym); @@ -1136,8 +1063,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { } /** - * @param elementId - * the elementId to set + * @param elementId the elementId to set * @see #elementId */ public void setElementId(final String elementId) { diff --git a/persist/src/main/resources/db/migration/hsql/18.0.8/V18.0.8.20241230.2__set_proper_pathway_and_compartment.sql b/persist/src/main/resources/db/migration/hsql/18.0.8/V18.0.8.20241230.2__set_proper_pathway_and_compartment.sql new file mode 100644 index 0000000000000000000000000000000000000000..d69460f18a8fbc7f7edec8f85b60587d41bee205 --- /dev/null +++ b/persist/src/main/resources/db/migration/hsql/18.0.8/V18.0.8.20241230.2__set_proper_pathway_and_compartment.sql @@ -0,0 +1,31 @@ +update element_table child +set compartment_id = null +where element_type_db = 'PATHWAY'; + +update element_table child +set compartment_id = + (select id + from element_table parent + where parent.element_type_db like '%COMPARTMENT' + and parent.model_id = child.model_id + and parent.x < child.x + child.width + and parent.x + parent.width > child.x + and parent.y < child.y + child.height + and parent.y + parent.height > child.y + order by parent.width * parent.height + limit 1) +where element_type_db <> 'PATHWAY'; +; + +update element_table child +set pathway_id = + (select id + from element_table parent + where parent.element_type_db = 'PATHWAY' + and parent.model_id = child.model_id + and parent.x < child.x + child.width + and parent.x + parent.width > child.x + and parent.y < child.y + child.height + and parent.y + parent.height > child.y + order by parent.width * parent.height + limit 1); diff --git a/persist/src/main/resources/db/migration/hsql/18.0.8/V18.0.8.20241230__add_pathway_to_element.sql b/persist/src/main/resources/db/migration/hsql/18.0.8/V18.0.8.20241230__add_pathway_to_element.sql new file mode 100644 index 0000000000000000000000000000000000000000..fc251495f2400b37a78496bb45f450c2c42728b8 --- /dev/null +++ b/persist/src/main/resources/db/migration/hsql/18.0.8/V18.0.8.20241230__add_pathway_to_element.sql @@ -0,0 +1,5 @@ +alter table element_table + add column pathway_id integer; + +ALTER TABLE element_table + ADD CONSTRAINT element_table_pathway_fk FOREIGN KEY (pathway_id) REFERENCES public.element_table (id); diff --git a/persist/src/main/resources/db/migration/postgres/18.0.8/V18.0.8.20241230.2__set_proper_pathway_and_compartment.sql b/persist/src/main/resources/db/migration/postgres/18.0.8/V18.0.8.20241230.2__set_proper_pathway_and_compartment.sql new file mode 100644 index 0000000000000000000000000000000000000000..d69460f18a8fbc7f7edec8f85b60587d41bee205 --- /dev/null +++ b/persist/src/main/resources/db/migration/postgres/18.0.8/V18.0.8.20241230.2__set_proper_pathway_and_compartment.sql @@ -0,0 +1,31 @@ +update element_table child +set compartment_id = null +where element_type_db = 'PATHWAY'; + +update element_table child +set compartment_id = + (select id + from element_table parent + where parent.element_type_db like '%COMPARTMENT' + and parent.model_id = child.model_id + and parent.x < child.x + child.width + and parent.x + parent.width > child.x + and parent.y < child.y + child.height + and parent.y + parent.height > child.y + order by parent.width * parent.height + limit 1) +where element_type_db <> 'PATHWAY'; +; + +update element_table child +set pathway_id = + (select id + from element_table parent + where parent.element_type_db = 'PATHWAY' + and parent.model_id = child.model_id + and parent.x < child.x + child.width + and parent.x + parent.width > child.x + and parent.y < child.y + child.height + and parent.y + parent.height > child.y + order by parent.width * parent.height + limit 1); diff --git a/persist/src/main/resources/db/migration/postgres/18.0.8/V18.0.8.20241230__add_pathway_to_element.sql b/persist/src/main/resources/db/migration/postgres/18.0.8/V18.0.8.20241230__add_pathway_to_element.sql new file mode 100644 index 0000000000000000000000000000000000000000..fc251495f2400b37a78496bb45f450c2c42728b8 --- /dev/null +++ b/persist/src/main/resources/db/migration/postgres/18.0.8/V18.0.8.20241230__add_pathway_to_element.sql @@ -0,0 +1,5 @@ +alter table element_table + add column pathway_id integer; + +ALTER TABLE element_table + ADD CONSTRAINT element_table_pathway_fk FOREIGN KEY (pathway_id) REFERENCES public.element_table (id); diff --git a/persist/src/test/java/lcsb/mapviewer/persist/PersistTestFunctionsNoTransaction.java b/persist/src/test/java/lcsb/mapviewer/persist/PersistTestFunctionsNoTransaction.java index d4078c8e1ecc0f12fe3e954914d222352061f4d1..826d9aee4c2fe5e21000e78c1bf0b2761573abd1 100644 --- a/persist/src/test/java/lcsb/mapviewer/persist/PersistTestFunctionsNoTransaction.java +++ b/persist/src/test/java/lcsb/mapviewer/persist/PersistTestFunctionsNoTransaction.java @@ -1,13 +1,5 @@ package lcsb.mapviewer.persist; -import java.awt.Color; -import java.awt.geom.Point2D; - -import org.junit.Rule; -import org.junit.runner.RunWith; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - import lcsb.mapviewer.common.geometry.PointTransformation; import lcsb.mapviewer.common.tests.TestUtils; import lcsb.mapviewer.common.tests.UnitTestFailedWatcher; @@ -38,17 +30,24 @@ import lcsb.mapviewer.model.map.species.field.ModificationResidue; import lcsb.mapviewer.model.map.species.field.ModificationSite; import lcsb.mapviewer.model.map.species.field.ModificationState; import lcsb.mapviewer.model.map.species.field.Residue; +import org.junit.Rule; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import java.awt.Color; +import java.awt.geom.Point2D; @ContextConfiguration(classes = SpringPersistTestConfig.class) @RunWith(SpringJUnit4ClassRunner.class) -public class PersistTestFunctionsNoTransaction extends TestUtils { +public abstract class PersistTestFunctionsNoTransaction extends TestUtils { @Rule public UnitTestFailedWatcher unitTestFailedWatcher = new UnitTestFailedWatcher(); private static int identifierCounter = 0; - private PointTransformation pt = new PointTransformation(); + private final PointTransformation pt = new PointTransformation(); private static int z = 0; diff --git a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/AllLayoutTests.java b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/AllLayoutTests.java index 343374f35cef6307a76e009e579d07b05ac8897e..4589a948d912fce5a7d1bd5eaf7aec97b7905301 100644 --- a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/AllLayoutTests.java +++ b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/AllLayoutTests.java @@ -4,10 +4,8 @@ import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; -import lcsb.mapviewer.persist.dao.map.layout.alias.AllAliasTests; - @RunWith(Suite.class) -@SuiteClasses({ AllAliasTests.class, +@SuiteClasses({ ReferenceGenomeDaoTest.class, ReferenceGenomeGeneMappingDaoTest.class, }) diff --git a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/AllAliasTests.java b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/AllAliasTests.java deleted file mode 100644 index ff90f895e38e5d5d572169e595fe25c87f87b686..0000000000000000000000000000000000000000 --- a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/AllAliasTests.java +++ /dev/null @@ -1,15 +0,0 @@ -package lcsb.mapviewer.persist.dao.map.layout.alias; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -@RunWith(Suite.class) -@SuiteClasses({ AntisenseRnaTest.class, - ElementDaoTest.class, - ElementDaoGetByQueryTest.class, - RnaTest.class, -}) -public class AllAliasTests { - -} diff --git a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/AntisenseRnaTest.java b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/AntisenseRnaTest.java index 8807f4d53dc0a25c338ea96eaa780e6440e0d0df..f950c5984786b157525251c2080cfb814177bc42 100644 --- a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/AntisenseRnaTest.java +++ b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/AntisenseRnaTest.java @@ -1,14 +1,5 @@ package lcsb.mapviewer.persist.dao.map.layout.alias; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; - import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelFullIndexed; @@ -18,6 +9,14 @@ import lcsb.mapviewer.model.map.species.field.CodingRegion; import lcsb.mapviewer.model.user.User; import lcsb.mapviewer.persist.PersistTestFunctions; import lcsb.mapviewer.persist.dao.ProjectDao; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; public class AntisenseRnaTest extends PersistTestFunctions { @@ -25,7 +24,7 @@ public class AntisenseRnaTest extends PersistTestFunctions { @Autowired private ProjectDao projectDao; - + @Before public void setUp() throws Exception { admin = userDao.getUserByLogin(BUILT_IN_TEST_ADMIN_LOGIN); @@ -48,7 +47,7 @@ public class AntisenseRnaTest extends PersistTestFunctions { Project project2 = projectDao.getProjectByProjectId(TEST_PROJECT_ID); assertNotNull(project2); - assertFalse(project2.equals(project)); + assertNotEquals(project2, project); assertEquals(project.getId(), project2.getId()); Model model2 = new ModelFullIndexed(project2.getModels().iterator().next()); diff --git a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/ElementDaoGetByQueryTest.java b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/ElementDaoGetByQueryTest.java index 052bfe179d2ffbfd8f1bdeebcadc4b07f06dbb98..255e923374ea11f991ed9f3179af92139f437249 100644 --- a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/ElementDaoGetByQueryTest.java +++ b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/ElementDaoGetByQueryTest.java @@ -1,28 +1,5 @@ package lcsb.mapviewer.persist.dao.map.layout.alias; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.data.domain.PageRequest; - import lcsb.mapviewer.model.map.BioEntity; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelData; @@ -37,6 +14,29 @@ import lcsb.mapviewer.persist.SpringPersistTestConfig; import lcsb.mapviewer.persist.dao.map.species.ElementProperty; import lcsb.mapviewer.persist.utils.TransactionalElementDao; import lcsb.mapviewer.persist.utils.TransactionalModelDao; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.data.domain.PageRequest; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; @RunWith(Parameterized.class) public class ElementDaoGetByQueryTest extends PersistTestFunctions { @@ -44,24 +44,21 @@ public class ElementDaoGetByQueryTest extends PersistTestFunctions { private static ApplicationContext applicationContext; @SuppressWarnings("unused") - private Logger logger = LogManager.getLogger(); - - private TransactionalElementDao elementDao; + private static final Logger logger = LogManager.getLogger(); - private List<ModelData> maps; + private final TransactionalElementDao elementDao; private static List<ModelData> testMaps; - private String query; + private final String query; - private boolean perfect; + private final boolean perfect; - private List<Element> expectedResult; + private final List<Element> expectedResult; - private List<Class<? extends BioEntity>> types; + private final List<Class<? extends BioEntity>> types; public ElementDaoGetByQueryTest(final String testName, final Model map, final String query, final boolean perfect, final Object result) { - maps = Arrays.asList(map.getModelData()); this.query = query; this.perfect = perfect; this.expectedResult = new ArrayList<>(); @@ -69,7 +66,7 @@ public class ElementDaoGetByQueryTest extends PersistTestFunctions { this.types = new ElementUtils().getClassesByStringTypes(new ElementUtils().getBioEntityStringTypes()); } else if (result instanceof Element) { Element bioEntity = (Element) result; - this.types = Arrays.asList(bioEntity.getClass()); + this.types = Collections.singletonList(bioEntity.getClass()); this.expectedResult.add(bioEntity); } else { this.types = new ArrayList<>(); @@ -109,35 +106,35 @@ public class ElementDaoGetByQueryTest extends PersistTestFunctions { applicationContext = new AnnotationConfigApplicationContext(SpringPersistTestConfig.class); - Collection<Object[]> data = new ArrayList<Object[]>(); - data.add(new Object[] { "existing name perfect match", map, protein.getName(), true, protein }); - data.add(new Object[] { "existing name not-perfect match", map, "snn", false, protein }); - data.add(new Object[] { "not existing name perfect match", map, "snn", true, null }); - data.add(new Object[] { "not existing name not-perfect match", map, "bla", false, null }); + Collection<Object[]> data = new ArrayList<>(); + data.add(new Object[]{"existing name perfect match", map, protein.getName(), true, protein}); + data.add(new Object[]{"existing name not-perfect match", map, "snn", false, protein}); + data.add(new Object[]{"not existing name perfect match", map, "snn", true, null}); + data.add(new Object[]{"not existing name not-perfect match", map, "bla", false, null}); - data.add(new Object[] { "existing full name perfect match", map, protein.getFullName(), true, protein }); - data.add(new Object[] { "existing full name not-perfect match", map, "BTR5", false, protein }); - data.add(new Object[] { "not existing full name perfect match", map, "BTR5", true, null }); + data.add(new Object[]{"existing full name perfect match", map, protein.getFullName(), true, protein}); + data.add(new Object[]{"existing full name not-perfect match", map, "BTR5", false, protein}); + data.add(new Object[]{"not existing full name perfect match", map, "BTR5", true, null}); - data.add(new Object[] { "existing element id perfect match", map, protein.getElementId(), true, protein }); - data.add(new Object[] { "existing element id not-perfect match", map, protein.getElementId().substring(1), false, - protein }); + data.add(new Object[]{"existing element id perfect match", map, protein.getElementId(), true, protein}); + data.add(new Object[]{"existing element id not-perfect match", map, protein.getElementId().substring(1), false, + protein}); - data.add(new Object[] { "existing synonym perfect match", map, "fancy synonym", true, protein }); - data.add(new Object[] { "existing synonym not-perfect match", map, "synonym", false, protein }); - data.add(new Object[] { "not existing synonym perfect match", map, "synonym", true, null }); + data.add(new Object[]{"existing synonym perfect match", map, "fancy synonym", true, protein}); + data.add(new Object[]{"existing synonym not-perfect match", map, "synonym", false, protein}); + data.add(new Object[]{"not existing synonym perfect match", map, "synonym", true, null}); - data.add(new Object[] { "existing former symbol perfect match", map, "former symbol2", true, protein }); - data.add(new Object[] { "existing former symbol not-perfect match", map, "symbol2", false, protein }); - data.add(new Object[] { "not existing former symbol perfect match", map, "symbol2", true, null }); + data.add(new Object[]{"existing former symbol perfect match", map, "former symbol2", true, protein}); + data.add(new Object[]{"existing former symbol not-perfect match", map, "symbol2", false, protein}); + data.add(new Object[]{"not existing former symbol perfect match", map, "symbol2", true, null}); - data.add(new Object[] { "element without synonym and former symbol ", map, ion.getElementId(), false, ion }); + data.add(new Object[]{"element without synonym and former symbol ", map, ion.getElementId(), false, ion}); - data.add(new Object[] { "type selection", map, "ion", false, ion }); + data.add(new Object[]{"type selection", map, "ion", false, ion}); - data.add(new Object[] { "sort order", map, "ion", false, Arrays.asList(falseIon, falseIon2, ion) }); + data.add(new Object[]{"sort order", map, "ion", false, Arrays.asList(falseIon, falseIon2, ion)}); - testMaps = Arrays.asList(map.getModelData()); + testMaps = Collections.singletonList(map.getModelData()); return data; } @@ -150,7 +147,7 @@ public class ElementDaoGetByQueryTest extends PersistTestFunctions { } @AfterClass - public static void shutdown() throws Exception { + public static void shutdown() { TransactionalModelDao modelDao = applicationContext.getBean(TransactionalModelDao.class); for (final ModelData map : testMaps) { modelDao.delete(map); @@ -159,12 +156,12 @@ public class ElementDaoGetByQueryTest extends PersistTestFunctions { @Test public void test() throws Exception { - Map<ElementProperty, List<? extends Object>> filter = new HashMap<>(); - filter.put(ElementProperty.MAP, maps); + Map<ElementProperty, List<?>> filter = new HashMap<>(); + filter.put(ElementProperty.MAP, testMaps); if (perfect) { - filter.put(ElementProperty.PERFECT_TEXT, Arrays.asList(query)); + filter.put(ElementProperty.PERFECT_TEXT, Collections.singletonList(query)); } else { - filter.put(ElementProperty.TEXT, Arrays.asList(query)); + filter.put(ElementProperty.TEXT, Collections.singletonList(query)); } filter.put(ElementProperty.CLASS, types); List<Element> elements = elementDao.getByFilter(PageRequest.of(0, 10), filter).getContent(); diff --git a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/ElementDaoTest.java b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/ElementDaoTest.java index bf1133aaa3df1fa75e91d1cbb716e6f560256db5..0f6ebe00c97fe6df86560592976dab12d82bde9a 100644 --- a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/ElementDaoTest.java +++ b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/ElementDaoTest.java @@ -39,6 +39,7 @@ import org.springframework.data.domain.Pageable; import java.awt.geom.Point2D; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -60,13 +61,13 @@ public class ElementDaoTest extends PersistTestFunctions { @Autowired private ProjectDao projectDao; - private Integer testChargeVal = 1; - private String testIdAlias = "a"; - private Double testInitialAmount = 2.0; - private Double testInitialConcentration = 3.0; - private String testName = "d"; - private String testNotes = "e"; - private Boolean testOnlySubstanceunits = true; + private final Integer testChargeVal = 1; + private final String testIdAlias = "a"; + private final Double testInitialAmount = 2.0; + private final Double testInitialConcentration = 3.0; + private final String testName = "d"; + private final String testNotes = "e"; + private final Boolean testOnlySubstanceunits = true; @Before public void setUp() throws Exception { @@ -474,7 +475,7 @@ public class ElementDaoTest extends PersistTestFunctions { modelDao.add(map); List<Element> elements = elementDao.getByCoordinates(map.getModelData(), new Point2D.Double(150, 150), 3, - Arrays.asList(Ion.class)); + Collections.singletonList(Ion.class)); assertNotNull(elements); assertEquals(1, elements.size()); @@ -504,8 +505,8 @@ public class ElementDaoTest extends PersistTestFunctions { modelDao.add(map); Map<ElementProperty, List<? extends Object>> properties = new HashMap<>(); - properties.put(ElementProperty.MAP, Arrays.asList(map.getModelData())); - properties.put(ElementProperty.ANNOTATION, Arrays.asList(new MiriamData(MiriamType.HGNC_SYMBOL, "SNCA"))); + properties.put(ElementProperty.MAP, Collections.singletonList(map.getModelData())); + properties.put(ElementProperty.ANNOTATION, Collections.singletonList(new MiriamData(MiriamType.HGNC_SYMBOL, "SNCA"))); Page<Element> elements = elementDao.getByFilter(PageRequest.of(0, 10), properties); @@ -524,8 +525,8 @@ public class ElementDaoTest extends PersistTestFunctions { modelDao.add(map); Map<ElementProperty, List<? extends Object>> properties = new HashMap<>(); - properties.put(ElementProperty.MAP, Arrays.asList(map.getModelData())); - properties.put(ElementProperty.ANNOTATION, Arrays.asList(new MiriamData(MiriamType.HGNC_SYMBOL, "snca"))); + properties.put(ElementProperty.MAP, Collections.singletonList(map.getModelData())); + properties.put(ElementProperty.ANNOTATION, Collections.singletonList(new MiriamData(MiriamType.HGNC_SYMBOL, "snca"))); Page<Element> elements = elementDao.getByFilter(PageRequest.of(0, 10), properties); @@ -547,7 +548,7 @@ public class ElementDaoTest extends PersistTestFunctions { Map<ElementProperty, List<? extends Object>> properties = new HashMap<>(); properties.put(ElementProperty.MAP, Arrays.asList(map.getModelData(), map2.getModelData())); - properties.put(ElementProperty.ANNOTATION, Arrays.asList(new MiriamData(MiriamType.HGNC_SYMBOL, "SNCA"))); + properties.put(ElementProperty.ANNOTATION, Collections.singletonList(new MiriamData(MiriamType.HGNC_SYMBOL, "SNCA"))); Page<Element> elements = elementDao.getByFilter(PageRequest.of(0, 10), properties); @@ -566,8 +567,8 @@ public class ElementDaoTest extends PersistTestFunctions { modelDao.add(map); Map<ElementProperty, List<? extends Object>> properties = new HashMap<>(); - properties.put(ElementProperty.MAP, Arrays.asList(map.getModelData())); - properties.put(ElementProperty.ANNOTATION, Arrays.asList(new MiriamData(MiriamType.HGNC_SYMBOL, "SNCA"))); + properties.put(ElementProperty.MAP, Collections.singletonList(map.getModelData())); + properties.put(ElementProperty.ANNOTATION, Collections.singletonList(new MiriamData(MiriamType.HGNC_SYMBOL, "SNCA"))); Page<Element> elements = elementDao.getByFilter(PageRequest.of(0, 10), properties); @@ -585,8 +586,8 @@ public class ElementDaoTest extends PersistTestFunctions { modelDao.add(map); Map<ElementProperty, List<?>> properties = new HashMap<>(); - properties.put(ElementProperty.MAP, Arrays.asList(map.getModelData())); - properties.put(ElementProperty.ANNOTATION, Arrays.asList(new MiriamData(MiriamType.HGNC_SYMBOL, "SNCA"))); + properties.put(ElementProperty.MAP, Collections.singletonList(map.getModelData())); + properties.put(ElementProperty.ANNOTATION, Collections.singletonList(new MiriamData(MiriamType.HGNC_SYMBOL, "SNCA"))); Page<Element> elements = elementDao.getByFilter(PageRequest.of(0, 10), properties); @@ -605,8 +606,8 @@ public class ElementDaoTest extends PersistTestFunctions { modelDao.add(map); Map<ElementProperty, List<?>> properties = new HashMap<>(); - properties.put(ElementProperty.MAP, Arrays.asList(map.getModelData())); - properties.put(ElementProperty.ANNOTATION, Arrays.asList(new MiriamData(MiriamType.HGNC_SYMBOL, "snca"))); + properties.put(ElementProperty.MAP, Collections.singletonList(map.getModelData())); + properties.put(ElementProperty.ANNOTATION, Collections.singletonList(new MiriamData(MiriamType.HGNC_SYMBOL, "snca"))); Page<Element> elements = elementDao.getByFilter(PageRequest.of(0, 10), properties); @@ -628,7 +629,7 @@ public class ElementDaoTest extends PersistTestFunctions { Map<ElementProperty, List<?>> properties = new HashMap<>(); properties.put(ElementProperty.MAP, Arrays.asList(map.getModelData(), map2.getModelData())); - properties.put(ElementProperty.ANNOTATION, Arrays.asList(new MiriamData(MiriamType.HGNC_SYMBOL, "SNCA"))); + properties.put(ElementProperty.ANNOTATION, Collections.singletonList(new MiriamData(MiriamType.HGNC_SYMBOL, "SNCA"))); Page<Element> elements = elementDao.getByFilter(PageRequest.of(0, 10), properties); @@ -647,8 +648,8 @@ public class ElementDaoTest extends PersistTestFunctions { modelDao.add(map); Map<ElementProperty, List<?>> properties = new HashMap<>(); - properties.put(ElementProperty.MAP, Arrays.asList(map.getModelData())); - properties.put(ElementProperty.ANNOTATION, Arrays.asList(new MiriamData(MiriamType.HGNC_SYMBOL, "SNCA"))); + properties.put(ElementProperty.MAP, Collections.singletonList(map.getModelData())); + properties.put(ElementProperty.ANNOTATION, Collections.singletonList(new MiriamData(MiriamType.HGNC_SYMBOL, "SNCA"))); Page<Element> elements = elementDao.getByFilter(PageRequest.of(0, 10), properties); @@ -666,8 +667,8 @@ public class ElementDaoTest extends PersistTestFunctions { modelDao.add(map); Map<ElementProperty, List<?>> properties = new HashMap<>(); - properties.put(ElementProperty.MAP, Arrays.asList(map.getModelData())); - properties.put(ElementProperty.NAME, Arrays.asList("BLA")); + properties.put(ElementProperty.MAP, Collections.singletonList(map.getModelData())); + properties.put(ElementProperty.NAME, Collections.singletonList("BLA")); Page<Element> elements = elementDao.getByFilter(PageRequest.of(0, 10), properties); @@ -689,12 +690,12 @@ public class ElementDaoTest extends PersistTestFunctions { modelDao.add(map); Map<ElementProperty, List<?>> properties = new HashMap<>(); - properties.put(ElementProperty.MAP, Arrays.asList(map.getModelData())); - properties.put(ElementProperty.SUBMAP_CONNECTION, Arrays.asList(Boolean.TRUE)); + properties.put(ElementProperty.MAP, Collections.singletonList(map.getModelData())); + properties.put(ElementProperty.SUBMAP_CONNECTION, Collections.singletonList(Boolean.TRUE)); Page<Element> elements = elementDao.getByFilter(PageRequest.of(0, 10), properties); - assertEquals(Arrays.asList(protein), elements.getContent()); + assertEquals(Collections.singletonList(protein), elements.getContent()); } @Test @@ -707,8 +708,8 @@ public class ElementDaoTest extends PersistTestFunctions { modelDao.add(map); Map<ElementProperty, List<?>> properties = new HashMap<>(); - properties.put(ElementProperty.MAP, Arrays.asList(map.getModelData())); - properties.put(ElementProperty.NAME, Arrays.asList("BL")); + properties.put(ElementProperty.MAP, Collections.singletonList(map.getModelData())); + properties.put(ElementProperty.NAME, Collections.singletonList("BL")); Page<Element> elements = elementDao.getByFilter(PageRequest.of(0, 10), properties); @@ -733,7 +734,7 @@ public class ElementDaoTest extends PersistTestFunctions { modelDao.add(map); - List<String> elements = elementDao.getSuggestedQueries(Arrays.asList(map.getModelData())); + List<String> elements = elementDao.getSuggestedQueries(Collections.singletonList(map.getModelData())); assertEquals(Arrays.asList("fname", "name1", "symb1", "symb2", "syn1", "syn2"), elements); } @@ -758,7 +759,7 @@ public class ElementDaoTest extends PersistTestFunctions { projectDao.add(project2); Map<ElementProperty, List<?>> properties = new HashMap<>(); - properties.put(ElementProperty.PROJECT, Arrays.asList(map.getProject())); + properties.put(ElementProperty.PROJECT, Collections.singletonList(map.getProject())); Page<Element> elements = elementDao.getByFilter(PageRequest.of(0, 10), properties); @@ -776,7 +777,7 @@ public class ElementDaoTest extends PersistTestFunctions { modelDao.add(map); Map<ElementProperty, List<?>> properties = new HashMap<>(); - properties.put(ElementProperty.CLASS, Arrays.asList(Ion.class)); + properties.put(ElementProperty.CLASS, Collections.singletonList(Ion.class)); Page<Element> elements = elementDao.getByFilter(PageRequest.of(0, 10), properties); @@ -794,8 +795,8 @@ public class ElementDaoTest extends PersistTestFunctions { modelDao.add(map); Map<ElementProperty, List<?>> properties = new HashMap<>(); - properties.put(ElementProperty.ID, Arrays.asList(ion.getId())); - properties.put(ElementProperty.MAP, Arrays.asList(map.getModelData())); + properties.put(ElementProperty.ID, Collections.singletonList(ion.getId())); + properties.put(ElementProperty.MAP, Collections.singletonList(map.getModelData())); Page<Element> element = elementDao.getByFilter(Pageable.unpaged(), properties); @@ -814,9 +815,9 @@ public class ElementDaoTest extends PersistTestFunctions { modelDao.add(model); Map<ElementProperty, List<?>> properties = new HashMap<>(); - properties.put(ElementProperty.ID, Arrays.asList(ion.getId())); - properties.put(ElementProperty.MAP, Arrays.asList(model.getModelData())); - properties.put(ElementProperty.PROJECT, Arrays.asList(project)); + properties.put(ElementProperty.ID, Collections.singletonList(ion.getId())); + properties.put(ElementProperty.MAP, Collections.singletonList(model.getModelData())); + properties.put(ElementProperty.PROJECT, Collections.singletonList(project)); Page<Element> element = elementDao.getByFilter(Pageable.unpaged(), properties); @@ -833,8 +834,8 @@ public class ElementDaoTest extends PersistTestFunctions { modelDao.add(map); Map<ElementProperty, List<?>> properties = new HashMap<>(); - properties.put(ElementProperty.PERFECT_TEXT, Arrays.asList(ion.getId() + "")); - properties.put(ElementProperty.MAP, Arrays.asList(map.getModelData())); + properties.put(ElementProperty.PERFECT_TEXT, Collections.singletonList(ion.getId() + "")); + properties.put(ElementProperty.MAP, Collections.singletonList(map.getModelData())); Page<Element> element = elementDao.getByFilter(Pageable.unpaged(), properties); @@ -855,8 +856,8 @@ public class ElementDaoTest extends PersistTestFunctions { modelDao.add(map); Map<ElementProperty, List<?>> properties = new HashMap<>(); - properties.put(ElementProperty.MAP, Arrays.asList(map.getModelData())); - properties.put(ElementProperty.INCLUDED_IN_COMPARTMENT, Arrays.asList(compartment.getId())); + properties.put(ElementProperty.MAP, Collections.singletonList(map.getModelData())); + properties.put(ElementProperty.INCLUDED_IN_COMPARTMENT, Collections.singletonList(compartment.getId())); Page<Element> elements = elementDao.getByFilter(Pageable.unpaged(), properties); assertEquals(1, elements.getContent().size()); @@ -878,8 +879,8 @@ public class ElementDaoTest extends PersistTestFunctions { modelDao.add(map); Map<ElementProperty, List<?>> properties = new HashMap<>(); - properties.put(ElementProperty.MAP, Arrays.asList(map.getModelData())); - properties.put(ElementProperty.EXCLUDED_FROM_COMPARTMENT, Arrays.asList(compartment.getId())); + properties.put(ElementProperty.MAP, Collections.singletonList(map.getModelData())); + properties.put(ElementProperty.EXCLUDED_FROM_COMPARTMENT, Collections.singletonList(compartment.getId())); Page<Element> elements = elementDao.getByFilter(Pageable.unpaged(), properties); assertEquals(2, elements.getContent().size()); @@ -896,7 +897,7 @@ public class ElementDaoTest extends PersistTestFunctions { modelDao.add(map); Map<ElementProperty, List<?>> properties = new HashMap<>(); - properties.put(ElementProperty.ID, Arrays.asList(ion.getId())); + properties.put(ElementProperty.ID, Collections.singletonList(ion.getId())); Page<Element> element = elementDao.getByFilter(Pageable.unpaged(), properties); @@ -920,7 +921,7 @@ public class ElementDaoTest extends PersistTestFunctions { modelDao.add(map); - Map<MiriamType, Integer> result = elementDao.getAnnotationStatistics(Arrays.asList(map.getModelData())); + Map<MiriamType, Integer> result = elementDao.getAnnotationStatistics(Collections.singletonList(map.getModelData())); assertEquals((Integer) 4, result.get(MiriamType.HGNC_SYMBOL)); assertEquals((Integer) 1, result.get(MiriamType.HGNC)); diff --git a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/RnaTest.java b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/RnaTest.java index cad5536e4abfcd58c0c6e8fb0a307d8c9f27a3dc..e4c0b009068b658b11075bb3b47d3fe081afb8b7 100644 --- a/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/RnaTest.java +++ b/persist/src/test/java/lcsb/mapviewer/persist/dao/map/layout/alias/RnaTest.java @@ -1,14 +1,5 @@ package lcsb.mapviewer.persist.dao.map.layout.alias; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; - import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelFullIndexed; @@ -16,6 +7,14 @@ import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.Rna; import lcsb.mapviewer.persist.PersistTestFunctions; import lcsb.mapviewer.persist.dao.ProjectDao; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; public class RnaTest extends PersistTestFunctions { @@ -43,7 +42,7 @@ public class RnaTest extends PersistTestFunctions { Project project2 = projectDao.getProjectByProjectId(TEST_PROJECT_ID); assertNotNull(project2); - assertFalse(project2.equals(project)); + assertNotEquals(project2, project); assertEquals(project.getId(), project2.getId()); Model model2 = new ModelFullIndexed(project2.getModels().iterator().next()); diff --git a/web/src/test/java/lcsb/mapviewer/web/api/NewApiDocs.java b/web/src/test/java/lcsb/mapviewer/web/api/NewApiDocs.java index 3f6b1a2084d87ff86df142a81b71efbe41af8aea..62ad21b1637c23c0a76ceb99b37f52ae8350a251 100644 --- a/web/src/test/java/lcsb/mapviewer/web/api/NewApiDocs.java +++ b/web/src/test/java/lcsb/mapviewer/web/api/NewApiDocs.java @@ -149,7 +149,7 @@ public class NewApiDocs { .optional() .type(JsonFieldType.NUMBER), fieldWithPath(prefix + "color") - .description("color that shoyld be used when drawing overlay entry") + .description("color that should be used when drawing overlay entry") .optional() .type(JsonFieldType.OBJECT), fieldWithPath(prefix + "description") @@ -163,8 +163,7 @@ public class NewApiDocs { } private List<FieldDescriptor> getReactionCsvFields() { - final List<FieldDescriptor> result = new ArrayList<>(); - result.addAll(Arrays.asList( + return new ArrayList<>(Arrays.asList( fieldWithPath("elementTypes") .description("list of element types") .type(JsonFieldType.ARRAY), @@ -186,12 +185,10 @@ public class NewApiDocs { fieldWithPath("excludedCompartmentIds") .description("list of compartment identifiers where all participant should not be present") .type(JsonFieldType.ARRAY))); - return result; } private List<FieldDescriptor> getElementCsvFields() { - final List<FieldDescriptor> result = new ArrayList<>(); - result.addAll(Arrays.asList( + return new ArrayList<>(Arrays.asList( fieldWithPath("types") .description("list of element types") .type(JsonFieldType.ARRAY), @@ -210,7 +207,6 @@ public class NewApiDocs { fieldWithPath("excludedCompartmentIds") .description("list of compartment identifiers from which elements should be excluded") .type(JsonFieldType.ARRAY))); - return result; } private List<FieldDescriptor> getBioEntityFields(final String prefix) { @@ -310,8 +306,7 @@ public class NewApiDocs { } private List<FieldDescriptor> getSpeciesSpecificFields(final String prefix) { - final List<FieldDescriptor> result = new ArrayList<>(); - result.addAll(Arrays.asList( + final List<FieldDescriptor> result = new ArrayList<>(Arrays.asList( fieldWithPath(prefix + "nameX") .description("x coordinate of the element name on the map") .type(JsonFieldType.NUMBER) @@ -452,6 +447,11 @@ public class NewApiDocs { .type(JsonFieldType.NUMBER) .optional(), + fieldWithPath(prefix + "pathway") + .description("identifier of a pathway in which element is located") + .type(JsonFieldType.NUMBER) + .optional(), + fieldWithPath(prefix + "compartmentName") .description("name of a compartment in which element is located") .type(JsonFieldType.STRING) @@ -549,7 +549,7 @@ public class NewApiDocs { final List<FieldDescriptor> result = new ArrayList<>(); result.addAll(Arrays.asList( fieldWithPath(prefix + "idReaction") - .description("resction identifier taken from source file") + .description("reaction identifier taken from source file") .type(JsonFieldType.STRING) .optional(), fieldWithPath(prefix + "reversible")