diff --git a/frontend-js/src/main/js/ServerConnector.js b/frontend-js/src/main/js/ServerConnector.js index 338cdf24e3abedd8b981a611a0fdec6b4a58a648..85f25c7cb3f54c39058ab98b61e35d370195a381 100644 --- a/frontend-js/src/main/js/ServerConnector.js +++ b/frontend-js/src/main/js/ServerConnector.js @@ -283,8 +283,9 @@ ServerConnector.getProjectsUrl = function(queryParams, filterParams) { }; ServerConnector.getProjectUrl = function(queryParams, filterParams) { + var id = this.getIdOrAsterisk(queryParams.projectId); return this.getApiUrl({ - url : this.getProjectsUrl(queryParams) + queryParams.projectId + "/", + url : this.getProjectsUrl(queryParams) + id + "/", params : filterParams, }); }; @@ -1283,24 +1284,18 @@ ServerConnector.addOverlay = function(params) { }); }; -ServerConnector.updateOverlay = function(params) { +ServerConnector.updateOverlay = function(overlay) { var self = this; var queryParams = { - overlayId : params.overlayId + overlayId : overlay.getId(), }; var filterParams = { - overlay : {} + overlay : { + name : overlay.getName(), + description : overlay.getDescription(), + } }; - if (params.name !== undefined) { - filterParams.overlay.name = params.name; - } - if (params.description !== undefined) { - filterParams.overlay.description = params.description; - } - return self.getProjectId(params.projectId).then(function(result) { - queryParams.projectId = result; - return self.sendPatchRequest(self.updateOverlayUrl(queryParams), filterParams); - }); + return self.sendPatchRequest(self.updateOverlayUrl(queryParams), filterParams); }; ServerConnector.removeOverlay = function(params) { diff --git a/frontend-js/src/main/js/gui/admin/EditProjectDialog.js b/frontend-js/src/main/js/gui/admin/EditProjectDialog.js index 4767d3dd82f9d2f5073189852344867bd685be04..d5a64cd81c91e38fea8b820274903e0a9ad437f7 100644 --- a/frontend-js/src/main/js/gui/admin/EditProjectDialog.js +++ b/frontend-js/src/main/js/gui/admin/EditProjectDialog.js @@ -249,10 +249,54 @@ EditProjectDialog.prototype.createOverlaysTab = function(tabMenuDiv, tabContentD }; EditProjectDialog.prototype.createOverlaysTabContent = function() { - return Functions.createElement({ + var self = this; + var result = Functions.createElement({ type : "div", - content : "Helo" }); + result.appendChild(self._createOverlayTable()); + return result; +}; + +EditProjectDialog.prototype._createOverlayTable = function() { + var self = this; + var overlaysTable = Functions.createElement({ + type : "table", + name : "overlaysTable", + className : "display", + style : "width:100%", + }); + + $(overlaysTable).DataTable({ + fnRowCallback : function(nRow, aData, iDisplayIndex) { + nRow.setAttribute('id', "overlay-" + aData[0]); + }, + columns : [ { + title : 'Id', + }, { + title : 'Name', + }, { + title : 'Description', + }, { + title : 'Owner', + }, { + title : 'Data', + }, { + title : 'Update', + }, { + title : 'Remove', + }, ], + }); + $(overlaysTable).on("click", "[name='removeOverlay']", function() { + var button = this; + return self.removeOverlay($(button).attr("data")).then(null, GuiConnector.alert); + }); + + $(overlaysTable).on("click", "[name='saveOverlay']", function() { + var button = this; + return self.saveOverlay($(button).attr("data")).then(null, GuiConnector.alert); + }); + + return overlaysTable; }; EditProjectDialog.prototype.createUsersTab = function(tabMenuDiv, tabContentDiv) { @@ -274,6 +318,47 @@ EditProjectDialog.prototype.createUsersTabContent = function() { }; EditProjectDialog.prototype.init = function() { + var self = this; + return ServerConnector.getOverlays({ + projectId : self.getProject().getProjectId() + }).then(function(overlays) { + return self.setOverlays(overlays); + }).then(function() { + $(window).trigger('resize'); + }); +}; + +EditProjectDialog.prototype.setOverlays = function(overlays) { + var self = this; + self._overlayById = []; + // return ServerConnector.getUsers().then(function(users) { + var users = []; + var dataTable = $($("[name='overlaysTable']", self.getElement())[0]).DataTable(); + var data = []; + for (var i = 0; i < overlays.length; i++) { + var overlay = overlays[i]; + self._overlayById[overlay.getId()] = overlay; + var rowData = self.overlayToTableRow(overlay, users) + data.push(rowData); + } + dataTable.clear().rows.add(data).draw(); + // }); +}; + +EditProjectDialog.prototype.overlayToTableRow = function(overlay, users) { + var row = []; + var id = overlay.getId(); + + row[0] = id; + row[1] = "<input name='name-" + id + "' value='" + overlay.getName() + "'/>"; + row[2] = "<input name='description-" + id + "' value='" + overlay.getDescription() + "'/>"; + row[3] = overlay.getCreator(); + row[4] = overlay.getInputDataAvailable(); + row[5] = "<button name='saveOverlay' data='" + id + "'>SAVE</button>"; + row[6] = "<button name='removeOverlay' data='" + id + "'>REMOVE</button>"; + + logger.debug(overlay.getId()); + return row; }; EditProjectDialog.prototype.destroy = function() { @@ -286,7 +371,8 @@ EditProjectDialog.prototype.open = function() { if (!$(div).hasClass("ui-dialog-content")) { $(div).dialog({ title : self.getProject().getProjectId(), - width : 400, + width : window.innerWidth / 2, + height : window.innerHeight / 2, }); } $(div).dialog("open"); @@ -320,4 +406,13 @@ EditProjectDialog.prototype.close = function() { $(this.getElement()).dialog("close"); }; +EditProjectDialog.prototype.saveOverlay = function(overlayId) { + var self = this; + var overlay = self._overlayById[overlayId]; + overlay.setName($("[name='name-" + overlayId + "']", self.getElement())[0].value); + overlay.setDescription($("[name='description-" + overlayId + "']", self.getElement())[0].value); + + return ServerConnector.updateOverlay(overlay); +}; + module.exports = EditProjectDialog; diff --git a/frontend-js/src/main/js/gui/admin/MapsAdminPanel.js b/frontend-js/src/main/js/gui/admin/MapsAdminPanel.js index 78881ee703a902bcf162f8ad607c1c22b7fbb7b8..c956c68be39dd6fd56e41d014fc5ecf60662e2cf 100644 --- a/frontend-js/src/main/js/gui/admin/MapsAdminPanel.js +++ b/frontend-js/src/main/js/gui/admin/MapsAdminPanel.js @@ -171,7 +171,6 @@ MapsAdminPanel.prototype.setProjects = function(projects) { data.push(rowData); } dataTable.clear().rows.add(data).draw(); - }; MapsAdminPanel.prototype.addUpdateListener = function(project, dataTableRow) { @@ -208,19 +207,22 @@ MapsAdminPanel.prototype.onRefreshClicked = function() { MapsAdminPanel.prototype.showEditDialog = function(id) { GuiConnector.showProcessing(); + var dialog; return ServerConnector.getProject(id).then(function(project) { - var dialog = new EditProjectDialog({ + dialog = new EditProjectDialog({ element : Functions.createElement({ type : "div" }), project : project, customMap : null, }); + return dialog.init(); + }).then(function() { dialog.open(); GuiConnector.hideProcessing(); }).then(null, function(error) { GuiConnector.hideProcessing(); - Promise.reject(error); + return Promise.reject(error); }); }; MapsAdminPanel.prototype.removeProject = function(id) { diff --git a/frontend-js/src/main/js/gui/leftPanel/OverlayPanel.js b/frontend-js/src/main/js/gui/leftPanel/OverlayPanel.js index 7a7615342f9b58e8fa7b60836114107aec2f203b..cbc48b60a3d09c7632fb4fc508125b2d3283f45f 100644 --- a/frontend-js/src/main/js/gui/leftPanel/OverlayPanel.js +++ b/frontend-js/src/main/js/gui/leftPanel/OverlayPanel.js @@ -26,7 +26,7 @@ function OverlayPanel(params) { var addButton = this.getControlElement(PanelControlElementType.OVERLAY_ADD_OVERLAY_BUTTON); - addButton.onclick = function () { + addButton.onclick = function() { self.openAddOverlayDialog(); }; @@ -38,51 +38,51 @@ function OverlayPanel(params) { OverlayPanel.prototype = Object.create(Panel.prototype); OverlayPanel.prototype.constructor = OverlayPanel; -OverlayPanel.prototype._createOverlayPanelGui = function () { +OverlayPanel.prototype._createOverlayPanelGui = function() { var generalOverlaysDiv = Functions.createElement({ - type: "div", - name: "generalOverlays", - className: "searchPanel" + type : "div", + name : "generalOverlays", + className : "searchPanel" }); this.getElement().appendChild(generalOverlaysDiv); this.setControlElement(PanelControlElementType.OVERLAY_GENERAL_OVERLAY_DIV, generalOverlaysDiv); var generalOverlaysTitle = Functions.createElement({ - type: "h5", - content: "GENERAL OVERLAYS:" + type : "h5", + content : "GENERAL OVERLAYS:" }); generalOverlaysDiv.appendChild(generalOverlaysTitle); var generalOverlaysTableDiv = Functions.createElement({ - type: "table", - name: "generalOverlaysTab", - className: "table table-bordered", - style: "width:100%" + type : "table", + name : "generalOverlaysTab", + className : "table table-bordered", + style : "width:100%" }); generalOverlaysDiv.appendChild(generalOverlaysTableDiv); this.setControlElement(PanelControlElementType.OVERLAY_GENERAL_OVERLAY_TABLE, generalOverlaysTableDiv); var customOverlaysDiv = Functions.createElement({ - type: "div", - name: "customOverlays", - className: "searchPanel" + type : "div", + name : "customOverlays", + className : "searchPanel" }); this.getElement().appendChild(customOverlaysDiv); this.setControlElement(PanelControlElementType.OVERLAY_CUSTOM_OVERLAY_DIV, customOverlaysDiv); var customOverlaysTitle = Functions.createElement({ - type: "h5", - name: "customOverlaysTitle", - content: "USER-PROVIDED OVERLAYS:" + type : "h5", + name : "customOverlaysTitle", + content : "USER-PROVIDED OVERLAYS:" }); customOverlaysDiv.appendChild(customOverlaysTitle); this.setControlElement(PanelControlElementType.OVERLAY_CUSTOM_OVERLAY_TITLE, customOverlaysTitle); var customOverlaysTableDiv = Functions.createElement({ - type: "table", - name: "customOverlaysTab", - className: "table table-bordered", - style: "width:100%" + type : "table", + name : "customOverlaysTab", + className : "table table-bordered", + style : "width:100%" }); customOverlaysDiv.appendChild(customOverlaysTableDiv); this.setControlElement(PanelControlElementType.OVERLAY_CUSTOM_OVERLAY_TABLE, customOverlaysTableDiv); @@ -212,57 +212,55 @@ OverlayPanel.prototype.createOverlayRow = function (overlay, checked) { return result; }; -OverlayPanel.prototype.openEditOverlayDialog = function (overlay) { +OverlayPanel.prototype.openEditOverlayDialog = function(overlay) { var self = this; var guiUtils = self.getGuiUtils(); var content = document.createElement("fieldset"); var nameInput = guiUtils.createInputText(overlay.getName()); - var row = guiUtils.createTableRow([guiUtils.createLabel("Name: "), nameInput]); + var row = guiUtils.createTableRow([ guiUtils.createLabel("Name: "), nameInput ]); content.appendChild(row); var descriptionInput = guiUtils.createTextArea(overlay.getDescription()); - row = guiUtils.createTableRow([guiUtils.createLabel("Description: "), descriptionInput]); + row = guiUtils.createTableRow([ guiUtils.createLabel("Description: "), descriptionInput ]); content.appendChild(row); - var buttons = [{ - text: "SAVE", - click: function () { + var buttons = [ { + text : "SAVE", + click : function() { var windowSelf = this; - return ServerConnector.updateOverlay({ - overlayId: overlay.id, - name: nameInput.value, - description: descriptionInput.value - }).then(function () { + overlay.setName(nameInput.value); + overlay.setDescription(descriptionInput.value); + return ServerConnector.updateOverlay(overlay).then(function() { return self.refresh(); - }).then(function () { + }).then(function() { $(windowSelf).dialog("close"); }).then(null, GuiConnector.alert); } }, { - text: "REMOVE", - click: function () { + text : "REMOVE", + click : function() { self.getMap().removeSelectedLayout(overlay.getId()); var windowSelf = this; return ServerConnector.removeOverlay({ - overlayId: overlay.getId() - }).then(function () { + overlayId : overlay.getId() + }).then(function() { return self.refresh(); - }).then(function () { + }).then(function() { $(windowSelf).dialog("close"); }).then(null, GuiConnector.alert); } }, { - text: "CANCEL", - click: function () { + text : "CANCEL", + click : function() { $(this).dialog("close"); } - }]; + } ]; self.openDialog(content, { - id: overlay.getId(), - buttons: buttons, - title: "Data overlay: " + overlay.getName(), - className: "minerva-overlay-dialog", + id : overlay.getId(), + buttons : buttons, + title : "Data overlay: " + overlay.getName(), + className : "minerva-overlay-dialog", }); }; @@ -289,26 +287,26 @@ OverlayPanel.prototype.refresh = function () { creator : user.getLogin(), }); }).then( - function (customOverlays) { + function(customOverlays) { - var id = self.getMap().getGoogleMap().getMapTypeId().substring(2); - selectedOverlay[id] = true; + var id = self.getMap().getGoogleMap().getMapTypeId().substring(2); + selectedOverlay[id] = true; - self.clear(); + self.clear(); - var generalOverlays = []; - var overlay; + var generalOverlays = []; + var overlay; - var overlays = self.getMap().getLayouts(); - for (var i = 0; i < overlays.length; i++) { - overlay = overlays[i]; - if (overlay.getCreator() === undefined || overlay.getCreator() === "") { - generalOverlays.push(overlay); + var overlays = self.getMap().getLayouts(); + for (var i = 0; i < overlays.length; i++) { + overlay = overlays[i]; + if (overlay.getCreator() === undefined || overlay.getCreator() === "") { + generalOverlays.push(overlay); + } } - } - var table = self.getControlElement(PanelControlElementType.OVERLAY_GENERAL_OVERLAY_TABLE); - table.appendChild(self.createTableHeader()); + var table = self.getControlElement(PanelControlElementType.OVERLAY_GENERAL_OVERLAY_TABLE); + table.appendChild(self.createTableHeader()); var body = document.createElement("tbody"); table.appendChild(body); diff --git a/frontend-js/src/test/js/ServerConnector-test.js b/frontend-js/src/test/js/ServerConnector-test.js index f39aeef4f05e8fa1260df646d6b59caa9edad971..2a0296c2d5b0ed5f1505808364b41d1a413ba8f2 100644 --- a/frontend-js/src/test/js/ServerConnector-test.js +++ b/frontend-js/src/test/js/ServerConnector-test.js @@ -8,6 +8,7 @@ var HttpStatus = require('http-status-codes'); var Alias = require('../../main/js/map/data/Alias'); var Configuration = require('../../main/js/Configuration'); +var LayoutData= require('../../main/js/map/data/LayoutData'); var LayoutAlias = require('../../main/js/map/data/LayoutAlias'); var MapModel = require('../../main/js/map/data/MapModel'); var NetworkError = require('../../main/js/NetworkError'); @@ -192,11 +193,12 @@ describe('ServerConnector', function() { }); it('updateOverlay', function() { - return ServerConnector.updateOverlay({ - overlayId : 17296, - name : "test nam2", - description : "test desc2", - }); + var overlay = new LayoutData({}); + overlay.setId(17296); + overlay.setName("test nam2"); + overlay.setDescription("test desc2"); + + return ServerConnector.updateOverlay(overlay); }); it('logout', function() { diff --git a/frontend-js/src/test/js/gui/admin/EditProjectDialog.js b/frontend-js/src/test/js/gui/admin/EditProjectDialog.js index 78ffb0c1eab810bb32810584141cbccc512ad4b2..085132d5739fe7b46203456a88c5afdd3b020988 100644 --- a/frontend-js/src/test/js/gui/admin/EditProjectDialog.js +++ b/frontend-js/src/test/js/gui/admin/EditProjectDialog.js @@ -26,6 +26,36 @@ describe('EditProjectDialog', function() { }); }); + it('init', function() { + var dialog; + var project; + return ServerConnector.getProject().then(function(result) { + project = result; + dialog = new EditProjectDialog({ + element : testDiv, + project : project, + customMap : null, + }); + return dialog.init(); + }); + }); + it('saveOverlay', function() { + var dialog; + var project; + return ServerConnector.getProject().then(function(result) { + project = result; + dialog = new EditProjectDialog({ + element : testDiv, + project : project, + customMap : null, + }); + return dialog.init(); + }).then(function(){ + return dialog.saveOverlay(14081); + }); + }); + + it('onSaveClicked', function() { var dialog; var project; diff --git a/frontend-js/testFiles/apiCalls/projects/all/overlays/14081/PATCH_overlay.name=Pathways and compartments&token=MOCK_TOKEN_ID& b/frontend-js/testFiles/apiCalls/projects/all/overlays/14081/PATCH_overlay.name=Pathways and compartments&token=MOCK_TOKEN_ID& new file mode 100644 index 0000000000000000000000000000000000000000..84110294c8c0a0ad8a7aeb9ebc48f8c11fda10cb --- /dev/null +++ b/frontend-js/testFiles/apiCalls/projects/all/overlays/14081/PATCH_overlay.name=Pathways and compartments&token=MOCK_TOKEN_ID& @@ -0,0 +1,3 @@ +{ + "status": "OK" +} \ No newline at end of file diff --git a/frontend-js/testFiles/apiCalls/projects/all/overlays/17296/PATCH_overlay.description=test desc2&overlay.name=test nam2&token=MOCK_TOKEN_ID& b/frontend-js/testFiles/apiCalls/projects/all/overlays/17296/PATCH_overlay.description=test desc2&overlay.name=test nam2&token=MOCK_TOKEN_ID& new file mode 100644 index 0000000000000000000000000000000000000000..84110294c8c0a0ad8a7aeb9ebc48f8c11fda10cb --- /dev/null +++ b/frontend-js/testFiles/apiCalls/projects/all/overlays/17296/PATCH_overlay.description=test desc2&overlay.name=test nam2&token=MOCK_TOKEN_ID& @@ -0,0 +1,3 @@ +{ + "status": "OK" +} \ No newline at end of file diff --git a/frontend-js/testFiles/apiCalls/projects/sample/overlays/token=MOCK_TOKEN_ID& b/frontend-js/testFiles/apiCalls/projects/sample/overlays/token=MOCK_TOKEN_ID& new file mode 100644 index 0000000000000000000000000000000000000000..f19c8c7dd8ff820159276e47d820eceb81ff8b9e --- /dev/null +++ b/frontend-js/testFiles/apiCalls/projects/sample/overlays/token=MOCK_TOKEN_ID& @@ -0,0 +1 @@ +[{"idObject":14081,"modelId":15781,"name":"Pathways and compartments","description":"","status":"Not available","publicOverlay":true,"progress":"0.00","directory":"5e8ff9bf55ba3508199d22e984129be6/_nested0","creator":"","inputDataAvailable":"false"},{"idObject":14082,"modelId":15781,"name":"Network","description":"","status":"Not available","publicOverlay":true,"progress":"0.00","directory":"5e8ff9bf55ba3508199d22e984129be6/_normal0","creator":"","inputDataAvailable":"false"},{"idObject":14083,"modelId":15781,"name":"Empty","description":"","status":"Not available","publicOverlay":true,"progress":"0.00","directory":"5e8ff9bf55ba3508199d22e984129be6/_empty0","creator":"","inputDataAvailable":"false"},{"idObject":18076,"modelId":15781,"name":"C:\\fakepath\\test.txt","description":"xxx","status":"OK","publicOverlay":true,"progress":"0.00","directory":"5e8ff9bf55ba3508199d22e984129be6/.18076","creator":"","inputDataAvailable":"true"},{"idObject":18077,"modelId":15781,"name":"xxx","description":"yyy","status":"OK","publicOverlay":true,"progress":"0.00","directory":"5e8ff9bf55ba3508199d22e984129be6/.18077","creator":"","inputDataAvailable":"true"},{"idObject":18095,"modelId":15781,"name":"a test","description":"test2 casadsadasdqqq","status":"OK","publicOverlay":false,"progress":"0.00","directory":"5e8ff9bf55ba3508199d22e984129be6/.18095","creator":"admin","inputDataAvailable":"true"},{"idObject":20660,"modelId":15781,"name":"","description":"","status":"OK","publicOverlay":false,"progress":"0.00","directory":"5e8ff9bf55ba3508199d22e984129be6/.20660","creator":"admin","inputDataAvailable":"true"}] \ No newline at end of file diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java index b6bc43c0baca458297d1b6eccbf307a531fbb0c3..d42c8d428c09f93b038443fa2d9b4397b03cf995 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java @@ -120,7 +120,7 @@ public class OverlayRestImpl extends BaseRestImpl { if (model == null) { throw new QueryException("Project with given id doesn't exist"); } - return layoutService.getLayoutById(model, Integer.valueOf(overlayId), authenticationToken); + return layoutService.getLayoutById(Integer.valueOf(overlayId), authenticationToken); } public FileEntry getOverlaySource(String token, String projectId, String overlayId) throws SecurityException, QueryException { @@ -145,21 +145,16 @@ public class OverlayRestImpl extends BaseRestImpl { public LayoutView updateOverlay(String token, String projectId, String overlayId, Map<String, Object> overlayData) throws QueryException, SecurityException { AuthenticationToken authenticationToken = getUserService().getToken(token); - Model model = getModelService().getLastModelByProjectId(projectId, authenticationToken); - if (model == null) { - throw new ObjectNotFoundException("Project with given id doesn't exist"); - } if (overlayData == null) { throw new QueryException("overlay field cannot be undefined"); } - Project project = model.getProject(); - boolean isAdmin = getUserService().userHasPrivilege(authenticationToken, PrivilegeType.LAYOUT_MANAGEMENT, project); try { Integer id = Integer.valueOf(overlayId); Layout layout = layoutService.getLayoutDataById(id, authenticationToken); if (layout == null) { throw new ObjectNotFoundException("overlay doesn't exist"); } + boolean isAdmin = getUserService().userHasPrivilege(authenticationToken, PrivilegeType.LAYOUT_MANAGEMENT, layout.getModel().getProject()); if (layout.isPublicLayout() && !isAdmin) { throw new SecurityException("You cannot modify given overlay"); } @@ -170,7 +165,7 @@ public class OverlayRestImpl extends BaseRestImpl { layout.setTitle((String) overlayData.get("name")); } layoutDao.update(layout); - return layoutService.getLayoutById(model, Integer.valueOf(overlayId), authenticationToken); + return layoutService.getLayoutById(Integer.valueOf(overlayId), authenticationToken); } catch (NumberFormatException e) { throw new ObjectNotFoundException("overlay doesn't exist"); } @@ -184,7 +179,7 @@ public class OverlayRestImpl extends BaseRestImpl { } try { Integer id = Integer.valueOf(overlayId); - LayoutView layout = layoutService.getLayoutById(model, id, authenticationToken); + LayoutView layout = layoutService.getLayoutById(id, authenticationToken); if (layout == null) { throw new ObjectNotFoundException("Overlay doesn't exist"); } @@ -244,7 +239,7 @@ public class OverlayRestImpl extends BaseRestImpl { new CreateLayoutParams() .async(false).colorInputStream(stream).description(description).layoutFileName(filename).model(model).name(name).user(user) .colorSchemaType(colorSchemaType).directory(".")); - return layoutService.getLayoutById(model, Integer.valueOf(layout.getIdObject()), authenticationToken); + return layoutService.getLayoutById(Integer.valueOf(layout.getIdObject()), authenticationToken); } catch (InvalidColorSchemaException e) { throw new QueryException(e.getMessage(), e); } diff --git a/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java b/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java index a53089ee5c1c49a60528b6a6ec27d873367ebc02..646931a61237fc94f527d9a6b2a79774adba940f 100644 --- a/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java +++ b/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java @@ -918,7 +918,7 @@ public class LayoutService implements ILayoutService { * @throws SecurityException */ private byte[] getInputDataForLayout(int layoutId, AuthenticationToken token) throws SecurityException { - Layout layout = getLayoutById(layoutId, token); + Layout layout = getLayoutDataById(layoutId, token); if (layout == null) { return null; } else { @@ -930,18 +930,6 @@ public class LayoutService implements ILayoutService { } } - private Layout getLayoutById(int layoutId, AuthenticationToken token) throws SecurityException { - Layout layout = layoutDao.getById(layoutId); - if (layout == null) { - return null; - } - User user = userService.getUserByToken(token); - if (!userCanViewOverlay(layout, user)) { - throw new SecurityException("User doesn't have access to overlay"); - } - return layout; - } - @Override public List<LightLayoutAliasView> getAliasesForLayout(Model model, int layoutId, AuthenticationToken token) throws SecurityException { try { @@ -1052,8 +1040,8 @@ public class LayoutService implements ILayoutService { } @Override - public LayoutView getLayoutById(Model model, int overlayId, AuthenticationToken token) throws SecurityException { - Layout layout = getLayoutById(overlayId, token); + public LayoutView getLayoutById(int overlayId, AuthenticationToken token) throws SecurityException { + Layout layout = getLayoutDataById(overlayId, token); if (layout == null) { return null; } @@ -1062,7 +1050,15 @@ public class LayoutService implements ILayoutService { @Override public Layout getLayoutDataById(int overlayId, AuthenticationToken token) throws SecurityException { - return getLayoutById(overlayId, token); + Layout layout = layoutDao.getById(overlayId); + if (layout == null) { + return null; + } + User user = userService.getUserByToken(token); + if (!userCanViewOverlay(layout, user)) { + throw new SecurityException("User doesn't have access to overlay"); + } + return layout; } @Override diff --git a/service/src/main/java/lcsb/mapviewer/services/interfaces/ILayoutService.java b/service/src/main/java/lcsb/mapviewer/services/interfaces/ILayoutService.java index 35e662b9231100f39736c4fb8f3d0b55a772d8a5..8918cbb8e460f4bd5860eb74e6e91c6bc490940d 100644 --- a/service/src/main/java/lcsb/mapviewer/services/interfaces/ILayoutService.java +++ b/service/src/main/java/lcsb/mapviewer/services/interfaces/ILayoutService.java @@ -523,7 +523,7 @@ public interface ILayoutService { List<LayoutView> getCustomLayouts(Model model, String token, Boolean publicOverlay, User creator) throws SecurityException; - LayoutView getLayoutById(Model model, int overlayId, AuthenticationToken token) throws SecurityException; + LayoutView getLayoutById(int overlayId, AuthenticationToken token) throws SecurityException; Layout getLayoutDataById(int overlayId, AuthenticationToken authenticationToken) throws SecurityException; diff --git a/service/src/main/java/lcsb/mapviewer/services/view/LayoutView.java b/service/src/main/java/lcsb/mapviewer/services/view/LayoutView.java index 5a20b3629acc99e847cda5e82efeb546871d8f5d..a85a32ed3b4a282bfbdf4a981136a9f768fba795 100644 --- a/service/src/main/java/lcsb/mapviewer/services/view/LayoutView.java +++ b/service/src/main/java/lcsb/mapviewer/services/view/LayoutView.java @@ -15,73 +15,75 @@ public class LayoutView extends AbstractView<Layout> implements Serializable { /** * */ - private static final long serialVersionUID = 1L; - + private static final long serialVersionUID = 1L; + /** * Comparator for {@link LayoutView} that use database identifier as a key for * comparison. */ - public static final Comparator<LayoutView> ID_COMPARATOR = new Comparator<LayoutView>() { - - @Override - public int compare(LayoutView arg0, LayoutView arg1) { - if (arg0 == null) { - return -1; - } else if (arg1 == null) { - return 1; - } else if (arg0.getIdObject() == null) { - return -1; - } else if (arg1.getIdObject() == null) { - return 1; - } else { - return arg0.getIdObject() - arg1.getIdObject(); + public static final Comparator<LayoutView> ID_COMPARATOR = new Comparator<LayoutView>() { + + @Override + public int compare(LayoutView arg0, LayoutView arg1) { + if (arg0 == null) { + return -1; + } else if (arg1 == null) { + return 1; + } else if (arg0.getIdObject() == null) { + return -1; + } else if (arg1.getIdObject() == null) { + return 1; + } else { + return arg0.getIdObject() - arg1.getIdObject(); + } } - } - }; - + }; + /** * Database identifier of the model to which layout belongs to. */ - private Integer modelId; - + private Integer modelId; + /** * Name of the layout. */ - private String name; - + private String name; + /** * Short description of the layout. */ - private String description; - + private String description; + /** * Status of processing the layout. * {@link lcsb.mapviewer.db.model.map.layout.LayoutStatus LayoutStatus} * defines possible values. */ - private String status; - + private String status; + + private Boolean publicOverlay; + /** * Processing progress (value between 0..100). */ - private String progress; - + private String progress; + /** * Where the files generated for this layout are stored. */ - private String directory; + private String directory; /** * Who created the layout. */ - private String creator; + private String creator; /** * "true" if input file from which layout was created is available, "false" * otherwise. */ - private String inputDataAvailable; + private String inputDataAvailable; /** * Default constructor. @@ -228,11 +230,29 @@ public class LayoutView extends AbstractView<Layout> implements Serializable { } /** - * @param inputDataAvailable the inputDataAvailable to set + * @param inputDataAvailable + * the inputDataAvailable to set * @see #inputDataAvailable */ public void setInputDataAvailable(String inputDataAvailable) { this.inputDataAvailable = inputDataAvailable; } + /** + * @return the publicOverlay + * @see #publicOverlay + */ + public Boolean getPublicOverlay() { + return publicOverlay; + } + + /** + * @param publicOverlay + * the publicOverlay to set + * @see #publicOverlay + */ + public void setPublicOverlay(Boolean publicOverlay) { + this.publicOverlay = publicOverlay; + } + } diff --git a/service/src/main/java/lcsb/mapviewer/services/view/LayoutViewFactory.java b/service/src/main/java/lcsb/mapviewer/services/view/LayoutViewFactory.java index d5185d30a9e2e58d861f11c379b2ade8c25eeeb1..ba968d0c1b9a216becdb4c0d962e05b4e9d49bb3 100644 --- a/service/src/main/java/lcsb/mapviewer/services/view/LayoutViewFactory.java +++ b/service/src/main/java/lcsb/mapviewer/services/view/LayoutViewFactory.java @@ -38,11 +38,12 @@ public class LayoutViewFactory extends AbstractViewFactory<Layout, LayoutView> { result.setDirectory(layout.getDirectory()); } if (layout.getCreator() != null) { - result.setCreator(layout.getCreator().getName() + " " + layout.getCreator().getSurname()); + result.setCreator(layout.getCreator().getLogin()); } else { result.setCreator(""); } result.setStatus(layout.getStatus().getCommonName()); + result.setPublicOverlay(layout.isPublicLayout()); result.setProgress(String.format("%1$,.2f", layout.getProgress())); result.setDescription(layout.getDescription());