Commit 02c1436d authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '1273-exported-as-gpml-that-can-not-upload-to-minerva' into 'master'

Resolve "exported as GPML that can not upload to MINERVA"

Closes #1273

See merge request !1167
parents 61cc24c2 40bfd53f
Pipeline #27980 passed with stage
in 12 minutes and 21 seconds
......@@ -15,7 +15,9 @@ minerva (15.0.0~beta.5) unstable; urgency=medium
* Bug fix: proper color is parsed from CellDesigner species marked as 'brief'
(#1268)
* Bug fix: unknown elements are exported to 'Unknown' data nodes in GPML
(#1273)
(#1274)
* Bug fix: uploading map with elements having identifiers like "artX" could
break upload (#1273)
-- Piotr Gawron <piotr.gawron@uni.lu> Tue, 2 Jun 2020 16:00:00 +0200
......
......@@ -151,7 +151,9 @@ public class CreateHierarchyCommand extends ModelCommand {
int id = 0;
for (Layer layer : model.getLayers()) {
for (LayerRect rect : layer.getRectangles()) {
PathwayCompartment compartment = new PathwayCompartment("art" + (id++));
int nextId = getNextArtId(model, id);
id = nextId + 1;
PathwayCompartment compartment = new PathwayCompartment("art" + nextId);
compartment.setX(rect.getX());
compartment.setY(rect.getY());
compartment.setWidth(rect.getWidth());
......@@ -170,7 +172,9 @@ public class CreateHierarchyCommand extends ModelCommand {
model.addElement(compartment);
}
for (LayerText text : layer.getTexts()) {
PathwayCompartment compartment = new PathwayCompartment("art" + (id++));
int nextId = getNextArtId(model, id);
id = nextId + 1;
PathwayCompartment compartment = new PathwayCompartment("art" + nextId);
compartment.setX(text.getX());
compartment.setY(text.getY());
compartment.setWidth(text.getWidth());
......@@ -195,6 +199,18 @@ public class CreateHierarchyCommand extends ModelCommand {
}
}
private int getNextArtId(Model model, int id) {
int result = id;
int numberOfElements = model.getElements().size();
for (int i = 0; i < numberOfElements + 1; i++) {
if (model.getElementByElementId("art" + result) == null) {
return result;
}
result++;
}
return result;
}
private String extractNotesFromText(String notes) {
if (notes.indexOf("\n") >= 0) {
return notes.substring(notes.indexOf("\n"));
......
......@@ -21,8 +21,7 @@ import lcsb.mapviewer.model.map.layout.graphics.Layer;
import lcsb.mapviewer.model.map.layout.graphics.LayerRect;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.*;
import lcsb.mapviewer.modelutils.map.ElementUtils;
public class CreateHierarchyCommandTest extends CommandTestFunctions {
......@@ -316,4 +315,35 @@ public class CreateHierarchyCommandTest extends CommandTestFunctions {
assertEquals(pathway.getBorderColor(), pathway.getFontColor());
}
@Test
public void testCreatePathwayWhenIdIsTaken() throws Exception {
Model model = new ModelFullIndexed(null);
Layer layer = new Layer();
LayerRect layerRect = new LayerRect();
layerRect.setBorderColor(Color.BLUE);
layerRect.setFillColor(Color.YELLOW);
layer.addLayerRect(layerRect);
LayerRect layerRect2 = new LayerRect();
layerRect2.setBorderColor(Color.BLUE);
layerRect2.setFillColor(Color.YELLOW);
layer.addLayerRect(layerRect2);
model.addLayer(layer);
Protein protein = createProtein();
protein.setElementId("art0");
model.addElement(protein);
Protein protein2 = createProtein();
protein2.setElementId("art1");
model.addElement(protein2);
CreateHierarchyCommand command = new CreateHierarchyCommand(model, 4, 80);
command.createArtificials();
PathwayCompartment pathway = (PathwayCompartment) model.getCompartments().get(0);
assertNotNull(pathway);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment