Commit 9a1a42e0 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '1230-comments-in-submap' into 'devel_14.0.x'

Resolve "in submap the comment's bubble is not displayed"

See merge request !1119
parents 9dfb64e7 4e3584de
Pipeline #26528 passed with stage
in 13 minutes and 50 seconds
minerva (14.0.12) stable; urgency=medium
* Bug fix: comments on submaps were not visible (#1230)
* Bug fix: removing comment from submap did not work
-- Piotr Gawron <piotr.gawron@uni.lu> Mon, 11 May 2020 17:00:00 +0200
minerva (14.0.11) stable; urgency=medium minerva (14.0.11) stable; urgency=medium
* Bug fix: complex with no border was inproperly imported from CellDesigner * Bug fix: complex with no border was inproperly imported from CellDesigner
(#1198) (#1198)
......
...@@ -35,7 +35,7 @@ public class EnsemblAnnotator extends ElementAnnotator implements IExternalServi ...@@ -35,7 +35,7 @@ public class EnsemblAnnotator extends ElementAnnotator implements IExternalServi
/** /**
* Version of the rest API that is supported by this annotator. * Version of the rest API that is supported by this annotator.
*/ */
static final String SUPPORTED_VERSION = "11.2"; static final String SUPPORTED_VERSION = "12.0";
/** /**
* Url address of ensembl restful service. * Url address of ensembl restful service.
......
...@@ -47,6 +47,7 @@ public class CommentController extends BaseController { ...@@ -47,6 +47,7 @@ public class CommentController extends BaseController {
Authentication authentication, Authentication authentication,
@PathVariable(value = "projectId") String projectId, @PathVariable(value = "projectId") String projectId,
@RequestParam(value = "columns", defaultValue = "") String columns, @RequestParam(value = "columns", defaultValue = "") String columns,
@PathVariable(value = "modelId") String modelId,
@RequestParam(value = "removed", defaultValue = "") String removed) throws QueryException { @RequestParam(value = "removed", defaultValue = "") String removed) throws QueryException {
boolean isAdmin = authentication.getAuthorities() boolean isAdmin = authentication.getAuthorities()
.contains(new SimpleGrantedAuthority(PrivilegeType.IS_ADMIN.name())); .contains(new SimpleGrantedAuthority(PrivilegeType.IS_ADMIN.name()));
...@@ -56,7 +57,7 @@ public class CommentController extends BaseController { ...@@ -56,7 +57,7 @@ public class CommentController extends BaseController {
.contains(new SimpleGrantedAuthority(PrivilegeType.READ_PROJECT.name() + ":" + projectId)); .contains(new SimpleGrantedAuthority(PrivilegeType.READ_PROJECT.name() + ":" + projectId));
List<Map<String, Object>> comments = commentController.getCommentList( List<Map<String, Object>> comments = commentController.getCommentList(
projectId, columns, "", "", removed); projectId, columns, "", "", removed, modelId);
if (!isAdmin && !isProjectCurator) { if (!isAdmin && !isProjectCurator) {
comments.forEach(comment -> { comments.forEach(comment -> {
comment.remove("author"); comment.remove("author");
...@@ -89,10 +90,11 @@ public class CommentController extends BaseController { ...@@ -89,10 +90,11 @@ public class CommentController extends BaseController {
public List<Map<String, Object>> getCommentsByReaction( public List<Map<String, Object>> getCommentsByReaction(
@PathVariable(value = "projectId") String projectId, @PathVariable(value = "projectId") String projectId,
@RequestParam(value = "columns", defaultValue = "") String columns, @RequestParam(value = "columns", defaultValue = "") String columns,
@PathVariable(value = "modelId") String modelId,
@PathVariable(value = "reactionId") String reactionId, @PathVariable(value = "reactionId") String reactionId,
@RequestParam(value = "removed", defaultValue = "") String removed) throws QueryException { @RequestParam(value = "removed", defaultValue = "") String removed) throws QueryException {
return commentController.getCommentList(projectId, columns, reactionId, return commentController.getCommentList(projectId, columns, reactionId,
ElementIdentifierType.REACTION.getJsName(), removed); ElementIdentifierType.REACTION.getJsName(), removed, modelId);
} }
@PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)") @PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)")
...@@ -105,9 +107,10 @@ public class CommentController extends BaseController { ...@@ -105,9 +107,10 @@ public class CommentController extends BaseController {
@PathVariable(value = "projectId") String projectId, @PathVariable(value = "projectId") String projectId,
@RequestParam(value = "columns", defaultValue = "") String columns, @RequestParam(value = "columns", defaultValue = "") String columns,
@PathVariable(value = "elementId") String elementId, @PathVariable(value = "elementId") String elementId,
@PathVariable(value = "modelId") String modelId,
@RequestParam(value = "removed", defaultValue = "") String removed) throws QueryException { @RequestParam(value = "removed", defaultValue = "") String removed) throws QueryException {
return commentController.getCommentList( return commentController.getCommentList(
projectId, columns, elementId, ElementIdentifierType.ALIAS.getJsName(), removed); projectId, columns, elementId, ElementIdentifierType.ALIAS.getJsName(), removed, modelId);
} }
@PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)") @PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)")
...@@ -120,9 +123,10 @@ public class CommentController extends BaseController { ...@@ -120,9 +123,10 @@ public class CommentController extends BaseController {
@PathVariable(value = "projectId") String projectId, @PathVariable(value = "projectId") String projectId,
@RequestParam(value = "columns", defaultValue = "") String columns, @RequestParam(value = "columns", defaultValue = "") String columns,
@PathVariable(value = "coordinates") String coordinates, @PathVariable(value = "coordinates") String coordinates,
@PathVariable(value = "modelId") String modelId,
@RequestParam(value = "removed", defaultValue = "") String removed) throws QueryException { @RequestParam(value = "removed", defaultValue = "") String removed) throws QueryException {
return commentController.getCommentList(projectId, columns, coordinates, return commentController.getCommentList(projectId, columns, coordinates,
ElementIdentifierType.POINT.getJsName(), removed); ElementIdentifierType.POINT.getJsName(), removed, modelId);
} }
@PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)") @PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)")
......
...@@ -15,7 +15,7 @@ import lcsb.mapviewer.common.Configuration; ...@@ -15,7 +15,7 @@ import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.geometry.PointTransformation; import lcsb.mapviewer.common.geometry.PointTransformation;
import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.Comment; import lcsb.mapviewer.model.map.Comment;
import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.*;
import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.user.User; import lcsb.mapviewer.model.user.User;
...@@ -49,7 +49,7 @@ public class CommentRestImpl extends BaseRestImpl { ...@@ -49,7 +49,7 @@ public class CommentRestImpl extends BaseRestImpl {
public List<Map<String, Object>> getCommentList( public List<Map<String, Object>> getCommentList(
String projectId, String columns, String elementId, String projectId, String columns, String elementId,
String elementType, String removed) throws QueryException { String elementType, String removed, String modelId) throws QueryException {
Project project = getProjectService().getProjectByProjectId(projectId); Project project = getProjectService().getProjectByProjectId(projectId);
if (project == null) { if (project == null) {
throw new ObjectNotFoundException("Project with given id doesn't exist"); throw new ObjectNotFoundException("Project with given id doesn't exist");
...@@ -58,7 +58,9 @@ public class CommentRestImpl extends BaseRestImpl { ...@@ -58,7 +58,9 @@ public class CommentRestImpl extends BaseRestImpl {
List<Map<String, Object>> result = new ArrayList<>(); List<Map<String, Object>> result = new ArrayList<>();
List<Comment> comments = commentService.getCommentsByProject(project); List<Model> models = super.getModels(projectId, modelId);
List<Comment> comments = commentService.getCommentsByModel(models);
for (Comment comment : comments) { for (Comment comment : comments) {
boolean reject = false; boolean reject = false;
if (!"".equals(elementType)) { if (!"".equals(elementType)) {
...@@ -246,7 +248,8 @@ public class CommentRestImpl extends BaseRestImpl { ...@@ -246,7 +248,8 @@ public class CommentRestImpl extends BaseRestImpl {
} }
public Map<String, Object> addComment(String projectId, String elementType, String elementId, public Map<String, Object> addComment(String projectId, String elementType, String elementId,
String name, String email, String content, boolean pinned, Point2D pointCoordinates, String submodelId, User owner) String name, String email, String content, boolean pinned, Point2D pointCoordinates, String submodelId,
User owner)
throws QueryException { throws QueryException {
Model model = getModelService().getLastModelByProjectId(projectId); Model model = getModelService().getLastModelByProjectId(projectId);
if (model == null) { if (model == null) {
...@@ -292,9 +295,26 @@ public class CommentRestImpl extends BaseRestImpl { ...@@ -292,9 +295,26 @@ public class CommentRestImpl extends BaseRestImpl {
throw new ObjectNotFoundException("Project with given id doesn't exist"); throw new ObjectNotFoundException("Project with given id doesn't exist");
} }
Comment comment = commentService.getCommentById(commentId); Comment comment = commentService.getCommentById(commentId);
if (comment == null || comment.getModelData().getProject().getId() != project.getId()) {
if (comment == null) {
throw new ObjectNotFoundException("Comment with given id doesn't exist");
}
if (comment.getModelData().getProject() != null && comment.getModelData().getProject().getId() != project.getId()) {
throw new ObjectNotFoundException("Comment with given id doesn't exist"); throw new ObjectNotFoundException("Comment with given id doesn't exist");
} }
boolean isSubmap = false;
if (comment.getModelData().getProject() == null) {
for (ModelData model : project.getModels()) {
for (ModelSubmodelConnection submodel : model.getSubmodels()) {
if (submodel.getSubmodel().getId().equals(comment.getModelData().getId())) {
isSubmap = true;
}
}
}
if (!isSubmap) {
throw new ObjectNotFoundException("Comment with given id doesn't exist");
}
}
commentService.deleteComment(comment, reason); commentService.deleteComment(comment, reason);
return okStatus(); return okStatus();
......
...@@ -37,14 +37,7 @@ public class CommentRestImplTest extends RestTestFunctions { ...@@ -37,14 +37,7 @@ public class CommentRestImplTest extends RestTestFunctions {
@Test(expected = QueryException.class) @Test(expected = QueryException.class)
public void testGetForNonExisting() throws Exception { public void testGetForNonExisting() throws Exception {
_commentRestImpl.getCommentList("unk", "", "", "", ""); _commentRestImpl.getCommentList("unk", "", "", "", "", "*");
}
@Test
public void testGetCommentsDependencies() throws Exception {
CommentRestImpl commentRestImpl = createMockProjectRest("testFiles/model/sample.xml");
commentRestImpl.getCommentList("sample", "", "", "", "");
Mockito.verify(commentRestImpl.getModelService(), times(0)).getLastModelByProjectId(anyString());
} }
private CommentRestImpl createMockProjectRest(String string) throws Exception { private CommentRestImpl createMockProjectRest(String string) throws Exception {
......
...@@ -140,9 +140,9 @@ public class CommentService implements ICommentService { ...@@ -140,9 +140,9 @@ public class CommentService implements ICommentService {
} }
@Override @Override
public List<Comment> getCommentsByProject(Project project) { public List<Comment> getCommentsByModel(List<Model> models) {
List<Comment> comments = new ArrayList<>(); List<Comment> comments = new ArrayList<>();
for (ModelData model : project.getModels()) { for (Model model : models) {
List<Comment> modelComments = commentDao.getCommentByModel(model, null, null); List<Comment> modelComments = commentDao.getCommentByModel(model, null, null);
comments.addAll(modelComments); comments.addAll(modelComments);
} }
......
...@@ -55,7 +55,7 @@ public interface ICommentService { ...@@ -55,7 +55,7 @@ public interface ICommentService {
void deleteComment(Comment comment, String reason); void deleteComment(Comment comment, String reason);
List<Comment> getCommentsByProject(Project project); List<Comment> getCommentsByModel(List<Model> models);
/** /**
* Returns number of comments in the system. * Returns number of comments in the system.
......
...@@ -4,7 +4,6 @@ import static org.junit.Assert.*; ...@@ -4,7 +4,6 @@ import static org.junit.Assert.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.awt.geom.Point2D;
import java.util.Arrays; import java.util.Arrays;
import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.entity.UrlEncodedFormEntity;
...@@ -86,7 +85,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -86,7 +85,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
createComments(); createComments();
RequestBuilder request = get("/projects/" + TEST_PROJECT + "/comments/models/" + map.getIdModel() + "/") RequestBuilder request = get("/projects/" + TEST_PROJECT + "/comments/models/" + map.getId() + "/")
.contentType(MediaType.APPLICATION_FORM_URLENCODED) .contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session); .session(session);
...@@ -107,7 +106,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -107,7 +106,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
createComments(); createComments();
RequestBuilder request = get("/projects/*/comments/models/" + map.getIdModel() + "/") RequestBuilder request = get("/projects/*/comments/models/" + map.getId() + "/")
.contentType(MediaType.APPLICATION_FORM_URLENCODED) .contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session); .session(session);
...@@ -124,7 +123,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -124,7 +123,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
createComments(); createComments();
RequestBuilder request = get("/projects/" + TEST_PROJECT + "/comments/models/" + map.getIdModel() + "/") RequestBuilder request = get("/projects/" + TEST_PROJECT + "/comments/models/" + map.getId() + "/")
.contentType(MediaType.APPLICATION_FORM_URLENCODED) .contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session); .session(session);
...@@ -159,7 +158,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -159,7 +158,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
createComments(); createComments();
RequestBuilder request = get("/projects/" + TEST_PROJECT + "/comments/models/" + map.getIdModel() + "/") RequestBuilder request = get("/projects/" + TEST_PROJECT + "/comments/models/" + map.getId() + "/")
.contentType(MediaType.APPLICATION_FORM_URLENCODED) .contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session); .session(session);
...@@ -184,7 +183,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -184,7 +183,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
comment.setPinned(true); comment.setPinned(true);
commentDao.add(comment); commentDao.add(comment);
RequestBuilder request = get("/projects/" + TEST_PROJECT + "/comments/models/" + map.getIdModel() + "/") RequestBuilder request = get("/projects/" + TEST_PROJECT + "/comments/models/" + map.getId() + "/")
.contentType(MediaType.APPLICATION_FORM_URLENCODED) .contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session); .session(session);
...@@ -209,7 +208,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -209,7 +208,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
comment.setPinned(true); comment.setPinned(true);
commentDao.add(comment); commentDao.add(comment);
RequestBuilder request = get("/projects/" + TEST_PROJECT + "/comments/models/" + map.getIdModel() + "/") RequestBuilder request = get("/projects/" + TEST_PROJECT + "/comments/models/" + map.getId() + "/")
.contentType(MediaType.APPLICATION_FORM_URLENCODED) .contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session); .session(session);
...@@ -234,7 +233,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -234,7 +233,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
comment.setPinned(true); comment.setPinned(true);
commentDao.add(comment); commentDao.add(comment);
RequestBuilder request = get("/projects/" + TEST_PROJECT + "/comments/models/" + map.getIdModel() + "/") RequestBuilder request = get("/projects/" + TEST_PROJECT + "/comments/models/" + map.getId() + "/")
.contentType(MediaType.APPLICATION_FORM_URLENCODED) .contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session); .session(session);
...@@ -256,7 +255,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -256,7 +255,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
createComments(); createComments();
RequestBuilder request = get("/projects/" + TEST_PROJECT + "/comments/models/" + map.getIdModel() + "/") RequestBuilder request = get("/projects/" + TEST_PROJECT + "/comments/models/" + map.getId() + "/")
.contentType(MediaType.APPLICATION_FORM_URLENCODED) .contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session); .session(session);
...@@ -874,6 +873,45 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest ...@@ -874,6 +873,45 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
.andExpect(status().isNotFound()); .andExpect(status().isNotFound());
} }
@Test
public void testCommentsOnNonExistingModel() throws Exception {
createAdmin(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
createComments();
RequestBuilder request = get("/projects/" + TEST_PROJECT + "/comments/models/0/")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
mockMvc.perform(request)
.andExpect(status().isNotFound());
}
@Test
public void testRemoveFromSubmap() throws Exception {
createAdmin(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
ModelData submap = map.getSubmodels().iterator().next().getSubmodel();
Comment comment = createComment(submap);
commentDao.add(comment);
RequestBuilder request = delete("/projects/" + TEST_PROJECT + "/comments/" + comment.getId() + "/")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
mockMvc.perform(request)
.andExpect(status().is2xxSuccessful());
assertEquals(true, comment.isDeleted());
}
private Comment createReactionComment() { private Comment createReactionComment() {
Comment comment = createComment(map); Comment comment = createComment(map);
comment.setTableName(reaction.getClass()); comment.setTableName(reaction.getClass());
......
...@@ -38,7 +38,7 @@ import lcsb.mapviewer.model.map.Comment; ...@@ -38,7 +38,7 @@ import lcsb.mapviewer.model.map.Comment;
import lcsb.mapviewer.model.map.layout.ColorSchemaType; import lcsb.mapviewer.model.map.layout.ColorSchemaType;
import lcsb.mapviewer.model.map.layout.Layout; import lcsb.mapviewer.model.map.layout.Layout;
import lcsb.mapviewer.model.map.layout.graphics.Glyph; import lcsb.mapviewer.model.map.layout.graphics.Glyph;
import lcsb.mapviewer.model.map.model.ModelData; import lcsb.mapviewer.model.map.model.*;
import lcsb.mapviewer.model.map.reaction.*; import lcsb.mapviewer.model.map.reaction.*;
import lcsb.mapviewer.model.map.reaction.type.TransportReaction; import lcsb.mapviewer.model.map.reaction.type.TransportReaction;
import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.Element;
...@@ -248,6 +248,15 @@ abstract public class ControllerIntegrationTest { ...@@ -248,6 +248,15 @@ abstract public class ControllerIntegrationTest {
product.setLine(new PolylineData(new Point2D.Double(10, 0), new Point2D.Double(20, 0))); product.setLine(new PolylineData(new Point2D.Double(10, 0), new Point2D.Double(20, 0)));
reaction.addProduct(product); reaction.addProduct(product);
ModelData submap = new ModelData();
submap.setTileSize(256);
submap.setWidth(100);
submap.setHeight(100);
ModelSubmodelConnection submodelConnection = new ModelSubmodelConnection(submap, SubmodelType.UNKNOWN);
map.addSubmodel(submodelConnection);
project.addModel(map); project.addModel(map);
projectDao.add(project); projectDao.add(project);
return project; return project;
......
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