Skip to content
Snippets Groups Projects
Commit 794bf0f4 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

filtering comments by type and identifier added for rest api

parent 8a1d6600
No related branches found
No related tags found
1 merge request!5Frontend refactor
......@@ -24,8 +24,9 @@ public class CommentController extends BaseController {
@RequestMapping(value = "/getCommentList", method = { RequestMethod.GET, RequestMethod.POST }, produces = { MediaType.APPLICATION_JSON_VALUE })
public List<Map<String, Object>> getOverlayList(@RequestParam(value = "token") String token, @RequestParam(value = "projectId") String projectId,
@RequestParam(value = "columns", defaultValue = "") String columns) throws SecurityException, QueryException {
return commentController.getCommentList(token, projectId, columns);
@RequestParam(value = "columns", defaultValue = "") String columns, @RequestParam(value = "elementId", defaultValue = "") String elementId,
@RequestParam(value = "elementType", defaultValue = "") String elementType) throws SecurityException, QueryException {
return commentController.getCommentList(token, projectId, columns, elementId, elementType);
}
@RequestMapping(value = "/addComment", method = { RequestMethod.GET, RequestMethod.POST }, produces = { MediaType.APPLICATION_JSON_VALUE })
......
......@@ -49,7 +49,8 @@ public class CommentRestImpl {
@Autowired
private ElementDao elementDao;
public List<Map<String, Object>> getCommentList(String token, String projectId, String columns) throws SecurityException, QueryException {
public List<Map<String, Object>> getCommentList(String token, String projectId, String columns, String elementId, String elementType)
throws SecurityException, QueryException {
AuthenticationToken authenticationToken = userService.getToken(token);
Model model = modelService.getLastModelByProjectId(projectId, authenticationToken);
if (model == null) {
......@@ -63,7 +64,24 @@ public class CommentRestImpl {
List<Comment> comments = commentService.getCommentsByProject(project, authenticationToken);
for (Comment comment : comments) {
result.add(preparedComment(comment, columnsSet, isAdmin));
boolean reject = false;
if (!"".equals(elementType)) {
if (elementType.equals(ElementIdentifierType.POINT.getJsName())) {
reject = comment.getTableName() != null;
} else if (elementType.equals(ElementIdentifierType.REACTION.getJsName())) {
reject = comment.getTableName() == null || !comment.getTableName().getName().contains("Reaction");
} else if (elementType.equals(ElementIdentifierType.ALIAS.getJsName())) {
reject = comment.getTableName() == null || comment.getTableName().getName().contains("Reaction");
} else {
throw new QueryException("Unknown element type: " + elementType);
}
}
if (!"".equals(elementId)) {
reject |= (!elementId.equals(getId(comment)));
}
if (!reject) {
result.add(preparedComment(comment, columnsSet, isAdmin));
}
}
return result;
......
......@@ -32,7 +32,7 @@ public class CommentRestImplTest extends RestTestFunctions {
@Test
public void testGetForNonExisting() throws Exception {
try {
commentRestImpl.getCommentList(token.getId(), "unk", "");
commentRestImpl.getCommentList(token.getId(), "unk", "","","");
fail("Exception expected");
} catch (QueryException e2) {
assertTrue(e2.getMessage().contains("Project with given id doesn't exist"));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment