Commit 1c30ba89 authored by Daniel Gerhardt's avatar Daniel Gerhardt
Browse files

Refactor repository method signatures and variable names

* Prefer ids over "foreign" domain objects.
* Consistently use final keyword for implementation parameters and
  variables.
* As a consequence, session id is used instead of the object as cache
  key for `skillquestions`, `lecturequestions`, `preparationquestions`
  and`flashcardquestions` caches.
* Rename occurances of `questionId` to `contentId`.
parent db209f2c
...@@ -27,23 +27,22 @@ import java.util.List; ...@@ -27,23 +27,22 @@ import java.util.List;
public interface AnswerRepository { public interface AnswerRepository {
Answer get(String id); Answer get(String id);
Answer getMyAnswer(User me, String questionId, int piRound); Answer getMyAnswer(User me, String questionId, int piRound);
List<Answer> getAnswers(Content content, int piRound); List<Answer> getAnswers(String contentId, int piRound);
List<Answer> getAnswers(Content content); List<Answer> getAllAnswers(String contentId);
List<Answer> getAllAnswers(Content content); int getAnswerCount(String contentId, int round);
int getAnswerCount(Content content, int piRound); int getTotalAnswerCountByQuestion(String contentId);
int getTotalAnswerCountByQuestion(Content content); int getAbstentionAnswerCount(String contentId);
int getAbstentionAnswerCount(String questionId); List<Answer> getFreetextAnswers(String contentId, int start, int limit);
List<Answer> getFreetextAnswers(String questionId, final int start, final int limit); List<Answer> getMyAnswers(User user, String sessionId);
List<Answer> getMyAnswers(User me, Session session);
int getTotalAnswerCount(String sessionKey); int getTotalAnswerCount(String sessionKey);
int deleteAnswers(Content content); int deleteAnswers(String contentId);
Answer saveAnswer(Answer answer, User user, Content content, Session session); Answer saveAnswer(Answer answer, User user, Content content, Session session);
Answer updateAnswer(Answer answer); Answer updateAnswer(Answer answer);
void deleteAnswer(String answerId); void deleteAnswer(String answerId);
int countLectureQuestionAnswers(Session session); int countLectureQuestionAnswers(String sessionId);
int countPreparationQuestionAnswers(Session session); int countPreparationQuestionAnswers(String sessionId);
int deleteAllQuestionsAnswers(Session session); int deleteAllQuestionsAnswers(String sessionId);
int deleteAllPreparationAnswers(Session session); int deleteAllPreparationAnswers(String sessionId);
int deleteAllLectureAnswers(Session session); int deleteAllLectureAnswers(String sessionId);
int[] deleteAllAnswersWithQuestions(List<Content> contents); int[] deleteAllAnswersWithQuestions(List<Content> contents);
} }
...@@ -2,21 +2,20 @@ package de.thm.arsnova.persistance; ...@@ -2,21 +2,20 @@ package de.thm.arsnova.persistance;
import de.thm.arsnova.entities.Comment; import de.thm.arsnova.entities.Comment;
import de.thm.arsnova.entities.CommentReadingCount; import de.thm.arsnova.entities.CommentReadingCount;
import de.thm.arsnova.entities.Session;
import de.thm.arsnova.entities.User; import de.thm.arsnova.entities.User;
import java.util.List; import java.util.List;
public interface CommentRepository { public interface CommentRepository {
int getInterposedCount(String sessionKey); int getInterposedCount(String sessionKey);
CommentReadingCount getInterposedReadingCount(Session session); CommentReadingCount getInterposedReadingCount(String sessionId);
CommentReadingCount getInterposedReadingCount(Session session, User user); CommentReadingCount getInterposedReadingCount(String sessionId, User user);
List<Comment> getInterposedQuestions(Session session, final int start, final int limit); List<Comment> getInterposedQuestions(String sessionId, int start, int limit);
List<Comment> getInterposedQuestions(Session session, User user, final int start, final int limit); List<Comment> getInterposedQuestions(String sessionId, User user, int start, int limit);
Comment getInterposedQuestion(String commentId); Comment getInterposedQuestion(String commentId);
Comment saveQuestion(Session session, Comment comment, User user); Comment saveQuestion(String sessionId, Comment comment, User user);
void markInterposedQuestionAsRead(Comment comment); void markInterposedQuestionAsRead(Comment comment);
void deleteInterposedQuestion(Comment comment); void deleteInterposedQuestion(Comment comment);
int deleteAllInterposedQuestions(Session session); int deleteAllInterposedQuestions(String sessionId);
int deleteAllInterposedQuestions(Session session, User user); int deleteAllInterposedQuestions(String sessionId, User user);
} }
package de.thm.arsnova.persistance; package de.thm.arsnova.persistance;
import de.thm.arsnova.entities.Content; import de.thm.arsnova.entities.Content;
import de.thm.arsnova.entities.Session;
import de.thm.arsnova.entities.User; import de.thm.arsnova.entities.User;
import java.util.List; import java.util.List;
...@@ -9,36 +8,36 @@ import java.util.List; ...@@ -9,36 +8,36 @@ import java.util.List;
public interface ContentRepository { public interface ContentRepository {
List<Content> getQuestions(Object... keys); List<Content> getQuestions(Object... keys);
Content getQuestion(String id); Content getQuestion(String id);
Content saveQuestion(Session session, Content content); Content saveQuestion(String sessionId, Content content);
List<Content> getSkillQuestionsForUsers(Session session); List<Content> getSkillQuestionsForUsers(String sessionId);
List<Content> getSkillQuestionsForTeachers(Session session); List<Content> getSkillQuestionsForTeachers(String sessionId);
int getSkillQuestionCount(Session session); int getSkillQuestionCount(String sessionId);
List<String> getQuestionIds(Session session, User user); List<String> getQuestionIds(String sessionId, User user);
int deleteQuestionWithAnswers(Content content); int deleteQuestionWithAnswers(String contentId);
int[] deleteAllQuestionsWithAnswers(Session session); int[] deleteAllQuestionsWithAnswers(String sessionId);
List<String> getUnAnsweredQuestionIds(Session session, User user); List<String> getUnAnsweredQuestionIds(String sessionId, User user);
Content updateQuestion(Content content); Content updateQuestion(Content content);
List<Content> getLectureQuestionsForUsers(Session session); List<Content> getLectureQuestionsForUsers(String sessionId);
List<Content> getLectureQuestionsForTeachers(Session session); List<Content> getLectureQuestionsForTeachers(String sessionId);
List<Content> getFlashcardsForUsers(Session session); List<Content> getFlashcardsForUsers(String sessionId);
List<Content> getFlashcardsForTeachers(Session session); List<Content> getFlashcardsForTeachers(String sessionId);
List<Content> getPreparationQuestionsForUsers(Session session); List<Content> getPreparationQuestionsForUsers(String sessionId);
List<Content> getPreparationQuestionsForTeachers(Session session); List<Content> getPreparationQuestionsForTeachers(String sessionId);
List<Content> getAllSkillQuestions(Session session); List<Content> getAllSkillQuestions(String sessionId);
int getLectureQuestionCount(Session session); int getLectureQuestionCount(String sessionId);
int getFlashcardCount(Session session); int getFlashcardCount(String sessionId);
int getPreparationQuestionCount(Session session); int getPreparationQuestionCount(String sessionId);
void publishQuestions(Session session, boolean publish, List<Content> contents); void publishQuestions(String sessionId, boolean publish, List<Content> contents);
List<Content> publishAllQuestions(Session session, boolean publish); List<Content> publishAllQuestions(String sessionId, boolean publish);
List<String> getQuestionIdsBySubject(Session session, String questionVariant, String subject); List<String> getQuestionIdsBySubject(String sessionId, String questionVariant, String subject);
List<Content> getQuestionsByIds(List<String> ids, Session session); List<Content> getQuestionsByIds(List<String> ids);
void resetQuestionsRoundState(Session session, List<Content> contents); void resetQuestionsRoundState(String sessionId, List<Content> contents);
void setVotingAdmissions(Session session, boolean disableVoting, List<Content> contents); void setVotingAdmissions(String sessionId, boolean disableVoting, List<Content> contents);
List<Content> setVotingAdmissionForAllQuestions(Session session, boolean disableVoting); List<Content> setVotingAdmissionForAllQuestions(String sessionId, boolean disableVoting);
int[] deleteAllLectureQuestionsWithAnswers(Session session); int[] deleteAllLectureQuestionsWithAnswers(String sessionId);
int[] deleteAllFlashcardsWithAnswers(Session session); int[] deleteAllFlashcardsWithAnswers(String sessionId);
int[] deleteAllPreparationQuestionsWithAnswers(Session session); int[] deleteAllPreparationQuestionsWithAnswers(String sessionId);
List<String> getSubjects(Session session, String questionVariant); List<String> getSubjects(String sessionId, String questionVariant);
List<String> getUnAnsweredLectureQuestionIds(Session session, User user); List<String> getUnAnsweredLectureQuestionIds(String sessionId, User user);
List<String> getUnAnsweredPreparationQuestionIds(Session session, User user); List<String> getUnAnsweredPreparationQuestionIds(String sessionId, User user);
} }
...@@ -41,7 +41,7 @@ public interface LogEntryRepository { ...@@ -41,7 +41,7 @@ public interface LogEntryRepository {
* @param payload arbitrary logging data * @param payload arbitrary logging data
* @param level severity of the event * @param level severity of the event
*/ */
default void log(String event, Map<String, Object> payload, LogEntry.LogLevel level) { default void log(final String event, final Map<String, Object> payload, final LogEntry.LogLevel level) {
create(event, level, payload); create(event, level, payload);
} }
...@@ -53,7 +53,7 @@ public interface LogEntryRepository { ...@@ -53,7 +53,7 @@ public interface LogEntryRepository {
* @param event type of the event * @param event type of the event
* @param payload arbitrary logging data * @param payload arbitrary logging data
*/ */
default void log(String event, Map<String, Object> payload) { default void log(final String event, final Map<String, Object> payload) {
create(event, LogEntry.LogLevel.INFO, payload); create(event, LogEntry.LogLevel.INFO, payload);
} }
...@@ -65,7 +65,7 @@ public interface LogEntryRepository { ...@@ -65,7 +65,7 @@ public interface LogEntryRepository {
* @param level severity of the event * @param level severity of the event
* @param rawPayload key/value pairs of arbitrary logging data * @param rawPayload key/value pairs of arbitrary logging data
*/ */
default void log(String event, LogEntry.LogLevel level, Object... rawPayload) { default void log(final String event, final LogEntry.LogLevel level, final Object... rawPayload) {
if (rawPayload.length % 2 != 0) { if (rawPayload.length % 2 != 0) {
throw new IllegalArgumentException(""); throw new IllegalArgumentException("");
} }
...@@ -84,7 +84,7 @@ public interface LogEntryRepository { ...@@ -84,7 +84,7 @@ public interface LogEntryRepository {
* @param event type of the event * @param event type of the event
* @param rawPayload key/value pairs of arbitrary logging data * @param rawPayload key/value pairs of arbitrary logging data
*/ */
default void log(String event, Object... rawPayload) { default void log(final String event, final Object... rawPayload) {
log(event, LogEntry.LogLevel.INFO, rawPayload); log(event, LogEntry.LogLevel.INFO, rawPayload);
} }
} }
...@@ -3,6 +3,6 @@ package de.thm.arsnova.persistance; ...@@ -3,6 +3,6 @@ package de.thm.arsnova.persistance;
import de.thm.arsnova.entities.MotdList; import de.thm.arsnova.entities.MotdList;
public interface MotdListRepository { public interface MotdListRepository {
MotdList getMotdListForUser(final String username); MotdList getMotdListForUser(String username);
MotdList createOrUpdateMotdList(MotdList motdlist); MotdList createOrUpdateMotdList(MotdList motdlist);
} }
...@@ -27,7 +27,7 @@ public interface MotdRepository { ...@@ -27,7 +27,7 @@ public interface MotdRepository {
List<Motd> getMotdsForLoggedIn(); List<Motd> getMotdsForLoggedIn();
List<Motd> getMotdsForTutors(); List<Motd> getMotdsForTutors();
List<Motd> getMotdsForStudents(); List<Motd> getMotdsForStudents();
List<Motd> getMotdsForSession(final String sessionkey); List<Motd> getMotdsForSession(String sessionkey);
Motd getMotdByKey(String key); Motd getMotdByKey(String key);
Motd createOrUpdateMotd(Motd motd); Motd createOrUpdateMotd(Motd motd);
boolean deleteMotd(Motd motd); boolean deleteMotd(Motd motd);
......
...@@ -41,19 +41,19 @@ public interface SessionRepository { ...@@ -41,19 +41,19 @@ public interface SessionRepository {
Session changeSessionCreator(Session session, String newCreator); Session changeSessionCreator(Session session, String newCreator);
int[] deleteInactiveGuestSessions(long lastActivityBefore); int[] deleteInactiveGuestSessions(long lastActivityBefore);
List<Session> getMySessions(User user, final int start, final int limit); List<Session> getMySessions(User user, int start, int limit);
List<Session> getSessionsForUsername(String username, final int start, final int limit); List<Session> getSessionsForUsername(String username, int start, int limit);
List<Session> getPublicPoolSessions(); List<Session> getPublicPoolSessions();
List<Session> getMyPublicPoolSessions(User user); List<Session> getMyPublicPoolSessions(User user);
boolean sessionKeyAvailable(String keyword); boolean sessionKeyAvailable(String keyword);
Session updateSessionOwnerActivity(Session session); Session updateSessionOwnerActivity(Session session);
List<Session> getVisitedSessionsForUsername(String username, final int start, final int limit); List<Session> getVisitedSessionsForUsername(String username, int start, int limit);
List<SessionInfo> getMySessionsInfo(User user, final int start, final int limit); List<SessionInfo> getMySessionsInfo(User user, int start, int limit);
List<SessionInfo> getPublicPoolSessionsInfo(); List<SessionInfo> getPublicPoolSessionsInfo();
List<SessionInfo> getMyPublicPoolSessionsInfo(final User user); List<SessionInfo> getMyPublicPoolSessionsInfo(User user);
List<SessionInfo> getMyVisitedSessionsInfo(User currentUser, final int start, final int limit); List<SessionInfo> getMyVisitedSessionsInfo(User currentUser, int start, int limit);
List<Session> getCourseSessions(List<Course> courses); List<Session> getCourseSessions(List<Course> courses);
SessionInfo importSession(User user, ImportExportSession importSession); SessionInfo importSession(User user, ImportExportSession importSession);
ImportExportSession exportSession(String sessionkey, Boolean withAnswer, Boolean withFeedbackQuestions); ImportExportSession exportSession(String sessionkey, Boolean withAnswer, Boolean withFeedbackQuestions);
LoggedIn registerAsOnlineUser(final User user, final Session session); LoggedIn registerAsOnlineUser(User user, Session session);
} }
...@@ -25,7 +25,6 @@ import org.slf4j.Logger; ...@@ -25,7 +25,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
...@@ -34,6 +33,7 @@ import java.util.ArrayList; ...@@ -34,6 +33,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Queue; import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.stream.Collectors;
public class CouchDbAnswerRepository extends CouchDbRepositorySupport<Answer> implements AnswerRepository, ApplicationEventPublisherAware { public class CouchDbAnswerRepository extends CouchDbRepositorySupport<Answer> implements AnswerRepository, ApplicationEventPublisherAware {
private static final int BULK_PARTITION_SIZE = 500; private static final int BULK_PARTITION_SIZE = 500;
...@@ -52,7 +52,7 @@ public class CouchDbAnswerRepository extends CouchDbRepositorySupport<Answer> im ...@@ -52,7 +52,7 @@ public class CouchDbAnswerRepository extends CouchDbRepositorySupport<Answer> im
private ApplicationEventPublisher publisher; private ApplicationEventPublisher publisher;
public CouchDbAnswerRepository(CouchDbConnector db, boolean createIfNotExists) { public CouchDbAnswerRepository(final CouchDbConnector db, final boolean createIfNotExists) {
super(Answer.class, db, createIfNotExists); super(Answer.class, db, createIfNotExists);
} }
...@@ -78,32 +78,32 @@ public class CouchDbAnswerRepository extends CouchDbRepositorySupport<Answer> im ...@@ -78,32 +78,32 @@ public class CouchDbAnswerRepository extends CouchDbRepositorySupport<Answer> im
for (AnswerQueueElement e : elements) { for (AnswerQueueElement e : elements) {
this.publisher.publishEvent(new NewAnswerEvent(this, e.getSession(), e.getAnswer(), e.getUser(), e.getQuestion())); this.publisher.publishEvent(new NewAnswerEvent(this, e.getSession(), e.getAnswer(), e.getUser(), e.getQuestion()));
} }
} catch (DbAccessException e) { } catch (final DbAccessException e) {
logger.error("Could not bulk save answers from queue.", e); logger.error("Could not bulk save answers from queue.", e);
} }
} }
@Override @Override
public void setApplicationEventPublisher(ApplicationEventPublisher publisher) { public void setApplicationEventPublisher(final ApplicationEventPublisher publisher) {
this.publisher = publisher; this.publisher = publisher;
} }
@CacheEvict("answers") @CacheEvict("answers")
@Override @Override
public int deleteAnswers(final Content content) { public int deleteAnswers(final String contentId) {
try { try {
final ViewResult result = db.queryView(createQuery("by_questionid") final ViewResult result = db.queryView(createQuery("by_questionid")
.key(content.getId())); .key(contentId));
final List<List<ViewResult.Row>> partitions = Lists.partition(result.getRows(), BULK_PARTITION_SIZE); final List<List<ViewResult.Row>> partitions = Lists.partition(result.getRows(), BULK_PARTITION_SIZE);
int count = 0; int count = 0;
for (List<ViewResult.Row> partition: partitions) { for (final List<ViewResult.Row> partition: partitions) {
List<BulkDeleteDocument> answersToDelete = new ArrayList<>(); final List<BulkDeleteDocument> answersToDelete = new ArrayList<>();
for (final ViewResult.Row a : partition) { for (final ViewResult.Row a : partition) {
final BulkDeleteDocument d = new BulkDeleteDocument(a.getId(), a.getValueAsNode().get("_rev").asText()); final BulkDeleteDocument d = new BulkDeleteDocument(a.getId(), a.getValueAsNode().get("_rev").asText());
answersToDelete.add(d); answersToDelete.add(d);
} }
List<DocumentOperationResult> errors = db.executeBulk(answersToDelete); final List<DocumentOperationResult> errors = db.executeBulk(answersToDelete);
count += partition.size() - errors.size(); count += partition.size() - errors.size();
if (errors.size() > 0) { if (errors.size() > 0) {
logger.error("Could not bulk delete {} of {} answers.", errors.size(), partition.size()); logger.error("Could not bulk delete {} of {} answers.", errors.size(), partition.size());
...@@ -113,29 +113,29 @@ public class CouchDbAnswerRepository extends CouchDbRepositorySupport<Answer> im ...@@ -113,29 +113,29 @@ public class CouchDbAnswerRepository extends CouchDbRepositorySupport<Answer> im
return count; return count;
} catch (final DbAccessException e) { } catch (final DbAccessException e) {
logger.error("Could not delete answers for content {}.", content.getId(), e); logger.error("Could not delete answers for content {}.", contentId, e);
} }
return 0; return 0;
} }
@Override @Override
public Answer getMyAnswer(final User me, final String questionId, final int piRound) { public Answer getMyAnswer(final User me, final String contentId, final int piRound) {
final List<Answer> answerList = queryView("by_questionid_user_piround", final List<Answer> answerList = queryView("by_questionid_user_piround",
ComplexKey.of(questionId, me.getUsername(), piRound)); ComplexKey.of(contentId, me.getUsername(), piRound));
return answerList.isEmpty() ? null : answerList.get(0); return answerList.isEmpty() ? null : answerList.get(0);
} }
@Override @Override
public List<Answer> getAnswers(final Content content, final int piRound) { public List<Answer> getAnswers(final String contentId, final int piRound) {
final String questionId = content.getId(); final String questionId = contentId;
final ViewResult result = db.queryView(createQuery("by_questionid_piround_text_subject") final ViewResult result = db.queryView(createQuery("by_questionid_piround_text_subject")
.group(true) .group(true)
.startKey(ComplexKey.of(questionId, piRound)) .startKey(ComplexKey.of(questionId, piRound))
.endKey(ComplexKey.of(questionId, piRound, ComplexKey.emptyObject()))); .endKey(ComplexKey.of(questionId, piRound, ComplexKey.emptyObject())));
final int abstentionCount = getAbstentionAnswerCount(questionId); final int abstentionCount = getAbstentionAnswerCount(questionId);
List<Answer> answers = new ArrayList<>(); final List<Answer> answers = new ArrayList<>();
for (final ViewResult.Row d : result) { for (final ViewResult.Row d : result) {
final Answer a = new Answer(); final Answer a = new Answer();
a.setAnswerCount(d.getValueAsInt()); a.setAnswerCount(d.getValueAsInt());
...@@ -151,13 +151,12 @@ public class CouchDbAnswerRepository extends CouchDbRepositorySupport<Answer> im ...@@ -151,13 +151,12 @@ public class CouchDbAnswerRepository extends CouchDbRepositorySupport<Answer> im
} }
@Override @Override
public List<Answer> getAllAnswers(final Content content) { public List<Answer> getAllAnswers(final String contentId) {
final String questionId = content.getId();
final ViewResult result = db.queryView(createQuery("by_questionid_piround_text_subject") final ViewResult result = db.queryView(createQuery("by_questionid_piround_text_subject")
.group(true) .group(true)
.startKey(ComplexKey.of(questionId)) .startKey(ComplexKey.of(contentId))
.endKey(ComplexKey.of(questionId, ComplexKey.emptyObject()))); .endKey(ComplexKey.of(contentId, ComplexKey.emptyObject())));
final int abstentionCount = getAbstentionAnswerCount(questionId); final int abstentionCount = getAbstentionAnswerCount(contentId);
final List<Answer> answers = new ArrayList<>(); final List<Answer> answers = new ArrayList<>();
for (final ViewResult.Row d : result.getRows()) { for (final ViewResult.Row d : result.getRows()) {
...@@ -177,44 +176,38 @@ public class CouchDbAnswerRepository extends CouchDbRepositorySupport<Answer> im ...@@ -177,44 +176,38 @@ public class CouchDbAnswerRepository extends CouchDbRepositorySupport<Answer> im
return answers; return answers;
} }
@Cacheable("answers")
@Override
public List<Answer> getAnswers(final Content content) {
return this.getAnswers(content, content.getPiRound());
}
@Override @Override
public int getAbstentionAnswerCount(final String questionId) { public int getAbstentionAnswerCount(final String contentId) {
final ViewResult result = db.queryView(createQuery("by_questionid_piround_text_subject") final ViewResult result = db.queryView(createQuery("by_questionid_piround_text_subject")
//.group(true) //.group(true)
.startKey(ComplexKey.of(questionId)) .startKey(ComplexKey.of(contentId))
.endKey(ComplexKey.of(questionId, ComplexKey.emptyObject()))); .endKey(ComplexKey.of(contentId, ComplexKey.emptyObject())));
return result.isEmpty() ? 0 : result.getRows().get(0).getValueAsInt(); return result.isEmpty() ? 0 : result.getRows().get(0).getValueAsInt();
} }
@Override @Override
public int getAnswerCount(final Content content, final int piRound) { public int getAnswerCount(final String contentId, final int round) {
final ViewResult result = db.queryView(createQuery("by_questionid_piround_text_subject") final ViewResult result = db.queryView(createQuery("by_questionid_piround_text_subject")
//.group(true) //.group(true)
.startKey(ComplexKey.of(content.getId(), piRound)) .startKey(ComplexKey.of(contentId, round))
.endKey(ComplexKey.of(content.getId(), piRound, ComplexKey.emptyObject()))); .endKey(ComplexKey.of(contentId, round, ComplexKey.emptyObject())));
return result.isEmpty() ? 0 : result.getRows().get(0).getValueAsInt(); return result.isEmpty() ? 0 : result.getRows().get(0).getValueAsInt();
} }
@Override @Override
public int getTotalAnswerCountByQuestion(final Content content) { public int getTotalAnswerCountByQuestion(final String contentId) {
final ViewResult result = db.queryView(createQuery("by_questionid_piround_text_subject") final ViewResult result = db.queryView(createQuery("by_questionid_piround_text_subject")
//.group(true) //.group(true)
.startKey(ComplexKey.of(content.getId())) .startKey(ComplexKey.of(contentId))
.endKey(ComplexKey.of(content.getId(), ComplexKey.emptyObject()))); .endKey(ComplexKey.of(contentId, ComplexKey.emptyObject())));
return result.isEmpty() ? 0 : result.getRows().get(0).getValueAsInt(); return result.isEmpty() ? 0 : result.getRows().get(0).getValueAsInt();
} }
@Override @Override
public List<Answer> getFreetextAnswers(final String questionId, final int start, final int limit) { public List<Answer> getFreetextAnswers(final String contentId, final int start, final int limit) {
final int qSkip = start > 0 ? start : -1; final int qSkip = start > 0 ? start : -1;
final int qLimit = limit > 0 ? limit : -1; final int qLimit = limit > 0 ? limit : -1;
...@@ -222,8 +215,8 @@ public class CouchDbAnswerRepository extends CouchDbRepositorySupport<Answer> im ...@@ -222,8 +215,8 @@ public class CouchDbAnswerRepository extends CouchDbRepositorySupport<Answer> im
.skip(qSkip) .skip(qSkip)
.limit(qLimit) .limit(qLimit)
//.includeDocs(true) //.includeDocs(true)
.startKey(ComplexKey.of(questionId)) .startKey(ComplexKey.of(contentId))
.endKey(ComplexKey.of(questionId, ComplexKey.emptyObject())) .endKey(ComplexKey.of(contentId, ComplexKey.emptyObject()))
.descending(true), .descending(true),
Answer.class); Answer.class);
...@@ -231,8 +224,8 @@ public class CouchDbAnswerRepository extends CouchDbRepositorySupport<Answer> im ...@@ -231,8 +224,8 @@ public class CouchDbAnswerRepository extends CouchDbRepositorySupport<Answer> im
} }