diff --git a/src/main/java/de/thm/arsnova/controller/CommentController.java b/src/main/java/de/thm/arsnova/controller/CommentController.java index 656e54b69a4d5fb2d9b268093e6b60b820de6de1..428a6172b0e84c9b78b25e6ae1b9f79d019ea949 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.transport.Comment; import de.thm.arsnova.exceptions.BadRequestException; import de.thm.arsnova.services.CommentService; import de.thm.arsnova.web.DeprecatedApi; @@ -74,14 +74,14 @@ public class CommentController extends PaginationController { @RequestMapping(value = "/", method = RequestMethod.GET) @Pagination public List<Comment> getInterposedQuestions(@ApiParam(value = "Session-Key from current session", required = true) @RequestParam final String sessionkey) { - return Comment.fromList(commentService.getBySessionKey(sessionkey, offset, limit)); + return commentService.getBySessionKey(sessionkey, offset, limit); } @ApiOperation(value = "Retrieves an Comment", nickname = "getInterposedQuestion") @RequestMapping(value = "/{questionId}", method = RequestMethod.GET) public Comment getInterposedQuestion(@ApiParam(value = "ID of the Comment that needs to be deleted", required = true) @PathVariable final String questionId) { - return new Comment(commentService.getAndMarkRead(questionId)); + return commentService.getAndMarkRead(questionId); } @ApiOperation(value = "Creates a new Comment for a Session and returns the Comment's data", diff --git a/src/main/java/de/thm/arsnova/controller/ContentController.java b/src/main/java/de/thm/arsnova/controller/ContentController.java index 166c579b4bea12e52974a929f47b344ea45a2d4a..a0b323ad3723f946a95f80c2fb115c469c96fc70 100644 --- a/src/main/java/de/thm/arsnova/controller/ContentController.java +++ b/src/main/java/de/thm/arsnova/controller/ContentController.java @@ -458,7 +458,7 @@ public class ContentController extends PaginationController { @RequestMapping(value = "/{questionId}/answer/", method = RequestMethod.POST) public Answer saveAnswer( @PathVariable final String questionId, - @RequestBody final de.thm.arsnova.entities.transport.Answer answer, + @RequestBody final Answer answer, final HttpServletResponse response ) { return contentService.saveAnswer(questionId, answer); diff --git a/src/main/java/de/thm/arsnova/entities/transport/Answer.java b/src/main/java/de/thm/arsnova/entities/transport/Answer.java deleted file mode 100644 index 02e1f2fe4b40524b9f171960635c4ca038ff1d34..0000000000000000000000000000000000000000 --- a/src/main/java/de/thm/arsnova/entities/transport/Answer.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * 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.transport; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonView; -import de.thm.arsnova.entities.Content; -import de.thm.arsnova.entities.User; -import de.thm.arsnova.entities.serialization.View; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; - -import java.io.Serializable; -import java.util.Date; - -/** - * A user's answer to a question. - */ -@JsonInclude(JsonInclude.Include.NON_DEFAULT) -@ApiModel(value = "session/answer", description = "the Answer API") -public class Answer implements Serializable { - - private String answerSubject; - - private String answerSubjectRaw; - - private String answerText; - private String answerTextRaw; - private double freeTextScore; - private boolean successfulFreeTextAnswer; - - private String answerImage; - - private boolean abstention; - - public Answer() { - - } - - public Answer(de.thm.arsnova.entities.Answer a) { - answerSubject = a.getAnswerSubject(); - answerText = a.getAnswerText(); - answerImage = a.getAnswerImage(); - abstention = a.isAbstention(); - successfulFreeTextAnswer = a.isSuccessfulFreeTextAnswer(); - } - - @ApiModelProperty(required = true, value = "used to display text answer") - @JsonView(View.Public.class) - public String getAnswerText() { - return answerText; - } - - public void setAnswerText(String answerText) { - this.answerText = answerText; - } - - @ApiModelProperty(required = true, value = "used to display subject answer") - @JsonView(View.Public.class) - public String getAnswerSubject() { - return answerSubject; - } - - public void setAnswerSubject(String answerSubject) { - this.answerSubject = answerSubject; - } - - @JsonView(View.Public.class) - public final String getAnswerTextRaw() { - return this.answerTextRaw; - } - - public final void setAnswerTextRaw(final String answerTextRaw) { - this.answerTextRaw = answerTextRaw; - } - - @JsonView(View.Public.class) - public final String getAnswerSubjectRaw() { - return this.answerSubjectRaw; - } - - public final void setAnswerSubjectRaw(final String answerSubjectRaw) { - this.answerSubjectRaw = answerSubjectRaw; - } - - @JsonView(View.Public.class) - public final double getFreeTextScore() { - return this.freeTextScore; - } - - public final void setFreeTextScore(final double freeTextScore) { - this.freeTextScore = freeTextScore; - } - - @ApiModelProperty(required = true, value = "successfulFreeTextAnswer") - public final boolean isSuccessfulFreeTextAnswer() { - return this.successfulFreeTextAnswer; - } - - public final void setSuccessfulFreeTextAnswer(final boolean successfulFreeTextAnswer) { - this.successfulFreeTextAnswer = successfulFreeTextAnswer; - } - - @ApiModelProperty(required = true, value = "abstention") - @JsonView(View.Public.class) - public boolean isAbstention() { - return abstention; - } - - public void setAbstention(boolean abstention) { - this.abstention = abstention; - } - - public de.thm.arsnova.entities.Answer generateAnswerEntity(final User user, final Content content) { - // rewrite all fields so that no manipulated data gets written - // only answerText, answerSubject, and abstention are allowed - de.thm.arsnova.entities.Answer theAnswer = new de.thm.arsnova.entities.Answer(); - theAnswer.setAnswerSubject(this.getAnswerSubject()); - theAnswer.setAnswerText(this.getAnswerText()); - theAnswer.setAnswerTextRaw(this.getAnswerTextRaw()); - theAnswer.setSessionId(content.getSessionId()); - theAnswer.setUser(user.getUsername()); - theAnswer.setQuestionId(content.getId()); - theAnswer.setTimestamp(new Date().getTime()); - theAnswer.setQuestionVariant(content.getQuestionVariant()); - theAnswer.setAbstention(this.isAbstention()); - // calculate score value after all properties are set - theAnswer.setQuestionValue(content.calculateValue(theAnswer)); - theAnswer.setAnswerImage(this.getAnswerImage()); - theAnswer.setSuccessfulFreeTextAnswer(this.isSuccessfulFreeTextAnswer()); - - if ("freetext".equals(content.getQuestionType())) { - theAnswer.setPiRound(0); - } else { - theAnswer.setPiRound(content.getPiRound()); - } - - return theAnswer; - } - - @ApiModelProperty(required = true, value = "used to display image answer") - @JsonView(View.Public.class) - public String getAnswerImage() { - return answerImage; - } - - public void setAnswerImage(String answerImage) { - this.answerImage = answerImage; - } -} diff --git a/src/main/java/de/thm/arsnova/entities/transport/Comment.java b/src/main/java/de/thm/arsnova/entities/transport/Comment.java deleted file mode 100644 index e3006b9913bdb7aa80aa5faa074a303a61b64411..0000000000000000000000000000000000000000 --- a/src/main/java/de/thm/arsnova/entities/transport/Comment.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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.transport; - -import com.fasterxml.jackson.annotation.JsonView; -import de.thm.arsnova.entities.serialization.View; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; - -import java.util.ArrayList; -import java.util.List; - -/** - * A question a student is asking. Also known as comment, feedback or audience question. - */ -@ApiModel(value = "audiencequestion/{questionId}", description = "the comment API") -public class Comment { - - private String id; - private String subject; - private String text; - private long timestamp; - private boolean read; - - public static List<Comment> fromList(List<de.thm.arsnova.entities.Comment> comments) { - ArrayList<Comment> transportComments = new ArrayList<>(); - for (de.thm.arsnova.entities.Comment comment : comments) { - transportComments.add(new Comment(comment)); - } - return transportComments; - } - - public Comment(de.thm.arsnova.entities.Comment comment) { - this.id = comment.getId(); - this.subject = comment.getSubject(); - this.text = comment.getText(); - this.timestamp = comment.getTimestamp(); - this.read = comment.isRead(); - } - - public Comment() { } - - @ApiModelProperty(required = true, value = "used to display Id") - @JsonView(View.Public.class) - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - @ApiModelProperty(required = true, value = "used to display Subject") - @JsonView(View.Public.class) - public String getSubject() { - return subject; - } - - public void setSubject(String subject) { - this.subject = subject; - } - - @ApiModelProperty(required = true, value = "used to display Text") - @JsonView(View.Public.class) - public String getText() { - return text; - } - - public void setText(String text) { - this.text = text; - } - - @ApiModelProperty(required = true, value = "used to display Timetamp") - @JsonView(View.Public.class) - public long getTimestamp() { - return timestamp; - } - - public void setTimestamp(long timestamp) { - this.timestamp = timestamp; - } - - @ApiModelProperty(required = true, value = "is read") - @JsonView(View.Public.class) - public boolean isRead() { - return read; - } - - public void setRead(boolean read) { - this.read = read; - } -} 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 1ef60232f0e80f12197be2720cdb27886dfa4191..ee56a2d13e666948e55bbc7f48c7a324316f9b2d 100644 --- a/src/main/java/de/thm/arsnova/entities/transport/ImportExportSession.java +++ b/src/main/java/de/thm/arsnova/entities/transport/ImportExportSession.java @@ -18,6 +18,8 @@ package de.thm.arsnova.entities.transport; import com.fasterxml.jackson.annotation.JsonView; +import de.thm.arsnova.entities.Answer; +import de.thm.arsnova.entities.Comment; import de.thm.arsnova.entities.Content; import de.thm.arsnova.entities.Motd; import de.thm.arsnova.entities.Session; diff --git a/src/main/java/de/thm/arsnova/entities/transport/ScoreOptions.java b/src/main/java/de/thm/arsnova/entities/transport/ScoreOptions.java deleted file mode 100644 index 5bf0b49a82d0cd04c358a40a96a129e1ad602f6e..0000000000000000000000000000000000000000 --- a/src/main/java/de/thm/arsnova/entities/transport/ScoreOptions.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.transport; - -/** - * A session's settings regarding the calculation of the score. - */ -public class ScoreOptions { - - private String sessionKeyword; - - private String type; - - private String questionVariant; - - public String getSessionKeyword() { - return sessionKeyword; - } - - public void setSessionKeyword(String sessionKeyword) { - this.sessionKeyword = sessionKeyword; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getQuestionVariant() { - return questionVariant; - } - - public void setQuestionVariant(String questionVariant) { - this.questionVariant = questionVariant; - } - - public de.thm.arsnova.entities.ScoreOptions toEntity() { - de.thm.arsnova.entities.ScoreOptions entity = new de.thm.arsnova.entities.ScoreOptions(); - entity.setType(this.getType()); - entity.setQuestionVariant(this.getQuestionVariant()); - return entity; - } -} 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 91be570e14f91ebda378abbc4b9e936a4cfe460d..724755064b1cf9f90af963ce8559949956fc6994 100644 --- a/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbSessionRepository.java +++ b/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbSessionRepository.java @@ -18,12 +18,12 @@ package de.thm.arsnova.persistance.couchdb; import de.thm.arsnova.connector.model.Course; +import de.thm.arsnova.entities.Comment; import de.thm.arsnova.entities.LoggedIn; import de.thm.arsnova.entities.Session; import de.thm.arsnova.entities.SessionInfo; import de.thm.arsnova.entities.User; import de.thm.arsnova.entities.VisitedSession; -import de.thm.arsnova.entities.transport.Comment; import de.thm.arsnova.entities.transport.ImportExportSession; import de.thm.arsnova.exceptions.NotFoundException; import de.thm.arsnova.persistance.LogEntryRepository; diff --git a/src/main/java/de/thm/arsnova/services/ContentService.java b/src/main/java/de/thm/arsnova/services/ContentService.java index 0c3f13037ff3a4c60c55c58de912db702a9002a5..6a66cc99935a056d3942c56b854d0ba38aea3402 100644 --- a/src/main/java/de/thm/arsnova/services/ContentService.java +++ b/src/main/java/de/thm/arsnova/services/ContentService.java @@ -78,7 +78,7 @@ public interface ContentService { void deleteAnswers(String questionId); - Answer saveAnswer(String questionId, de.thm.arsnova.entities.transport.Answer answer); + Answer saveAnswer(String questionId, Answer answer); Answer updateAnswer(Answer answer); diff --git a/src/main/java/de/thm/arsnova/services/ContentServiceImpl.java b/src/main/java/de/thm/arsnova/services/ContentServiceImpl.java index becc677eafe97194a17e5a88ef87720096ab9531..8f3c6715b9d2239ee1fca4df1cab8da4e24a7f1a 100644 --- a/src/main/java/de/thm/arsnova/services/ContentServiceImpl.java +++ b/src/main/java/de/thm/arsnova/services/ContentServiceImpl.java @@ -712,7 +712,7 @@ public class ContentServiceImpl extends EntityService<Content> implements Conten @Override @PreAuthorize("isAuthenticated()") @CacheEvict(value = "answers", key = "#contentId") - public Answer saveAnswer(final String contentId, final de.thm.arsnova.entities.transport.Answer answer) { + public Answer saveAnswer(final String contentId, final Answer answer) { final User user = getCurrentUser(); final Content content = get(contentId); if (content == null) { @@ -720,26 +720,32 @@ public class ContentServiceImpl extends EntityService<Content> implements Conten } final Session session = sessionRepository.findOne(content.getSessionId()); - Answer theAnswer = answer.generateAnswerEntity(user, content); - theAnswer.setUser(user.getUsername()); - theAnswer.setQuestionId(content.getId()); - theAnswer.setSessionId(session.getId()); + answer.setUser(user.getUsername()); + answer.setQuestionId(content.getId()); + answer.setSessionId(session.getId()); + answer.setQuestionVariant(content.getQuestionVariant()); + answer.setQuestionValue(content.calculateValue(answer)); + answer.setTimestamp(new Date().getTime()); + if ("freetext".equals(content.getQuestionType())) { - imageUtils.generateThumbnailImage(theAnswer); + answer.setPiRound(0); + imageUtils.generateThumbnailImage(answer); if (content.isFixedAnswer() && content.getText() != null) { - theAnswer.setAnswerTextRaw(theAnswer.getAnswerText()); + answer.setAnswerTextRaw(answer.getAnswerText()); if (content.isStrictMode()) { - content.checkTextStrictOptions(theAnswer); + content.checkTextStrictOptions(answer); } - theAnswer.setQuestionValue(content.evaluateCorrectAnswerFixedText(theAnswer.getAnswerTextRaw())); - theAnswer.setSuccessfulFreeTextAnswer(content.isSuccessfulFreeTextAnswer(theAnswer.getAnswerTextRaw())); + answer.setQuestionValue(content.evaluateCorrectAnswerFixedText(answer.getAnswerTextRaw())); + answer.setSuccessfulFreeTextAnswer(content.isSuccessfulFreeTextAnswer(answer.getAnswerTextRaw())); } + } else { + answer.setPiRound(content.getPiRound()); } - this.answerQueue.offer(new AnswerQueueElement(session, content, theAnswer, user)); + this.answerQueue.offer(new AnswerQueueElement(session, content, answer, user)); - return theAnswer; + return answer; } @Override diff --git a/src/main/java/de/thm/arsnova/websocket/ArsnovaSocketioServerImpl.java b/src/main/java/de/thm/arsnova/websocket/ArsnovaSocketioServerImpl.java index a473408f06f7be33afca0dd20ac2856a2023a2ab..8cb3664e12550816a022ed8d0a4d85c606983542 100644 --- a/src/main/java/de/thm/arsnova/websocket/ArsnovaSocketioServerImpl.java +++ b/src/main/java/de/thm/arsnova/websocket/ArsnovaSocketioServerImpl.java @@ -29,8 +29,8 @@ 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.ScoreOptions; import de.thm.arsnova.entities.User; -import de.thm.arsnova.entities.transport.ScoreOptions; import de.thm.arsnova.events.*; import de.thm.arsnova.exceptions.NoContentException; import de.thm.arsnova.exceptions.NotFoundException; @@ -189,15 +189,16 @@ public class ArsnovaSocketioServerImpl implements ArsnovaSocketioServer, Arsnova } }); + /* TODO: This listener expects a Comment entity but only uses the ID. Reduce transmitted data. */ server.addEventListener( "readInterposedQuestion", - de.thm.arsnova.entities.transport.Comment.class, - new DataListener<de.thm.arsnova.entities.transport.Comment>() { + Comment.class, + new DataListener<Comment>() { @Override @Timed(name = "readInterposedQuestionEvent.onData") public void onData( SocketIOClient client, - de.thm.arsnova.entities.transport.Comment comment, + Comment comment, AckRequest ackRequest) { final User user = userService.getUser2SocketId(client.getSessionId()); try { @@ -228,11 +229,12 @@ public class ArsnovaSocketioServerImpl implements ArsnovaSocketioServer, Arsnova @Timed(name = "setLearningProgressOptionsEvent.onData") public void onData(SocketIOClient client, ScoreOptions scoreOptions, AckRequest ack) { final User user = userService.getUser2SocketId(client.getSessionId()); - final de.thm.arsnova.entities.Session session = sessionService.getInternal(scoreOptions.getSessionKeyword(), user); + final String sessionKey = userService.getSessionByUsername(user.getUsername()); + final de.thm.arsnova.entities.Session session = sessionService.getInternal(sessionKey, user); if (session.isCreator(user)) { - session.setLearningProgressOptions(scoreOptions.toEntity()); + session.setLearningProgressOptions(scoreOptions); sessionService.updateInternal(session, user); - broadcastInSession(session.getKeyword(), "learningProgressOptions", scoreOptions.toEntity()); + broadcastInSession(session.getKeyword(), "learningProgressOptions", scoreOptions); } } });