Commit 2cfe6a53 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

implementation of ChemicalDbOverlay

parent e2f6baa9
......@@ -736,6 +736,41 @@ ServerConnector.getDrugsByTargetUrl = function(params) {
});
};
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.getConfigurationParam = function(paramId) {
var self = this;
return new Promise(function(resolve, reject) {
......@@ -1023,6 +1058,28 @@ ServerConnector.getDrugsByQuery = function(params) {
});
};
ServerConnector.getChemicalsByQuery = function(params) {
var self = this;
return new Promise(function(resolve, reject) {
return self.getProjectId(params.projectId).then(function(result) {
params.projectId = result;
return self.getToken();
}).then(function(token) {
params.token = token;
return self.readFile(self.getChemicalsByQueryUrl(params));
}).then(function(content) {
var array=JSON.parse(content);
var result = [];
for (var i = 0; i < array.length; i++) {
result.push(new Drug(array[i]));
}
resolve(result);
}).catch(function(exception){
reject(exception);
});
});
};
ServerConnector.getDrugNamesByTarget = function(params) {
var self = this;
params.columns = ["name"];
......@@ -1046,6 +1103,29 @@ ServerConnector.getDrugNamesByTarget = function(params) {
});
};
ServerConnector.getChemicalNamesByTarget = function(params) {
var self = this;
params.columns = ["name"];
return new Promise(function(resolve, reject) {
return self.getProjectId(params.projectId).then(function(result) {
params.projectId = result;
return self.getToken();
}).then(function(token) {
params.token = token;
return self.readFile(self.getChemicalsByTargetUrl(params));
}).then(function(content) {
var result = [];
var object = JSON.parse(content);
for (var i=0;i<object.length;i++){
result.push(object[i].name);
}
resolve(result);
}).catch(function(exception){
reject(exception);
});
});
};
ServerConnector.addComment = function(params) {
var self = this;
return new Promise(function(resolve, reject) {
......
......@@ -34,6 +34,8 @@ SessionData.prototype.setQuery = function(param) {
this.setDrugQuery(param.query);
} else if (param.type === "search") {
this.setSearchQuery(param.query);
} else if (param.type === "chemical") {
this.setChemicalQuery(param.query);
} else {
throw new Error("Invalid query type: " + param.type);
}
......@@ -62,6 +64,20 @@ SessionData.prototype.getDrugQuery = function() {
return result;
};
SessionData.prototype.setChemicalQuery = function(value) {
var key = this.getKey(SessionObjectType.CHEMICAL_QUERY);
Cookies.set(key, JSON.stringify(value));
};
SessionData.prototype.getChemicalQuery = function() {
var key = this.getKey(SessionObjectType.CHEMICAL_QUERY);
var result = Cookies.get(key);
if (result !== undefined) {
result = JSON.parse(result);
}
return result;
};
SessionData.prototype.setShowComments = function(value) {
var key = this.getKey(SessionObjectType.SHOW_COMMENT);
Cookies.set(key, value + "");
......
"use strict";
var SessionObjectType = {
CHEMICAL_QUERY : "CHEMICAL_QUERY",
DRUG_QUERY : "DRUG_QUERY",
SHOW_COMMENT : "SHOW_COMMENT",
SELECTED_BACKGROUND_OVERLAY : "SELECTED_BACKGROUND_OVERLAY",
......
"use strict";
var logger = require('../../logger');
var Promise = require("bluebird");
var IdentifiedElement = require('../data/IdentifiedElement');
var AbstractTargettingDbOverlay = require('./AbstractTargettingDbOverlay');
var ServerConnector = require('../../ServerConnector');
function ChemicalDbOverlay(params) {
params.iconType= "ball";
params.iconColorStart = 1;
// call super constructor
AbstractTargettingDbOverlay.call(this, params);
}
ChemicalDbOverlay.prototype = Object.create(AbstractTargettingDbOverlay.prototype);
ChemicalDbOverlay.prototype.constructor = ChemicalDbOverlay;
ChemicalDbOverlay.prototype.getNamesByTargetFromServer = function(param) {
return ServerConnector.getChemicalNamesByTarget(param);
}
ChemicalDbOverlay.prototype.getElementsByQueryFromServer = function(param) {
return ServerConnector.getChemicalsByQuery(param);
}
module.exports = ChemicalDbOverlay;
......@@ -4,6 +4,7 @@ require("./mocha-config");
var Alias = require("../../main/js/map/data/Alias");
var AbstractCustomMap = require("../../main/js/map/AbstractCustomMap");
var ChemicalDbOverlay = require("../../main/js/map/overlay/ChemicalDbOverlay");
var Comment = require("../../main/js/map/data/Comment");
var CommentDbOverlay = require("../../main/js/map/overlay/CommentDbOverlay");
var CustomMap = require("../../main/js/map/CustomMap");
......@@ -99,6 +100,17 @@ Helper.prototype.createDrugDbOverlay = function(map) {
return result;
};
Helper.prototype.createChemicalDbOverlay = function(map) {
var result = new ChemicalDbOverlay({
map : map,
name : "chemical",
allowGeneralSearch : true,
allowSearchById : true,
});
map.registerSource(result);
return result;
};
Helper.prototype.createComment = function(element) {
var elementType = "ALIAS";
var elementId = this.idCounter++;
......
"use strict";
var Helper = require('../../Helper');
var logger = require('../../logger');
var IdentifiedElement = require('../../../../main/js/map/data/IdentifiedElement');
var ChemicalDbOverlay = require('../../../../main/js/map/overlay/ChemicalDbOverlay');
var assert = require('assert');
describe('ChemicalDbOverlay', function() {
var helper;
before(function() {
helper = new Helper();
});
it("constructor 1", function() {
var map = helper.createCustomMap();
var oc = new ChemicalDbOverlay({
map : map,
name : 'chemical'
});
assert.ok(oc);
assert.equal(oc.getName(), 'chemical');
assert.equal(logger.getWarnings.length, 0);
});
it("searchByQuery", function() {
var map = helper.createCustomMap();
map.getModel().setId(15781);
var searchDb = helper.createChemicalDbOverlay(map);
return searchDb.searchByQuery("rotenone").then(function(chemicals) {
assert.equal(chemicals.length, 1);
assert.equal(searchDb.getQueries().length, 1);
return searchDb.getElementsByQuery(searchDb.getQueries()[0]);
}).then(function(elements) {
//these are targets
assert.ok(elements.length>0);
var chemical = elements.element;
assert.equal(chemical.getName(), "Rotenone");
return searchDb.getIdentifiedElements();
}).then(function(elements) {
assert.equal(elements.length,0);
});
});
it("searchNamesByTarget", function() {
var map = helper.createCustomMap();
map.getModel().setId(15781);
var searchDb = helper.createChemicalDbOverlay(map);
var target = new IdentifiedElement({
type : "ALIAS",
id : 329170,
modelId : 15781,
});
return searchDb.searchNamesByTarget(target).then(function(chemicalNames) {
assert.equal(chemicalNames.length, 0);
});
});
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment