diff --git a/src/main/java/de/thm/arsnova/controller/CommentController.java b/src/main/java/de/thm/arsnova/controller/CommentController.java index b074df1c41c6d857858138165720f6345eb6596e..33e0d2e94ce880b1164bfdf1f2a9277bbeaaaf2c 100644 --- a/src/main/java/de/thm/arsnova/controller/CommentController.java +++ b/src/main/java/de/thm/arsnova/controller/CommentController.java @@ -17,8 +17,8 @@ */ package de.thm.arsnova.controller; -import de.thm.arsnova.entities.Comment; -import de.thm.arsnova.entities.CommentReadingCount; +import de.thm.arsnova.entities.migration.v2.Comment; +import de.thm.arsnova.entities.migration.v2.CommentReadingCount; import de.thm.arsnova.exceptions.BadRequestException; import de.thm.arsnova.services.CommentService; import de.thm.arsnova.web.DeprecatedApi; @@ -93,7 +93,7 @@ public class CommentController extends PaginationController { @ResponseStatus(HttpStatus.CREATED) public void postInterposedQuestion( @ApiParam(value = "Session-Key from current session", required = true) @RequestParam final String sessionkey, - @ApiParam(value = "the body from the new comment", required = true) @RequestBody final de.thm.arsnova.entities.Comment comment + @ApiParam(value = "the body from the new comment", required = true) @RequestBody final Comment comment ) { if (commentService.save(comment)) { return; diff --git a/src/main/java/de/thm/arsnova/entities/Comment.java b/src/main/java/de/thm/arsnova/entities/Comment.java index 4d69e84cd5d8c147f2009ed48b52c2d39d110b1c..4d692bce7749fb4d67f614994db998478f5dbec5 100644 --- a/src/main/java/de/thm/arsnova/entities/Comment.java +++ b/src/main/java/de/thm/arsnova/entities/Comment.java @@ -1,132 +1,99 @@ -/* - * This file is part of ARSnova Backend. - * Copyright (C) 2012-2018 The ARSnova Team and Contributors - * - * ARSnova Backend is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ARSnova Backend is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ package de.thm.arsnova.entities; import com.fasterxml.jackson.annotation.JsonView; import de.thm.arsnova.entities.serialization.View; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -/** - * A question the user is asking the teacher. Also known as comment, feedback or audience question. - */ -@ApiModel(value = "comment", description = "the comment entity") public class Comment implements Entity { private String id; private String rev; - private String subject; - private String text; - /* FIXME sessionId actually is used to hold the sessionKey. - * This really needs to be changed because it leads to a lot - * of confusion. It can not be easily changed without a lot of - * refactoring since the client application depends on the - * current naming */ private String sessionId; + private String creatorId; + private String subject; + private String body; private long timestamp; private boolean read; - private String creator; + @Override @JsonView({View.Persistence.class, View.Public.class}) public String getId() { return id; } + @Override @JsonView({View.Persistence.class, View.Public.class}) public void setId(final String id) { this.id = id; } + @Override + @JsonView({View.Persistence.class, View.Public.class}) + public String getRevision() { + return rev; + } + + @Override @JsonView({View.Persistence.class, View.Public.class}) public void setRevision(final String rev) { this.rev = rev; } @JsonView({View.Persistence.class, View.Public.class}) - public String getRevision() { - return rev; + public String getSessionId() { + return sessionId; } - @ApiModelProperty(required = true, value = "is read") - @JsonView({View.Persistence.class, View.Public.class}) - public boolean isRead() { - return read; + @JsonView(View.Persistence.class) + public void setSessionId(final String sessionId) { + this.sessionId = sessionId; } - @JsonView({View.Persistence.class, View.Public.class}) - public void setRead(boolean read) { - this.read = read; + @JsonView(View.Persistence.class) + public String getCreatorId() { + return creatorId; + } + + @JsonView(View.Persistence.class) + public void setCreatorId(final String creatorId) { + this.creatorId = creatorId; } - @ApiModelProperty(required = true, value = "the subject") @JsonView({View.Persistence.class, View.Public.class}) public String getSubject() { return subject; } @JsonView({View.Persistence.class, View.Public.class}) - public void setSubject(String subject) { + public void setSubject(final String subject) { this.subject = subject; } - @ApiModelProperty(required = true, value = "the Text") @JsonView({View.Persistence.class, View.Public.class}) - public String getText() { - return text; + public String getBody() { + return body; } @JsonView({View.Persistence.class, View.Public.class}) - public void setText(String text) { - this.text = text; - } - - @ApiModelProperty(required = true, value = "ID of the session, the comment is assigned to") - @JsonView(View.Persistence.class) - public String getSessionId() { - return sessionId; + public void setBody(final String body) { + this.body = body; } - @JsonView({View.Persistence.class, View.Public.class}) - public void setSessionId(String sessionId) { - this.sessionId = sessionId; - } - - @ApiModelProperty(required = true, value = "creation date timestamp") @JsonView({View.Persistence.class, View.Public.class}) public long getTimestamp() { return timestamp; } - @JsonView({View.Persistence.class, View.Public.class}) - public void setTimestamp(long timestamp) { - this.timestamp = timestamp; - } - @JsonView(View.Persistence.class) - public String getCreator() { - return creator; + public void setTimestamp(final long timestamp) { + this.timestamp = timestamp; } - @JsonView(View.Persistence.class) - public void setCreator(String creator) { - this.creator = creator; + @JsonView({View.Persistence.class, View.Public.class}) + public boolean isRead() { + return read; } - public boolean isCreator(User user) { - return user.getUsername().equals(creator); + @JsonView({View.Persistence.class, View.Public.class}) + public void setRead(final boolean read) { + this.read = read; } } diff --git a/src/main/java/de/thm/arsnova/entities/migration/V2Migrator.java b/src/main/java/de/thm/arsnova/entities/migration/V2Migrator.java index 93b6aa898a716b8c0f9688576d7eca9090aefb4b..f12beab19a79c4b1a6f1fa127242c3ec64d1aa1a 100644 --- a/src/main/java/de/thm/arsnova/entities/migration/V2Migrator.java +++ b/src/main/java/de/thm/arsnova/entities/migration/V2Migrator.java @@ -7,6 +7,7 @@ import de.thm.arsnova.entities.Entity; import de.thm.arsnova.entities.TextAnswer; import de.thm.arsnova.entities.migration.v2.Answer; import de.thm.arsnova.entities.migration.v2.AnswerOption; +import de.thm.arsnova.entities.migration.v2.Comment; import de.thm.arsnova.entities.migration.v2.Content; import de.thm.arsnova.entities.migration.v2.Session; @@ -103,4 +104,20 @@ public class V2Migrator { return to; } + + public de.thm.arsnova.entities.Comment migrate(final Comment from, final DbUser creator) { + if (!creator.getUsername().equals(from.getCreator())) { + throw new IllegalArgumentException("Username of creator object does not match comment creator."); + } + final de.thm.arsnova.entities.Comment to = new de.thm.arsnova.entities.Comment(); + copyCommonProperties(from, to); + to.setSessionId(from.getSessionId()); + to.setCreatorId(creator.getId()); + to.setSubject(from.getSubject()); + to.setBody(from.getText()); + to.setTimestamp(from.getTimestamp()); + to.setRead(from.isRead()); + + return to; + } } diff --git a/src/main/java/de/thm/arsnova/entities/migration/v2/Comment.java b/src/main/java/de/thm/arsnova/entities/migration/v2/Comment.java new file mode 100644 index 0000000000000000000000000000000000000000..f0ea862d6b376bce8629ff9103668243bd18558b --- /dev/null +++ b/src/main/java/de/thm/arsnova/entities/migration/v2/Comment.java @@ -0,0 +1,134 @@ +/* + * This file is part of ARSnova Backend. + * Copyright (C) 2012-2017 The ARSnova Team + * + * ARSnova Backend is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ARSnova Backend is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +package de.thm.arsnova.entities.migration.v2; + +import com.fasterxml.jackson.annotation.JsonView; +import de.thm.arsnova.entities.Entity; +import de.thm.arsnova.entities.User; +import de.thm.arsnova.entities.serialization.View; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * A question the user is asking the teacher. Also known as comment, feedback or audience question. + */ +@ApiModel(value = "comment", description = "the comment entity") +public class Comment implements Entity { + private String id; + private String rev; + private String subject; + private String text; + /* FIXME sessionId actually is used to hold the sessionKey. + * This really needs to be changed because it leads to a lot + * of confusion. It can not be easily changed without a lot of + * refactoring since the client application depends on the + * current naming */ + private String sessionId; + private long timestamp; + private boolean read; + private String creator; + + @JsonView({View.Persistence.class, View.Public.class}) + public String getId() { + return id; + } + + @JsonView({View.Persistence.class, View.Public.class}) + public void setId(final String id) { + this.id = id; + } + + @JsonView({View.Persistence.class, View.Public.class}) + public void setRevision(final String rev) { + this.rev = rev; + } + + @JsonView({View.Persistence.class, View.Public.class}) + public String getRevision() { + return rev; + } + + @ApiModelProperty(required = true, value = "is read") + @JsonView({View.Persistence.class, View.Public.class}) + public boolean isRead() { + return read; + } + + @JsonView({View.Persistence.class, View.Public.class}) + public void setRead(boolean read) { + this.read = read; + } + + @ApiModelProperty(required = true, value = "the subject") + @JsonView({View.Persistence.class, View.Public.class}) + public String getSubject() { + return subject; + } + + @JsonView({View.Persistence.class, View.Public.class}) + public void setSubject(String subject) { + this.subject = subject; + } + + @ApiModelProperty(required = true, value = "the Text") + @JsonView({View.Persistence.class, View.Public.class}) + public String getText() { + return text; + } + + @JsonView({View.Persistence.class, View.Public.class}) + public void setText(String text) { + this.text = text; + } + + @ApiModelProperty(required = true, value = "ID of the session, the comment is assigned to") + @JsonView(View.Persistence.class) + public String getSessionId() { + return sessionId; + } + + @JsonView({View.Persistence.class, View.Public.class}) + public void setSessionId(String sessionId) { + this.sessionId = sessionId; + } + + @ApiModelProperty(required = true, value = "creation date timestamp") + @JsonView({View.Persistence.class, View.Public.class}) + public long getTimestamp() { + return timestamp; + } + + @JsonView({View.Persistence.class, View.Public.class}) + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + @JsonView(View.Persistence.class) + public String getCreator() { + return creator; + } + + @JsonView(View.Persistence.class) + public void setCreator(String creator) { + this.creator = creator; + } + + public boolean isCreator(User user) { + return user.getUsername().equals(creator); + } +} diff --git a/src/main/java/de/thm/arsnova/entities/CommentReadingCount.java b/src/main/java/de/thm/arsnova/entities/migration/v2/CommentReadingCount.java similarity index 97% rename from src/main/java/de/thm/arsnova/entities/CommentReadingCount.java rename to src/main/java/de/thm/arsnova/entities/migration/v2/CommentReadingCount.java index 169b687aa9125292bda66b07949f4e1ecb28f22c..ef6d4daf59d4a36684c510eb36b459348f2a8e30 100644 --- a/src/main/java/de/thm/arsnova/entities/CommentReadingCount.java +++ b/src/main/java/de/thm/arsnova/entities/migration/v2/CommentReadingCount.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package de.thm.arsnova.entities; +package de.thm.arsnova.entities.migration.v2; import com.fasterxml.jackson.annotation.JsonView; import de.thm.arsnova.entities.serialization.View; diff --git a/src/main/java/de/thm/arsnova/entities/serialization/CouchDbTypeFieldConverter.java b/src/main/java/de/thm/arsnova/entities/serialization/CouchDbTypeFieldConverter.java index 69c7ae0f6a9ab891ddeb7306d67f7b9776ad262a..1844741bd7289374783d63058198a57cb7c7da82 100644 --- a/src/main/java/de/thm/arsnova/entities/serialization/CouchDbTypeFieldConverter.java +++ b/src/main/java/de/thm/arsnova/entities/serialization/CouchDbTypeFieldConverter.java @@ -21,7 +21,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.type.TypeFactory; import com.fasterxml.jackson.databind.util.Converter; import de.thm.arsnova.entities.migration.v2.Answer; -import de.thm.arsnova.entities.Comment; +import de.thm.arsnova.entities.migration.v2.Comment; import de.thm.arsnova.entities.DbUser; import de.thm.arsnova.entities.Entity; import de.thm.arsnova.entities.LogEntry; diff --git a/src/main/java/de/thm/arsnova/entities/transport/ImportExportSession.java b/src/main/java/de/thm/arsnova/entities/transport/ImportExportSession.java index 3d4e8cccf704d0108ba1057848c2da5cf574892e..88555f38acba0d1792c671400f10211acc0fad28 100644 --- a/src/main/java/de/thm/arsnova/entities/transport/ImportExportSession.java +++ b/src/main/java/de/thm/arsnova/entities/transport/ImportExportSession.java @@ -19,7 +19,7 @@ package de.thm.arsnova.entities.transport; import com.fasterxml.jackson.annotation.JsonView; import de.thm.arsnova.entities.migration.v2.Answer; -import de.thm.arsnova.entities.Comment; +import de.thm.arsnova.entities.migration.v2.Comment; import de.thm.arsnova.entities.migration.v2.Content; import de.thm.arsnova.entities.Motd; import de.thm.arsnova.entities.migration.v2.Session; diff --git a/src/main/java/de/thm/arsnova/events/DeleteCommentEvent.java b/src/main/java/de/thm/arsnova/events/DeleteCommentEvent.java index 6689ca22695ab6f316add4fda2ea9be4d86ccda7..44a5cb64455650a745d8cdb95404664b8cdcb8ac 100644 --- a/src/main/java/de/thm/arsnova/events/DeleteCommentEvent.java +++ b/src/main/java/de/thm/arsnova/events/DeleteCommentEvent.java @@ -17,7 +17,7 @@ */ package de.thm.arsnova.events; -import de.thm.arsnova.entities.Comment; +import de.thm.arsnova.entities.migration.v2.Comment; import de.thm.arsnova.entities.migration.v2.Session; /** diff --git a/src/main/java/de/thm/arsnova/events/NewCommentEvent.java b/src/main/java/de/thm/arsnova/events/NewCommentEvent.java index 5d5c57ff7fb259d97e8d6dd375ac246a69b3ae0b..345b54c3a0f68122999b1aaf05a85a6f4221dcac 100644 --- a/src/main/java/de/thm/arsnova/events/NewCommentEvent.java +++ b/src/main/java/de/thm/arsnova/events/NewCommentEvent.java @@ -17,7 +17,7 @@ */ package de.thm.arsnova.events; -import de.thm.arsnova.entities.Comment; +import de.thm.arsnova.entities.migration.v2.Comment; import de.thm.arsnova.entities.migration.v2.Session; /** diff --git a/src/main/java/de/thm/arsnova/persistance/CommentRepository.java b/src/main/java/de/thm/arsnova/persistance/CommentRepository.java index 6e97fb98a70399eebca6150a28dad0ac21a5289c..8efb72401582c050da3c1ece09678dfa4986bcca 100644 --- a/src/main/java/de/thm/arsnova/persistance/CommentRepository.java +++ b/src/main/java/de/thm/arsnova/persistance/CommentRepository.java @@ -1,7 +1,7 @@ package de.thm.arsnova.persistance; -import de.thm.arsnova.entities.Comment; -import de.thm.arsnova.entities.CommentReadingCount; +import de.thm.arsnova.entities.migration.v2.Comment; +import de.thm.arsnova.entities.migration.v2.CommentReadingCount; import de.thm.arsnova.entities.User; import org.springframework.data.repository.CrudRepository; diff --git a/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbCommentRepository.java b/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbCommentRepository.java index 6276c44fbed535d262a3080bc229c45a4be69444..f8b878d79d2b3e55e29cc1f24e65902cb6bf35d1 100644 --- a/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbCommentRepository.java +++ b/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbCommentRepository.java @@ -1,8 +1,8 @@ package de.thm.arsnova.persistance.couchdb; import com.fasterxml.jackson.databind.JsonNode; -import de.thm.arsnova.entities.Comment; -import de.thm.arsnova.entities.CommentReadingCount; +import de.thm.arsnova.entities.migration.v2.Comment; +import de.thm.arsnova.entities.migration.v2.CommentReadingCount; import de.thm.arsnova.entities.User; import de.thm.arsnova.persistance.CommentRepository; import de.thm.arsnova.persistance.LogEntryRepository; diff --git a/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbSessionRepository.java b/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbSessionRepository.java index 0d55949d10a8113ec793a56d0a0f8f94a2337f32..678027b2929d6aefa7991d7b045e508f37d7516f 100644 --- a/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbSessionRepository.java +++ b/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbSessionRepository.java @@ -18,7 +18,7 @@ package de.thm.arsnova.persistance.couchdb; import de.thm.arsnova.connector.model.Course; -import de.thm.arsnova.entities.Comment; +import de.thm.arsnova.entities.migration.v2.Comment; import de.thm.arsnova.entities.LoggedIn; import de.thm.arsnova.entities.migration.v2.Session; import de.thm.arsnova.entities.migration.v2.SessionInfo; diff --git a/src/main/java/de/thm/arsnova/security/ApplicationPermissionEvaluator.java b/src/main/java/de/thm/arsnova/security/ApplicationPermissionEvaluator.java index ce58a78030318fa73c5a60f25304fc4d15f4c52b..e6640a2d7ae5a9cbd1cd0212da1f207558e900fa 100644 --- a/src/main/java/de/thm/arsnova/security/ApplicationPermissionEvaluator.java +++ b/src/main/java/de/thm/arsnova/security/ApplicationPermissionEvaluator.java @@ -17,7 +17,7 @@ */ package de.thm.arsnova.security; -import de.thm.arsnova.entities.Comment; +import de.thm.arsnova.entities.migration.v2.Comment; import de.thm.arsnova.entities.migration.v2.Content; import de.thm.arsnova.entities.migration.v2.Session; import de.thm.arsnova.entities.User; diff --git a/src/main/java/de/thm/arsnova/services/CommentService.java b/src/main/java/de/thm/arsnova/services/CommentService.java index 4713dfb8d30fb318cc0bb381a23dbc6db6d68348..1525981ec21e96f4b36c9b1ad3078cc0637a4262 100644 --- a/src/main/java/de/thm/arsnova/services/CommentService.java +++ b/src/main/java/de/thm/arsnova/services/CommentService.java @@ -1,7 +1,7 @@ package de.thm.arsnova.services; -import de.thm.arsnova.entities.Comment; -import de.thm.arsnova.entities.CommentReadingCount; +import de.thm.arsnova.entities.migration.v2.Comment; +import de.thm.arsnova.entities.migration.v2.CommentReadingCount; import de.thm.arsnova.entities.User; import java.util.List; diff --git a/src/main/java/de/thm/arsnova/services/CommentServiceImpl.java b/src/main/java/de/thm/arsnova/services/CommentServiceImpl.java index 4678aff6edafd222851d86e4e7cee1f958b45077..c0fd1fbc0821b49462fec508d874f11fa0b34d39 100644 --- a/src/main/java/de/thm/arsnova/services/CommentServiceImpl.java +++ b/src/main/java/de/thm/arsnova/services/CommentServiceImpl.java @@ -1,7 +1,7 @@ package de.thm.arsnova.services; -import de.thm.arsnova.entities.Comment; -import de.thm.arsnova.entities.CommentReadingCount; +import de.thm.arsnova.entities.migration.v2.Comment; +import de.thm.arsnova.entities.migration.v2.CommentReadingCount; import de.thm.arsnova.entities.migration.v2.Session; import de.thm.arsnova.entities.User; import de.thm.arsnova.events.DeleteCommentEvent; diff --git a/src/main/java/de/thm/arsnova/websocket/ArsnovaSocketioServerImpl.java b/src/main/java/de/thm/arsnova/websocket/ArsnovaSocketioServerImpl.java index a343a7230316b432a797e467ace66d89393c8b1d..00e52aa8f789fc13dbfd2f5cb3614fa020ae4382 100644 --- a/src/main/java/de/thm/arsnova/websocket/ArsnovaSocketioServerImpl.java +++ b/src/main/java/de/thm/arsnova/websocket/ArsnovaSocketioServerImpl.java @@ -28,7 +28,7 @@ import com.corundumstudio.socketio.listener.DataListener; import com.corundumstudio.socketio.listener.DisconnectListener; import com.corundumstudio.socketio.protocol.Packet; import com.corundumstudio.socketio.protocol.PacketType; -import de.thm.arsnova.entities.Comment; +import de.thm.arsnova.entities.migration.v2.Comment; import de.thm.arsnova.entities.ScoreOptions; import de.thm.arsnova.entities.User; import de.thm.arsnova.entities.migration.v2.SessionFeature;