Commit 756a6c3c authored by Piotr Gawron's avatar Piotr Gawron
Browse files

gpml shape is a proper enum

parent b4b5d5e7
Pipeline #29744 passed with stage
in 10 minutes and 59 seconds
......@@ -53,23 +53,23 @@ public class ModelContructor {
* List of {@link Shape#shape shapes} that are not supported to be part of a
* {@link Complex complex}.
*/
private static final Set<String> INALID_COMPLEX_SHAPE_CHILDREN = new HashSet<>();
private static final Set<GpmlShape> INALID_COMPLEX_SHAPE_CHILDREN = new HashSet<>();
static {
INALID_COMPLEX_SHAPE_CHILDREN.add("Rectangle");
INALID_COMPLEX_SHAPE_CHILDREN.add("Oval");
INALID_COMPLEX_SHAPE_CHILDREN.add("RoundedRectangle");
INALID_COMPLEX_SHAPE_CHILDREN.add("Golgi Apparatus");
INALID_COMPLEX_SHAPE_CHILDREN.add("Brace");
INALID_COMPLEX_SHAPE_CHILDREN.add("Sarcoplasmic Reticulum");
INALID_COMPLEX_SHAPE_CHILDREN.add("Mitochondria");
INALID_COMPLEX_SHAPE_CHILDREN.add("Endoplasmic Reticulum");
INALID_COMPLEX_SHAPE_CHILDREN.add("Arc");
INALID_COMPLEX_SHAPE_CHILDREN.add("Triangle");
INALID_COMPLEX_SHAPE_CHILDREN.add("Hexagon");
INALID_COMPLEX_SHAPE_CHILDREN.add("None");
INALID_COMPLEX_SHAPE_CHILDREN.add("Pentagon");
INALID_COMPLEX_SHAPE_CHILDREN.add("mim-phosphorylated");
INALID_COMPLEX_SHAPE_CHILDREN.add(GpmlShape.RECTANGLE);
INALID_COMPLEX_SHAPE_CHILDREN.add(GpmlShape.OVAL);
INALID_COMPLEX_SHAPE_CHILDREN.add(GpmlShape.ROUNDED_RECTANGLE);
INALID_COMPLEX_SHAPE_CHILDREN.add(GpmlShape.GOLGI_APPARATUS);
INALID_COMPLEX_SHAPE_CHILDREN.add(GpmlShape.BRACE);
INALID_COMPLEX_SHAPE_CHILDREN.add(GpmlShape.SACROPLASMIC_RETICULUM);
INALID_COMPLEX_SHAPE_CHILDREN.add(GpmlShape.MITOCHONDRIA);
INALID_COMPLEX_SHAPE_CHILDREN.add(GpmlShape.ENDOPLASMIC_RETICULUM);
INALID_COMPLEX_SHAPE_CHILDREN.add(GpmlShape.ARC);
INALID_COMPLEX_SHAPE_CHILDREN.add(GpmlShape.TRIANGLE);
INALID_COMPLEX_SHAPE_CHILDREN.add(GpmlShape.HEXAGON);
INALID_COMPLEX_SHAPE_CHILDREN.add(GpmlShape.NONE);
INALID_COMPLEX_SHAPE_CHILDREN.add(GpmlShape.PENTAGON);
INALID_COMPLEX_SHAPE_CHILDREN.add(GpmlShape.PHOSPHORYLATED);
}
/**
......@@ -234,7 +234,7 @@ public class ModelContructor {
} else {
if (!shape.isCompartment()) {
if (shape.getShape().equalsIgnoreCase("oval")) {
if (shape.getShape().equals(GpmlShape.OVAL)) {
LayerOval oval = createOval(shape);
data.layer.addLayerOval(oval);
} else if (shape.getComments().size() > 0 || shape.getTextLabel() != null) {
......@@ -463,7 +463,7 @@ public class ModelContructor {
*/
public Element updateAlias(GraphicalPathwayElement gpmlElement, Element element) {
if (element instanceof Compartment) {
if (((Shape) gpmlElement).getShape().equalsIgnoreCase("oval")) {
if (((Shape) gpmlElement).getShape().equals(GpmlShape.OVAL)) {
element = new OvalCompartment((Compartment) element);
} else {
element = new SquareCompartment((Compartment) element);
......@@ -569,7 +569,7 @@ public class ModelContructor {
*/
private Species createSpecies(Shape shape) {
Species result = null;
if (shape.getShape() != null && shape.getShape().equals("mim-degradation")) {
if (shape.getShape() != null && shape.getShape().equals(GpmlShape.DEGRADATION)) {
result = new Degraded(shape.getGraphId());
} else {
logger.warn(shape.getLogMarker(), " Shape can not be part of reaction. Tranforming to Unknown");
......
......@@ -14,8 +14,7 @@ import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.ConverterException;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.graphics.LineType;
import lcsb.mapviewer.wikipathway.model.Shape;
import lcsb.mapviewer.wikipathway.model.UnknownTypeException;
import lcsb.mapviewer.wikipathway.model.*;
/**
* Parser class that creates {@link Shape} objects from Xml {@link Element node}
......@@ -157,7 +156,14 @@ public class ShapeParser extends GraphicalPathwayElementParser<Shape> {
height = Double.valueOf(entry.getRight());
break;
case ("ShapeType"):
shape.setShape(entry.getRight());
if (entry.getRight() != null && !entry.getRight().isEmpty()) {
GpmlShape gpmlShape = GpmlShape.stringToGpmlShape(entry.getRight());
if (gpmlShape != null) {
shape.setShape(gpmlShape);
} else {
logger.warn("Unknown shape type: " + entry.getRight());
}
}
break;
case ("Color"):
shape.setColor(hexStringToColor(entry.getRight()));
......
package lcsb.mapviewer.wikipathway.model;
public enum GpmlShape {
HEXAGON ("Hexagon"), OVAL("Oval"), RECTANGLE("Rectangle"), DEGRADATION("mim-degradation");
HEXAGON("Hexagon"),
OVAL("Oval"),
RECTANGLE("Rectangle"),
TRIANGLE("Triangle"),
DEGRADATION("mim-degradation"),
SACROPLASMIC_RETICULUM("Sarcoplasmic Reticulum"),
GOLGI_APPARATUS("Golgi Apparatus"),
ENDOPLASMIC_RETICULUM("Endoplasmic Reticulum"),
MITOCHONDRIA("Mitochondria"),
ROUNDED_RECTANGLE("RoundedRectangle"),
BRACE("Brace"),
ARC("Arc"),
NONE("None"),
PENTAGON("Pentagon"),
PHOSPHORYLATED("mim-phosphorylated"),
;
private String stringRepresentation;
GpmlShape(String stringRepresentation) {
......@@ -12,4 +27,13 @@ public enum GpmlShape {
public String getStringRepresentation() {
return stringRepresentation;
}
public static GpmlShape stringToGpmlShape(String string) {
for (GpmlShape shape : GpmlShape.values()) {
if (shape.getStringRepresentation().equalsIgnoreCase(string)) {
return shape;
}
}
return null;
}
}
......@@ -15,9 +15,11 @@ import lcsb.mapviewer.model.ProjectLogEntryType;
*/
public class Shape extends GraphicalPathwayElement {
private static final List<String> SPECIAL_SHAPE_NAMES = Arrays.asList("Sarcoplasmic Reticulum", "Golgi Apparatus",
"Endoplasmic Reticulum",
"Mitochondria");
private static final List<GpmlShape> SPECIAL_SHAPE_NAMES = Arrays.asList(
GpmlShape.SACROPLASMIC_RETICULUM,
GpmlShape.GOLGI_APPARATUS,
GpmlShape.ENDOPLASMIC_RETICULUM,
GpmlShape.MITOCHONDRIA);
/**
*
......@@ -27,7 +29,7 @@ public class Shape extends GraphicalPathwayElement {
/**
* Shape type of the node.
*/
private String shape;
private GpmlShape shape;
/**
* ???
......@@ -86,9 +88,9 @@ public class Shape extends GraphicalPathwayElement {
public String getName() {
if (SPECIAL_SHAPE_NAMES.contains(shape)) {
if (textLabel != null && !textLabel.isEmpty()) {
return shape + ":" + textLabel;
return shape.getStringRepresentation() + ":" + textLabel;
} else {
return shape;
return shape.getStringRepresentation();
}
}
if (textLabel == null) {
......@@ -100,14 +102,14 @@ public class Shape extends GraphicalPathwayElement {
@Override
public LogMarker getLogMarker() {
return new LogMarker(ProjectLogEntryType.PARSING_ISSUE, getShape(), getGraphId(), getMapName());
return new LogMarker(ProjectLogEntryType.PARSING_ISSUE, getName(), getGraphId(), getMapName());
}
/**
* @return the shape
* @see #shape
*/
public String getShape() {
public GpmlShape getShape() {
return shape;
}
......@@ -116,9 +118,9 @@ public class Shape extends GraphicalPathwayElement {
* the shape to set
* @see #shape
*/
public void setShape(String shape) {
public void setShape(GpmlShape shape) {
this.shape = shape;
if (shape!=null && shape.equals("mim-degradation")) {
if (shape != null && shape.equals(GpmlShape.DEGRADATION)) {
setTreatAsNode(true);
}
}
......
......@@ -2,7 +2,7 @@ package lcsb.mapviewer.wikipathway.XML;
import static org.junit.Assert.*;
import java.awt.*;
import java.awt.Color;
import org.junit.After;
import org.junit.Test;
......@@ -11,6 +11,7 @@ import org.w3c.dom.Element;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.model.graphics.LineType;
import lcsb.mapviewer.wikipathway.WikipathwaysTestFunctions;
import lcsb.mapviewer.wikipathway.model.GpmlShape;
import lcsb.mapviewer.wikipathway.model.Shape;
public class ShapeParserTest extends WikipathwaysTestFunctions {
......@@ -31,7 +32,7 @@ public class ShapeParserTest extends WikipathwaysTestFunctions {
assertEquals((Integer) 16384, shape.getzOrder());
assertEquals((Double) 10.0, shape.getFontSize());
assertEquals("Middle", shape.getvAlign());
assertEquals("Arc", shape.getShape());
assertEquals(GpmlShape.ARC, shape.getShape());
assertEquals((Double) 0.0, shape.getRotation());
assertTrue(shape.getComments().contains("arc c"));
assertTrue(shape.getComments().contains("Type your comment here"));
......@@ -53,7 +54,7 @@ public class ShapeParserTest extends WikipathwaysTestFunctions {
assertEquals((Integer) 16384, shape.getzOrder());
assertEquals((Double) 10.0, shape.getFontSize());
assertEquals("Middle", shape.getvAlign());
assertEquals("Brace", shape.getShape());
assertEquals(GpmlShape.BRACE, shape.getShape());
assertEquals((Double) 0.44830711094422787, shape.getRotation(), Configuration.EPSILON);
assertTrue(shape.getComments().contains("1"));
assertTrue(shape.getComments().contains("Type your comment here"));
......@@ -77,7 +78,7 @@ public class ShapeParserTest extends WikipathwaysTestFunctions {
assertEquals((Double) 3.0, shape.getLineThickness());
assertEquals(LineType.DOUBLE, shape.getLineType());
assertEquals("Middle", shape.getvAlign());
assertEquals("RoundedRectangle", shape.getShape());
assertEquals(GpmlShape.ROUNDED_RECTANGLE, shape.getShape());
assertEquals((Double) 0.0, shape.getRotation(), Configuration.EPSILON);
assertTrue(shape.getComments().contains("compartment comment here"));
assertTrue(shape.getComments().contains("Type your comment here"));
......
......@@ -32,21 +32,28 @@ public class ShapeTest extends WikipathwaysTestFunctions {
@Test
public void getNameForSpecialShapes() {
List<String> specialShapeNames = Arrays.asList("Sarcoplasmic Reticulum", "Golgi Apparatus", "Endoplasmic Reticulum",
"Mitochondria");
for (String string : specialShapeNames) {
List<GpmlShape> specialShapeNames = Arrays.asList(
GpmlShape.SACROPLASMIC_RETICULUM,
GpmlShape.GOLGI_APPARATUS,
GpmlShape.ENDOPLASMIC_RETICULUM,
GpmlShape.MITOCHONDRIA);
for (GpmlShape gpmlShape : specialShapeNames) {
Shape shape = new Shape();
shape.setShape(string);
assertEquals(string, shape.getName());
shape.setShape(gpmlShape);
assertEquals(gpmlShape.getStringRepresentation(), shape.getName());
shape.setTextLabel("bla");
assertTrue(shape.getName().contains(string));
assertTrue(shape.getName().contains(gpmlShape.getStringRepresentation()));
}
}
@Test
public void getNameForGenericShapes() {
List<String> otherShapes = Arrays.asList("Rectangle", "Triangle", "Oval");
for (String string : otherShapes) {
List<GpmlShape> otherShapes = Arrays.asList(
GpmlShape.RECTANGLE,
GpmlShape.TRIANGLE,
GpmlShape.OVAL);
for (GpmlShape string : otherShapes) {
Shape shape = new Shape();
shape.setShape(string);
assertTrue(shape.getName().isEmpty());
......
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