Commit c558e399 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

targetting structure constructor accepts a copy of the same object as a parameter

parent d025155f
......@@ -17,19 +17,26 @@ var logger = require('../../logger');
/**
*
* @param {TargetOptions} javaObject
* @param {TargetOptions|Target} javaObject
* @constructor
*/
function Target(javaObject) {
this.setName(javaObject.name);
this.setTargetElements(javaObject.targetElements);
this.setTargetParticipants(javaObject.targetParticipants);
this.setReferences(javaObject.references);
if (javaObject instanceof Target) {
this.setName(javaObject.getName());
this.setTargetElements(javaObject.getTargetElements());
this.setTargetParticipants(javaObject.getTargetParticipants());
this.setReferences(javaObject.getReferences());
} else {
this.setName(javaObject.name);
this.setTargetElements(javaObject.targetElements);
this.setTargetParticipants(javaObject.targetParticipants);
this.setReferences(javaObject.references);
}
}
/**
*
* @param {IdentifiedElementInput[]} targetElements
* @param {IdentifiedElementInput[]|IdentifiedElement[]} targetElements
*/
Target.prototype.setTargetElements = function (targetElements) {
this._targetElements = [];
......@@ -49,7 +56,7 @@ Target.prototype.getTargetElements = function () {
/**
*
* @param {AnnotationOptions[]} targetParticipants
* @param {AnnotationOptions[]|Annotation[]} targetParticipants
*/
Target.prototype.setTargetParticipants = function (targetParticipants) {
this._targetParticipants = [];
......@@ -100,7 +107,7 @@ Target.prototype.isVisible = function () {
/**
*
* @param {AnnotationOptions[]} references
* @param {AnnotationOptions[]|Annotation[]} references
*/
Target.prototype.setReferences = function (references) {
this._references = [];
......
......@@ -4,21 +4,32 @@
var Target = require("./Target");
// noinspection JSUnusedLocalSymbols
var logger = require('../../logger');
/**
* @typedef {Object} TargettingStructureOptions
* @property {string} name
* @property {number} id
* @property {TargetOptions[]} targets
*/
/**
*
* @param {Object} [javaObject]
* @param {string} javaObject.name
* @param {number} javaObject.id
* @param {TargetOptions[]} javaObject.targets
* @param {TargettingStructureOptions|TargettingStructure} javaObject
* @constructor
*/
function TargettingStructure(javaObject) {
if (javaObject !== undefined) {
this.setName(javaObject.name);
this.setId(javaObject.id);
this.setTargets(javaObject.targets);
if (javaObject instanceof TargettingStructure) {
this.setName(javaObject.getName());
this.setId(javaObject.getId());
this.setTargets(javaObject.getTargets());
} else {
this.setName(javaObject.name);
this.setId(javaObject.id);
this.setTargets(javaObject.targets);
}
}
}
......@@ -26,7 +37,7 @@ function TargettingStructure(javaObject) {
*
* @param {string} name
*/
TargettingStructure.prototype.setName = function(name) {
TargettingStructure.prototype.setName = function (name) {
this._name = name;
};
......@@ -34,7 +45,7 @@ TargettingStructure.prototype.setName = function(name) {
*
* @returns {string}
*/
TargettingStructure.prototype.getName = function() {
TargettingStructure.prototype.getName = function () {
return this._name;
};
......@@ -42,7 +53,7 @@ TargettingStructure.prototype.getName = function() {
*
* @param {number} id
*/
TargettingStructure.prototype.setId = function(id) {
TargettingStructure.prototype.setId = function (id) {
this._id = id;
};
......@@ -50,15 +61,15 @@ TargettingStructure.prototype.setId = function(id) {
*
* @returns {number}
*/
TargettingStructure.prototype.getId = function() {
TargettingStructure.prototype.getId = function () {
return this._id;
};
/**
*
* @param {TargetOptions[]} targets
* @param {TargetOptions[]|Target[]} targets
*/
TargettingStructure.prototype.setTargets = function(targets) {
TargettingStructure.prototype.setTargets = function (targets) {
this._targets = [];
for (var i = 0; i < targets.length; i++) {
this._targets.push(new Target(targets[i]));
......@@ -69,7 +80,7 @@ TargettingStructure.prototype.setTargets = function(targets) {
*
* @returns {Target[]}
*/
TargettingStructure.prototype.getTargets = function() {
TargettingStructure.prototype.getTargets = function () {
return this._targets;
};
......@@ -78,11 +89,11 @@ TargettingStructure.prototype.getTargets = function() {
* @param {IdentifiedElement[]} targetIdentifiedElement
* @returns {Target[]}
*/
TargettingStructure.prototype.getTargetsForIdentifiedElement = function(targetIdentifiedElement) {
TargettingStructure.prototype.getTargetsForIdentifiedElement = function (targetIdentifiedElement) {
var result = [];
this.getTargets().forEach(function(target) {
this.getTargets().forEach(function (target) {
var targetOk = false;
target.getTargetElements().forEach(function(identifiedElement){
target.getTargetElements().forEach(function (identifiedElement) {
if (targetIdentifiedElement.equals(identifiedElement)) {
targetOk = true;
}
......
......@@ -3,6 +3,7 @@
require("../../mocha-config");
var IdentifiedElement = require('../../../../main/js/map/data/IdentifiedElement');
var TargettingStructure = require('../../../../main/js/map/data/TargettingStructure');
var ServerConnector = require('../../ServerConnector-mock');
var logger = require('../../logger');
......@@ -39,4 +40,22 @@ describe('TargettingStructure', function () {
assert.equal(0, logger.getWarnings().length);
});
});
describe("constructor", function () {
it("from existing instance", function () {
helper.setUrl("http://test/?id=drug_target_sample");
var map, searchDb;
return ServerConnector.getProject("drug_target_sample").then(function (project) {
map = helper.createCustomMap(project);
searchDb = helper.createDrugDbOverlay(map);
return searchDb.searchByQuery("NADH");
}).then(function (drugs) {
var drug = drugs[0][0];
var newDrug = new TargettingStructure(drug);
assert.equal(newDrug.getId(), drug.getId());
assert.equal(newDrug.getName(), drug.getName());
assert.equal(newDrug.getTargets().length, drug.getTargets().length);
});
});
});
});
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