From dceb31d4f3908a8253d9247bd4fae2c916a87287 Mon Sep 17 00:00:00 2001
From: Daniel Gerhardt <code@dgerhardt.net>
Date: Tue, 12 Jun 2018 14:23:20 +0200
Subject: [PATCH] Make use of prepare methods for CommentServiceImpl

This enables the manipulation of Comments (creatorId) before creation
for API v3.

Closes !80.
---
 .../thm/arsnova/controller/v2/CommentController.java  |  6 +-----
 .../java/de/thm/arsnova/services/CommentService.java  |  2 --
 .../de/thm/arsnova/services/CommentServiceImpl.java   | 11 ++---------
 3 files changed, 3 insertions(+), 16 deletions(-)

diff --git a/src/main/java/de/thm/arsnova/controller/v2/CommentController.java b/src/main/java/de/thm/arsnova/controller/v2/CommentController.java
index 29e21a494..0f9f6e12f 100644
--- a/src/main/java/de/thm/arsnova/controller/v2/CommentController.java
+++ b/src/main/java/de/thm/arsnova/controller/v2/CommentController.java
@@ -120,11 +120,7 @@ public class CommentController extends PaginationController {
 		de.thm.arsnova.entities.Comment commentV3 = fromV2Migrator.migrate(comment);
 		Room roomV3 = roomService.getByShortId(roomShortId);
 		commentV3.setRoomId(roomV3.getId());
-		if (commentService.save(commentV3)) {
-			return;
-		}
-
-		throw new BadRequestException();
+		commentService.create(commentV3);
 	}
 
 	@ApiOperation(value = "Deletes a Comment",
diff --git a/src/main/java/de/thm/arsnova/services/CommentService.java b/src/main/java/de/thm/arsnova/services/CommentService.java
index 0720538f6..021499325 100644
--- a/src/main/java/de/thm/arsnova/services/CommentService.java
+++ b/src/main/java/de/thm/arsnova/services/CommentService.java
@@ -7,8 +7,6 @@ import java.io.IOException;
 import java.util.List;
 
 public interface CommentService extends EntityService<Comment> {
-	boolean save(Comment comment);
-
 	int count(String roomId);
 
 	CommentReadingCount countRead(String roomId, String username);
diff --git a/src/main/java/de/thm/arsnova/services/CommentServiceImpl.java b/src/main/java/de/thm/arsnova/services/CommentServiceImpl.java
index 3ca7b5aec..e48c84852 100644
--- a/src/main/java/de/thm/arsnova/services/CommentServiceImpl.java
+++ b/src/main/java/de/thm/arsnova/services/CommentServiceImpl.java
@@ -55,7 +55,7 @@ public class CommentServiceImpl extends DefaultEntityServiceImpl<Comment> implem
 
 	@Override
 	@PreAuthorize("isAuthenticated()")
-	public boolean save(final Comment comment) {
+	public void prepareCreate(final Comment comment) {
 		final Room room = roomRepository.findOne(comment.getRoomId());
 		final ClientAuthentication user = userService.getCurrentUser();
 		comment.setCreatorId(user.getId());
@@ -63,14 +63,7 @@ public class CommentServiceImpl extends DefaultEntityServiceImpl<Comment> implem
 		if (comment.getTimestamp() == null) {
 			comment.setTimestamp(new Date());
 		}
-		final Comment result = super.create(comment);
-
-		if (null != result) {
-			final NewCommentEvent event = new NewCommentEvent(this, room, result);
-			this.publisher.publishEvent(event);
-			return true;
-		}
-		return false;
+		/* TODO: fire event */
 	}
 
 	@Override
-- 
GitLab