From c33a50a5e89c39103c565227be248ca13b12dc91 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Mon, 12 Jun 2017 12:13:29 +0200
Subject: [PATCH] full reactions have information about products, reactants and
 modifiers

---
 frontend-js/src/main/js/map/data/MapModel.js  | 17 +++------
 frontend-js/src/main/js/map/data/Reaction.js  | 38 ++++++++++++-------
 frontend-js/src/test/js/minerva-test.js       | 22 +++++++++++
 .../id=329167,329168&token=MOCK_TOKEN_ID&     |  1 +
 .../id=329167,329169&token=MOCK_TOKEN_ID&     |  1 +
 .../id=329167,329172&token=MOCK_TOKEN_ID&     |  1 +
 6 files changed, 55 insertions(+), 25 deletions(-)
 create mode 100644 frontend-js/testFiles/apiCalls/projects/sample/models/all/bioEntities/elements/id=329167,329168&token=MOCK_TOKEN_ID&
 create mode 100644 frontend-js/testFiles/apiCalls/projects/sample/models/all/bioEntities/elements/id=329167,329169&token=MOCK_TOKEN_ID&
 create mode 100644 frontend-js/testFiles/apiCalls/projects/sample/models/all/bioEntities/elements/id=329167,329172&token=MOCK_TOKEN_ID&

diff --git a/frontend-js/src/main/js/map/data/MapModel.js b/frontend-js/src/main/js/map/data/MapModel.js
index b6137d4703..b9927e770f 100644
--- a/frontend-js/src/main/js/map/data/MapModel.js
+++ b/frontend-js/src/main/js/map/data/MapModel.js
@@ -194,18 +194,10 @@ MapModel.prototype.getCompleteReactionById = function(id) {
     return Promise.resolve(self._reactions[id]);
   } else {
     var result;
-    return ServerConnector.getReactions({
-      ids : [ id ]
-    }).then(
-        function(reactions) {
-          if (self._reactions[id] === undefined) {
-            self._reactions[id] = reactions[0];
-          } else {
-            self._reactions[id].update(reactions[0]);
-          }
+    return self.getReactionById(id).then(
+        function(result) {
           var ids = [];
           var i;
-          result = self._reactions[id];
           for (i = 0; i < result.getReactants().length; i++) {
             if (!(result.getReactants()[i] instanceof Alias)) {
               if (self._aliases[result.getReactants()[i]] === undefined
@@ -304,7 +296,8 @@ MapModel.prototype.getMissingElements = function(elements) {
   var reactionPromise = null;
   if (reactionIds.length > 0) {
     reactionPromise = ServerConnector.getReactions({
-      ids : reactionIds
+      ids : reactionIds,
+      complete : elements.complete
     });
   }
 
@@ -674,7 +667,7 @@ MapModel.prototype.getByIdentifiedElements = function(identifiedElements, comple
   }).then(function() {
     var promises = [];
     for (var i = 0; i < identifiedElements.length; i++) {
-      promises.push(self.getByIdentifiedElement(identifiedElements[i]));
+      promises.push(self.getByIdentifiedElement(identifiedElements[i], complete));
     }
     return Promise.all(promises);
   });
diff --git a/frontend-js/src/main/js/map/data/Reaction.js b/frontend-js/src/main/js/map/data/Reaction.js
index 9393da43ee..ade385e75a 100644
--- a/frontend-js/src/main/js/map/data/Reaction.js
+++ b/frontend-js/src/main/js/map/data/Reaction.js
@@ -1,5 +1,7 @@
 "use strict";
 
+var Alias = require('./Alias');
+
 /**
  * Class representing reaction data.
  * 
@@ -106,7 +108,7 @@ Reaction.prototype.update = function(javaObject) {
   this.setDescription(javaObject.notes);
   this.setOther(javaObject.other);
   this.setReferences(javaObject.references);
-  
+
   if (javaObject.reactants !== "") {
     this.setReactants(javaObject.reactants.split(","));
   } else {
@@ -122,13 +124,23 @@ Reaction.prototype.update = function(javaObject) {
   } else {
     this.setModifiers([]);
   }
-  
+
   this.setHierarchyVisibilityLevel(javaObject.hierarchyVisibilityLevel);
   this.setIsComplete(true);
 };
 
 Reaction.prototype.isComplete = function() {
-  return this._complete;
+  var self = this;
+  var result = self._complete;
+  var reactants = self.getReactants();
+  if (reactants.length === 0) {
+    result = false;
+  } else {
+    if (!(self.getReactants()[0] instanceof Alias)) {
+      result = false;
+    }
+  }
+  return result;
 };
 
 Reaction.prototype.setIsComplete = function(complete) {
@@ -151,15 +163,15 @@ Reaction.prototype.setSymbol = function(symbol) {
   this._symbol = symbol;
 };
 
-Reaction.prototype.getAbbreviation= function() {
+Reaction.prototype.getAbbreviation = function() {
   return this._abbreviation;
 };
 
-Reaction.prototype.setAbbreviation= function(abbreviation) {
+Reaction.prototype.setAbbreviation = function(abbreviation) {
   this._abbreviation = abbreviation;
 };
 
-Reaction.prototype.getFormula= function() {
+Reaction.prototype.getFormula = function() {
   return this._formula;
 };
 
@@ -167,7 +179,7 @@ Reaction.prototype.setFormula = function(formula) {
   this._formula = formula;
 };
 
-Reaction.prototype.getMechanicalConfidenceScore= function() {
+Reaction.prototype.getMechanicalConfidenceScore = function() {
   return this._mechanicalConfidenceScore;
 };
 
@@ -175,7 +187,7 @@ Reaction.prototype.setMechanicalConfidenceScore = function(mechanicalConfidenceS
   this._mechanicalConfidenceScore = mechanicalConfidenceScore;
 };
 
-Reaction.prototype.getLowerBound= function() {
+Reaction.prototype.getLowerBound = function() {
   return this._lowerBound;
 };
 
@@ -183,7 +195,7 @@ Reaction.prototype.setLowerBound = function(lowerBound) {
   this._lowerBound = lowerBound;
 };
 
-Reaction.prototype.getUpperBound= function() {
+Reaction.prototype.getUpperBound = function() {
   return this._upperBound;
 };
 
@@ -195,7 +207,7 @@ Reaction.prototype.setGeneProteinReaction = function(geneProteinReaction) {
   this._geneProteinReaction = geneProteinReaction;
 };
 
-Reaction.prototype.getGeneProteinReaction= function() {
+Reaction.prototype.getGeneProteinReaction = function() {
   return this._geneProteinReaction;
 };
 
@@ -203,7 +215,7 @@ Reaction.prototype.setSubsystem = function(subsystem) {
   this._subsystem = subsystem;
 };
 
-Reaction.prototype.getSubsystem= function() {
+Reaction.prototype.getSubsystem = function() {
   return this._subsystem;
 };
 
@@ -211,7 +223,7 @@ Reaction.prototype.setSynonyms = function(synonyms) {
   this._synonyms = synonyms;
 };
 
-Reaction.prototype.getSynonyms= function() {
+Reaction.prototype.getSynonyms = function() {
   return this._synonyms;
 };
 
@@ -219,7 +231,7 @@ Reaction.prototype.setDescription = function(description) {
   this._description = description;
 };
 
-Reaction.prototype.getDescription= function() {
+Reaction.prototype.getDescription = function() {
   return this._description;
 };
 
diff --git a/frontend-js/src/test/js/minerva-test.js b/frontend-js/src/test/js/minerva-test.js
index a784b86354..a12b0aa3d2 100644
--- a/frontend-js/src/test/js/minerva-test.js
+++ b/frontend-js/src/test/js/minerva-test.js
@@ -4,6 +4,7 @@ var Helper = require('./helper');
 
 require("./mocha-config.js");
 
+var Alias = require('../../main/js/map/data/Alias');
 var minerva = require('../../main/js/minerva');
 var Project = require('../../main/js/map/data/Project');
 var GuiConnectorMock = require('./GuiConnector-mock');
@@ -281,6 +282,27 @@ describe('minerva global', function() {
     });
   });
 
+  it("getBioEntityById for reaction", function() {
+    var options = {
+      projectId : "sample",
+      element : testDiv
+    };
+    var globalResult;
+    return minerva.create(options).then(function(result) {
+      globalResult = result;
+      return result.getBioEntityById({
+        id : 153508,
+        modelId : 15781,
+        type : "REACTION"
+      });
+    }).then(function(result) {
+      assert.ok(result);
+      assert.ok(result.getReactants()[0] instanceof Alias);
+    }).then(function() {
+      globalResult.destroy();
+    });
+  });
+
   it("showElement", function() {
     var options = {
       projectId : "sample",
diff --git a/frontend-js/testFiles/apiCalls/projects/sample/models/all/bioEntities/elements/id=329167,329168&token=MOCK_TOKEN_ID& b/frontend-js/testFiles/apiCalls/projects/sample/models/all/bioEntities/elements/id=329167,329168&token=MOCK_TOKEN_ID&
new file mode 100644
index 0000000000..4f5e996668
--- /dev/null
+++ b/frontend-js/testFiles/apiCalls/projects/sample/models/all/bioEntities/elements/id=329167,329168&token=MOCK_TOKEN_ID&
@@ -0,0 +1 @@
+[{"symbol":null,"formerSymbols":[],"references":[],"modelId":15781,"synonyms":[],"description":"","fullName":null,"complexId":null,"type":"Antisense RNA","abbreviation":null,"compartmentId":null,"name":"s6","bounds":{"x":101.0,"width":90.0,"y":129.5,"height":25.0},"formula":null,"id":329167,"hierarchyVisibilityLevel":0},{"symbol":null,"formerSymbols":[],"references":[],"modelId":15781,"synonyms":[],"description":"","fullName":null,"complexId":null,"type":"RNA","abbreviation":null,"compartmentId":null,"name":"s5","bounds":{"x":0.0,"width":90.0,"y":118.5,"height":25.0},"formula":null,"id":329168,"hierarchyVisibilityLevel":0}]
\ No newline at end of file
diff --git a/frontend-js/testFiles/apiCalls/projects/sample/models/all/bioEntities/elements/id=329167,329169&token=MOCK_TOKEN_ID& b/frontend-js/testFiles/apiCalls/projects/sample/models/all/bioEntities/elements/id=329167,329169&token=MOCK_TOKEN_ID&
new file mode 100644
index 0000000000..1442772f36
--- /dev/null
+++ b/frontend-js/testFiles/apiCalls/projects/sample/models/all/bioEntities/elements/id=329167,329169&token=MOCK_TOKEN_ID&
@@ -0,0 +1 @@
+[{"symbol":null,"formerSymbols":[],"references":[],"modelId":15781,"synonyms":[],"description":"","fullName":null,"complexId":null,"type":"Antisense RNA","abbreviation":null,"compartmentId":null,"name":"s6","bounds":{"x":101.0,"width":90.0,"y":129.5,"height":25.0},"formula":null,"id":329167,"hierarchyVisibilityLevel":0},{"symbol":null,"formerSymbols":[],"references":[],"modelId":15781,"synonyms":[],"description":"","fullName":null,"complexId":null,"type":"Unknown","abbreviation":null,"compartmentId":null,"name":"s11","bounds":{"x":105.0,"width":70.0,"y":203.5,"height":25.0},"formula":null,"id":329169,"hierarchyVisibilityLevel":0}]
\ No newline at end of file
diff --git a/frontend-js/testFiles/apiCalls/projects/sample/models/all/bioEntities/elements/id=329167,329172&token=MOCK_TOKEN_ID& b/frontend-js/testFiles/apiCalls/projects/sample/models/all/bioEntities/elements/id=329167,329172&token=MOCK_TOKEN_ID&
new file mode 100644
index 0000000000..3ae84c4067
--- /dev/null
+++ b/frontend-js/testFiles/apiCalls/projects/sample/models/all/bioEntities/elements/id=329167,329172&token=MOCK_TOKEN_ID&
@@ -0,0 +1 @@
+[{"symbol":null,"formerSymbols":[],"references":[],"modelId":15781,"synonyms":[],"description":"","fullName":null,"complexId":null,"type":"Antisense RNA","abbreviation":null,"compartmentId":null,"name":"s6","bounds":{"x":101.0,"width":90.0,"y":129.5,"height":25.0},"formula":null,"id":329167,"hierarchyVisibilityLevel":0},{"symbol":null,"formerSymbols":[],"references":[],"modelId":15781,"synonyms":[],"description":"","fullName":null,"complexId":null,"type":"Phenotype","abbreviation":null,"compartmentId":null,"name":"s7","bounds":{"x":213.0,"width":80.0,"y":128.0,"height":30.0},"formula":null,"id":329172,"hierarchyVisibilityLevel":0}]
\ No newline at end of file
-- 
GitLab