diff --git a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java index fa2345703d0b483d4c0e5b6d9833c8b6489f86fa..2008b27eb159f94407fca8dae5bdc874291690e6 100644 --- a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java +++ b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java @@ -913,13 +913,16 @@ public class CouchDBDao implements IDatabaseDao { } view.setGroup(true); ViewResults results = this.getDatabase().view(view); + int abstentionCount = this.getAbstentionAnswerCount(questionId); List<Answer> answers = new ArrayList<Answer>(); for (Document d : results.getResults()) { Answer a = new Answer(); a.setAnswerCount(d.getInt("value")); + a.setAbstentionCount(abstentionCount); a.setQuestionId(d.getJSONObject().getJSONArray("key").getString(0)); a.setPiRound(piRound); - a.setAnswerText(d.getJSONObject().getJSONArray("key").getString(2)); + String answerText = d.getJSONObject().getJSONArray("key").getString(2); + a.setAnswerText(answerText == "null" ? null : answerText); answers.add(a); } return answers; @@ -928,6 +931,22 @@ public class CouchDBDao implements IDatabaseDao { } return null; } + + private int getAbstentionAnswerCount(final String questionId) { + try { + View view = new View("skill_question/count_abstention_answers_by_question"); + view.setKey(URLEncoder.encode("\"" + questionId + "\"", "UTF-8")); + view.setGroup(true); + ViewResults results = this.getDatabase().view(view); + if (results.getResults().size() == 0) { + return 0; + } + return results.getJSONArray("rows").optJSONObject(0).optInt("value"); + } catch (UnsupportedEncodingException e) { + LOGGER.error("Error while retrieving abstention answers", e); + } + return 0; + } @Override public final int getAnswerCount(final String questionId) { diff --git a/src/main/java/de/thm/arsnova/entities/Answer.java b/src/main/java/de/thm/arsnova/entities/Answer.java index 5aded99a5762f924b2ae42c370c0bc91520ac1ba..278ac92d50b61363859b23a4133e836993b331a9 100644 --- a/src/main/java/de/thm/arsnova/entities/Answer.java +++ b/src/main/java/de/thm/arsnova/entities/Answer.java @@ -13,7 +13,8 @@ public class Answer { private String user; private long timestamp; private int answerCount = 1; - private boolean abstention; // Currently available only for freetext answers! + private boolean abstention; // Currently available only for freetext and mc answers! + private int abstentionCount; // Currently available only for freetext and mc answers! public Answer() { this.type = "skill_question_answer"; @@ -115,6 +116,14 @@ public class Answer { this.abstention = abstention; } + public int getAbstentionCount() { + return abstentionCount; + } + + public void setAbstentionCount(int abstentionCount) { + this.abstentionCount = abstentionCount; + } + @Override public final String toString() { return "Answer type:'" + type + "'"