From 3339ce8320c316766da18b70421808a43c4dba31 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Thu, 26 Apr 2018 16:41:14 +0200
Subject: [PATCH] JS doc for IdentifiedElement

---
 frontend-js/src/main/js/map/data/BioEntity.js |  2 +-
 .../src/main/js/map/data/IdentifiedElement.js | 84 +++++++++++--------
 frontend-js/src/main/js/map/data/PointData.js |  7 +-
 .../js/map/data/IdentifiedElement-test.js     |  4 +-
 4 files changed, 59 insertions(+), 38 deletions(-)

diff --git a/frontend-js/src/main/js/map/data/BioEntity.js b/frontend-js/src/main/js/map/data/BioEntity.js
index b62cc329ee..572b8e6547 100644
--- a/frontend-js/src/main/js/map/data/BioEntity.js
+++ b/frontend-js/src/main/js/map/data/BioEntity.js
@@ -39,7 +39,7 @@ BioEntity.prototype.setId = function(id) {
 /**
  * Returns model identifier where {@link BioEntity} is located.
  * 
- * @returns model identifier where {@link BioEntity} is located
+ * @returns {number} model identifier where {@link BioEntity} is located
  */
 BioEntity.prototype.getModelId = function() {
   return this._modelId;
diff --git a/frontend-js/src/main/js/map/data/IdentifiedElement.js b/frontend-js/src/main/js/map/data/IdentifiedElement.js
index d3244ad698..82f4344c40 100644
--- a/frontend-js/src/main/js/map/data/IdentifiedElement.js
+++ b/frontend-js/src/main/js/map/data/IdentifiedElement.js
@@ -9,6 +9,15 @@ var Point = require('../canvas/Point');
 
 var logger = require('../../logger');
 
+/**
+ * @typedef {Object} IdentifiedElementInput
+ * @property {string|number} [id]
+ * @property {string|number} [objectId]
+ * @property {number} modelId
+ * @property {string} type
+ * @property {string} [icon]
+ */
+
 /**
  * This is object representing element tha should be visualized on the map. It's
  * very light and contains only the most important data. There are three types
@@ -19,42 +28,45 @@ var logger = require('../../logger');
  * <li>"POINT" - for any point on the map, the data connected to this kind of
  * objects are stored in {@link PointData}</li>
  * </ul>
+ *
+ * @param {BioEntity|LayoutAlias|LayoutReaction|PointData|IdentifiedElementInput} object
+ * @constructor
  */
-function IdentifiedElement(javaObject) {
+function IdentifiedElement(object) {
   this._visualizationdata = {};
-  if (javaObject instanceof Alias) {
-    this.setId(javaObject.getId());
-    this.setModelId(javaObject.getModelId());
+  if (object instanceof Alias) {
+    this.setId(object.getId());
+    this.setModelId(object.getModelId());
     this.setType("ALIAS");
-  } else if (javaObject instanceof LayoutAlias) {
-    this.setId(javaObject.getId());
-    this.setModelId(javaObject.getModelId());
+  } else if (object instanceof LayoutAlias) {
+    this.setId(object.getId());
+    this.setModelId(object.getModelId());
     this.setType("ALIAS");
-  } else if (javaObject instanceof Reaction) {
-    this.setId(javaObject.getId());
-    this.setModelId(javaObject.getModelId());
+  } else if (object instanceof Reaction) {
+    this.setId(object.getId());
+    this.setModelId(object.getModelId());
     this.setType("REACTION");
-  } else if (javaObject instanceof LayoutReaction) {
-    this.setId(javaObject.getId());
-    this.setModelId(javaObject.getModelId());
+  } else if (object instanceof LayoutReaction) {
+    this.setId(object.getId());
+    this.setModelId(object.getModelId());
     this.setType("REACTION");
-  } else if (javaObject instanceof PointData) {
-    this.setId(javaObject.getId());
-    this.setModelId(javaObject.getModelId());
+  } else if (object instanceof PointData) {
+    this.setId(object.getId());
+    this.setModelId(object.getModelId());
     this.setType("POINT");
   } else {
     // identifier of the object to visualize
-    if (javaObject.objectId === undefined) {
-      this.setId(javaObject.id);
+    if (object.objectId === undefined) {
+      this.setId(object.id);
     } else {
-      this.setId(javaObject.objectId);
+      this.setId(object.objectId);
     }
     // which marker should be used to show this object
-    this.setIcon(javaObject.icon);
+    this.setIcon(object.icon);
     // on which model the element is located
-    this.setModelId(javaObject.modelId);
+    this.setModelId(object.modelId);
     // what kind of object we are talking about
-    this.setType(javaObject.type);
+    this.setType(object.type);
   }
 
   if (this.getType() === "POINT") {
@@ -75,8 +87,8 @@ function IdentifiedElement(javaObject) {
     throw new Error("Unknown type of identified element: " + this.getType());
   }
 
-  if (this.getId() === undefined || this.getId() === null) {
-    throw new Error("Id not defined for element: " + javaObject);
+  if (this.getId() === undefined) {
+    throw new Error("Id not defined for element: " + object);
   }
 }
 
@@ -84,7 +96,7 @@ function IdentifiedElement(javaObject) {
  * Returns point where it should be visualized when the type of object is
  * "POINT".
  *
- * @returns {@link Point} where it should be visualized when the
+ * @returns {Point|null} where it should be visualized when the
  *          type of object is "POINT".
  */
 IdentifiedElement.prototype.getPoint = function () {
@@ -114,6 +126,10 @@ IdentifiedElement.prototype.setId = function (id) {
   this.id = id;
 };
 
+/**
+ *
+ * @param {number|string} modelId
+ */
 IdentifiedElement.prototype.setModelId = function (modelId) {
   if (modelId === undefined || modelId === null) {
     throw new Error("ModelId is invalid");
@@ -156,12 +172,16 @@ IdentifiedElement.prototype.setType = function (type) {
 /**
  * Returns icon that should be used for visualization.
  *
- * @returns icon that should be used for visualization
+ * @returns {string} icon that should be used for visualization
  */
 IdentifiedElement.prototype.getIcon = function () {
   return this._visualizationdata._icon;
 };
 
+/**
+ *
+ * @param {string} icon
+ */
 IdentifiedElement.prototype.setIcon = function (icon) {
   this._visualizationdata._icon = icon;
 };
@@ -207,14 +227,6 @@ IdentifiedElement.prototype.setLineColor = function (lineColor) {
   this._visualizationdata._lineColor = lineColor;
 };
 
-IdentifiedElement.prototype.getOnClickHandler = function () {
-  return this._visualizationdata._onClickHandler;
-};
-
-IdentifiedElement.prototype.setOnClickHandler = function (onClickHandler) {
-  this._visualizationdata._onClickHandler = onClickHandler;
-};
-
 IdentifiedElement.prototype.equals = function (argument) {
   if (argument instanceof IdentifiedElement) {
     return (this.getType() === argument.getType() && //
@@ -225,6 +237,10 @@ IdentifiedElement.prototype.equals = function (argument) {
   }
 };
 
+/**
+ *
+ * @returns {string}
+ */
 IdentifiedElement.prototype.toString = function () {
   var self = this;
   return "[" + IdentifiedElement.prototype.constructor.name + "] " + self.getType() + " " + self.getId() + " (model: "
diff --git a/frontend-js/src/main/js/map/data/PointData.js b/frontend-js/src/main/js/map/data/PointData.js
index 4ba8d59fed..c97186d002 100644
--- a/frontend-js/src/main/js/map/data/PointData.js
+++ b/frontend-js/src/main/js/map/data/PointData.js
@@ -13,8 +13,7 @@ function PointData(javaObject, modelId) {
     this._point = javaObject.getPoint();
     this._modelId = javaObject.getModelId();
   } else {
-    var tmp = javaObject.idObject;
-    tmp = javaObject.idObject.replace("Point2D.Double", "");
+    var tmp = javaObject.idObject.replace("Point2D.Double", "");
     tmp = JSON.parse(tmp);
     var x = parseFloat(tmp[0]).toFixed(2);
     var y = parseFloat(tmp[1]).toFixed(2);
@@ -42,6 +41,10 @@ PointData.prototype.getPoint = function() {
   return this._point;
 };
 
+/**
+ *
+ * @returns {number}
+ */
 PointData.prototype.getModelId = function() {
   return this._modelId;
 };
diff --git a/frontend-js/src/test/js/map/data/IdentifiedElement-test.js b/frontend-js/src/test/js/map/data/IdentifiedElement-test.js
index 1f590dc195..511a360a8c 100644
--- a/frontend-js/src/test/js/map/data/IdentifiedElement-test.js
+++ b/frontend-js/src/test/js/map/data/IdentifiedElement-test.js
@@ -98,6 +98,7 @@ describe('IdentifiedElement', function () {
         modelId: 2
       };
       var code = function () {
+        // noinspection JSCheckFunctionSignatures
         new IdentifiedElement(javaObject);
       };
       assert.throws(code, new RegExp("Type not defined"));
@@ -130,6 +131,7 @@ describe('IdentifiedElement', function () {
         objectId: "el_id"
       };
       var code = function () {
+        // noinspection JSCheckFunctionSignatures
         new IdentifiedElement(javaObject);
       };
       assert.throws(code, new RegExp("ModelId is invalid"));
@@ -150,7 +152,7 @@ describe('IdentifiedElement', function () {
       var javaObject = {
         type: "alias",
         objectId: "el_id",
-        modelId: "m_id"
+        modelId: 123
       };
       var ie = new IdentifiedElement(javaObject);
       var point = ie.getPoint();
-- 
GitLab