Commit 68c80602 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

rest api for getting general info about layouts

parent 7dec57b3
......@@ -6,7 +6,7 @@ var logger = require('./logger');
var request = require('request');
var ConfigurationType = require('./ConfigurationType');
var LayoutData = require('./map/data/LayoutData');
var Project = require('./map/data/Project');
/**
......@@ -1067,6 +1067,10 @@ ServerConnector.getProjectUrl = function(projectId, token) {
return this.getServerBaseUrl() + "/api/project/getMetaData?projectId=" + projectId + "&token=" + token;
};
ServerConnector.getOverlaysUrl = function(projectId, token) {
return this.getServerBaseUrl() + "/api/overlay/getOverlayList?projectId=" + projectId + "&token=" + token;
};
ServerConnector.getConfigurationUrl = function(token) {
return this.getServerBaseUrl() + "/api/configuration/getAllValues?token=" + token;
};
......@@ -1089,6 +1093,9 @@ ServerConnector.getConfigurationParam = function(paramId) {
var value = conf.value;
self._configurationParam[type] = value;
}
if (self._configurationParam[paramId] === undefined) {
reject("Cannot find param config: " + paramId);
}
resolve(self._configurationParam[paramId]);
}, reject);
}, reject);
......@@ -1100,11 +1107,8 @@ ServerConnector.getProject = function(projectId) {
if (projectId === undefined || projectId === null || projectId === "") {
return new Promise(function(resolve, reject) {
self.getConfigurationParam(ConfigurationType.DEFAULT_MAP).then(function(defaultMap) {
if (defaultMap === undefined) {
reject("Cannot find default map");
}
self.getProject(defaultMap).then(function(result) {
resolve(result);
self.getProject(defaultMap).then(function(project) {
resolve(project);
}, reject);
}, reject);
});
......@@ -1112,7 +1116,37 @@ ServerConnector.getProject = function(projectId) {
return new Promise(function(resolve, reject) {
self.getToken().then(function(token) {
self.readFile(self.getProjectUrl(projectId, token)).then(function(content) {
resolve(new Project(content));
var project = new Project(content);
self.getOverlays(projectId).then(function(overlays) {
project.getModel().addLayouts(overlays);
resolve(project);
}, reject);
}, reject);
}, reject);
});
};
ServerConnector.getOverlays = function(projectId) {
var self = this;
if (projectId === undefined || projectId === null || projectId === "") {
return new Promise(function(resolve, reject) {
self.getConfigurationParam(ConfigurationType.DEFAULT_MAP).then(function(defaultMap) {
self.getOverlays(defaultMap).then(function(overlays) {
resolve(overlays);
}, reject);
}, reject);
});
}
return new Promise(function(resolve, reject) {
self.getToken().then(function(token) {
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);
}, reject);
}, reject);
});
......
......@@ -4,23 +4,5 @@ var log4js = require('log4js');
var $depth = 10;
log4js.configure({
appenders : [ {
type : "console",
layout : {
type : "pattern",
pattern : "%[%p {%x{ln}} -%]\t%m",
tokens : {
ln : function() {
// The caller:
var filePath = (new Error()).stack.split("\n")[$depth].split("\\");
filePath = filePath[filePath.length - 1].split("/");
return filePath[filePath.length - 1];
}
}
}
} ]
});
var logger = log4js.getLogger();
module.exports = logger;
......@@ -6,8 +6,18 @@ var logger = require('../../logger');
* Class representing data in a specific layout.
*/
function LayoutData(layoutId, name) {
this.setId(layoutId);
this.setName(name);
if (name === undefined) {
// from jsonified structure
var object = layoutId;
this.setId(object.idObject)
this.setName(object.name);
this.setDirectory(object.directory);
this.setInputDataAvailable(object.inputDataAvailable);
} else {
// default two param call
this.setId(layoutId);
this.setName(name);
}
this.aliases = [];
this.aliasById = [];
this.reactions = [];
......@@ -47,7 +57,18 @@ LayoutData.prototype.getInputDataAvailable = function() {
};
LayoutData.prototype.setInputDataAvailable = function(inputDataAvailable) {
this._inputDataAvailable = inputDataAvailable;
var value = inputDataAvailable;
if (inputDataAvailable === undefined) {
value = false;
} else if (inputDataAvailable === "true") {
value = true;
} else if (inputDataAvailable === "false") {
value = false;
} else if (typeof (inputDataAvailable) !== "boolean") {
logger.warn("inputDataAvailable should be boolean");
value = false;
}
this._inputDataAvailable = value;
};
LayoutData.prototype.getName = function() {
......
......@@ -466,8 +466,7 @@ MapModel.prototype.addLayout = function(layout) {
if (layout instanceof LayoutData) {
layoutData = layout;
} else {
layoutData = new LayoutData(layout.idObject, layout.name);
layoutData.setDirectory(layout.directory);
layoutData = new LayoutData(layout);
}
var object = this._layoutsData[layoutData.getId()];
if (object === undefined) {
......
......@@ -296,4 +296,8 @@ ServerConnectorMock.getConfigurationUrl = function(token) {
return this.getServerBaseUrl() + "configuration/getAllValues-" + token;
};
ServerConnectorMock.getOverlaysUrl = function(projectId, token) {
return this.getServerBaseUrl() + "overlay/getOverlayList-" + projectId + "-" + token;
};
module.exports = ServerConnectorMock;
......@@ -50,9 +50,11 @@ Helper.prototype.createModel = function() {
};
Helper.prototype.createLayout = function() {
var layout = new LayoutData();
layout.setId(this.idCounter++);
layout.setName("testLayout" + layout.getId());
var id = this.idCounter++;
var layout = new LayoutData({
idObject : id,
name : "testLayout" + id,
});
return layout;
};
......
......@@ -17,6 +17,16 @@ describe('LayoutData', function() {
assert.equal(overlay.getName(), name);
});
it("contructor from json obj", function() {
var string = '{"modelId":15781,"name":"test","description":"test","status":"OK","progress":"0.00",'
+ '"directory":"5e8ff9bf55ba3508199d22e984129be6/sample0.0235076236865853214852",'
+ '"creator":"admin ","inputDataAvailable":"true","idObject":14852}';
var obj = JSON.parse(string);
var data = new LayoutData(obj);
assert.ok(data);
assert.equal(data.getInputDataAvailable(), true);
});
it("updateAlias", function() {
var layoutId = 3;
var name = "nm";
......
[{"modelId":15781,"name":"test","description":"test","status":"OK","progress":"0.00","directory":"5e8ff9bf55ba3508199d22e984129be6/sample0.0235076236865853214852","creator":"admin ","inputDataAvailable":"true","idObject":14852},{"modelId":15781,"name":"react","description":"","status":"OK","progress":"0.00","directory":"5e8ff9bf55ba3508199d22e984129be6/sample0.757974388121998714853","creator":"admin ","inputDataAvailable":"true","idObject":14853}]
\ No newline at end of file
......@@ -15,6 +15,9 @@ public abstract class BaseController {
logger.error(e, e);
if (e instanceof SecurityException) {
return new ResponseEntity<Object>("{\"error\" : \"Access denied.\",\"reason\":\"" + e.getMessage() + "\"}", new HttpHeaders(), HttpStatus.FORBIDDEN);
} else if (e instanceof QueryException) {
return new ResponseEntity<Object>(
"{\"error\" : \"Query server error.\",\"reason\":\"" + e.getMessage() + "\"}", new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR);
} else {
return new ResponseEntity<Object>(
"{\"error\" : \"Internal server error.\",\"reason\":\"" + e.getMessage() + "\"}", new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR);
......
package lcsb.mapviewer.api;
public class QueryException extends Exception {
public QueryException(String message) {
super(message);
}
}
package lcsb.mapviewer.api.overlay;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import lcsb.mapviewer.api.BaseController;
import lcsb.mapviewer.api.QueryException;
import lcsb.mapviewer.services.SecurityException;
import lcsb.mapviewer.services.view.LayoutView;
@RestController
@RequestMapping("/overlay")
public class OverlayController extends BaseController {
@Autowired
private OverlayRestImpl overlayController;
@RequestMapping(value = "/getOverlayList", method = { RequestMethod.GET, RequestMethod.POST }, produces = { MediaType.APPLICATION_JSON_VALUE })
public List<LayoutView> getOverlayList(@RequestParam(value = "token") String token, @RequestParam(value = "projectId") String projectId)
throws SecurityException, QueryException {
return overlayController.getOverlayList(token, projectId);
}
/**
* @return the overlayController
* @see #overlayController
*/
public OverlayRestImpl getOverlayController() {
return overlayController;
}
/**
* @param overlayController
* the overlayController to set
* @see #overlayController
*/
public void setOverlayController(OverlayRestImpl overlayController) {
this.overlayController = overlayController;
}
}
\ No newline at end of file
package lcsb.mapviewer.api.overlay;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.api.QueryException;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.services.SecurityException;
import lcsb.mapviewer.services.interfaces.ILayoutService;
import lcsb.mapviewer.services.interfaces.IModelService;
import lcsb.mapviewer.services.interfaces.IUserService;
import lcsb.mapviewer.services.view.LayoutView;
@Transactional(value = "txManager")
public class OverlayRestImpl {
@Autowired
private IUserService userService;
@Autowired
private IModelService modelService;
@Autowired
private ILayoutService layoutService;
public List<LayoutView> getOverlayList(String token, String projectId) throws SecurityException, QueryException {
Model model = modelService.getLastModelByProjectId(projectId);
if (model == null) {
throw new QueryException("Project with given id doesn't exist");
}
return layoutService.getCustomLayouts(model, token);
}
/**
* @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;
}
/**
* @return the layoutService
* @see #layoutService
*/
public ILayoutService getLayoutService() {
return layoutService;
}
/**
* @param layoutService
* the layoutService to set
* @see #layoutService
*/
public void setLayoutService(ILayoutService layoutService) {
this.layoutService = layoutService;
}
/**
* @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;
}
}
......@@ -11,7 +11,8 @@
http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="ProjectRestImpl" class="lcsb.mapviewer.api.project.ProjectRestImpl"/>
<bean id="ConfigurationRestImpl" class="lcsb.mapviewer.api.configuration.ConfigurationRestImpl"/>
<bean id="OverlayRestImpl" class="lcsb.mapviewer.api.overlay.OverlayRestImpl"/>
<bean id="ProjectRestImpl" class="lcsb.mapviewer.api.project.ProjectRestImpl"/>
</beans>
\ No newline at end of file
......@@ -52,6 +52,7 @@ import lcsb.mapviewer.model.user.PrivilegeType;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.persist.DbUtils;
import lcsb.mapviewer.persist.dao.map.LayoutDao;
import lcsb.mapviewer.services.SecurityException;
import lcsb.mapviewer.services.interfaces.IConfigurationService;
import lcsb.mapviewer.services.interfaces.ILayoutService;
import lcsb.mapviewer.services.interfaces.ILogService;
......@@ -66,6 +67,7 @@ import lcsb.mapviewer.services.search.layout.LightLayoutReactionViewFactory;
import lcsb.mapviewer.services.utils.ColorSchemaReader;
import lcsb.mapviewer.services.utils.EmailSender;
import lcsb.mapviewer.services.utils.data.ColorSchemaColumn;
import lcsb.mapviewer.services.view.ConfigurationView;
import lcsb.mapviewer.services.view.LayoutView;
import lcsb.mapviewer.services.view.LayoutViewFactory;
......@@ -999,4 +1001,9 @@ public class LayoutService implements ILayoutService {
public void setEmailSender(EmailSender emailSender) {
this.emailSender = emailSender;
}
@Override
public List<LayoutView> getCustomLayouts(Model model, String token) throws SecurityException {
return this.getCustomLayouts(model, userService.getUserByToken(token));
}
}
......@@ -13,11 +13,13 @@ import lcsb.mapviewer.model.map.layout.ColorSchema;
import lcsb.mapviewer.model.map.layout.InvalidColorSchemaException;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.services.SecurityException;
import lcsb.mapviewer.services.search.layout.FullLayoutAliasView;
import lcsb.mapviewer.services.search.layout.LightLayoutAliasView;
import lcsb.mapviewer.services.search.layout.LightLayoutReactionView;
import lcsb.mapviewer.services.utils.EmailSender;
import lcsb.mapviewer.services.utils.data.ColorSchemaType;
import lcsb.mapviewer.services.view.ConfigurationView;
import lcsb.mapviewer.services.view.LayoutView;
/**
......@@ -507,4 +509,6 @@ public interface ILayoutService {
*/
void setEmailSender(EmailSender emailSender);
List<LayoutView> getCustomLayouts(Model model, String token) throws SecurityException;
}
......@@ -227,7 +227,7 @@ public class LayoutServiceTest extends ServiceTestFunctions {
assertEquals(0, layouts.size());
// null user shouldn't have acces to custom layouts
layouts = layoutService.getCustomLayouts(model, null);
layouts = layoutService.getCustomLayouts(model, (User)null);
assertEquals(0, layouts.size());
layoutService.removeLayout(row, null);
......
......@@ -104486,7 +104486,7 @@ ServerConnector.readFile = function(url) {
ServerConnector.getToken = function() {
var self = this;
return new Promise(function(resolve, reject) {
return new Promise(function(resolve) {
if (self._token === undefined) {
self.setToken(document.getElementById("authenticationForm:authenticationToken").value);
}
......@@ -104496,9 +104496,9 @@ ServerConnector.getToken = function() {
ServerConnector.setToken = function(token) {
this._token = token;
}
};
ServerConnector.getServerBaseUrl = function(projectId) {
ServerConnector.getServerBaseUrl = function() {
if (this._serverBaseUrl === undefined) {
var location = window.location;
this._serverBaseUrl = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '')
......@@ -105698,6 +105698,14 @@ AbstractCustomMap.prototype.isDebug = function() {
return this.debug === true;
};
AbstractCustomMap.prototype.getTopLeftLatLng = function() {
return this.getModel().getTopLeftLatLng();
};
AbstractCustomMap.prototype.getBottomRightLatLng = function() {
return this.getModel().getBottomRightLatLng();
};
module.exports = AbstractCustomMap;
 
},{"../Functions":532,"../ObjectWithListeners":534,"../logger":538,"./marker/AliasMarker":557,"./marker/PointMarker":558,"./marker/ReactionMarker":559,"./overlay/AliasOverlay":561,"./overlay/ReactionOverlay":563,"./window/AliasInfoWindow":565,"./window/PointInfoWindow":566,"./window/ReactionInfoWindow":567}],540:[function(require,module,exports){
......@@ -105987,6 +105995,7 @@ CustomMap.prototype.openLayout = function(identifier) {
* identifier of the layout to present
*/
CustomMap.prototype.openLayoutById = function(identifier) {
identifier = parseInt(identifier);
logger.debug("Opening layout: " + identifier);
var index = null;
for (var i = 0; i < this.getLayouts().length; i++) {
......@@ -106004,6 +106013,24 @@ CustomMap.prototype.openLayoutById = function(identifier) {
}
};
CustomMap.prototype.openLayoutByName = function(name) {
logger.debug("Opening layout: " + name);
var index = null;
var layouts = this.getLayouts();
for (var i = 0; i < layouts.length; i++) {
var layout = layouts [i];
if (layout.getName() === name) {
index = 'cv' + layout.getId();
}
}
// if layout doesn't exist print error
if (index == null) {
alert("You have no privileges for selected layout");
} else {
this.openLayout(index);
}
};
CustomMap.prototype.createMapMenu = function() {
var selfMap = this;
......@@ -106411,6 +106438,7 @@ CustomMap.prototype.createMapChangedCallbacks = function() {
* @returns submodel (or this model) with given identfier of the model
*/
CustomMap.prototype.getSubmodelById = function(identifier) {
identifier = parseInt(identifier);
if (this.getId() === identifier) {
return this;
}
......@@ -107064,8 +107092,8 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou
overlayCollection.aliasMarkers[element.getId()] = aliasMarker;
if (!missingElements) {
bounds = aliasMarker.getBounds();
boundsArray[element.modelId].extend(bounds.getNorthEast());
boundsArray[element.modelId].extend(bounds.getSouthWest());
boundsArray[element.getModelId()].extend(bounds.getNorthEast());
boundsArray[element.getModelId()].extend(bounds.getSouthWest());
}
}
} else if (element.type === "REACTION") {
......@@ -107091,8 +107119,8 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou
overlayCollection.reactionMarkers[element.getId()] = marker;
if (!missingElements) {
bounds = marker.getBounds();
boundsArray[element.modelId].extend(bounds.getNorthEast());
boundsArray[element.modelId].extend(bounds.getSouthWest());
boundsArray[element.getModelId()].extend(bounds.getNorthEast());
boundsArray[element.getModelId()].extend(bounds.getSouthWest());
}
} else if (element.type === "POINT") {
......@@ -107101,8 +107129,8 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou
overlayCollection.pointMarkers[pointData.getId()] = pointMarker;
if (!missingElements) {
bounds = pointMarker.getBounds();
boundsArray[element.modelId].extend(bounds.getNorthEast());
boundsArray[element.modelId].extend(bounds.getSouthWest());
boundsArray[element.getModelId()].extend(bounds.getNorthEast());
boundsArray[element.getModelId()].extend(bounds.getSouthWest());
}
} else {
logger.warn("Unknown type of the element in overlay: " + element.type);
......@@ -108298,15 +108326,15 @@ var logger = require('../../logger');
function IdentifiedElement(javaObject) {
if (javaObject instanceof Alias) {
this.setId(javaObject.getId());
this.modelId = javaObject.getModelId();
this.setModelId(javaObject.getModelId());
this.type = "ALIAS";
} else if (javaObject instanceof Reaction) {
this.setId(javaObject.getId());
this.modelId = javaObject.getModelId();
this.setModelId(javaObject.getModelId());
this.type = "REACTION";
} else if (javaObject instanceof PointData) {
this.setId(javaObject.getId());
this.modelId = javaObject.getModelId();
this.setModelId(javaObject.getModelId());
this.type = "POINT";
} else {
// identifier of the object to visualize
......@@ -108314,7 +108342,7 @@ function IdentifiedElement(javaObject) {
// which marker should be used to show this object
this.icon = javaObject.icon;
// on which model the element is located
this.modelId = javaObject.modelId;
this.setModelId(javaObject.modelId);
// what kind of object we are talking about
this.type = javaObject.type;
}
......@@ -108344,9 +108372,6 @@ function IdentifiedElement(javaObject) {
if (this.getId() === undefined || this.getId() === null) {
throw "Id not defined for element: " + javaObject;
}
if (this.modelId === undefined || this.modelId === null) {
throw "Model id not defined for element: " + javaObject;
}
}
/**
......@@ -108375,9 +108400,26 @@ IdentifiedElement.prototype.getId = function() {
};
IdentifiedElement.prototype.setId = function(id) {
// some elements are identfied by id that is not a number (like point on the
// map)
if (!isNaN(id)) {
id = parseInt(id);
}
this.id = id;
};
IdentifiedElement.prototype.getModelId = function() {
return this.modelId;
};
IdentifiedElement.prototype.setModelId = function(modelId) {
if (modelId === undefined || modelId === null) {
throw "ModelId is invalid";
}
this.modelId = parseInt(modelId);
};