From 996f1e2de258cc34f35c7848c039ac253411d899 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Mon, 20 Nov 2017 13:55:19 +0100
Subject: [PATCH] fix on retrieving reaction in submaps

---
 frontend-js/src/main/js/ServerConnector.js    |   4 +-
 frontend-js/src/main/js/map/data/MapModel.js  |   5 +-
 ...,329183,329184,329185&token=MOCK_TOKEN_ID& |   0
 .../participantId=329167&token=MOCK_TOKEN_ID& |   0
 .../reactions/ReactionsRestImpl.java          | 325 +++++++++---------
 5 files changed, 169 insertions(+), 165 deletions(-)
 rename frontend-js/testFiles/apiCalls/projects/sample/models/{all => 15781}/bioEntities/reactions/participantId=329156,329157,329158,329159,329160,329161,329162,329163,329164,329165,329166,329167,329168,329169,329170,329171,329172,329173,329174,329175,329176,329177,329178,329179,329180,329181,329182,329183,329184,329185&token=MOCK_TOKEN_ID& (100%)
 rename frontend-js/testFiles/apiCalls/projects/sample/models/{all => 15781}/bioEntities/reactions/participantId=329167&token=MOCK_TOKEN_ID& (100%)

diff --git a/frontend-js/src/main/js/ServerConnector.js b/frontend-js/src/main/js/ServerConnector.js
index 5dd2d408f4..a09ffb94f0 100644
--- a/frontend-js/src/main/js/ServerConnector.js
+++ b/frontend-js/src/main/js/ServerConnector.js
@@ -1194,7 +1194,9 @@ ServerConnector.getOverlayById = function (overlayId, projectId) {
 
 ServerConnector.getReactions = function (params) {
   var self = this;
-  var queryParams = {};
+  var queryParams = {
+    modelId: params.modelId
+  };
   if (params.ids === undefined) {
     params.ids = [];
   }
diff --git a/frontend-js/src/main/js/map/data/MapModel.js b/frontend-js/src/main/js/map/data/MapModel.js
index 1e4e53b9f6..000602857d 100644
--- a/frontend-js/src/main/js/map/data/MapModel.js
+++ b/frontend-js/src/main/js/map/data/MapModel.js
@@ -746,7 +746,8 @@ MapModel.prototype.getReactionsForElements = function(elements, complete) {
 
   var result = [];
   return ServerConnector.getReactions({
-    participantId : ids,
+    modelId: self.getId(),
+    participantId : ids
   }).then(function(reactions) {
     result = reactions;
 
@@ -781,7 +782,7 @@ MapModel.prototype.getCompartments = function() {
     promise = ServerConnector.getAliases({
       columns : "id,bounds,modelId",
       type : "Compartment",
-      modelId : self.getId(),
+      modelId : self.getId()
     }).then(function(compartments) {
       self._compartments = [];
       for (var i = 0; i < compartments.length; i++) {
diff --git a/frontend-js/testFiles/apiCalls/projects/sample/models/all/bioEntities/reactions/participantId=329156,329157,329158,329159,329160,329161,329162,329163,329164,329165,329166,329167,329168,329169,329170,329171,329172,329173,329174,329175,329176,329177,329178,329179,329180,329181,329182,329183,329184,329185&token=MOCK_TOKEN_ID& b/frontend-js/testFiles/apiCalls/projects/sample/models/15781/bioEntities/reactions/participantId=329156,329157,329158,329159,329160,329161,329162,329163,329164,329165,329166,329167,329168,329169,329170,329171,329172,329173,329174,329175,329176,329177,329178,329179,329180,329181,329182,329183,329184,329185&token=MOCK_TOKEN_ID&
similarity index 100%
rename from frontend-js/testFiles/apiCalls/projects/sample/models/all/bioEntities/reactions/participantId=329156,329157,329158,329159,329160,329161,329162,329163,329164,329165,329166,329167,329168,329169,329170,329171,329172,329173,329174,329175,329176,329177,329178,329179,329180,329181,329182,329183,329184,329185&token=MOCK_TOKEN_ID&
rename to frontend-js/testFiles/apiCalls/projects/sample/models/15781/bioEntities/reactions/participantId=329156,329157,329158,329159,329160,329161,329162,329163,329164,329165,329166,329167,329168,329169,329170,329171,329172,329173,329174,329175,329176,329177,329178,329179,329180,329181,329182,329183,329184,329185&token=MOCK_TOKEN_ID&
diff --git a/frontend-js/testFiles/apiCalls/projects/sample/models/all/bioEntities/reactions/participantId=329167&token=MOCK_TOKEN_ID& b/frontend-js/testFiles/apiCalls/projects/sample/models/15781/bioEntities/reactions/participantId=329167&token=MOCK_TOKEN_ID&
similarity index 100%
rename from frontend-js/testFiles/apiCalls/projects/sample/models/all/bioEntities/reactions/participantId=329167&token=MOCK_TOKEN_ID&
rename to frontend-js/testFiles/apiCalls/projects/sample/models/15781/bioEntities/reactions/participantId=329167&token=MOCK_TOKEN_ID&
diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/reactions/ReactionsRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/reactions/ReactionsRestImpl.java
index 276e9256cc..d8a8ed17ac 100644
--- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/reactions/ReactionsRestImpl.java
+++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/reactions/ReactionsRestImpl.java
@@ -28,167 +28,168 @@ import lcsb.mapviewer.services.search.data.LightReactionView;
 @Transactional(value = "txManager")
 public class ReactionsRestImpl extends BaseRestImpl {
 
-	/**
-	 * Default class logger.
-	 */
-	@SuppressWarnings("unused")
-	private Logger				logger = Logger.getLogger(ReactionsRestImpl.class);
-
-	@Autowired
-	private IUserService	userService;
-
-	@Autowired
-	private IModelService	modelService;
-
-	/**
-	 * @return the userService
-	 * @see #userService
-	 */
-	public IUserService getUserService() {
-		return userService;
-	}
-
-	/**
-	 * @param userService
-	 *          the userService to set
-	 * @see #userService
-	 */
-	public void setUserService(IUserService userService) {
-		this.userService = userService;
-	}
-
-	public List<Map<String, Object>> getReactions(String projectId, String id, String columns, String modelId, String token, String participantElementId)
-			throws UserAccessException, SecurityException {
-		Model model = modelService.getLastModelByProjectId(projectId, userService.getToken(token));
-		Set<Integer> ids = new HashSet<>();
-		if (!id.equals("")) {
-			for (String str : id.split(",")) {
-				ids.add(Integer.valueOf(str));
-			}
-		}
-		Set<Element> elementSet = new HashSet<>();
-		if (!participantElementId.equals("")) {
-			for (String str : participantElementId.split(",")) {
-				elementSet.add(model.getElementByDbId(Integer.valueOf(str)));
-			}
-		}
-		Set<String> columnsSet = createReactionColumnSet(columns);
-
-		List<Map<String, Object>> result = new ArrayList<>();
-
-		List<Model> models = getModels(projectId, modelId, token);
-
-		for (Model model2 : models) {
-			for (Reaction reaction : model2.getReactions()) {
-				if (ids.size() == 0 || ids.contains(reaction.getId())) {
-					if (elementSet.size() == 0 || reactionContainsElement(reaction, elementSet)) {
-						result.add(preparedReaction(reaction, columnsSet));
-					}
-				}
-			}
-		}
-
-		return result;
-	}
-
-	private boolean reactionContainsElement(Reaction reaction, Set<Element> elementSet) {
-		for (Element element : elementSet) {
-			if (reaction.containsElement(element)) {
-				return true;
-			}
-		}
-		return false;
-	}
-
-	private Map<String, Object> preparedReaction(Reaction reaction, Set<String> columnsSet) {
-		Map<String, Object> result = new HashMap<>();
-		for (String string : columnsSet) {
-			String column = string.toLowerCase();
-			Object value = null;
-			if (column.equals("id") || column.equals("idobject")) {
-				value = reaction.getId();
-			} else if (column.equals("modelid")) {
-				value = reaction.getModelData().getId();
-			} else if (column.equals("reactionid")) {
-				value = reaction.getIdReaction();
-			} else if (column.equals("name")) {
-				value = reaction.getName();
-			} else if (column.equals("centerpoint")) {
-				value = reaction.getCenterPoint();
-			} else if (column.equals("products")) {
-				List<Integer> ids = new ArrayList<>();
-				for (Product product : reaction.getProducts()) {
-					ids.add(product.getElement().getId());
-				}
-				value = StringUtils.join(ids, ",");
-			} else if (column.equals("reactants")) {
-				List<Integer> ids = new ArrayList<>();
-				for (Reactant reactant : reaction.getReactants()) {
-					ids.add(reactant.getElement().getId());
-				}
-				value = StringUtils.join(ids, ",");
-			} else if (column.equals("modifiers")) {
-				List<Integer> ids = new ArrayList<>();
-				for (Modifier product : reaction.getModifiers()) {
-					ids.add(product.getElement().getId());
-				}
-				value = StringUtils.join(ids, ",");
-			} else if (column.equals("type")) {
-				value = reaction.getStringType();
-			} else if (column.equals("hierarchyvisibilitylevel")) {
-				value = reaction.getVisibilityLevel();
-			} else if (column.equals("lines")) {
-				value = new LightReactionView(reaction).getLines();
-			} else if (column.equals("notes")) {
-				value = reaction.getNotes();
-			} else if (column.equals("references")) {
-				value = createAnnotations(reaction.getMiriamData());
-			} else {
-				value = "Unknown column";
-			}
-			result.put(string, value);
-		}
-		return result;
-	}
-
-	private Set<String> createReactionColumnSet(String columns) {
-		Set<String> columnsSet = new HashSet<>();
-		if (columns.equals("")) {
-			columnsSet.add("id");
-			columnsSet.add("reactionId");
-			columnsSet.add("modelId");
-			columnsSet.add("type");
-			columnsSet.add("lines");
-			columnsSet.add("centerPoint");
-			columnsSet.add("products");
-			columnsSet.add("reactants");
-			columnsSet.add("modifiers");
-			columnsSet.add("hierarchyVisibilityLevel");
-			columnsSet.add("references");
-			columnsSet.add("notes");
-		} else {
-			for (String str : columns.split(",")) {
-				columnsSet.add(str);
-			}
-		}
-		return columnsSet;
-	}
-
-	/**
-	 * @return the modelService
-	 * @see #modelService
-	 */
-	public IModelService getModelService() {
-		return modelService;
-	}
-
-	/**
-	 * @param modelService
-	 *          the modelService to set
-	 * @see #modelService
-	 */
-	public void setModelService(IModelService modelService) {
-		this.modelService = modelService;
-	}
+  /**
+   * Default class logger.
+   */
+  @SuppressWarnings("unused")
+  private Logger logger = Logger.getLogger(ReactionsRestImpl.class);
+
+  @Autowired
+  private IUserService userService;
+
+  @Autowired
+  private IModelService modelService;
+
+  /**
+   * @return the userService
+   * @see #userService
+   */
+  public IUserService getUserService() {
+    return userService;
+  }
+
+  /**
+   * @param userService
+   *          the userService to set
+   * @see #userService
+   */
+  public void setUserService(IUserService userService) {
+    this.userService = userService;
+  }
+
+  public List<Map<String, Object>> getReactions(String projectId, String id, String columns, String modelId,
+      String token, String participantElementId) throws UserAccessException, SecurityException {
+    Set<Integer> ids = new HashSet<>();
+    if (!id.equals("")) {
+      for (String str : id.split(",")) {
+        ids.add(Integer.valueOf(str));
+      }
+    }
+    List<Model> models = getModels(projectId, modelId, token);
+
+    Set<Element> elementSet = new HashSet<>();
+    if (!participantElementId.equals("")) {
+      for (String str : participantElementId.split(",")) {
+        for (Model model : models) {
+          elementSet.add(model.getElementByDbId(Integer.valueOf(str)));
+        }
+      }
+    }
+    Set<String> columnsSet = createReactionColumnSet(columns);
+
+    List<Map<String, Object>> result = new ArrayList<>();
+
+    for (Model model2 : models) {
+      for (Reaction reaction : model2.getReactions()) {
+        if (ids.size() == 0 || ids.contains(reaction.getId())) {
+          if (elementSet.size() == 0 || reactionContainsElement(reaction, elementSet)) {
+            result.add(preparedReaction(reaction, columnsSet));
+          }
+        }
+      }
+    }
+
+    return result;
+  }
+
+  private boolean reactionContainsElement(Reaction reaction, Set<Element> elementSet) {
+    for (Element element : elementSet) {
+      if (reaction.containsElement(element)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  private Map<String, Object> preparedReaction(Reaction reaction, Set<String> columnsSet) {
+    Map<String, Object> result = new HashMap<>();
+    for (String string : columnsSet) {
+      String column = string.toLowerCase();
+      Object value = null;
+      if (column.equals("id") || column.equals("idobject")) {
+        value = reaction.getId();
+      } else if (column.equals("modelid")) {
+        value = reaction.getModelData().getId();
+      } else if (column.equals("reactionid")) {
+        value = reaction.getIdReaction();
+      } else if (column.equals("name")) {
+        value = reaction.getName();
+      } else if (column.equals("centerpoint")) {
+        value = reaction.getCenterPoint();
+      } else if (column.equals("products")) {
+        List<Integer> ids = new ArrayList<>();
+        for (Product product : reaction.getProducts()) {
+          ids.add(product.getElement().getId());
+        }
+        value = StringUtils.join(ids, ",");
+      } else if (column.equals("reactants")) {
+        List<Integer> ids = new ArrayList<>();
+        for (Reactant reactant : reaction.getReactants()) {
+          ids.add(reactant.getElement().getId());
+        }
+        value = StringUtils.join(ids, ",");
+      } else if (column.equals("modifiers")) {
+        List<Integer> ids = new ArrayList<>();
+        for (Modifier product : reaction.getModifiers()) {
+          ids.add(product.getElement().getId());
+        }
+        value = StringUtils.join(ids, ",");
+      } else if (column.equals("type")) {
+        value = reaction.getStringType();
+      } else if (column.equals("hierarchyvisibilitylevel")) {
+        value = reaction.getVisibilityLevel();
+      } else if (column.equals("lines")) {
+        value = new LightReactionView(reaction).getLines();
+      } else if (column.equals("notes")) {
+        value = reaction.getNotes();
+      } else if (column.equals("references")) {
+        value = createAnnotations(reaction.getMiriamData());
+      } else {
+        value = "Unknown column";
+      }
+      result.put(string, value);
+    }
+    return result;
+  }
+
+  private Set<String> createReactionColumnSet(String columns) {
+    Set<String> columnsSet = new HashSet<>();
+    if (columns.equals("")) {
+      columnsSet.add("id");
+      columnsSet.add("reactionId");
+      columnsSet.add("modelId");
+      columnsSet.add("type");
+      columnsSet.add("lines");
+      columnsSet.add("centerPoint");
+      columnsSet.add("products");
+      columnsSet.add("reactants");
+      columnsSet.add("modifiers");
+      columnsSet.add("hierarchyVisibilityLevel");
+      columnsSet.add("references");
+      columnsSet.add("notes");
+    } else {
+      for (String str : columns.split(",")) {
+        columnsSet.add(str);
+      }
+    }
+    return columnsSet;
+  }
+
+  /**
+   * @return the modelService
+   * @see #modelService
+   */
+  public IModelService getModelService() {
+    return modelService;
+  }
+
+  /**
+   * @param modelService
+   *          the modelService to set
+   * @see #modelService
+   */
+  public void setModelService(IModelService modelService) {
+    this.modelService = modelService;
+  }
 
 }
-- 
GitLab