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

elementType changfed to ElementIdentifierType

parent aa051e2f
......@@ -13,9 +13,16 @@ import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.web.bind.annotation.*;
import lcsb.mapviewer.api.*;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import lcsb.mapviewer.api.BaseController;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.model.security.PrivilegeType;
import lcsb.mapviewer.model.user.User;
......@@ -59,7 +66,7 @@ public class CommentController extends BaseController {
.contains(new SimpleGrantedAuthority(PrivilegeType.READ_PROJECT.name() + ":" + projectId));
List<Map<String, Object>> comments = commentController.getCommentList(
projectId, columns, "", "", removed, modelId);
projectId, columns, "", null, removed, modelId);
if (!isAdmin && !isProjectCurator) {
comments.forEach(comment -> {
comment.remove("author");
......@@ -96,7 +103,7 @@ public class CommentController extends BaseController {
@PathVariable(value = "reactionId") String reactionId,
@RequestParam(value = "removed", defaultValue = "") String removed) throws QueryException {
return commentController.getCommentList(projectId, columns, reactionId,
ElementIdentifierType.REACTION.getJsName(), removed, modelId);
ElementIdentifierType.REACTION, removed, modelId);
}
@PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)")
......@@ -112,7 +119,7 @@ public class CommentController extends BaseController {
@PathVariable(value = "modelId") String modelId,
@RequestParam(value = "removed", defaultValue = "") String removed) throws QueryException {
return commentController.getCommentList(
projectId, columns, elementId, ElementIdentifierType.ALIAS.getJsName(), removed, modelId);
projectId, columns, elementId, ElementIdentifierType.ALIAS, removed, modelId);
}
@PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)")
......@@ -128,7 +135,7 @@ public class CommentController extends BaseController {
@PathVariable(value = "modelId") String modelId,
@RequestParam(value = "removed", defaultValue = "") String removed) throws QueryException {
return commentController.getCommentList(projectId, columns, coordinates,
ElementIdentifierType.POINT.getJsName(), removed, modelId);
ElementIdentifierType.POINT, removed, modelId);
}
@PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)")
......
......@@ -2,7 +2,13 @@ package lcsb.mapviewer.api.projects.comments;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -12,6 +18,7 @@ import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.api.BaseRestImpl;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.common.geometry.PointTransformation;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.Comment;
......@@ -25,7 +32,9 @@ import lcsb.mapviewer.persist.dao.map.ReactionDao;
import lcsb.mapviewer.persist.dao.map.species.ElementDao;
import lcsb.mapviewer.services.ObjectNotFoundException;
import lcsb.mapviewer.services.QueryException;
import lcsb.mapviewer.services.interfaces.*;
import lcsb.mapviewer.services.interfaces.ICommentService;
import lcsb.mapviewer.services.interfaces.IElementService;
import lcsb.mapviewer.services.interfaces.IReactionService;
@Transactional
@Service
......@@ -52,7 +61,7 @@ public class CommentRestImpl extends BaseRestImpl {
public List<Map<String, Object>> getCommentList(
String projectId, String columns, String elementId,
String elementType, String removed, String modelId) throws QueryException {
ElementIdentifierType elementType, String removed, String modelId) throws QueryException {
Project project = getProjectService().getProjectByProjectId(projectId);
if (project == null) {
throw new ObjectNotFoundException("Project with given id doesn't exist");
......@@ -64,15 +73,22 @@ public class CommentRestImpl extends BaseRestImpl {
List<Comment> comments = commentService.getCommentsByModel(project, modelId);
for (Comment comment : comments) {
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 (elementType!=null) {
switch (elementType) {
case POINT: {
reject = comment.getTableName() != null;
break;
}
case REACTION: {
reject = comment.getTableName() == null || !comment.getTableName().getName().contains("Reaction");
break;
}
case ALIAS: {
reject = comment.getTableName() == null || comment.getTableName().getName().contains("Reaction");
break;
}
default:
throw new QueryException("Unknown element type: " + elementType);
}
}
if (!"".equals(elementId)) {
......
......@@ -4,7 +4,6 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import lcsb.mapviewer.api.projects.comments.AllCommentTests;
import lcsb.mapviewer.api.projects.drugs.AllDrugTests;
import lcsb.mapviewer.api.projects.mirnas.AllMiRnaTests;
import lcsb.mapviewer.api.projects.models.AllModelsTests;
......@@ -12,7 +11,6 @@ import lcsb.mapviewer.api.projects.overlays.OverlayRestImplTest;
@RunWith(Suite.class)
@SuiteClasses({
AllCommentTests.class,
AllDrugTests.class,
AllMiRnaTests.class,
AllModelsTests.class,
......
package lcsb.mapviewer.api.projects.comments;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ CommentRestImplTest.class })
public class AllCommentTests {
}
package lcsb.mapviewer.api.projects.comments;
import org.junit.*;
import org.springframework.beans.factory.annotation.Autowired;
import lcsb.mapviewer.api.RestTestFunctions;
import lcsb.mapviewer.services.QueryException;
public class CommentRestImplTest extends RestTestFunctions {
@Autowired
public CommentRestImpl _commentRestImpl;
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test(expected = QueryException.class)
public void testGetForNonExisting() throws Exception {
_commentRestImpl.getCommentList("unk", "", "", "", "", "*");
}
}
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