Skip to content
Snippets Groups Projects
ServerConnector.js 37.6 KiB
Newer Older
"use strict";

Piotr Gawron's avatar
Piotr Gawron committed
/* exported logger */

var logger = require('./logger');
var request = require('request');

Piotr Gawron's avatar
Piotr Gawron committed
var Alias = require('./map/data/Alias');
var Chemical = require('./map/data/Chemical');
var Comment = require('./map/data/Comment');
var Drug = require('./map/data/Drug');
var ConfigurationType = require('./ConfigurationType');
var IdentifiedElement = require('./map/data/IdentifiedElement');
Piotr Gawron's avatar
Piotr Gawron committed
var LayoutAlias = require('./map/data/LayoutAlias');
var LayoutData = require('./map/data/LayoutData');
Piotr Gawron's avatar
Piotr Gawron committed
var LayoutReaction = require('./map/data/LayoutReaction');
var MiRna = require('./map/data/MiRna');
var Project = require('./map/data/Project');
Piotr Gawron's avatar
Piotr Gawron committed
var Reaction = require('./map/data/Reaction');
var ReferenceGenome = require('./map/data/ReferenceGenome');
var SessionData = require('./SessionData');
var User = require('./map/data/User');
var GuiConnector = require('./GuiConnector');

/**
 * This object contains methods that will communicate with server.
 */
Piotr Gawron's avatar
Piotr Gawron committed
var ServerConnector = {};
ServerConnector._configurationParam = [];
ServerConnector.getMinOverlayColorInt = function() {
  var self = this;
Piotr Gawron's avatar
Piotr Gawron committed
  var userColor;
  return self.getLoggedUser().then(function(user) {
Piotr Gawron's avatar
Piotr Gawron committed
    userColor = user.getMinColor();
    return self.getConfigurationParam(ConfigurationType.MIN_COLOR_VAL);
  }).then(function(systemMinColor) {
Piotr Gawron's avatar
Piotr Gawron committed
    var color = userColor;
    if (userColor === null || userColor === undefined || userColor === "") {
Piotr Gawron's avatar
Piotr Gawron committed
      color = systemMinColor;
    }
    color = parseInt(color, 16);
    /* jslint bitwise: true */
    color = (color & 0xFFFFFF);
    return color;
ServerConnector.getMaxOverlayColorInt = function() {
  var self = this;
Piotr Gawron's avatar
Piotr Gawron committed
  var userColor;
  return self.getLoggedUser().then(function(user) {
Piotr Gawron's avatar
Piotr Gawron committed
    userColor = user.getMaxColor();
    return self.getConfigurationParam(ConfigurationType.MAX_COLOR_VAL);
  }).then(function(systemMaxColor) {
Piotr Gawron's avatar
Piotr Gawron committed
    var color = userColor;
    if (userColor === null || userColor === undefined || userColor === "") {
Piotr Gawron's avatar
Piotr Gawron committed
      color = systemMaxColor;
    }
    color = parseInt(color, 16);
    /* jslint bitwise: true */
    color = (color & 0xFFFFFF);
    return color;
ServerConnector.readFile = function(url) {
  return new Promise(function(resolve, reject) {
    request.get(url, function(error, response, body) {
      if (error) {
        reject(error);

      } else if (response.statusCode !== 200) {
        reject(response);
ServerConnector.sendPostRequest = function(url, params) {
  return new Promise(function(resolve, reject) {
    request.post({
      url : url,
      form : params
    }, function(error, response, body) {
      if (error) {
        reject(error);

      } else if (response.statusCode !== 200) {
        reject(response);
      } else {
        resolve(body);
      }
    });
  });
};

ServerConnector.sendPutRequest = function(url, params) {
  return new Promise(function(resolve, reject) {
    request.put({
      url : url,
      form : params
    }, function(error, response, body) {
      if (error) {
        reject(error);
      } else if (response.statusCode !== 200) {
        reject(response);
      } else {
        resolve(body);
      }
    });
  });
};

ServerConnector.sendDeleteRequest = function(url, params) {
  return new Promise(function(resolve, reject) {
    request.del({
      url : url,
      form : params
    }, function(error, response, body) {
      if (error) {
        reject(error);
      } else if (response.statusCode !== 200) {
        reject(response);
      } else {
        resolve(body);
      }
    });
  });
};

ServerConnector.getToken = function() {
  var self = this;
Piotr Gawron's avatar
Piotr Gawron committed
  var token = self.getSessionData(null).getToken();
  if (token === undefined) {
Piotr Gawron's avatar
Piotr Gawron committed
    return self.login();
Piotr Gawron's avatar
Piotr Gawron committed
  } else {
    if (self.getSessionData().getProject() === null) {
      return self.isValidToken(token).then(function(isOk) {
Piotr Gawron's avatar
Piotr Gawron committed
        if (isOk) {
          return token;
        } else {
          return self.login();
        }
      });
Piotr Gawron's avatar
Piotr Gawron committed
      return Promise.resolve(token);
ServerConnector.getApiBaseUrl = function() {
  return this.getServerBaseUrl() + "/api/";
Piotr Gawron's avatar
Piotr Gawron committed
};
ServerConnector.getServerBaseUrl = function() {
  if (this._serverBaseUrl === undefined) {
    var url = "" + window.location.href;
    if (!url.endsWith("/")) {
      url = url.substr(0, url.lastIndexOf("/") + 1);
    }
    this._serverBaseUrl = url;
ServerConnector.createGetParams = function(params) {
  var sorted = [], key;
    if (params.hasOwnProperty(key)) {
      sorted.push(key);
    }
Piotr Gawron's avatar
Piotr Gawron committed
  var result = "";
  for (var i = 0; i < sorted.length; i++) {
    if (params[sorted[i]] !== undefined) {
      result += sorted[i] + "=" + params[sorted[i]] + "&";
Piotr Gawron's avatar
Piotr Gawron committed
};

ServerConnector.getApiUrl = function(paramObj) {
  var type = paramObj.type;
  var method = paramObj.method;
  var params = this.createGetParams(paramObj.params);

  var result = this.getApiBaseUrl() + "/" + type + "/" + method;
  if (params !== "") {
    result += "?" + params;
Piotr Gawron's avatar
Piotr Gawron committed
};
ServerConnector.getProjectUrl = function(projectId, token) {
  return this.getApiUrl({
    type : "project",
    method : "getMetaData",
    params : {
      projectId : projectId,
      token : token,
ServerConnector.getImageConvertersUrl = function(params) {
  return this.getApiUrl({
    type : "configuration",
    method : "getImageFormats",
    params : {
      token : params.token,
ServerConnector.getModelConvertersUrl = function(params) {
  return this.getApiUrl({
    type : "configuration",
    method : "getModelFormats",
    params : {
      token : params.token,
ServerConnector.getPublicationsUrl = function(params) {
  var projectId = params.projectId;
  var token = params.token;
  var start = params.start || 0;
  var length = params.length || 10;

  return this.getApiUrl({
    type : "project",
    method : "getPublications",
    params : {
      projectId : projectId,
      token : token,
      start : start,
      length : length,
ServerConnector.getReferenceGenomeUrl = function(params) {
  return this.getApiUrl({
    type : "genomics",
    method : "getReferenceGenome",
    params : {
      token : params.token,
      type : params.type,
      version : params.version,
      organism : params.organism,
ServerConnector.loginUrl = function() {
  return this.getApiUrl({
    type : "user",
    method : "login"
ServerConnector.getSuggestedQueryListUrl = function(params) {
  return this.getApiUrl({
    type : "project",
    method : "getSuggestedQueryList",
    params : params,
ServerConnector.addCommentUrl = function() {
  return this.getApiUrl({
    type : "comment",
    method : "addComment",
ServerConnector.addOverlayUrl = function() {
  return this.getApiUrl({
    type : "overlay",
    method : "addOverlay",
  });
};

ServerConnector.updateOverlayUrl = function() {
  return this.getApiUrl({
    type : "overlay",
    method : "updateOverlay",
  });
};

ServerConnector.deleteOverlayUrl = function() {
  return this.getApiUrl({
    type : "overlay",
    method : "removeOverlay",
ServerConnector.getOverlaysUrl = function(projectId, token) {
  return this.getApiUrl({
    type : "overlay",
    method : "getOverlayList",
    params : {
      projectId : projectId,
      token : token,
ServerConnector.getOverlayTypesUrl = function(params) {
  return this.getApiUrl({
    type : "overlay",
    method : "getOverlayTypes",
    params : {
      token : params.token,
ServerConnector.getCommentsUrl = function(params) {
  var elementId = params.elementId;
  var elementType = params.elementType;
  var columns = this.columnsToString(params.columns);
  var projectId = params.projectId;
  var token = params.token;

  return this.getApiUrl({
    type : "comment",
    method : "getCommentList",
    params : {
      projectId : projectId,
      columns : columns,
      elementId : elementId,
      elementType : elementType,
      token : token
    },
Piotr Gawron's avatar
Piotr Gawron committed
ServerConnector.getOverlayByIdUrl = function(overlayId, projectId, token) {
  return this.getApiUrl({
    type : "overlay",
    method : "getOverlayById",
    params : {
      projectId : projectId,
      token : token,
      overlayId : overlayId,
Piotr Gawron's avatar
Piotr Gawron committed
};

ServerConnector.getOverlayElementsUrl = function(overlayId, projectId, token) {
  return this.getApiUrl({
    type : "overlay",
    method : "getOverlayElements",
    params : {
      projectId : projectId,
      token : token,
      overlayId : overlayId,
ServerConnector.getFullOverlayElementUrl = function(params, token) {
  return this.getApiUrl({
    type : "overlay",
    method : "getOverlayElement",
    params : {
      projectId : params.projectId,
      token : token,
      overlayId : params.overlay.getId(),
      modelId : params.element.getModelId(),
      elementId : params.element.getId(),
      elementType : params.element.getType(),
ServerConnector.idsToString = function(ids) {
  if (ids !== undefined) {
    ids.sort(function(a, b) {
      return a - b;
    });
    for (var i = 0; i < ids.length; i++) {
      if (result !== "") {
        if (ids[i - 1] !== ids[i]) {
          result = result + "," + ids[i];
        } // we ignore duplicates
      } else {
        result = ids[i];
      }
ServerConnector.pointToString = function(point) {
  return point.x.toFixed(2) + "," + point.y.toFixed(2);
ServerConnector.columnsToString = function(columns) {
Piotr Gawron's avatar
Piotr Gawron committed
  if (columns === undefined) {
Piotr Gawron's avatar
Piotr Gawron committed
  }
  return columns;
};

ServerConnector.getReactionsUrl = function(reactionIds, projectId, token, columns) {
  var id = this.idsToString(reactionIds);
  columns = this.columnsToString(columns);
  return this.getApiUrl({
    type : "project",
    method : "getReactions",
    params : {
      projectId : projectId,
      token : token,
      columns : columns,
      id : id,
Piotr Gawron's avatar
Piotr Gawron committed
};
ServerConnector.getAliasesUrl = function(params) {
  var id = this.idsToString(params.ids);
  var columns = this.columnsToString(params.columns);
  var projectId = params.projectId;
  var token = params.token;

  return this.getApiUrl({
    type : "project",
    method : "getElements",
    params : {
      projectId : projectId,
      columns : columns,
      id : id,
      token : token
    },
Piotr Gawron's avatar
Piotr Gawron committed
};
ServerConnector.getConfigurationUrl = function(token) {
  var result = this.getApiUrl({
    type : "configuration",
    method : "getAllValues",
    params : {
      token : token,
ServerConnector.getClosestElementsByCoordinatesUrl = function(params) {
  var coordinates = this.pointToString(params.coordinates);
  var projectId = params.projectId;
  var modelId = params.modelId;
  var token = params.token;
  var count = params.count;
  return this.getApiUrl({
    type : "project",
    method : "getClosestElementsByCoordinates",
    params : {
      projectId : projectId,
      coordinates : coordinates,
      modelId : modelId,
      count : count,
      token : token
    },
Piotr Gawron's avatar
Piotr Gawron committed

Piotr Gawron's avatar
Piotr Gawron committed
ServerConnector.getElementsByQueryUrl = function(params) {
  var query = params.query;
  var projectId = params.projectId;
  var token = params.token;
  var perfectMatch = params.perfectMatch;

  return this.getApiUrl({
    type : "project",
    method : "getElementsByQuery",
    params : {
      projectId : projectId,
      query : query,
      perfectMatch : perfectMatch,
      token : token
    },
ServerConnector.getDrugsByQueryUrl = function(params) {
  var query = params.query;
  var projectId = params.projectId;
  var token = params.token;

  return this.getApiUrl({
    type : "drug",
    method : "getDrugsByQuery",
    params : {
      projectId : projectId,
      query : query,
      token : token
    },
  });
};

ServerConnector.getDrugsByTargetUrl = function(params) {
  var query = params.query;
  var projectId = params.projectId;
  var token = params.token;
  var columns = this.idsToString(params.columns);
  var targetId = params.target.getId();
  var targetType = params.target.getType();

  return this.getApiUrl({
    type : "drug",
    method : "getDrugsByTarget",
    params : {
      projectId : projectId,
      query : query,
      columns : columns,
      token : token,
      targetId : targetId,
      targetType : targetType,
    },
ServerConnector.getMiRnasByQueryUrl = function(params) {
  var query = params.query;
  var projectId = params.projectId;
  var token = params.token;

  return this.getApiUrl({
    type : "miRna",
    method : "getMiRnasByQuery",
    params : {
      projectId : projectId,
      query : query,
      token : token
    },
ServerConnector.getOverlaySourceUrl = function(params) {
  var overlayId = params.overlayId;
  var projectId = params.projectId;
  var token = params.token;

  return this.getApiUrl({
    type : "overlay",
    method : "getOverlaySource",
    params : {
      overlayId : overlayId,
      projectId : projectId,
      token : token
    },
ServerConnector.getImageUrl = function(params) {
  var projectId = params.projectId;
  var token = params.token;
  var polygonString = params.polygonString;
  var modelId = params.modelId;
  var handlerClass = params.handlerClass;
  var backgroundOverlayId = params.backgroundOverlayId.replace(/cv/g, '');
  var zoomLevel = params.zoomLevel;
  var overlayIds = this.idsToString(params.overlayIds);

  return this.getApiUrl({
    type : "project",
    method : "getModelAsImage",
    params : {
      polygonString : polygonString,
      modelId : modelId,
      handlerClass : handlerClass,
      backgroundOverlayId : backgroundOverlayId,
      zoomLevel : zoomLevel,
      overlayIds : overlayIds,
      projectId : projectId,
      token : token,
    },
ServerConnector.getModelPartUrl = function(params) {
  var projectId = params.projectId;
  var token = params.token;
  var polygonString = params.polygonString;
  var modelId = params.modelId;
  var handlerClass = params.handlerClass;
  var backgroundOverlayId = params.backgroundOverlayId.replace(/cv/g, '');
  var zoomLevel = params.zoomLevel;
  var overlayIds = this.idsToString(params.overlayIds);

  return this.getApiUrl({
    type : "project",
    method : "getModelAsModelFile",
    params : {
      polygonString : polygonString,
      modelId : modelId,
      handlerClass : handlerClass,
      backgroundOverlayId : backgroundOverlayId,
      zoomLevel : zoomLevel,
      overlayIds : overlayIds,
      projectId : projectId,
      token : token,
    },
ServerConnector.getProjectSourceUrl = function(params) {
  var projectId = params.projectId;
  var token = params.token;

  return this.getApiUrl({
    type : "project",
    method : "getProjectSource",
    params : {
      projectId : projectId,
      token : token
    },
ServerConnector.getMiRnasByTargetUrl = function(params) {
  var query = params.query;
  var projectId = params.projectId;
  var token = params.token;
  var columns = this.idsToString(params.columns);
  var targetId = params.target.getId();
  var targetType = params.target.getType();

  return this.getApiUrl({
    type : "miRna",
    method : "getMiRnasByTarget",
    params : {
      projectId : projectId,
      query : query,
      columns : columns,
      token : token,
      targetId : targetId,
      targetType : targetType,
    },
ServerConnector.getChemicalsByQueryUrl = function(params) {
  var query = params.query;
  var projectId = params.projectId;
  var token = params.token;

  return this.getApiUrl({
    type : "chemical",
    method : "getChemicalsByQuery",
    params : {
      projectId : projectId,
      query : query,
      token : token
    },
  });
};

ServerConnector.getChemicalsByTargetUrl = function(params) {
  var query = params.query;
  var projectId = params.projectId;
  var token = params.token;
  var columns = this.idsToString(params.columns);
  var targetId = params.target.getId();
  var targetType = params.target.getType();

  return this.getApiUrl({
    type : "chemical",
    method : "getChemicalsByTarget",
    params : {
      projectId : projectId,
      query : query,
      columns : columns,
      token : token,
      targetId : targetId,
      targetType : targetType,
    },
ServerConnector.getUserUrl = function(params) {
  var userId = params.userId;
  var token = params.token;

  return this.getApiUrl({
    type : "user",
    method : "getUser",
    params : {
      userId : userId,
      token : token,
    },
ServerConnector.isValidTokenUrl = function(params) {
  var token = params.token;

  return this.getApiUrl({
    type : "user",
    method : "tokenStatus",
    params : {
      token : token,
    },
ServerConnector.getConfigurationParam = function(paramId) {
  var self = this;
  return new Promise(function(resolve, reject) {
    if (paramId === undefined) {
      reject(new Error("Invalid param identifier"));
    } else if (self._configurationParam[paramId] !== undefined) {
      resolve(self._configurationParam[paramId]);
    } else {
      return self.getToken().then(function(token) {
        return self.readFile(self.getConfigurationUrl(token));
      }).then(function(content) {
        var configs = JSON.parse(content);
        for (var i = 0; i < configs.length; i++) {
          var conf = configs[i];
          var type = conf.type;
          var value = conf.value;
          self._configurationParam[type] = value;
        }
        self._configurationParam[ConfigurationType.LEGEND_FILES] = [];
        if (self._configurationParam["LENGEND_FILE_1"] !== undefined) {
          self._configurationParam[ConfigurationType.LEGEND_FILES].push(self._configurationParam["LENGEND_FILE_1"]);
        }
        if (self._configurationParam["LENGEND_FILE_2"] !== undefined) {
          self._configurationParam[ConfigurationType.LEGEND_FILES].push(self._configurationParam["LENGEND_FILE_2"]);
        }
        if (self._configurationParam["LENGEND_FILE_3"] !== undefined) {
          self._configurationParam[ConfigurationType.LEGEND_FILES].push(self._configurationParam["LENGEND_FILE_3"]);
        }
        if (self._configurationParam["LENGEND_FILE_4"] !== undefined) {
          self._configurationParam[ConfigurationType.LEGEND_FILES].push(self._configurationParam["LENGEND_FILE_4"]);
        }
        if (self._configurationParam[paramId] === undefined) {
          reject(new Error("Cannot find param config: " + paramId));
        resolve(self._configurationParam[paramId]);
  });
};

ServerConnector.getProject = function(projectId) {
  var project;
  return self.getProjectId(projectId).then(function(result) {
    projectId = result;
    return self.getToken();
  }).then(function(token) {
    return self.readFile(self.getProjectUrl(projectId, token));
  }).then(function(content) {
    project = new Project(content);
    return self.getOverlays(projectId);
  }).then(function(overlays) {
    project.getModel().addLayouts(overlays);
    return project;
ServerConnector.getLoggedUser = function() {
  var self = this;
  if (self._loggedUser !== undefined) {
    return Promise.resolve(self._loggedUser);
  } else {
    return self.getUser().then(function(user) {
      self._loggedUser = user;
      return self._loggedUser;
    });
  }
};

ServerConnector.getUser = function(userId) {
Piotr Gawron's avatar
Piotr Gawron committed
  return self.getToken().then(function(token) {
    return self.readFile(self.getUserUrl({
      token : token,
      userId : userId
    }));
Piotr Gawron's avatar
Piotr Gawron committed
  }).then(function(content) {
    var obj = JSON.parse(content);
    return new User(obj);
  });
};

ServerConnector.getOverlays = function(projectId) {
  var self = this;
  return new Promise(function(resolve, reject) {
    self.getProjectId(projectId).then(function(result) {
      projectId = result;
      return self.getToken();
    }).then(function(token) {
      return self.readFile(self.getOverlaysUrl(projectId, token));
    }).then(function(content) {
      var arr = JSON.parse(content);
      var result = [];
      for (var i = 0; i < arr.length; i++) {
        var layout = new LayoutData(arr[i]);
        result.push(layout);
      }
      resolve(result);
Piotr Gawron's avatar
Piotr Gawron committed
ServerConnector.getOverlayElements = function(layoutId, projectId) {
  var self = this;
  if (layoutId === undefined) {
    throw new Error("Layout id must be defined");
Piotr Gawron's avatar
Piotr Gawron committed
  }

  var token = null;
  return self.getToken().then(function(result) {
    token = result;
    return self.getProjectId(projectId);
  }).then(function(result) {
    projectId = result;
    return self.readFile(self.getOverlayElementsUrl(layoutId, projectId, token));
  }).then(function(content) {
    var arr = JSON.parse(content);
    var result = [];
    for (var i = 0; i < arr.length; i++) {
      var element = arr[i];
      if (element.type === "REACTION") {
        result.push(new LayoutReaction(element.overlayContent));
      } else if (element.type === "ALIAS") {
        result.push(new LayoutAlias(element.overlayContent));
      } else {
        throw new Error("Unknown element type: " + element.type);
    }
    return result;
ServerConnector.getFullOverlayElement = function(params) {
  var self = this;
  var token = null;
  return self.getToken().then(function(result) {
    token = result;
    return self.getProjectId(params.projectId);
  }).then(function(result) {
    params.projectId = result;
    return self.readFile(self.getFullOverlayElementUrl(params, token));
  }).then(function(content) {
    var element = JSON.parse(content);
    var result = null;
    if (element.type === "REACTION") {
      result = new LayoutReaction(element.overlayContent);
    } else if (element.type === "ALIAS") {
      result = new LayoutAlias(element.overlayContent);
    } else {
      throw new Error("Unknown element type: " + element.type);
    }
    return result;
Piotr Gawron's avatar
Piotr Gawron committed
ServerConnector.getProjectId = function(projectId) {
  var self = this;
  return new Promise(function(resolve, reject) {
    if (projectId === undefined || projectId === null || projectId === "") {
      if (GuiConnector.getParams['id'] !== undefined) {
        resolve(GuiConnector.getParams['id']);
      } else {
        self.getConfigurationParam(ConfigurationType.DEFAULT_MAP).then(function(defaultMap) {
          resolve(defaultMap);
        }, reject);
      }
    } else {
Piotr Gawron's avatar
Piotr Gawron committed
      resolve(projectId);
ServerConnector.getLogoImg = function() {
  return this.getConfigurationParam(ConfigurationType.LOGO_IMG);
};

ServerConnector.getLogoLink = function() {
  return this.getConfigurationParam(ConfigurationType.LOGO_LINK);
};

Piotr Gawron's avatar
Piotr Gawron committed
ServerConnector.getOverlayById = function(layoutId, projectId) {
  var self = this;
  return new Promise(function(resolve, reject) {
    self.getProjectId(projectId).then(function(projectId) {
      self.getToken().then(function(token) {
        self.readFile(self.getOverlayByIdUrl(layoutId, projectId, token)).then(function(content) {
          var result = new LayoutData(JSON.parse(content));
          resolve(result);
        }, reject);
      }, reject);
    }, reject);
  });
};

ServerConnector.getReactions = function(reactionIds, projectId, columns) {
  var self = this;
  return self.getProjectId(projectId).then(function(result) {
    projectId = result;
    return self.getToken();
  }).then(function(token) {
    return self.readFile(self.getReactionsUrl(reactionIds, projectId, token, columns));
  }).then(function(content) {
    var array = JSON.parse(content);
    var result = [];
    for (var i = 0; i < array.length; i++) {
      result.push(new Reaction(array[i]));
    }
    return result;
ServerConnector.getAliases = function(aliasIds, projectId, columns) {
  var self = this;
  return self.getProjectId(projectId).then(function(result) {
    projectId = result;
    return self.getToken();
  }).then(function(token) {
    return self.readFile(self.getAliasesUrl({
      ids : aliasIds,
      projectId : projectId,
      token : token,
      columns : columns
    }));
  }).then(function(content) {
    var array = JSON.parse(content);
    var result = [];
    for (var i = 0; i < array.length; i++) {
      result.push(new Alias(array[i]));
    }
    return result;
ServerConnector.getLightComments = function(params) {
  params.columns = [ "id", "elementId", "modelId", "type", "icon", "removed" ];
  return this.getComments(params);
};

ServerConnector.getComments = function(params) {
  var self = this;
  return self.getProjectId(params.projectId).then(function(result) {
    params.projectId = result;
    return self.getToken();
  }).then(function(token) {
    params.token = token;
    return self.readFile(self.getCommentsUrl(params));
  }).then(function(content) {
    var array = JSON.parse(content);
    var result = [];
    for (var i = 0; i < array.length; i++) {
      result.push(new Comment(array[i]));
    }
    return result;
ServerConnector.getLightAliases = function(aliasIds, projectId) {
  return this.getAliases(aliasIds, projectId, "id,bounds,modelId");
ServerConnector.getSessionData = function(project) {
  if (this._sessionData === undefined) {
    this._sessionData = new SessionData(project);
  if (project !== undefined && this._sessionData.getProject() === null) {
Piotr Gawron's avatar
Piotr Gawron committed
    this._sessionData.setProject(project);
  return this._sessionData;
};

ServerConnector.getClosestElementsByCoordinates = function(params) {
  var self = this;
  return self.getProjectId(params.projectId).then(function(result) {
    params.projectId = result;
    return self.getToken();
  }).then(function(token) {
    params.token = token;