From 4363693a3ac49ec15dd637c2ed0fc3e51f4bb691 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Fri, 11 Jan 2019 13:46:52 +0100
Subject: [PATCH] error reporting improved when there is a problem with
 exporting reaction line

---
 .../celldesigner/reaction/ReactionToXml.java  | 42 +++++++++++--------
 .../model/map/InconsistentModelException.java |  4 ++
 .../modelutils/map/ElementUtils.java          |  6 ++-
 3 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/reaction/ReactionToXml.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/reaction/ReactionToXml.java
index 93b36d3da1..aaf6deac15 100644
--- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/reaction/ReactionToXml.java
+++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/reaction/ReactionToXml.java
@@ -156,8 +156,9 @@ public class ReactionToXml extends XmlParser {
    * @param reaction
    *          reaction for which list is generated
    * @return xml node with list of modification
+   * @throws InconsistentModelException 
    */
-  private String getListOfModificationsXmlStringForReaction(Reaction reaction) {
+  private String getListOfModificationsXmlStringForReaction(Reaction reaction) throws InconsistentModelException {
     StringBuilder sb = new StringBuilder();
     sb.append("<celldesigner:listOfModification>\n");
 
@@ -312,15 +313,16 @@ public class ReactionToXml extends XmlParser {
   }
 
   /**
-   * Creates xml node for given modifer.
+   * Creates xml node for given modifier.
    * 
    * @param modifier
-   *          modifier to be transaformed
+   *          modifier to be transformed
    * @param gate
    *          operator to which modifier is connected (if any)
-   * @return xml node for given modifer
+   * @return xml node for given modifier
+   * @throws InconsistentModelException 
    */
-  private String getModifierXmlString(Modifier modifier, NodeOperator gate) {
+  private String getModifierXmlString(Modifier modifier, NodeOperator gate) throws InconsistentModelException {
     StringBuilder sb = new StringBuilder();
     ModifierTypeUtils modifierTypeUtils = new ModifierTypeUtils();
     sb.append("<celldesigner:modification ");
@@ -340,21 +342,26 @@ public class ReactionToXml extends XmlParser {
       line.setStartPoint(start);
     }
 
-    List<Point2D> points = lineTransformation.getPointsFromLine(line);
-    if (points.size() > 0) {
+    try {
+      List<Point2D> points = lineTransformation.getPointsFromLine(line);
+      if (points.size() > 0) {
 
-      boolean first = true;
-      sb.append(" editPoints=\"");
+        boolean first = true;
+        sb.append(" editPoints=\"");
 
-      for (Point2D point : points) {
-        if (first) {
-          first = false;
-        } else {
-          sb.append(" ");
+        for (Point2D point : points) {
+          if (first) {
+            first = false;
+          } else {
+            sb.append(" ");
+          }
+          sb.append(point.getX() + "," + point.getY());
         }
-        sb.append(point.getX() + "," + point.getY());
+        sb.append("\"");
       }
-      sb.append("\"");
+    } catch (InvalidArgumentException e) {
+      throw new InconsistentModelException(new ElementUtils().getElementTag(modifier) + "Problem with exporting line",
+          e);
     }
 
     sb.append(">\n");
@@ -479,8 +486,9 @@ public class ReactionToXml extends XmlParser {
    * @param reaction
    *          reaction to be processed
    * @return xml node representing annotation part
+   * @throws InconsistentModelException 
    */
-  private String getAnnotationXmlStringForReaction(Reaction reaction) {
+  private String getAnnotationXmlStringForReaction(Reaction reaction) throws InconsistentModelException {
     ReactionLineData rdl = ReactionLineData.getByReactionType(reaction.getClass());
     if (rdl == null) {
       throw new InvalidArgumentException("Unknown reaction type: " + reaction.getClass());
diff --git a/model/src/main/java/lcsb/mapviewer/model/map/InconsistentModelException.java b/model/src/main/java/lcsb/mapviewer/model/map/InconsistentModelException.java
index 2cfa3c8905..b685b33806 100644
--- a/model/src/main/java/lcsb/mapviewer/model/map/InconsistentModelException.java
+++ b/model/src/main/java/lcsb/mapviewer/model/map/InconsistentModelException.java
@@ -22,6 +22,10 @@ public class InconsistentModelException extends Exception {
     super(message);
   }
 
+  public InconsistentModelException(String message, Throwable e) {
+    super(message, e);
+  }
+
   public InconsistentModelException(Exception e) {
     super(e);
   }
diff --git a/model/src/main/java/lcsb/mapviewer/modelutils/map/ElementUtils.java b/model/src/main/java/lcsb/mapviewer/modelutils/map/ElementUtils.java
index 5313c5b44f..932fb236d8 100644
--- a/model/src/main/java/lcsb/mapviewer/modelutils/map/ElementUtils.java
+++ b/model/src/main/java/lcsb/mapviewer/modelutils/map/ElementUtils.java
@@ -260,7 +260,11 @@ public final class ElementUtils {
   }
 
   public String getElementTag(ReactionNode node) {
-    return "[" + node.getClass().getSimpleName() + "]" + getElementTag(node.getElement());
+    String reactionPrefix = "";
+    if (node.getReaction() != null) {
+      reactionPrefix = getElementTag(node.getReaction()).replaceAll("\t", "");
+    }
+    return reactionPrefix + "[" + node.getClass().getSimpleName() + "]" + getElementTag(node.getElement());
   }
 
   public String getElementTag(ModificationResidue mr) {
-- 
GitLab