Commit b03b8638 authored by Daniel Gerhardt's avatar Daniel Gerhardt

Refactor method signatures to be be consistent with Spring Data

parent 747f9b62
......@@ -26,22 +26,20 @@ import org.springframework.data.repository.CrudRepository;
import java.util.List;
public interface AnswerRepository extends CrudRepository<Answer, String> {
Answer get(String id);
Answer getMyAnswer(User me, String questionId, int piRound);
List<Answer> getAnswers(String contentId, int piRound);
List<Answer> getAllAnswers(String contentId);
int getAnswerCount(String contentId, int round);
int getTotalAnswerCountByQuestion(String contentId);
int getAbstentionAnswerCount(String contentId);
List<Answer> getFreetextAnswers(String contentId, int start, int limit);
List<Answer> getMyAnswers(User user, String sessionId);
int getTotalAnswerCount(String sessionKey);
int deleteAnswers(String contentId);
Answer saveAnswer(Answer answer, User user, Content content, Session session);
Answer updateAnswer(Answer answer);
void deleteAnswer(String answerId);
int countLectureQuestionAnswers(String sessionId);
int countPreparationQuestionAnswers(String sessionId);
Answer findByQuestionIdUserPiRound(String questionId, User user, int piRound);
List<Answer> findByContentIdPiRound(String contentId, int piRound);
List<Answer> findByContentId(String contentId);
int countByContentIdRound(String contentId, int round);
int countByContentId(String contentId);
List<Answer> findByContentId(String contentId, int start, int limit);
List<Answer> findByUserSessionId(User user, String sessionId);
int countBySessionKey(String sessionKey);
int deleteByContentId(String contentId);
Answer create(Answer answer, User user, Content content, Session session);
void update(Answer answer);
void delete(String answerId);
int countBySessionIdLectureVariant(String sessionId);
int countBySessionIdPreparationVariant(String sessionId);
int deleteAllQuestionsAnswers(String sessionId);
int deleteAllPreparationAnswers(String sessionId);
int deleteAllLectureAnswers(String sessionId);
......
......@@ -8,15 +8,15 @@ import org.springframework.data.repository.CrudRepository;
import java.util.List;
public interface CommentRepository extends CrudRepository<Comment, String> {
int getInterposedCount(String sessionKey);
CommentReadingCount getInterposedReadingCount(String sessionId);
CommentReadingCount getInterposedReadingCount(String sessionId, User user);
List<Comment> getInterposedQuestions(String sessionId, int start, int limit);
List<Comment> getInterposedQuestions(String sessionId, User user, int start, int limit);
Comment getInterposedQuestion(String commentId);
Comment saveQuestion(String sessionId, Comment comment, User user);
int countBySessionKey(String sessionKey);
CommentReadingCount countReadingBySessionId(String sessionId);
CommentReadingCount countReadingBySessionIdAndUser(String sessionId, User user);
List<Comment> findBySessionId(String sessionId, int start, int limit);
List<Comment> findBySessionIdAndUser(String sessionId, User user, int start, int limit);
Comment findOne(String commentId);
Comment save(String sessionId, Comment comment, User user);
void markInterposedQuestionAsRead(Comment comment);
void deleteInterposedQuestion(Comment comment);
int deleteAllInterposedQuestions(String sessionId);
int deleteAllInterposedQuestions(String sessionId, User user);
void delete(Comment comment);
int deleteBySessionId(String sessionId);
int deleteBySessionIdAndUser(String sessionId, User user);
}
......@@ -7,38 +7,37 @@ import org.springframework.data.repository.CrudRepository;
import java.util.List;
public interface ContentRepository extends CrudRepository<Content, String> {
List<Content> getQuestions(Object... keys);
Content getQuestion(String id);
Content saveQuestion(String sessionId, Content content);
List<Content> getSkillQuestionsForUsers(String sessionId);
List<Content> getSkillQuestionsForTeachers(String sessionId);
int getSkillQuestionCount(String sessionId);
List<String> getQuestionIds(String sessionId, User user);
List<Content> findBySessionIdAndVariantAndActive(Object... keys);
Content findOne(String id);
Content save(String sessionId, Content content);
List<Content> findBySessionIdForUsers(String sessionId);
List<Content> findBySessionIdForSpeaker(String sessionId);
int countBySessionId(String sessionId);
List<String> findIdsBySessionId(String sessionId);
int deleteQuestionWithAnswers(String contentId);
int[] deleteAllQuestionsWithAnswers(String sessionId);
List<String> getUnAnsweredQuestionIds(String sessionId, User user);
Content updateQuestion(Content content);
List<Content> getLectureQuestionsForUsers(String sessionId);
List<Content> getLectureQuestionsForTeachers(String sessionId);
List<Content> getFlashcardsForUsers(String sessionId);
List<Content> getFlashcardsForTeachers(String sessionId);
List<Content> getPreparationQuestionsForUsers(String sessionId);
List<Content> getPreparationQuestionsForTeachers(String sessionId);
List<Content> getAllSkillQuestions(String sessionId);
int getLectureQuestionCount(String sessionId);
int getFlashcardCount(String sessionId);
int getPreparationQuestionCount(String sessionId);
List<String> findUnansweredIdsBySessionIdAndUser(String sessionId, User user);
void update(Content content);
List<Content> findBySessionIdOnlyLectureVariantAndActive(String sessionId);
List<Content> findBySessionIdOnlyLectureVariant(String sessionId);
List<Content> findBySessionIdOnlyFlashcardVariantAndActive(String sessionId);
List<Content> findBySessionIdOnlyFlashcardVariant(String sessionId);
List<Content> findBySessionIdOnlyPreparationVariantAndActive(String sessionId);
List<Content> findBySessionIdOnlyPreparationVariant(String sessionId);
List<Content> findBySessionId(String sessionId);
int countLectureVariantBySessionId(String sessionId);
int countFlashcardVariantBySessionId(String sessionId);
int countPreparationVariantBySessionId(String sessionId);
void publishQuestions(String sessionId, boolean publish, List<Content> contents);
List<Content> publishAllQuestions(String sessionId, boolean publish);
List<String> getQuestionIdsBySubject(String sessionId, String questionVariant, String subject);
List<Content> getQuestionsByIds(List<String> ids);
List<String> findIdsBySessionIdAndVariantAndSubject(String sessionId, String questionVariant, String subject);
void resetQuestionsRoundState(String sessionId, List<Content> contents);
void setVotingAdmissions(String sessionId, boolean disableVoting, List<Content> contents);
List<Content> setVotingAdmissionForAllQuestions(String sessionId, boolean disableVoting);
int[] deleteAllLectureQuestionsWithAnswers(String sessionId);
int[] deleteAllFlashcardsWithAnswers(String sessionId);
int[] deleteAllPreparationQuestionsWithAnswers(String sessionId);
List<String> getSubjects(String sessionId, String questionVariant);
List<String> getUnAnsweredLectureQuestionIds(String sessionId, User user);
List<String> getUnAnsweredPreparationQuestionIds(String sessionId, User user);
List<String> findSubjectsBySessionIdAndVariant(String sessionId, String questionVariant);
List<String> findUnansweredIdsBySessionIdAndUserOnlyLectureVariant(String sessionId, User user);
List<String> findUnansweredIdsBySessionIdAndUserOnlyPreparationVariant(String sessionId, User user);
}
......@@ -3,6 +3,6 @@ package de.thm.arsnova.persistance;
import de.thm.arsnova.entities.MotdList;
public interface MotdListRepository {
MotdList getMotdListForUser(String username);
MotdList createOrUpdateMotdList(MotdList motdlist);
MotdList findByUsername(String username);
MotdList save(MotdList motdlist);
}
......@@ -23,13 +23,13 @@ import org.springframework.data.repository.CrudRepository;
import java.util.List;
public interface MotdRepository extends CrudRepository<Motd, String> {
List<Motd> getAdminMotds();
List<Motd> getMotdsForAll();
List<Motd> getMotdsForLoggedIn();
List<Motd> getMotdsForTutors();
List<Motd> getMotdsForStudents();
List<Motd> getMotdsForSession(String sessionkey);
Motd getMotdByKey(String key);
Motd createOrUpdateMotd(Motd motd);
boolean deleteMotd(Motd motd);
List<Motd> findGlobalForAdmin();
List<Motd> findGlobalForAll();
List<Motd> findGlobalForLoggedIn();
List<Motd> findGlobalForTutors();
List<Motd> findForStudents();
List<Motd> findBySessionKey(String sessionkey);
Motd findByKey(String key);
Motd save(Motd motd);
void delete(Motd motd);
}
......@@ -28,10 +28,10 @@ import org.springframework.data.repository.CrudRepository;
import java.util.List;
public interface SessionRepository extends CrudRepository<Session, String> {
Session getSessionFromId(String sessionId);
Session getSessionFromKeyword(String keyword);
Session saveSession(User user, Session session);
Session updateSession(Session session);
Session findOne(String sessionId);
Session findByKeyword(String keyword);
Session save(User user, Session session);
void update(Session session);
/**
* Deletes a session and related data.
......@@ -42,18 +42,18 @@ public interface SessionRepository extends CrudRepository<Session, String> {
Session changeSessionCreator(Session session, String newCreator);
int[] deleteInactiveGuestSessions(long lastActivityBefore);
List<Session> getMySessions(User user, int start, int limit);
List<Session> getSessionsForUsername(String username, int start, int limit);
List<Session> getPublicPoolSessions();
List<Session> getMyPublicPoolSessions(User user);
List<Session> findByUser(User user, int start, int limit);
List<Session> findByUsername(String username, int start, int limit);
List<Session> findAllForPublicPool();
List<Session> findForPublicPoolByUser(User user);
boolean sessionKeyAvailable(String keyword);
Session updateSessionOwnerActivity(Session session);
List<Session> getVisitedSessionsForUsername(String username, int start, int limit);
List<Session> findVisitedByUsername(String username, int start, int limit);
List<SessionInfo> getMySessionsInfo(User user, int start, int limit);
List<SessionInfo> getPublicPoolSessionsInfo();
List<SessionInfo> getMyPublicPoolSessionsInfo(User user);
List<SessionInfo> getMyVisitedSessionsInfo(User currentUser, int start, int limit);
List<Session> getCourseSessions(List<Course> courses);
List<SessionInfo> findInfosForPublicPool();
List<SessionInfo> findInfosForPublicPoolByUser(User user);
List<SessionInfo> findInfoForVisitedByUser(User currentUser, int start, int limit);
List<Session> findSessionsByCourses(List<Course> courses);
SessionInfo importSession(User user, ImportExportSession importSession);
ImportExportSession exportSession(String sessionkey, Boolean withAnswer, Boolean withFeedbackQuestions);
LoggedIn registerAsOnlineUser(User user, Session session);
......
......@@ -89,7 +89,7 @@ public class CouchDbAnswerRepository extends CouchDbCrudRepository<Answer> imple
@CacheEvict("answers")
@Override
public int deleteAnswers(final String contentId) {
public int deleteByContentId(final String contentId) {
try {
final ViewResult result = db.queryView(createQuery("by_questionid")
.key(contentId));
......@@ -119,20 +119,20 @@ public class CouchDbAnswerRepository extends CouchDbCrudRepository<Answer> imple
}
@Override
public Answer getMyAnswer(final User me, final String contentId, final int piRound) {
public Answer findByQuestionIdUserPiRound(final String contentId, final User user, final int piRound) {
final List<Answer> answerList = queryView("by_questionid_user_piround",
ComplexKey.of(contentId, me.getUsername(), piRound));
ComplexKey.of(contentId, user.getUsername(), piRound));
return answerList.isEmpty() ? null : answerList.get(0);
}
@Override
public List<Answer> getAnswers(final String contentId, final int piRound) {
public List<Answer> findByContentIdPiRound(final String contentId, final int piRound) {
final String questionId = contentId;
final ViewResult result = db.queryView(createQuery("by_questionid_piround_text_subject")
.group(true)
.startKey(ComplexKey.of(questionId, piRound))
.endKey(ComplexKey.of(questionId, piRound, ComplexKey.emptyObject())));
final int abstentionCount = getAbstentionAnswerCount(questionId);
final int abstentionCount = countByContentId(questionId);
final List<Answer> answers = new ArrayList<>();
for (final ViewResult.Row d : result) {
......@@ -150,12 +150,12 @@ public class CouchDbAnswerRepository extends CouchDbCrudRepository<Answer> imple
}
@Override
public List<Answer> getAllAnswers(final String contentId) {
public List<Answer> findByContentId(final String contentId) {
final ViewResult result = db.queryView(createQuery("by_questionid_piround_text_subject")
.group(true)
.startKey(ComplexKey.of(contentId))
.endKey(ComplexKey.of(contentId, ComplexKey.emptyObject())));
final int abstentionCount = getAbstentionAnswerCount(contentId);
final int abstentionCount = countByContentId(contentId);
final List<Answer> answers = new ArrayList<>();
for (final ViewResult.Row d : result.getRows()) {
......@@ -176,9 +176,9 @@ public class CouchDbAnswerRepository extends CouchDbCrudRepository<Answer> imple
}
@Override
public int getAbstentionAnswerCount(final String contentId) {
public int countByContentId(final String contentId) {
final ViewResult result = db.queryView(createQuery("by_questionid_piround_text_subject")
//.group(true)
.reduce(true)
.startKey(ComplexKey.of(contentId))
.endKey(ComplexKey.of(contentId, ComplexKey.emptyObject())));
......@@ -186,9 +186,9 @@ public class CouchDbAnswerRepository extends CouchDbCrudRepository<Answer> imple
}
@Override
public int getAnswerCount(final String contentId, final int round) {
public int countByContentIdRound(final String contentId, final int round) {
final ViewResult result = db.queryView(createQuery("by_questionid_piround_text_subject")
//.group(true)
.reduce(true)
.startKey(ComplexKey.of(contentId, round))
.endKey(ComplexKey.of(contentId, round, ComplexKey.emptyObject())));
......@@ -196,17 +196,7 @@ public class CouchDbAnswerRepository extends CouchDbCrudRepository<Answer> imple
}
@Override
public int getTotalAnswerCountByQuestion(final String contentId) {
final ViewResult result = db.queryView(createQuery("by_questionid_piround_text_subject")
//.group(true)
.startKey(ComplexKey.of(contentId))
.endKey(ComplexKey.of(contentId, ComplexKey.emptyObject())));
return result.isEmpty() ? 0 : result.getRows().get(0).getValueAsInt();
}
@Override
public List<Answer> getFreetextAnswers(final String contentId, final int start, final int limit) {
public List<Answer> findByContentId(final String contentId, final int start, final int limit) {
final int qSkip = start > 0 ? start : -1;
final int qLimit = limit > 0 ? limit : -1;
......@@ -223,13 +213,13 @@ public class CouchDbAnswerRepository extends CouchDbCrudRepository<Answer> imple
}
@Override
public List<Answer> getMyAnswers(final User user, final String sessionId) {
public List<Answer> findByUserSessionId(final User user, final String sessionId) {
return queryView("by_user_sessionid", ComplexKey.of(user.getUsername(), sessionId));
}
@Override
public int getTotalAnswerCount(final String sessionKey) {
final Session s = sessionRepository.getSessionFromKeyword(sessionKey);
public int countBySessionKey(final String sessionKey) {
final Session s = sessionRepository.findByKeyword(sessionKey);
if (s == null) {
throw new NotFoundException();
}
......@@ -240,7 +230,7 @@ public class CouchDbAnswerRepository extends CouchDbCrudRepository<Answer> imple
@CacheEvict(value = "answers", key = "#content")
@Override
public Answer saveAnswer(final Answer answer, final User user, final Content content, final Session session) {
public Answer create(final Answer answer, final User user, final Content content, final Session session) {
db.create(answer);
this.answerQueue.offer(new AnswerQueueElement(session, content, answer, user));
......@@ -249,42 +239,40 @@ public class CouchDbAnswerRepository extends CouchDbCrudRepository<Answer> imple
/* TODO: Only evict cache entry for the answer's question. This requires some refactoring. */
@CacheEvict(value = "answers", allEntries = true)
@Override
public Answer updateAnswer(final Answer answer) {
public void update(final Answer answer) {
try {
update(answer);
return answer;
super.update(answer);
} catch (final UpdateConflictException e) {
logger.error("Could not update answer {}.", answer, e);
throw e;
}
return null;
}
/* TODO: Only evict cache entry for the answer's session. This requires some refactoring. */
@CacheEvict(value = "answers", allEntries = true)
@Override
public void deleteAnswer(final String answerId) {
public void delete(final String answerId) {
try {
/* TODO: use id and rev instead of loading the answer */
db.delete(get(answerId));
dbLogger.log("delete", "type", "answer");
} catch (final DbAccessException e) {
logger.error("Could not delete answer {}.", answerId, e);
throw e;
}
}
@Override
public int countLectureQuestionAnswers(final String sessionId) {
return countQuestionVariantAnswers(sessionId, "lecture");
public int countBySessionIdLectureVariant(final String sessionId) {
return countBySessionIdVariant(sessionId, "lecture");
}
@Override
public int countPreparationQuestionAnswers(final String sessionId) {
return countQuestionVariantAnswers(sessionId, "preparation");
public int countBySessionIdPreparationVariant(final String sessionId) {
return countBySessionIdVariant(sessionId, "preparation");
}
private int countQuestionVariantAnswers(final String sessionId, final String variant) {
private int countBySessionIdVariant(final String sessionId, final String variant) {
final ViewResult result = db.queryView(createQuery("by_sessionid_variant")
.key(ComplexKey.of(sessionId, variant)));
......@@ -295,7 +283,7 @@ public class CouchDbAnswerRepository extends CouchDbCrudRepository<Answer> imple
@CacheEvict(value = "answers", allEntries = true)
@Override
public int deleteAllQuestionsAnswers(final String sessionId) {
final List<Content> contents = contentRepository.getQuestions(sessionId);
final List<Content> contents = contentRepository.findBySessionIdAndVariantAndActive(sessionId);
contentRepository.resetQuestionsRoundState(sessionId, contents);
final List<String> contentIds = contents.stream().map(Content::getId).collect(Collectors.toList());
......@@ -306,7 +294,7 @@ public class CouchDbAnswerRepository extends CouchDbCrudRepository<Answer> imple
@CacheEvict(value = "answers", allEntries = true)
@Override
public int deleteAllPreparationAnswers(final String sessionId) {
final List<Content> contents = contentRepository.getQuestions(sessionId, "preparation");
final List<Content> contents = contentRepository.findBySessionIdAndVariantAndActive(sessionId, "preparation");
contentRepository.resetQuestionsRoundState(sessionId, contents);
final List<String> contentIds = contents.stream().map(Content::getId).collect(Collectors.toList());
......@@ -317,7 +305,7 @@ public class CouchDbAnswerRepository extends CouchDbCrudRepository<Answer> imple
@CacheEvict(value = "answers", allEntries = true)
@Override
public int deleteAllLectureAnswers(final String sessionId) {
final List<Content> contents = contentRepository.getQuestions(sessionId, "lecture");
final List<Content> contents = contentRepository.findBySessionIdAndVariantAndActive(sessionId, "lecture");
contentRepository.resetQuestionsRoundState(sessionId, contents);
final List<String> contentIds = contents.stream().map(Content::getId).collect(Collectors.toList());
......
......@@ -11,7 +11,6 @@ import de.thm.arsnova.persistance.LogEntryRepository;
import de.thm.arsnova.persistance.SessionRepository;
import org.ektorp.ComplexKey;
import org.ektorp.CouchDbConnector;
import org.ektorp.DocumentNotFoundException;
import org.ektorp.UpdateConflictException;
import org.ektorp.ViewResult;
import org.slf4j.Logger;
......@@ -34,13 +33,16 @@ public class CouchDbCommentRepository extends CouchDbCrudRepository<Comment> imp
}
@Override
public int getInterposedCount(final String sessionKey) {
final Session s = sessionRepository.getSessionFromKeyword(sessionKey);
public int countBySessionKey(final String sessionKey) {
final Session s = sessionRepository.findByKeyword(sessionKey);
if (s == null) {
throw new NotFoundException();
}
final ViewResult result = db.queryView(createQuery("by_sessionid").key(s.getId()).group(true));
final ViewResult result = db.queryView(createQuery("by_sessionid")
.key(s.getId())
.reduce(true)
.group(true));
if (result.isEmpty()) {
return 0;
}
......@@ -49,24 +51,26 @@ public class CouchDbCommentRepository extends CouchDbCrudRepository<Comment> imp
}
@Override
public CommentReadingCount getInterposedReadingCount(final String sessionId) {
public CommentReadingCount countReadingBySessionId(final String sessionId) {
final ViewResult result = db.queryView(createQuery("by_sessionid_read")
.startKey(ComplexKey.of(sessionId))
.endKey(ComplexKey.of(sessionId, ComplexKey.emptyObject()))
.reduce(true)
.group(true));
return getInterposedReadingCount(result);
return calculateReadingCount(result);
}
@Override
public CommentReadingCount getInterposedReadingCount(final String sessionId, final User user) {
public CommentReadingCount countReadingBySessionIdAndUser(final String sessionId, final User user) {
final ViewResult result = db.queryView(createQuery("by_sessionid_creator_read")
.startKey(ComplexKey.of(sessionId, user.getUsername()))
.endKey(ComplexKey.of(sessionId, user.getUsername(), ComplexKey.emptyObject()))
.reduce(true)
.group(true));
return getInterposedReadingCount(result);
return calculateReadingCount(result);
}
private CommentReadingCount getInterposedReadingCount(final ViewResult viewResult) {
private CommentReadingCount calculateReadingCount(final ViewResult viewResult) {
if (viewResult.isEmpty()) {
return new CommentReadingCount();
}
......@@ -110,7 +114,7 @@ public class CouchDbCommentRepository extends CouchDbCrudRepository<Comment> imp
}
@Override
public List<Comment> getInterposedQuestions(final String sessionId, final int start, final int limit) {
public List<Comment> findBySessionId(final String sessionId, final int start, final int limit) {
final int qSkip = start > 0 ? start : -1;
final int qLimit = limit > 0 ? limit : -1;
......@@ -130,7 +134,7 @@ public class CouchDbCommentRepository extends CouchDbCrudRepository<Comment> imp
}
@Override
public List<Comment> getInterposedQuestions(final String sessionId, final User user, final int start, final int limit) {
public List<Comment> findBySessionIdAndUser(final String sessionId, final User user, final int start, final int limit) {
final int qSkip = start > 0 ? start : -1;
final int qLimit = limit > 0 ? limit : -1;
......@@ -149,21 +153,9 @@ public class CouchDbCommentRepository extends CouchDbCrudRepository<Comment> imp
return comments;
}
/* TODO: Move to service layer. */
@Override
public Comment getInterposedQuestion(final String commentId) {
try {
final Comment comment = get(commentId);
/* TODO: Refactor code so the next line can be removed */
//comment.setSessionId(sessionRepository.getSessionFromKeyword(comment.getSessionId()).getId());
return comment;
} catch (final DocumentNotFoundException e) {
logger.error("Could not load comment {}.", commentId, e);
}
return null;
}
@Override
public Comment saveQuestion(final String sessionId, final Comment comment, final User user) {
public Comment save(final String sessionId, final Comment comment, final User user) {
/* TODO: This should be done on the service level. */
comment.setSessionId(sessionId);
comment.setCreator(user.getUsername());
......@@ -182,6 +174,7 @@ public class CouchDbCommentRepository extends CouchDbCrudRepository<Comment> imp
return null;
}
/* TODO: Move to service layer. */
@Override
public void markInterposedQuestionAsRead(final Comment comment) {
try {
......@@ -193,7 +186,7 @@ public class CouchDbCommentRepository extends CouchDbCrudRepository<Comment> imp
}
@Override
public void deleteInterposedQuestion(final Comment comment) {
public void delete(final Comment comment) {
try {
db.delete(comment.getId(), comment.getRevision());
dbLogger.log("delete", "type", "comment");
......@@ -203,22 +196,22 @@ public class CouchDbCommentRepository extends CouchDbCrudRepository<Comment> imp
}
@Override
public int deleteAllInterposedQuestions(final String sessionId) {
public int deleteBySessionId(final String sessionId) {
final ViewResult result = db.queryView(createQuery("by_sessionid").key(sessionId));
return deleteAllInterposedQuestions(sessionId, result);
return delete(result);
}
@Override
public int deleteAllInterposedQuestions(final String sessionId, final User user) {
public int deleteBySessionIdAndUser(final String sessionId, final User user) {
final ViewResult result = db.queryView(createQuery("by_sessionid_creator_read")
.startKey(ComplexKey.of(sessionId, user.getUsername()))
.endKey(ComplexKey.of(sessionId, user.getUsername(), ComplexKey.emptyObject())));
return deleteAllInterposedQuestions(sessionId, result);
return delete(result);
}
private int deleteAllInterposedQuestions(final String sessionId, final ViewResult comments) {
private int delete(final ViewResult comments) {
if (comments.isEmpty()) {
return 0;
}
......@@ -227,7 +220,7 @@ public class CouchDbCommentRepository extends CouchDbCrudRepository<Comment> imp
try {
db.delete(row.getId(), row.getValueAsNode().get("rev").asText());
} catch (final UpdateConflictException e) {
logger.error("Could not delete all comments {}.", sessionId, e);
logger.error("Could not delete comments.", e);
}
}
......
......@@ -21,14 +21,15 @@ public class CouchDbMotdListRepository extends CouchDbRepositorySupport<MotdList
@Override
@Cacheable(cacheNames = "motdlist", key = "#p0")
public MotdList getMotdListForUser(final String username) {
public MotdList findByUsername(final String username) {
final List<MotdList> motdListList = queryView("by_username", username);
return motdListList.isEmpty() ? new MotdList() : motdListList.get(0);
}
/* TODO: Move to service layer. */
@Override
@CachePut(cacheNames = "motdlist", key = "#p0.username")
public MotdList createOrUpdateMotdList(final MotdList motdlist) {
public MotdList save(final MotdList motdlist) {
try {
if (motdlist.getId() != null) {
update(motdlist);
......
......@@ -41,54 +41,54 @@ public class CouchDbMotdRepository extends CouchDbCrudRepository<Motd> implement
}
@Override
public List<Motd> getAdminMotds() {
return getMotds("by_audience_for_global", null);
public List<Motd> findGlobalForAdmin() {
return find("by_audience_for_global", null);
}
@Override
@Cacheable(cacheNames = "motds", key = "'all'")
public List<Motd> getMotdsForAll() {
return getMotds("by_audience_for_global", "all");
public List<Motd> findGlobalForAll() {
return find("by_audience_for_global", "all");
}
@Override
@Cacheable(cacheNames = "motds", key = "'loggedIn'")
public List<Motd> getMotdsForLoggedIn() {
return getMotds("by_audience_for_global", "loggedIn");
public List<Motd> findGlobalForLoggedIn() {
return find("by_audience_for_global", "loggedIn");
}
@Override
@Cacheable(cacheNames = "motds", key = "'tutors'")
public List<Motd> getMotdsForTutors() {
public List<Motd> findGlobalForTutors() {
final List<Motd> union = new ArrayList<>();
union.addAll(getMotds("by_audience_for_global", "loggedIn"));
union.addAll(getMotds("by_audience_for_global", "tutors"));
union.addAll(find("by_audience_for_global", "loggedIn"));
union.addAll(find("by_audience_for_global", "tutors"));
return union;
}
@Override
@Cacheable(cacheNames = "motds", key = "'students'")
public List<Motd> getMotdsForStudents() {
public List<Motd> findForStudents() {
final List<Motd> union = new ArrayList<>();
union.addAll(getMotds("by_audience_for_global", "loggedIn"));
union.addAll(getMotds("by_audience_for_global", "students"));
union.addAll(find("by_audience_for_global", "loggedIn"));
union.addAll(find("by_audience_for_global", "students"));
return union;
}
@Override
@Cacheable(cacheNames = "motds", key = "('session').concat(#p0)")
public List<Motd> getMotdsForSession(final String sessionkey) {
return getMotds("by_sessionkey", sessionkey);
public List<Motd> findBySessionKey(final String sessionkey) {
return find("by_sessionkey", sessionkey);
}
private List<Motd> getMotds(final String viewName, final String key) {
private List<Motd> find(final String viewName, final String key) {
return queryView(viewName, key);
}
@Override
public Motd getMotdByKey(final String key) {
public Motd findByKey(final String key) {
final List<Motd> motd = queryView("by_motdkey", key);
return motd.get(0);
......@@ -96,7 +96,7 @@ public class CouchDbMotdRepository extends CouchDbCrudRepository<Motd> implement
@Override
@CacheEvict(cacheNames = "motds", key = "#p0.audience.concat(#p0.sessionkey)")
public Motd createOrUpdateMotd(final Motd motd) {
public Motd save(final Motd motd) {
final String id = motd.getId();
final String rev = motd.getRevision();
......@@ -112,9 +112,10 @@ public class CouchDbMotdRepository extends CouchDbCrudRepository<Motd> implement
return motd;
}
/* TODO: Redundant -> remove. Move cache handling to service layer. */