Commit 0995fe1a authored by Piotr Gawron's avatar Piotr Gawron
Browse files

comment has owner assigned

parent 681fb6f4
......@@ -17,6 +17,8 @@ import org.springframework.web.bind.annotation.*;
import lcsb.mapviewer.api.*;
import lcsb.mapviewer.model.security.PrivilegeType;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.services.interfaces.IUserService;
@RestController
@RequestMapping(value = "/projects/{projectId}/comments", produces = MediaType.APPLICATION_JSON_VALUE)
......@@ -26,9 +28,12 @@ public class CommentController extends BaseController {
private CommentRestImpl commentController;
private IUserService userService;
@Autowired
public CommentController(CommentRestImpl commentController) {
public CommentController(CommentRestImpl commentController, IUserService userService) {
this.commentController = commentController;
this.userService = userService;
}
@PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)")
......@@ -129,10 +134,12 @@ public class CommentController extends BaseController {
@RequestParam(value = "content") String content,
@RequestParam(value = "pinned", defaultValue = "true") String pinned,
@RequestParam(value = "coordinates") String coordinates,
@PathVariable(value = "modelId") String modelId) throws QueryException {
@PathVariable(value = "modelId") String modelId, Authentication authentication) throws QueryException {
Point2D pointCoordinates = parseCoordinates(coordinates);
User user = userService.getUserByLogin(authentication.getName());
return commentController.addComment(projectId, ElementIdentifierType.ALIAS.getJsName(), elementId, name,
email, content, pinned.toLowerCase().equals("true"), pointCoordinates, modelId);
email, content, pinned.toLowerCase().equals("true"), pointCoordinates, modelId, user);
}
@PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)")
......@@ -145,10 +152,11 @@ public class CommentController extends BaseController {
@RequestParam(value = "content") String content,
@RequestParam(value = "pinned", defaultValue = "true") String pinned,
@RequestParam(value = "coordinates") String coordinates,
@PathVariable(value = "modelId") String modelId) throws QueryException {
@PathVariable(value = "modelId") String modelId, Authentication authentication) throws QueryException {
Point2D pointCoordinates = parseCoordinates(coordinates);
User user = userService.getUserByLogin(authentication.getName());
return commentController.addComment(projectId, ElementIdentifierType.REACTION.getJsName(), reactionId, name,
email, content, pinned.toLowerCase().equals("true"), pointCoordinates, modelId);
email, content, pinned.toLowerCase().equals("true"), pointCoordinates, modelId, user);
}
@PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)")
......@@ -160,10 +168,11 @@ public class CommentController extends BaseController {
@RequestParam(value = "content") String content,
@RequestParam(value = "pinned", defaultValue = "true") String pinned,
@PathVariable(value = "coordinates") String coordinates,
@PathVariable(value = "modelId") String modelId) throws QueryException {
@PathVariable(value = "modelId") String modelId, Authentication authentication) throws QueryException {
Point2D pointCoordinates = parseCoordinates(coordinates);
User user = userService.getUserByLogin(authentication.getName());
return commentController.addComment(projectId, ElementIdentifierType.POINT.getJsName(), coordinates, name,
email, content, pinned.toLowerCase().equals("true"), pointCoordinates, modelId);
email, content, pinned.toLowerCase().equals("true"), pointCoordinates, modelId, user);
}
private Point2D parseCoordinates(String coordinates) throws QueryException {
......
......@@ -18,6 +18,7 @@ import lcsb.mapviewer.model.map.Comment;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.persist.dao.map.ReactionDao;
import lcsb.mapviewer.persist.dao.map.species.ElementDao;
import lcsb.mapviewer.services.interfaces.ICommentService;
......@@ -245,7 +246,7 @@ public class CommentRestImpl extends BaseRestImpl {
}
public Map<String, Object> addComment(String projectId, String elementType, String elementId,
String name, String email, String content, boolean pinned, Point2D pointCoordinates, String submodelId)
String name, String email, String content, boolean pinned, Point2D pointCoordinates, String submodelId, User owner)
throws QueryException {
Model model = getModelService().getLastModelByProjectId(projectId);
if (model == null) {
......@@ -280,7 +281,7 @@ public class CommentRestImpl extends BaseRestImpl {
}
Comment comment = commentService.addComment(name, email, content, pointCoordinates, commentedObject, pinned,
submodel);
submodel, owner);
return preparedComment(comment, createCommentColumnSet(""));
}
......
......@@ -76,7 +76,7 @@ public class CommentService implements ICommentService {
@Override
public Comment addComment(String name, String email, String content, Point2D coordinates, Object object,
boolean pinned, Model submodel) {
boolean pinned, Model submodel, User owner) {
Comment comment = new Comment();
comment.setName(name);
comment.setEmail(email);
......@@ -87,7 +87,7 @@ public class CommentService implements ICommentService {
comment.setTableName(object.getClass());
comment.setTableId(ObjectUtils.getIdOfObject(object));
}
comment.setUser(null);
comment.setUser(owner);
comment.setPinned(pinned);
commentDao.add(comment);
......
......@@ -38,7 +38,7 @@ public interface ICommentService {
* @return comment object created based on the data provided as parameters
*/
Comment addComment(String name, String email, String content, Point2D coordinates, Object object,
boolean pinned, Model submodel);
boolean pinned, Model submodel, User owner);
/**
* This method remove comment. Comment is not removed from the system, only
......
......@@ -64,11 +64,11 @@ public class CommentServiceTest extends ServiceTestFunctions {
@Test
public void testGetAgregatedComments() throws Exception {
commentService.addComment("John Doe", "a@a.pl", "Conteneta 1", new Point2D.Double(0, 1), alias, false, model);
commentService.addComment("John Doe", "a@a.pl", "Contenetb 2", new Point2D.Double(0, 2), alias, false, model);
commentService.addComment("John Doe", "a@a.pl", "Contenetc 3", new Point2D.Double(0, 3), alias2, false, model);
commentService.addComment("John Doe", "a@a.pl", "Contenetc 4", new Point2D.Double(0, 4), null, false, model);
commentService.addComment("John Doe", "a@a.pl", "Contenetc 5", new Point2D.Double(0, 5), null, false, model);
commentService.addComment("John Doe", "a@a.pl", "Conteneta 1", new Point2D.Double(0, 1), alias, false, model, userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
commentService.addComment("John Doe", "a@a.pl", "Contenetb 2", new Point2D.Double(0, 2), alias, false, model, userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
commentService.addComment("John Doe", "a@a.pl", "Contenetc 3", new Point2D.Double(0, 3), alias2, false, model, userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
commentService.addComment("John Doe", "a@a.pl", "Contenetc 4", new Point2D.Double(0, 4), null, false, model, userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
commentService.addComment("John Doe", "a@a.pl", "Contenetc 5", new Point2D.Double(0, 5), null, false, model, userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
CommentService service = new CommentService(null, null, null, null);
service.setCommentDao(commentDao);
List<List<Comment>> comments = service.getAgregatedComments(model, null);
......@@ -89,7 +89,7 @@ public class CommentServiceTest extends ServiceTestFunctions {
@Test
public void testAddComment() throws Exception {
long counter = commentService.getCommentCount();
Comment feedback = commentService.addComment("a", "b", "c", new Point2D.Double(0, 0), null, false, model);
Comment feedback = commentService.addComment("a", "b", "c", new Point2D.Double(0, 0), null, false, model, userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
long counter2 = commentService.getCommentCount();
assertEquals(counter + 1, counter2);
commentDao.delete(feedback);
......@@ -99,7 +99,7 @@ public class CommentServiceTest extends ServiceTestFunctions {
public void testAddCommentForReaction() throws Exception {
long counter = commentService.getCommentCount();
Comment feedback = commentService.addComment("a", "b", "c", new Point2D.Double(0, 0),
model.getReactions().iterator().next(), false, model);
model.getReactions().iterator().next(), false, model, userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
long counter2 = commentService.getCommentCount();
assertEquals(counter + 1, counter2);
commentDao.delete(feedback);
......@@ -109,7 +109,7 @@ public class CommentServiceTest extends ServiceTestFunctions {
public void testAddCommentForAlias() throws Exception {
Element alias = model.getElementByElementId("sa1");
long counter = commentService.getCommentCount();
Comment feedback = commentService.addComment("a", "b", "c", new Point2D.Double(0, 0), alias, false, model);
Comment feedback = commentService.addComment("a", "b", "c", new Point2D.Double(0, 0), alias, false, model, userDao.getUserByLogin(ADMIN_BUILT_IN_LOGIN));
long counter2 = commentService.getCommentCount();
assertEquals(counter + 1, counter2);
commentDao.delete(feedback);
......
......@@ -40,6 +40,8 @@ import lcsb.mapviewer.services.interfaces.IUserService;
@Rollback
public class CommentControllerIntegrationTest extends ControllerIntegrationTest {
Logger logger = LogManager.getLogger();
private static final String TEST_PROJECT = "test_project";
private static final String TEST_USER_PASSWORD = "test_user_pass";
private static final String TEST_USER_LOGIN = "test_user";
......@@ -47,10 +49,10 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
private static final String TEST_CURATOR_LOGIN = "test_curator";
private static final String TEST_ADMIN_PASSWORD = "test_admin";
private static final String TEST_ADMIN_LOGIN = "test_admin";
Logger logger = LogManager.getLogger();
private ModelData map;
private Reaction reaction;
private Element element;
private Project project;
@Autowired
private CommentDao commentDao;
......@@ -63,7 +65,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
@Before
public void setup() {
Project project = createProject(TEST_PROJECT);
project = createProject(TEST_PROJECT);
project.setOwner(userService.getUserByLogin(BUILT_IN_TEST_ADMIN_LOGIN));
map = project.getModels().iterator().next();
reaction = map.getReactions().iterator().next();
......@@ -318,7 +320,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
@Test
public void testRemoveAsOwner() throws Exception {
User user = createCurator(TEST_USER_LOGIN, TEST_USER_PASSWORD);
User user = createUser(TEST_USER_LOGIN, TEST_USER_PASSWORD, project);
MockHttpSession session = createSession(TEST_USER_LOGIN, TEST_USER_PASSWORD);
......@@ -599,7 +601,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
@Test
public void testAddElementCommentAsUserWithAccess() throws Exception {
createUser(TEST_USER_LOGIN, TEST_USER_PASSWORD, map.getProject());
User user = createUser(TEST_USER_LOGIN, TEST_USER_PASSWORD, map.getProject());
MockHttpSession session = createSession(TEST_USER_LOGIN, TEST_USER_PASSWORD);
......@@ -621,6 +623,9 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
.andExpect(status().is2xxSuccessful());
assertEquals(1, commentDao.getCommentByModel(map, null, null).size());
Comment comment = commentDao.getCommentByModel(map, null, null).get(0);
assertEquals("Owner of the comment wasn't set properly", user, comment.getUser());
}
@Test
......
Supports Markdown
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