Commit 48d28b7f authored by Piotr Gawron's avatar Piotr Gawron
Browse files

default_compartment should be checked against existing element ids

parent bc864bfc
Pipeline #51104 failed with stage
in 13 minutes and 50 seconds
......@@ -13,6 +13,8 @@ minerva (16.0.6) stable; urgency=medium
* Bug fix: when there is problem with loading data from minerva
("Load failed") suggestion about retrying before submitting error report is
provided (#1623)
* Bug fix: export to SBML of model that contained compartment with
"default_compartment" id was crashing (#1622)
-- Piotr Gawron <piotr.gawron@uni.lu> Thu, 16 Dec 2021 11:00:00 +0200
......
package lcsb.mapviewer.converter.model.sbml.compartment;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.sbml.jsbml.Model;
import org.sbml.jsbml.ext.layout.*;
import org.sbml.jsbml.ext.layout.AbstractReferenceGlyph;
import org.sbml.jsbml.ext.layout.BoundingBox;
import org.sbml.jsbml.ext.layout.CompartmentGlyph;
import org.sbml.jsbml.ext.layout.Dimensions;
import org.sbml.jsbml.ext.layout.Point;
import org.sbml.jsbml.ext.multi.MultiCompartmentPlugin;
import org.sbml.jsbml.ext.render.*;
import org.sbml.jsbml.ext.render.Ellipse;
import org.sbml.jsbml.ext.render.LocalStyle;
import org.sbml.jsbml.ext.render.Rectangle;
import org.sbml.jsbml.ext.render.RelAbsVector;
import lcsb.mapviewer.converter.model.sbml.SbmlElementExporter;
import lcsb.mapviewer.converter.model.sbml.SbmlExtension;
......@@ -22,8 +31,8 @@ public class SbmlCompartmentExporter extends SbmlElementExporter<Compartment, or
@SuppressWarnings("unused")
private static Logger logger = LogManager.getLogger();
public SbmlCompartmentExporter(Model sbmlModel, lcsb.mapviewer.model.map.model.Model minervaModel,
Collection<SbmlExtension> sbmlExtensions) {
public SbmlCompartmentExporter(final Model sbmlModel, final lcsb.mapviewer.model.map.model.Model minervaModel,
final Collection<SbmlExtension> sbmlExtensions) {
super(sbmlModel, minervaModel, sbmlExtensions);
}
......@@ -45,7 +54,7 @@ public class SbmlCompartmentExporter extends SbmlElementExporter<Compartment, or
}
@Override
public org.sbml.jsbml.Compartment createSbmlElement(Compartment element) throws InconsistentModelException {
public org.sbml.jsbml.Compartment createSbmlElement(final Compartment element) throws InconsistentModelException {
org.sbml.jsbml.Compartment result;
if (element == null || getElementId(element).equals("default")) {
result = getSbmlModel().createCompartment("default");
......@@ -65,7 +74,7 @@ public class SbmlCompartmentExporter extends SbmlElementExporter<Compartment, or
}
@Override
public org.sbml.jsbml.Compartment getSbmlElement(Compartment element) throws InconsistentModelException {
public org.sbml.jsbml.Compartment getSbmlElement(final Compartment element) throws InconsistentModelException {
String mapKey = getSbmlIdKey(element);
if (element == null && sbmlElementByElementNameAndCompartmentName.get(mapKey) == null) {
org.sbml.jsbml.Compartment sbmlElement = createSbmlElement(element);
......@@ -75,7 +84,7 @@ public class SbmlCompartmentExporter extends SbmlElementExporter<Compartment, or
}
@Override
protected String getSbmlIdKey(Compartment compartment) {
protected String getSbmlIdKey(final Compartment compartment) {
if (compartment == null || getElementId(compartment).equals("default")) {
return "default";
}
......@@ -83,16 +92,20 @@ public class SbmlCompartmentExporter extends SbmlElementExporter<Compartment, or
}
@Override
protected AbstractReferenceGlyph createElementGlyph(String sbmlCompartmentId, String glyphId) {
protected AbstractReferenceGlyph createElementGlyph(final String sbmlCompartmentId, String glyphId) {
if (sbmlCompartmentId.equals("default")) {
glyphId = "default_compartment";
while (getMinervaModel().getElementByElementId(glyphId) != null ||
getMinervaModel().getReactionByReactionId(glyphId) != null) {
glyphId = "default_compartment_" + getNextId();
}
}
CompartmentGlyph result = getLayout().createCompartmentGlyph(glyphId, sbmlCompartmentId);
return result;
}
@Override
protected LocalStyle createStyle(Compartment element) {
protected LocalStyle createStyle(final Compartment element) {
LocalStyle style = super.createStyle(element);
style.getGroup().setStrokeWidth(element.getThickness());
style.getGroup().setFill(getColorDefinition(element.getFillColor()).getId());
......@@ -119,7 +132,7 @@ public class SbmlCompartmentExporter extends SbmlElementExporter<Compartment, or
}
@Override
protected void assignLayoutToGlyph(Compartment element, AbstractReferenceGlyph speciesGlyph) {
protected void assignLayoutToGlyph(final Compartment element, final AbstractReferenceGlyph speciesGlyph) {
if (getElementId(element).equals("default")) {
BoundingBox boundingBox = new BoundingBox();
......
......@@ -770,4 +770,16 @@ public class SbmlExporterTest extends SbmlTestFunctions {
}
@Test
public void testExportWithCompartmentWithProblematicId() throws Exception {
Model model = createEmptyModel();
Compartment defaultCompartment = createCompartment();
defaultCompartment.setElementId("default_compartment");
model.addElement(defaultCompartment);
exporter.toXml(model);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment