From b5e803f14708d5206fabe56b0f712fbf27328c6a Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Thu, 14 Jun 2018 14:15:57 +0200
Subject: [PATCH] BioEntity._linkedSubmodelId can be undefined or int only

---
 frontend-js/src/main/js/Functions.js          | 16 +++++
 .../src/main/js/gui/leftPanel/GuiUtils.js     | 11 ++-
 frontend-js/src/main/js/map/data/BioEntity.js | 67 ++++++++++---------
 3 files changed, 60 insertions(+), 34 deletions(-)

diff --git a/frontend-js/src/main/js/Functions.js b/frontend-js/src/main/js/Functions.js
index 8463ed20ac..b04ce60a4f 100644
--- a/frontend-js/src/main/js/Functions.js
+++ b/frontend-js/src/main/js/Functions.js
@@ -43,6 +43,22 @@ Functions.intToColorString = function (value) {
   return '#' + colorStr;
 };
 
+/**
+ *
+ * @param value
+ * @returns {number|undefined}
+ */
+Functions.getIntOrUndefined = function (value) {
+  if (Functions.isInt(value)) {
+    return value;
+  } else if (value === undefined || value === null) {
+    return undefined;
+  } else {
+    logger.warn("Invalid argument type: " + value);
+    return undefined;
+  }
+};
+
 
 /**
  *
diff --git a/frontend-js/src/main/js/gui/leftPanel/GuiUtils.js b/frontend-js/src/main/js/gui/leftPanel/GuiUtils.js
index 69fdb3189d..140eef9a8f 100644
--- a/frontend-js/src/main/js/gui/leftPanel/GuiUtils.js
+++ b/frontend-js/src/main/js/gui/leftPanel/GuiUtils.js
@@ -480,6 +480,14 @@ GuiUtils.prototype.createReactionElement = function (params) {
   return div;
 };
 
+/**
+ *
+ * @param {Alias} params.alias
+ * @param {string} [params.icon]
+ * @param {boolean} [params.showTitle]
+ *
+ * @returns {HTMLDivElement}
+ */
 GuiUtils.prototype.createAliasElement = function (params) {
   var alias = params.alias;
   var icon = params.icon;
@@ -505,7 +513,7 @@ GuiUtils.prototype.createAliasElement = function (params) {
       div.appendChild(self.createSubMapLink("In submap: ", alias.getModelId()));
     }
   }
-  if (alias.getLinkedSubmodelId() !== null && alias.getLinkedSubmodelId() !== undefined) {
+  if (alias.getLinkedSubmodelId() !== undefined) {
     div.appendChild(self.createSubMapLink("Associated submap: ", alias.getLinkedSubmodelId()));
   }
   if (showTitle) {
@@ -526,6 +534,7 @@ GuiUtils.prototype.createAliasElement = function (params) {
   div.appendChild(self.createAnnotations("Annotations: ", alias.getReferences()));
   return div;
 };
+
 GuiUtils.prototype.createSearchBioEntityGroupElement = function (group) {
   if (group.getBioEntities()[0] instanceof Alias) {
     return this.createAliasElement({alias: group, icon: group.getIcon()});
diff --git a/frontend-js/src/main/js/map/data/BioEntity.js b/frontend-js/src/main/js/map/data/BioEntity.js
index f5e5a83706..f2deb9b768 100644
--- a/frontend-js/src/main/js/map/data/BioEntity.js
+++ b/frontend-js/src/main/js/map/data/BioEntity.js
@@ -1,10 +1,11 @@
 "use strict";
 
 var Annotation = require("./Annotation");
+var Functions = require("../../Functions");
 
 /**
  * Class representing BioEntity.
- * 
+ *
  * @constructor
  */
 function BioEntity() {
@@ -12,9 +13,9 @@ function BioEntity() {
 
 /**
  *
- * @returns {number}
+ * @returns {number|undefined}
  */
-BioEntity.prototype.getLinkedSubmodelId = function() {
+BioEntity.prototype.getLinkedSubmodelId = function () {
   return this._linkedSubmodelId;
 };
 
@@ -22,16 +23,16 @@ BioEntity.prototype.getLinkedSubmodelId = function() {
  *
  * @param {number} linkedSubmodelId
  */
-BioEntity.prototype.setLinkedSubmodelId = function(linkedSubmodelId) {
-  this._linkedSubmodelId = linkedSubmodelId;
+BioEntity.prototype.setLinkedSubmodelId = function (linkedSubmodelId) {
+  this._linkedSubmodelId = Functions.getIntOrUndefined(linkedSubmodelId);
 };
 
 /**
  * Returns identifier of the BioEntity.
- * 
+ *
  * @returns {number} identifier of the BioEntity
  */
-BioEntity.prototype.getId = function() {
+BioEntity.prototype.getId = function () {
   return this.id;
 };
 
@@ -39,16 +40,16 @@ BioEntity.prototype.getId = function() {
  *
  * @param {number} id
  */
-BioEntity.prototype.setId = function(id) {
+BioEntity.prototype.setId = function (id) {
   this.id = id;
 };
 
 /**
  * Returns model identifier where {@link BioEntity} is located.
- * 
+ *
  * @returns {number} model identifier where {@link BioEntity} is located
  */
-BioEntity.prototype.getModelId = function() {
+BioEntity.prototype.getModelId = function () {
   return this._modelId;
 };
 
@@ -56,7 +57,7 @@ BioEntity.prototype.getModelId = function() {
  *
  * @param {number} modelId
  */
-BioEntity.prototype.setModelId = function(modelId) {
+BioEntity.prototype.setModelId = function (modelId) {
   this._modelId = modelId;
 };
 
@@ -64,7 +65,7 @@ BioEntity.prototype.setModelId = function(modelId) {
  *
  * @returns {boolean}
  */
-BioEntity.prototype.isComplete = function() {
+BioEntity.prototype.isComplete = function () {
   return this._complete;
 };
 
@@ -72,7 +73,7 @@ BioEntity.prototype.isComplete = function() {
  *
  * @param {boolean} complete
  */
-BioEntity.prototype.setIsComplete = function(complete) {
+BioEntity.prototype.setIsComplete = function (complete) {
   this._complete = complete;
 };
 
@@ -80,7 +81,7 @@ BioEntity.prototype.setIsComplete = function(complete) {
  *
  * @returns {string}
  */
-BioEntity.prototype.getSymbol = function() {
+BioEntity.prototype.getSymbol = function () {
   return this.symbol;
 };
 
@@ -88,7 +89,7 @@ BioEntity.prototype.getSymbol = function() {
  *
  * @param {string} symbol
  */
-BioEntity.prototype.setSymbol = function(symbol) {
+BioEntity.prototype.setSymbol = function (symbol) {
   this.symbol = symbol;
 };
 
@@ -96,7 +97,7 @@ BioEntity.prototype.setSymbol = function(symbol) {
  *
  * @returns {string}
  */
-BioEntity.prototype.getAbbreviation = function() {
+BioEntity.prototype.getAbbreviation = function () {
   return this._abbreviation;
 };
 
@@ -104,7 +105,7 @@ BioEntity.prototype.getAbbreviation = function() {
  *
  * @param {string} abbreviation
  */
-BioEntity.prototype.setAbbreviation = function(abbreviation) {
+BioEntity.prototype.setAbbreviation = function (abbreviation) {
   this._abbreviation = abbreviation;
 };
 
@@ -112,7 +113,7 @@ BioEntity.prototype.setAbbreviation = function(abbreviation) {
  *
  * @returns {string}
  */
-BioEntity.prototype.getFormula = function() {
+BioEntity.prototype.getFormula = function () {
   return this._formula;
 };
 
@@ -120,7 +121,7 @@ BioEntity.prototype.getFormula = function() {
  *
  * @param {string} formula
  */
-BioEntity.prototype.setFormula = function(formula) {
+BioEntity.prototype.setFormula = function (formula) {
   this._formula = formula;
 };
 
@@ -128,7 +129,7 @@ BioEntity.prototype.setFormula = function(formula) {
  *
  * @param {string[]} synonyms
  */
-BioEntity.prototype.setSynonyms = function(synonyms) {
+BioEntity.prototype.setSynonyms = function (synonyms) {
   this._synonyms = synonyms;
 };
 
@@ -136,7 +137,7 @@ BioEntity.prototype.setSynonyms = function(synonyms) {
  *
  * @returns {string[]}
  */
-BioEntity.prototype.getSynonyms = function() {
+BioEntity.prototype.getSynonyms = function () {
   return this._synonyms;
 };
 
@@ -144,7 +145,7 @@ BioEntity.prototype.getSynonyms = function() {
  *
  * @param {string} description
  */
-BioEntity.prototype.setDescription = function(description) {
+BioEntity.prototype.setDescription = function (description) {
   this._description = description;
 };
 
@@ -152,7 +153,7 @@ BioEntity.prototype.setDescription = function(description) {
  *
  * @returns {string}
  */
-BioEntity.prototype.getDescription = function() {
+BioEntity.prototype.getDescription = function () {
   return this._description;
 };
 
@@ -160,7 +161,7 @@ BioEntity.prototype.getDescription = function() {
  *
  * @param {string} type
  */
-BioEntity.prototype.setType = function(type) {
+BioEntity.prototype.setType = function (type) {
   if (type === undefined) {
     throw new Error("type cannot be undefined");
   }
@@ -171,7 +172,7 @@ BioEntity.prototype.setType = function(type) {
  *
  * @returns {string}
  */
-BioEntity.prototype.getType = function() {
+BioEntity.prototype.getType = function () {
   return this._type;
 };
 
@@ -180,7 +181,7 @@ BioEntity.prototype.getType = function() {
  * @param {string} type
  * @returns {Object}
  */
-BioEntity.prototype.getOther = function(type) {
+BioEntity.prototype.getOther = function (type) {
   if (this._other !== undefined) {
     return (type === undefined) ? this._other : this._other[type];
   }
@@ -190,7 +191,7 @@ BioEntity.prototype.getOther = function(type) {
  *
  * @param {Object} other
  */
-BioEntity.prototype.setOther = function(other) {
+BioEntity.prototype.setOther = function (other) {
   this._other = other;
 };
 
@@ -198,7 +199,7 @@ BioEntity.prototype.setOther = function(other) {
  *
  * @returns {number}
  */
-BioEntity.prototype.getHierarchyVisibilityLevel = function() {
+BioEntity.prototype.getHierarchyVisibilityLevel = function () {
   return this._hierarchyVisibilityLevel;
 };
 
@@ -206,7 +207,7 @@ BioEntity.prototype.getHierarchyVisibilityLevel = function() {
  *
  * @param {number} hierarchyVisibilityLevel
  */
-BioEntity.prototype.setHierarchyVisibilityLevel = function(hierarchyVisibilityLevel) {
+BioEntity.prototype.setHierarchyVisibilityLevel = function (hierarchyVisibilityLevel) {
   this._hierarchyVisibilityLevel = hierarchyVisibilityLevel;
 };
 
@@ -214,7 +215,7 @@ BioEntity.prototype.setHierarchyVisibilityLevel = function(hierarchyVisibilityLe
  *
  * @returns {Annotation[]}
  */
-BioEntity.prototype.getReferences = function() {
+BioEntity.prototype.getReferences = function () {
   return this.references;
 };
 
@@ -222,8 +223,8 @@ BioEntity.prototype.getReferences = function() {
  *
  * @param {Annotation[]} references
  */
-BioEntity.prototype.setReferences = function(references) {
-  if (references=== undefined) {
+BioEntity.prototype.setReferences = function (references) {
+  if (references === undefined) {
     throw new Error("references must be defined");
   }
   this.references = [];
@@ -235,7 +236,7 @@ BioEntity.prototype.setReferences = function(references) {
 /**
  * @returns {Point}
  */
-BioEntity.prototype.getCenter = function() {
+BioEntity.prototype.getCenter = function () {
   throw new Error("Not implemented");
 };
 
-- 
GitLab