diff --git a/src/main/java/de/thm/arsnova/persistance/AnswerRepository.java b/src/main/java/de/thm/arsnova/persistance/AnswerRepository.java index 303dfce9462d8a5e129c82f927c6c8c779e54970..be68c003820f67157437be2ae3d282c5c434a968 100644 --- a/src/main/java/de/thm/arsnova/persistance/AnswerRepository.java +++ b/src/main/java/de/thm/arsnova/persistance/AnswerRepository.java @@ -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); diff --git a/src/main/java/de/thm/arsnova/persistance/CommentRepository.java b/src/main/java/de/thm/arsnova/persistance/CommentRepository.java index fb8a4dcd2e77860fae3e05c520ef3c8b4a8f005f..a9e076d8b2cc67c644223ec40435f1505f246efb 100644 --- a/src/main/java/de/thm/arsnova/persistance/CommentRepository.java +++ b/src/main/java/de/thm/arsnova/persistance/CommentRepository.java @@ -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); } diff --git a/src/main/java/de/thm/arsnova/persistance/ContentRepository.java b/src/main/java/de/thm/arsnova/persistance/ContentRepository.java index 3c8d138cd22fac3856b190c6bc1c16b3025198c9..a40526c6b8077d7c1bcab499892672ad43568e61 100644 --- a/src/main/java/de/thm/arsnova/persistance/ContentRepository.java +++ b/src/main/java/de/thm/arsnova/persistance/ContentRepository.java @@ -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); } diff --git a/src/main/java/de/thm/arsnova/persistance/MotdListRepository.java b/src/main/java/de/thm/arsnova/persistance/MotdListRepository.java index fb3d3f131d559a8645f8cb2560ae3adb786dabbe..5b3a460f43216d8e8f70e9ac31160c59d41d3905 100644 --- a/src/main/java/de/thm/arsnova/persistance/MotdListRepository.java +++ b/src/main/java/de/thm/arsnova/persistance/MotdListRepository.java @@ -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); } diff --git a/src/main/java/de/thm/arsnova/persistance/MotdRepository.java b/src/main/java/de/thm/arsnova/persistance/MotdRepository.java index 7b47069d837c10f2ba41214187361f500e5fbd5c..44cdea7a3767cb1efd858e7e631315bec3dd0ae8 100644 --- a/src/main/java/de/thm/arsnova/persistance/MotdRepository.java +++ b/src/main/java/de/thm/arsnova/persistance/MotdRepository.java @@ -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); } diff --git a/src/main/java/de/thm/arsnova/persistance/SessionRepository.java b/src/main/java/de/thm/arsnova/persistance/SessionRepository.java index 9b41a6bcd9b432007fa94d01e5794881d3170079..55597d5c9c7511b897cac8986349af9f03ae8562 100644 --- a/src/main/java/de/thm/arsnova/persistance/SessionRepository.java +++ b/src/main/java/de/thm/arsnova/persistance/SessionRepository.java @@ -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); diff --git a/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbAnswerRepository.java b/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbAnswerRepository.java index 7fae9812173da3de418ac3628d64a7ae8c19ca08..281a230b17f9cbc74101483b45142c84b67f4c2b 100644 --- a/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbAnswerRepository.java +++ b/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbAnswerRepository.java @@ -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()); 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 1d4f333d701ebfc13872cd14de828fd43ec2fb57..f117e4679d576232b4bb278225be0574fd18c487 100644 --- a/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbCommentRepository.java +++ b/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbCommentRepository.java @@ -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); } } diff --git a/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbContentRepository.java b/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbContentRepository.java index e849580ed0baeadfe89a33b4770fac388c7e4c10..f3fd7153792fe786aae7449ea1330fe1f2d6f0ec 100644 --- a/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbContentRepository.java +++ b/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbContentRepository.java @@ -10,7 +10,6 @@ import org.ektorp.CouchDbConnector; import org.ektorp.DbAccessException; import org.ektorp.DocumentNotFoundException; import org.ektorp.UpdateConflictException; -import org.ektorp.ViewQuery; import org.ektorp.ViewResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,11 +42,11 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp @Cacheable("skillquestions") @Override - public List<Content> getSkillQuestionsForUsers(final String sessionId) { + public List<Content> findBySessionIdForUsers(final String sessionId) { final List<Content> contents = new ArrayList<>(); - final List<Content> questions1 = getQuestions(sessionId, "lecture", true); - final List<Content> questions2 = getQuestions(sessionId, "preparation", true); - final List<Content> questions3 = getQuestions(sessionId, "flashcard", true); + final List<Content> questions1 = findBySessionIdAndVariantAndActive(sessionId, "lecture", true); + final List<Content> questions2 = findBySessionIdAndVariantAndActive(sessionId, "preparation", true); + final List<Content> questions3 = findBySessionIdAndVariantAndActive(sessionId, "flashcard", true); contents.addAll(questions1); contents.addAll(questions2); contents.addAll(questions3); @@ -57,12 +56,12 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp @Cacheable("skillquestions") @Override - public List<Content> getSkillQuestionsForTeachers(final String sessionId) { - return getQuestions(new Object[] {sessionId}, sessionId); + public List<Content> findBySessionIdForSpeaker(final String sessionId) { + return findBySessionIdAndVariantAndActive(new Object[] {sessionId}, sessionId); } @Override - public int getSkillQuestionCount(final String sessionId) { + public int countBySessionId(final String sessionId) { final ViewResult result = db.queryView(createQuery("by_sessionid_variant_active") .startKey(ComplexKey.of(sessionId)) .endKey(ComplexKey.of(sessionId, ComplexKey.emptyObject()))); @@ -70,13 +69,14 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp return result.getSize(); } + /* TODO: Move to service layer. */ @Caching(evict = {@CacheEvict(value = "skillquestions", key = "#sessionId"), @CacheEvict(value = "lecturequestions", key = "#sessionId", condition = "#content.getQuestionVariant().equals('lecture')"), @CacheEvict(value = "preparationquestions", key = "#sessionId", condition = "#content.getQuestionVariant().equals('preparation')"), @CacheEvict(value = "flashcardquestions", key = "#sessionId", condition = "#content.getQuestionVariant().equals('flashcard')") }, put = {@CachePut(value = "questions", key = "#content.id")}) @Override - public Content saveQuestion(final String sessionId, final Content content) { + public Content save(final String sessionId, final Content content) { /* TODO: This should be done on the service level. */ content.setSessionId(sessionId); try { @@ -90,6 +90,7 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp return null; } + /* TODO: Move to service layer. */ /* TODO: Only evict cache entry for the content's session. This requires some refactoring. */ @Caching(evict = {@CacheEvict(value = "skillquestions", allEntries = true), @CacheEvict(value = "lecturequestions", allEntries = true, condition = "#content.getQuestionVariant().equals('lecture')"), @@ -97,7 +98,7 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp @CacheEvict(value = "flashcardquestions", allEntries = true, condition = "#content.getQuestionVariant().equals('flashcard')") }, put = {@CachePut(value = "questions", key = "#content.id")}) @Override - public Content updateQuestion(final Content content) { + public void update(final Content content) { try { /* TODO: This should be done on the service level. Make sure that * sessionId is valid before so the content does not need to be retrieved. */ @@ -106,18 +107,15 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp content.setRevision(oldContent.getRevision()); content.updateRoundManagementState(); update(content); - - return content; } catch (final UpdateConflictException e) { logger.error("Could not update content {}.", content, e); } - - return null; } + /* TODO: Move to service layer. */ @Cacheable("questions") @Override - public Content getQuestion(final String id) { + public Content findOne(final String id) { try { final Content content = get(id); content.updateRoundManagementState(); @@ -132,10 +130,11 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp } @Override - public List<String> getQuestionIds(final String sessionId, final User user) { + public List<String> findIdsBySessionId(final String sessionId) { return collectQuestionIds(db.queryView(createQuery("by_sessionid_variant_active").key(sessionId))); } + /* TODO: Move to service layer. */ /* TODO: Only evict cache entry for the content's session. This requires some refactoring. */ @Caching(evict = { @CacheEvict(value = "questions", key = "#content.id"), @CacheEvict(value = "skillquestions", allEntries = true), @@ -145,7 +144,7 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp @Override public int deleteQuestionWithAnswers(final String contentId) { try { - final int count = answerRepository.deleteAnswers(contentId); + final int count = answerRepository.deleteByContentId(contentId); db.delete(contentId); dbLogger.log("delete", "type", "content", "answerCount", count); @@ -157,6 +156,7 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp return 0; } + /* TODO: Move to service layer. */ @Caching(evict = { @CacheEvict(value = "questions", allEntries = true), @CacheEvict(value = "skillquestions", key = "#sessionId"), @CacheEvict(value = "lecturequestions", key = "#sessionId"), @@ -172,6 +172,7 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp return deleteAllQuestionDocumentsWithAnswers(result); } + /* TODO: Move to service layer. */ private int[] deleteAllQuestionDocumentsWithAnswers(final ViewResult viewResult) { List<Content> contents = new ArrayList<>(); for (final ViewResult.Row row : viewResult.getRows()) { @@ -189,7 +190,7 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp } @Override - public List<String> getUnAnsweredQuestionIds(final String sessionId, final User user) { + public List<String> findUnansweredIdsBySessionIdAndUser(final String sessionId, final User user) { final ViewResult result = db.queryView(createQuery("questionid_by_user_sessionid_variant") .designDocId("_design/Answer") .startKey(ComplexKey.of(user.getUsername(), sessionId)) @@ -198,11 +199,11 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp for (final ViewResult.Row row : result.getRows()) { answeredIds.add(row.getId()); } - return collectUnansweredQuestionIds(getQuestionIds(sessionId, user), answeredIds); + return collectUnansweredQuestionIds(findIdsBySessionId(sessionId), answeredIds); } @Override - public List<String> getUnAnsweredLectureQuestionIds(final String sessionId, final User user) { + public List<String> findUnansweredIdsBySessionIdAndUserOnlyLectureVariant(final String sessionId, final User user) { final ViewResult result = db.queryView(createQuery("questionid_piround_by_user_sessionid_variant") .designDocId("_design/Answer") .key(ComplexKey.of(user.getUsername(), sessionId, "lecture"))); @@ -211,11 +212,11 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp answeredQuestions.put(row.getId(), row.getKeyAsNode().get(2).asInt()); } - return collectUnansweredQuestionIdsByPiRound(getLectureQuestionsForUsers(sessionId), answeredQuestions); + return collectUnansweredQuestionIdsByPiRound(findBySessionIdOnlyLectureVariantAndActive(sessionId), answeredQuestions); } @Override - public List<String> getUnAnsweredPreparationQuestionIds(final String sessionId, final User user) { + public List<String> findUnansweredIdsBySessionIdAndUserOnlyPreparationVariant(final String sessionId, final User user) { final ViewResult result = db.queryView(createQuery("questionid_piround_by_user_sessionid_variant") .designDocId("_design/Answer") .key(ComplexKey.of(user.getUsername(), sessionId, "preparation"))); @@ -224,49 +225,49 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp answeredQuestions.put(row.getId(), row.getKeyAsNode().get(2).asInt()); } - return collectUnansweredQuestionIdsByPiRound(getPreparationQuestionsForUsers(sessionId), answeredQuestions); + return collectUnansweredQuestionIdsByPiRound(findBySessionIdOnlyPreparationVariantAndActive(sessionId), answeredQuestions); } @Cacheable("lecturequestions") @Override - public List<Content> getLectureQuestionsForUsers(final String sessionId) { - return getQuestions(sessionId, "lecture", true); + public List<Content> findBySessionIdOnlyLectureVariantAndActive(final String sessionId) { + return findBySessionIdAndVariantAndActive(sessionId, "lecture", true); } @Override - public List<Content> getLectureQuestionsForTeachers(final String sessionId) { - return getQuestions(sessionId, "lecture"); + public List<Content> findBySessionIdOnlyLectureVariant(final String sessionId) { + return findBySessionIdAndVariantAndActive(sessionId, "lecture"); } @Cacheable("flashcardquestions") @Override - public List<Content> getFlashcardsForUsers(final String sessionId) { - return getQuestions(sessionId, "flashcard", true); + public List<Content> findBySessionIdOnlyFlashcardVariantAndActive(final String sessionId) { + return findBySessionIdAndVariantAndActive(sessionId, "flashcard", true); } @Override - public List<Content> getFlashcardsForTeachers(final String sessionId) { - return getQuestions(sessionId, "flashcard"); + public List<Content> findBySessionIdOnlyFlashcardVariant(final String sessionId) { + return findBySessionIdAndVariantAndActive(sessionId, "flashcard"); } @Cacheable("preparationquestions") @Override - public List<Content> getPreparationQuestionsForUsers(final String sessionId) { - return getQuestions(sessionId, "preparation", true); + public List<Content> findBySessionIdOnlyPreparationVariantAndActive(final String sessionId) { + return findBySessionIdAndVariantAndActive(sessionId, "preparation", true); } @Override - public List<Content> getPreparationQuestionsForTeachers(final String sessionId) { - return getQuestions(sessionId, "preparation"); + public List<Content> findBySessionIdOnlyPreparationVariant(final String sessionId) { + return findBySessionIdAndVariantAndActive(sessionId, "preparation"); } @Override - public List<Content> getAllSkillQuestions(final String sessionId) { - return getQuestions(sessionId); + public List<Content> findBySessionId(final String sessionId) { + return findBySessionIdAndVariantAndActive(sessionId); } @Override - public List<Content> getQuestions(final Object... keys) { + public List<Content> findBySessionIdAndVariantAndActive(final Object... keys) { final Object[] endKeys = Arrays.copyOf(keys, keys.length + 1); endKeys[keys.length] = ComplexKey.emptyObject(); final List<Content> contents = db.queryView(createQuery("by_sessionid_variant_active") @@ -284,7 +285,7 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp } @Override - public int getLectureQuestionCount(final String sessionId) { + public int countLectureVariantBySessionId(final String sessionId) { /* TODO: reduce code duplication */ final ViewResult result = db.queryView(createQuery("by_sessionid_variant_active") .startKey(ComplexKey.of(sessionId, "lecture")) @@ -294,7 +295,7 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp } @Override - public int getFlashcardCount(final String sessionId) { + public int countFlashcardVariantBySessionId(final String sessionId) { /* TODO: reduce code duplication */ final ViewResult result = db.queryView(createQuery("by_sessionid_variant_active") .startKey(ComplexKey.of(sessionId, "flashcard")) @@ -304,7 +305,7 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp } @Override - public int getPreparationQuestionCount(final String sessionId) { + public int countPreparationVariantBySessionId(final String sessionId) { /* TODO: reduce code duplication */ final ViewResult result = db.queryView(createQuery("by_sessionid_variant_active") .startKey(ComplexKey.of(sessionId, "preparation")) @@ -313,6 +314,7 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp return result.isEmpty() ? 0 : result.getRows().get(0).getValueAsInt(); } + /* TODO: Move to service layer. */ /* TODO: Only evict cache entry for the answer's question. This requires some refactoring. */ @Caching(evict = { @CacheEvict(value = "questions", allEntries = true), @CacheEvict("skillquestions"), @@ -328,6 +330,7 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp return deleteAllQuestionDocumentsWithAnswers(result); } + /* TODO: Move to service layer. */ /* TODO: Only evict cache entry for the answer's question. This requires some refactoring. */ @Caching(evict = { @CacheEvict(value = "questions", allEntries = true), @CacheEvict("skillquestions"), @@ -343,6 +346,7 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp return deleteAllQuestionDocumentsWithAnswers(result); } + /* TODO: Move to service layer. */ /* TODO: Only evict cache entry for the answer's question. This requires some refactoring. */ @Caching(evict = { @CacheEvict(value = "questions", allEntries = true), @CacheEvict("skillquestions"), @@ -395,6 +399,7 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp return ids; } + /* TODO: Move to service layer. */ @Override public List<Content> publishAllQuestions(final String sessionId, final boolean publish) { final List<Content> contents = db.queryView(createQuery("by_sessionid_variant_active") @@ -407,6 +412,7 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp return contents; } + /* TODO: Move to service layer. */ @Caching(evict = { @CacheEvict(value = "contents", allEntries = true), @CacheEvict(value = "skillquestions", key = "#sessionId"), @CacheEvict(value = "lecturequestions", key = "#sessionId"), @@ -424,6 +430,7 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp } } + /* TODO: Move to service layer. */ @Override public List<Content> setVotingAdmissionForAllQuestions(final String sessionId, final boolean disableVoting) { final List<Content> contents = db.queryView(createQuery("by_sessionid_variant_active") @@ -459,7 +466,7 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp /* TODO: remove if this method is no longer used */ @Override - public List<String> getQuestionIdsBySubject(final String sessionId, final String questionVariant, final String subject) { + public List<String> findIdsBySessionIdAndVariantAndSubject(final String sessionId, final String questionVariant, final String subject) { final ViewResult result = db.queryView(createQuery("by_sessionid_variant_active") .startKey(ComplexKey.of(sessionId, questionVariant, 1, subject)) .endKey(ComplexKey.of(sessionId, questionVariant, 1, subject, ComplexKey.emptyObject()))); @@ -475,12 +482,7 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp } @Override - public List<Content> getQuestionsByIds(final List<String> ids) { - return db.queryView(new ViewQuery().allDocs().keys(ids).includeDocs(true), Content.class); - } - - @Override - public List<String> getSubjects(final String sessionId, final String questionVariant) { + public List<String> findSubjectsBySessionIdAndVariant(final String sessionId, final String questionVariant) { final ViewResult result = db.queryView(createQuery("by_sessionid_variant_active") .startKey(ComplexKey.of(sessionId, questionVariant)) .endKey(ComplexKey.of(sessionId, questionVariant, ComplexKey.emptyObject()))); @@ -494,6 +496,7 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp return new ArrayList<>(uniqueSubjects); } + /* TODO: Move to service layer. */ @Caching(evict = { @CacheEvict(value = "contents", allEntries = true), @CacheEvict(value = "skillquestions", key = "#sessionId"), @CacheEvict(value = "lecturequestions", key = "#sessionId"), diff --git a/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbMotdListRepository.java b/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbMotdListRepository.java index df5800aa9748265ad848ba0fa93b6e5527e060b3..1b7e36990be70b6157d4a45fa522ab319f86cef0 100644 --- a/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbMotdListRepository.java +++ b/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbMotdListRepository.java @@ -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); diff --git a/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbMotdRepository.java b/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbMotdRepository.java index d8478f8386a54dcfef1a67f129c504dce21f8647..38ccd027e99a0e2a50aa86fc4c6735f47998c6b2 100644 --- a/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbMotdRepository.java +++ b/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbMotdRepository.java @@ -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. */ @Override @CacheEvict(cacheNames = "motds", key = "#p0.audience.concat(#p0.sessionkey)") - public boolean deleteMotd(final Motd motd) { - return db.delete(motd) != null; + public void delete(final Motd motd) { + db.delete(motd); } } 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 e451be0e7bc86175ac152234dc853bea8c41ba2c..c4e1a2cdc175e50fade98815f79f685a06542ae9 100644 --- a/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbSessionRepository.java +++ b/src/main/java/de/thm/arsnova/persistance/couchdb/CouchDbSessionRepository.java @@ -72,21 +72,23 @@ public class CouchDbSessionRepository extends CouchDbCrudRepository<Session> imp @Override @Cacheable("sessions") - public Session getSessionFromKeyword(final String keyword) { + public Session findByKeyword(final String keyword) { final List<Session> session = queryView("by_keyword", keyword); return !session.isEmpty() ? session.get(0) : null; } + /* TODO: Redundant -> remove. Move cache handling to service layer. */ @Override @Cacheable("sessions") - public Session getSessionFromId(final String sessionId) { + public Session findOne(final String sessionId) { return get(sessionId); } + /* TODO: Move to service layer. */ @Override @Caching(evict = @CacheEvict(cacheNames = "sessions", key = "#result.keyword")) - public Session saveSession(final User user, final Session session) { + public Session save(final User user, final Session session) { session.setKeyword(sessionService.generateKeyword()); session.setCreator(user.getUsername()); session.setActive(true); @@ -101,11 +103,13 @@ public class CouchDbSessionRepository extends CouchDbCrudRepository<Session> imp return session.getId() != null ? session : null; } + /* TODO: Move to service layer. */ @Override public boolean sessionKeyAvailable(final String keyword) { - return getSessionFromKeyword(keyword) == null; + return findByKeyword(keyword) == null; } + /* TODO: Move to service layer. */ private String getSessionKeyword(final String internalSessionId) throws IOException { final Session session = get(internalSessionId); if (session == null) { @@ -117,6 +121,7 @@ public class CouchDbSessionRepository extends CouchDbCrudRepository<Session> imp return session.getKeyword(); } + /* TODO: Move to service layer. */ @Override @CachePut(value = "sessions") public Session updateSessionOwnerActivity(final Session session) { @@ -137,7 +142,7 @@ public class CouchDbSessionRepository extends CouchDbCrudRepository<Session> imp } @Override - public List<Session> getVisitedSessionsForUsername(final String username, final int start, final int limit) { + public List<Session> findVisitedByUsername(final String username, final int start, final int limit) { final int qSkip = start > 0 ? start : -1; final int qLimit = limit > 0 ? limit : -1; @@ -163,7 +168,7 @@ public class CouchDbSessionRepository extends CouchDbCrudRepository<Session> imp for (final Session s : visitedSessions) { try { /* FIXME: caching (getSessionFromKeyword) */ - final Session session = getSessionFromKeyword(s.getKeyword()); + final Session session = findByKeyword(s.getKeyword()); if (session != null && !(session.getCreator().equals(username))) { result.add(session); } else { @@ -197,8 +202,8 @@ public class CouchDbSessionRepository extends CouchDbCrudRepository<Session> imp } @Override - public List<SessionInfo> getMyVisitedSessionsInfo(final User user, final int start, final int limit) { - final List<Session> sessions = getVisitedSessionsForUsername(user.getUsername(), start, limit); + public List<SessionInfo> findInfoForVisitedByUser(final User user, final int start, final int limit) { + final List<Session> sessions = findVisitedByUsername(user.getUsername(), start, limit); if (sessions.isEmpty()) { return new ArrayList<>(); } @@ -206,25 +211,23 @@ public class CouchDbSessionRepository extends CouchDbCrudRepository<Session> imp } @Override - public List<Session> getCourseSessions(final List<Course> courses) { + public List<Session> findSessionsByCourses(final List<Course> courses) { return queryView("by_courseid", ComplexKey.of(courses.stream().map(Course::getId).collect(Collectors.toList()))); } + /* TODO: Redundant -> remove. Move cache handling to service layer. */ @Override @CachePut(value = "sessions") - public Session updateSession(final Session session) { + public void update(final Session session) { try { update(session); - - return session; } catch (final UpdateConflictException e) { logger.error("Could not update session {}.", session, e); } - - return null; } + /* TODO: Move to service layer. */ @Override @Caching(evict = { @CacheEvict("sessions"), @CacheEvict(cacheNames = "sessions", key = "#p0.keyword") }) public Session changeSessionCreator(final Session session, final String newCreator) { @@ -282,6 +285,7 @@ public class CouchDbSessionRepository extends CouchDbCrudRepository<Session> imp return count; } + /* TODO: Move to service layer. */ @Override public SessionInfo importSession(final User user, final ImportExportSession importSession) { /* FIXME: not yet migrated - move to service layer */ @@ -371,6 +375,7 @@ public class CouchDbSessionRepository extends CouchDbCrudRepository<Session> imp // return this.calculateSessionInfo(importSession, session); } + /* TODO: Move to service layer. */ @Override public ImportExportSession exportSession( final String sessionkey, @@ -417,6 +422,7 @@ public class CouchDbSessionRepository extends CouchDbCrudRepository<Session> imp // return importExportSession; } + /* TODO: Move to service layer. */ private SessionInfo calculateSessionInfo(final ImportExportSession importExportSession, final Session session) { int unreadComments = 0; int numUnanswered = 0; @@ -442,12 +448,12 @@ public class CouchDbSessionRepository extends CouchDbCrudRepository<Session> imp } @Override - public List<Session> getMySessions(final User user, final int start, final int limit) { - return getSessionsForUsername(user.getUsername(), start, limit); + public List<Session> findByUser(final User user, final int start, final int limit) { + return findByUsername(user.getUsername(), start, limit); } @Override - public List<Session> getSessionsForUsername(final String username, final int start, final int limit) { + public List<Session> findByUsername(final String username, final int start, final int limit) { final int qSkip = start > 0 ? start : -1; final int qLimit = limit > 0 ? limit : -1; @@ -463,19 +469,19 @@ public class CouchDbSessionRepository extends CouchDbCrudRepository<Session> imp } @Override - public List<Session> getPublicPoolSessions() { + public List<Session> findAllForPublicPool() { // TODO replace with new view return queryView("partial_by_ppsubject_name_for_publicpool"); } @Override - public List<SessionInfo> getPublicPoolSessionsInfo() { - final List<Session> sessions = this.getPublicPoolSessions(); + public List<SessionInfo> findInfosForPublicPool() { + final List<Session> sessions = this.findAllForPublicPool(); return getInfosForSessions(sessions); } @Override - public List<Session> getMyPublicPoolSessions(final User user) { + public List<Session> findForPublicPoolByUser(final User user) { /* TODO: Only load IDs and check against cache for data. */ return db.queryView( createQuery("partial_by_sessiontype_creator_name") @@ -485,24 +491,27 @@ public class CouchDbSessionRepository extends CouchDbCrudRepository<Session> imp Session.class); } + /* TODO: Move to service layer. */ @Override - public List<SessionInfo> getMyPublicPoolSessionsInfo(final User user) { - final List<Session> sessions = this.getMyPublicPoolSessions(user); + public List<SessionInfo> findInfosForPublicPoolByUser(final User user) { + final List<Session> sessions = this.findForPublicPoolByUser(user); if (sessions.isEmpty()) { return new ArrayList<>(); } return getInfosForSessions(sessions); } + /* TODO: Move to service layer. */ @Override public List<SessionInfo> getMySessionsInfo(final User user, final int start, final int limit) { - final List<Session> sessions = this.getMySessions(user, start, limit); + final List<Session> sessions = this.findByUser(user, start, limit); if (sessions.isEmpty()) { return new ArrayList<>(); } return getInfosForSessions(sessions); } + /* TODO: Move to service layer. */ private List<SessionInfo> getInfosForSessions(final List<Session> sessions) { final List<String> sessionIds = sessions.stream().map(Session::getId).collect(Collectors.toList()); final ViewQuery questionCountView = createQuery("by_sessionid").designDocId("_design/Content") @@ -517,6 +526,7 @@ public class CouchDbSessionRepository extends CouchDbCrudRepository<Session> imp return getSessionInfoData(sessions, questionCountView, answerCountView, commentCountView, unreadCommentCountView); } + /* TODO: Move to service layer. */ private List<SessionInfo> getInfosForVisitedSessions(final List<Session> sessions, final User user) { final ViewQuery answeredQuestionsView = createQuery("by_user_sessionid").designDocId("_design/Answer") .keys(sessions.stream().map(session -> ComplexKey.of(user.getUsername(), session.getId())).collect(Collectors.toList())); @@ -526,6 +536,7 @@ public class CouchDbSessionRepository extends CouchDbCrudRepository<Session> imp return getVisitedSessionInfoData(sessions, answeredQuestionsView, contentIdsView); } + /* TODO: Move to service layer. */ private List<SessionInfo> getVisitedSessionInfoData( final List<Session> sessions, final ViewQuery answeredQuestionsView, @@ -587,6 +598,7 @@ public class CouchDbSessionRepository extends CouchDbCrudRepository<Session> imp return sessionInfos; } + /* TODO: Move to service layer. */ private List<SessionInfo> getSessionInfoData( final List<Session> sessions, final ViewQuery questionCountView, @@ -635,6 +647,7 @@ public class CouchDbSessionRepository extends CouchDbCrudRepository<Session> imp return sessionInfos; } + /* TODO: Move to service layer. */ @Override public LoggedIn registerAsOnlineUser(final User user, final Session session) { LoggedIn loggedIn = new LoggedIn(); diff --git a/src/main/java/de/thm/arsnova/security/ApplicationPermissionEvaluator.java b/src/main/java/de/thm/arsnova/security/ApplicationPermissionEvaluator.java index fd72edb9c147432e3fa754f924cea85caac97b32..52db49481ace5cb1592516c186e5230d6b8c9c2e 100644 --- a/src/main/java/de/thm/arsnova/security/ApplicationPermissionEvaluator.java +++ b/src/main/java/de/thm/arsnova/security/ApplicationPermissionEvaluator.java @@ -112,9 +112,9 @@ public class ApplicationPermissionEvaluator implements PermissionEvaluator { final Object permission ) { if (permission instanceof String && ("owner".equals(permission) || "write".equals(permission))) { - return sessionRepository.getSessionFromKeyword(targetId.toString()).getCreator().equals(username); + return sessionRepository.findByKeyword(targetId.toString()).getCreator().equals(username); } else if (permission instanceof String && "read".equals(permission)) { - return sessionRepository.getSessionFromKeyword(targetId.toString()).isActive(); + return sessionRepository.findByKeyword(targetId.toString()).isActive(); } return false; } @@ -125,9 +125,9 @@ public class ApplicationPermissionEvaluator implements PermissionEvaluator { final Object permission ) { if (permission instanceof String && "owner".equals(permission)) { - final Content content = contentRepository.getQuestion(targetId.toString()); + final Content content = contentRepository.findOne(targetId.toString()); if (content != null) { - final Session session = sessionRepository.getSessionFromId(content.getSessionId()); + final Session session = sessionRepository.findOne(content.getSessionId()); return session != null && session.getCreator().equals(username); } @@ -141,14 +141,14 @@ public class ApplicationPermissionEvaluator implements PermissionEvaluator { final Object permission ) { if (permission instanceof String && "owner".equals(permission)) { - final Comment comment = commentRepository.getInterposedQuestion(targetId.toString()); + final Comment comment = commentRepository.findOne(targetId.toString()); if (comment != null) { // Does the creator want to delete his own comment? if (comment.getCreator() != null && comment.getCreator().equals(username)) { return true; } // Allow deletion if requested by session owner - final Session session = sessionRepository.getSessionFromKeyword(comment.getSessionId()); + final Session session = sessionRepository.findByKeyword(comment.getSessionId()); return session != null && session.getCreator().equals(username); } diff --git a/src/main/java/de/thm/arsnova/services/CommentServiceImpl.java b/src/main/java/de/thm/arsnova/services/CommentServiceImpl.java index 46a50ddc2bef0e105dc6c123d64a2f4a7f95ff8d..d0717a9f6db25b1beacd5acaf315ca7005e72a85 100644 --- a/src/main/java/de/thm/arsnova/services/CommentServiceImpl.java +++ b/src/main/java/de/thm/arsnova/services/CommentServiceImpl.java @@ -37,8 +37,8 @@ public class CommentServiceImpl implements CommentService { @Override @PreAuthorize("isAuthenticated()") public boolean saveQuestion(final Comment comment) { - final Session session = sessionRepository.getSessionFromKeyword(comment.getSessionId()); - final Comment result = commentRepository.saveQuestion(session.getId(), comment, userService.getCurrentUser()); + final Session session = sessionRepository.findByKeyword(comment.getSessionId()); + final Comment result = commentRepository.save(session.getId(), comment, userService.getCurrentUser()); if (null != result) { final NewCommentEvent event = new NewCommentEvent(this, session, result); @@ -51,13 +51,13 @@ public class CommentServiceImpl implements CommentService { @Override @PreAuthorize("isAuthenticated() and hasPermission(#commentId, 'comment', 'owner')") public void deleteInterposedQuestion(final String commentId) { - final Comment comment = commentRepository.getInterposedQuestion(commentId); + final Comment comment = commentRepository.findOne(commentId); if (comment == null) { throw new NotFoundException(); } - commentRepository.deleteInterposedQuestion(comment); + commentRepository.delete(comment); - final Session session = sessionRepository.getSessionFromKeyword(comment.getSessionId()); + final Session session = sessionRepository.findByKeyword(comment.getSessionId()); final DeleteCommentEvent event = new DeleteCommentEvent(this, session, comment); this.publisher.publishEvent(event); } @@ -65,40 +65,40 @@ public class CommentServiceImpl implements CommentService { @Override @PreAuthorize("isAuthenticated()") public void deleteAllInterposedQuestions(final String sessionKeyword) { - final Session session = sessionRepository.getSessionFromKeyword(sessionKeyword); + final Session session = sessionRepository.findByKeyword(sessionKeyword); if (session == null) { throw new UnauthorizedException(); } final User user = getCurrentUser(); if (session.isCreator(user)) { - commentRepository.deleteAllInterposedQuestions(session.getId()); + commentRepository.deleteBySessionId(session.getId()); } else { - commentRepository.deleteAllInterposedQuestions(session.getId(), user); + commentRepository.deleteBySessionIdAndUser(session.getId(), user); } } @Override @PreAuthorize("isAuthenticated()") public int getInterposedCount(final String sessionKey) { - return commentRepository.getInterposedCount(sessionKey); + return commentRepository.countBySessionKey(sessionKey); } @Override @PreAuthorize("isAuthenticated()") public CommentReadingCount getInterposedReadingCount(final String sessionKey, String username) { - final Session session = sessionRepository.getSessionFromKeyword(sessionKey); + final Session session = sessionRepository.findByKeyword(sessionKey); if (session == null) { throw new NotFoundException(); } if (username == null) { - return commentRepository.getInterposedReadingCount(session.getId()); + return commentRepository.countReadingBySessionId(session.getId()); } else { User currentUser = userService.getCurrentUser(); if (!currentUser.getUsername().equals(username)) { throw new ForbiddenException(); } - return commentRepository.getInterposedReadingCount(session.getId(), currentUser); + return commentRepository.countReadingBySessionIdAndUser(session.getId(), currentUser); } } @@ -108,9 +108,9 @@ public class CommentServiceImpl implements CommentService { final Session session = this.getSession(sessionKey); final User user = getCurrentUser(); if (session.isCreator(user)) { - return commentRepository.getInterposedQuestions(session.getId(), offset, limit); + return commentRepository.findBySessionId(session.getId(), offset, limit); } else { - return commentRepository.getInterposedQuestions(session.getId(), user, offset, limit); + return commentRepository.findBySessionIdAndUser(session.getId(), user, offset, limit); } } @@ -127,11 +127,11 @@ public class CommentServiceImpl implements CommentService { */ @Override public Comment readInterposedQuestionInternal(final String commentId, User user) { - final Comment comment = commentRepository.getInterposedQuestion(commentId); + final Comment comment = commentRepository.findOne(commentId); if (comment == null) { throw new NotFoundException(); } - final Session session = sessionRepository.getSessionFromId(comment.getSessionId()); + final Session session = sessionRepository.findOne(comment.getSessionId()); if (!comment.isCreator(user) && !session.isCreator(user)) { throw new UnauthorizedException(); } @@ -150,7 +150,7 @@ public class CommentServiceImpl implements CommentService { } private Session getSession(final String sessionkey) { - final Session session = sessionRepository.getSessionFromKeyword(sessionkey); + final Session session = sessionRepository.findByKeyword(sessionkey); if (session == null) { throw new NotFoundException(); } diff --git a/src/main/java/de/thm/arsnova/services/ContentServiceImpl.java b/src/main/java/de/thm/arsnova/services/ContentServiceImpl.java index f4e5bc66557f96ba0f573f2e83f9e70ce112dd2f..12b0746d47859b9dd6df076ef1c57fb5b753da3e 100644 --- a/src/main/java/de/thm/arsnova/services/ContentServiceImpl.java +++ b/src/main/java/de/thm/arsnova/services/ContentServiceImpl.java @@ -81,24 +81,24 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli final Session session = getSession(sessionkey); final User user = userService.getCurrentUser(); if (session.isCreator(user)) { - return contentRepository.getSkillQuestionsForTeachers(session.getId()); + return contentRepository.findBySessionIdForSpeaker(session.getId()); } else { - return contentRepository.getSkillQuestionsForUsers(session.getId()); + return contentRepository.findBySessionIdForUsers(session.getId()); } } @Override @PreAuthorize("isAuthenticated()") public int getSkillQuestionCount(final String sessionkey) { - final Session session = sessionRepository.getSessionFromKeyword(sessionkey); - return contentRepository.getSkillQuestionCount(session.getId()); + final Session session = sessionRepository.findByKeyword(sessionkey); + return contentRepository.countBySessionId(session.getId()); } /* FIXME: #content.getSessionKeyword() cannot be checked since keyword is no longer set for content. */ @Override @PreAuthorize("isAuthenticated() and hasPermission(#content.getSessionKeyword(), 'session', 'owner')") public Content saveQuestion(final Content content) { - final Session session = sessionRepository.getSessionFromKeyword(content.getSessionKeyword()); + final Session session = sessionRepository.findByKeyword(content.getSessionKeyword()); content.setSessionId(session.getId()); content.setTimestamp(System.currentTimeMillis() / 1000L); @@ -118,7 +118,7 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli } } - final Content result = contentRepository.saveQuestion(session.getId(), content); + final Content result = contentRepository.save(session.getId(), content); final NewQuestionEvent event = new NewQuestionEvent(this, session, result); this.publisher.publishEvent(event); @@ -129,7 +129,7 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli @Override @PreAuthorize("isAuthenticated()") public Content getQuestion(final String id) { - final Content result = contentRepository.getQuestion(id); + final Content result = contentRepository.findOne(id); if (result == null) { return null; } @@ -144,12 +144,12 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli @Override @PreAuthorize("isAuthenticated() and hasPermission(#questionId, 'content', 'owner')") public void deleteQuestion(final String questionId) { - final Content content = contentRepository.getQuestion(questionId); + final Content content = contentRepository.findOne(questionId); if (content == null) { throw new NotFoundException(); } - final Session session = sessionRepository.getSessionFromId(content.getSessionId()); + final Session session = sessionRepository.findOne(content.getSessionId()); if (session == null) { throw new UnauthorizedException(); } @@ -172,8 +172,8 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli @Override @PreAuthorize("isAuthenticated() and hasPermission(#questionId, 'content', 'owner')") public void startNewPiRound(final String questionId, User user) { - final Content content = contentRepository.getQuestion(questionId); - final Session session = sessionRepository.getSessionFromId(content.getSessionId()); + final Content content = contentRepository.findOne(questionId); + final Session session = sessionRepository.findOne(content.getSessionId()); if (null == user) { user = userService.getCurrentUser(); @@ -194,8 +194,8 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli public void startNewPiRoundDelayed(final String questionId, final int time) { final ContentService contentService = this; final User user = userService.getCurrentUser(); - final Content content = contentRepository.getQuestion(questionId); - final Session session = sessionRepository.getSessionFromId(content.getSessionId()); + final Content content = contentRepository.findOne(questionId); + final Session session = sessionRepository.findOne(content.getSessionId()); final Date date = new Date(); final Timer timer = new Timer(); @@ -217,8 +217,8 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli @Override @PreAuthorize("isAuthenticated() and hasPermission(#questionId, 'content', 'owner')") public void cancelPiRoundChange(final String questionId) { - final Content content = contentRepository.getQuestion(questionId); - final Session session = sessionRepository.getSessionFromId(content.getSessionId()); + final Content content = contentRepository.findOne(questionId); + final Session session = sessionRepository.findOne(content.getSessionId()); cancelDelayedPiRoundChange(questionId); content.resetRoundManagementState(); @@ -248,8 +248,8 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli @Override @PreAuthorize("isAuthenticated() and hasPermission(#questionId, 'content', 'owner')") public void resetPiRoundState(final String questionId) { - final Content content = contentRepository.getQuestion(questionId); - final Session session = sessionRepository.getSessionFromId(content.getSessionId()); + final Content content = contentRepository.findOne(questionId); + final Session session = sessionRepository.findOne(content.getSessionId()); cancelDelayedPiRoundChange(questionId); if ("freetext".equals(content.getQuestionType())) { @@ -259,7 +259,7 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli } content.resetRoundManagementState(); - answerRepository.deleteAnswers(content.getId()); + answerRepository.deleteByContentId(content.getId()); update(content); this.publisher.publishEvent(new PiRoundResetEvent(this, session, content)); } @@ -267,15 +267,15 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli @Override @PreAuthorize("isAuthenticated() and hasPermission(#questionId, 'content', 'owner')") public void setVotingAdmission(final String questionId, final boolean disableVoting) { - final Content content = contentRepository.getQuestion(questionId); - final Session session = sessionRepository.getSessionFromId(content.getSessionId()); + final Content content = contentRepository.findOne(questionId); + final Session session = sessionRepository.findOne(content.getSessionId()); content.setVotingDisabled(disableVoting); if (!disableVoting && !content.isActive()) { content.setActive(true); update(content); } else { - contentRepository.updateQuestion(content); + contentRepository.update(content); } ArsnovaEvent event; if (disableVoting) { @@ -324,7 +324,7 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli private Session getSessionWithAuthCheck(final String sessionKeyword) { final User user = userService.getCurrentUser(); - final Session session = sessionRepository.getSessionFromKeyword(sessionKeyword); + final Session session = sessionRepository.findByKeyword(sessionKeyword); if (user == null || session == null || !session.isCreator(user)) { throw new UnauthorizedException(); } @@ -334,10 +334,10 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli @Override @PreAuthorize("isAuthenticated() and hasPermission(#questionId, 'content', 'owner')") public void deleteAnswers(final String questionId) { - final Content content = contentRepository.getQuestion(questionId); + final Content content = contentRepository.findOne(questionId); content.resetQuestionState(); - contentRepository.updateQuestion(content); - answerRepository.deleteAnswers(content.getId()); + contentRepository.update(content); + answerRepository.deleteByContentId(content.getId()); } @Override @@ -345,7 +345,7 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli public List<String> getUnAnsweredQuestionIds(final String sessionKey) { final User user = getCurrentUser(); final Session session = getSession(sessionKey); - return contentRepository.getUnAnsweredQuestionIds(session.getId(), user); + return contentRepository.findUnansweredIdsBySessionIdAndUser(session.getId(), user); } private User getCurrentUser() { @@ -363,35 +363,35 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli if (content == null) { throw new NotFoundException(); } - return answerRepository.getMyAnswer(userService.getCurrentUser(), questionId, content.getPiRound()); + return answerRepository.findByQuestionIdUserPiRound(questionId, userService.getCurrentUser(), content.getPiRound()); } @Override public void readFreetextAnswer(final String answerId, final User user) { - final Answer answer = answerRepository.get(answerId); + final Answer answer = answerRepository.findOne(answerId); if (answer == null) { throw new NotFoundException(); } if (answer.isRead()) { return; } - final Session session = sessionRepository.getSessionFromId(answer.getSessionId()); + final Session session = sessionRepository.findOne(answer.getSessionId()); if (session.isCreator(user)) { answer.setRead(true); - answerRepository.updateAnswer(answer); + answerRepository.update(answer); } } @Override @PreAuthorize("isAuthenticated()") public List<Answer> getAnswers(final String questionId, final int piRound, final int offset, final int limit) { - final Content content = contentRepository.getQuestion(questionId); + final Content content = contentRepository.findOne(questionId); if (content == null) { throw new NotFoundException(); } return "freetext".equals(content.getQuestionType()) ? getFreetextAnswers(questionId, offset, limit) - : answerRepository.getAnswers(content.getId(), piRound); + : answerRepository.findByContentIdPiRound(content.getId(), piRound); } @Override @@ -404,7 +404,7 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli if ("freetext".equals(content.getQuestionType())) { return getFreetextAnswers(questionId, offset, limit); } else { - return answerRepository.getAnswers(content.getId(), content.getPiRound()); + return answerRepository.findByContentIdPiRound(content.getId(), content.getPiRound()); } } @@ -418,7 +418,7 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli if ("freetext".equals(content.getQuestionType())) { return getFreetextAnswers(questionId, offset, limit); } else { - return answerRepository.getAllAnswers(content.getId()); + return answerRepository.findByContentId(content.getId()); } } @@ -431,9 +431,9 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli } if ("freetext".equals(content.getQuestionType())) { - return answerRepository.getTotalAnswerCountByQuestion(content.getId()); + return answerRepository.countByContentId(content.getId()); } else { - return answerRepository.getAnswerCount(content.getId(), content.getPiRound()); + return answerRepository.countByContentIdRound(content.getId(), content.getPiRound()); } } @@ -445,7 +445,7 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli return 0; } - return answerRepository.getAnswerCount(content.getId(), piRound); + return answerRepository.countByContentIdRound(content.getId(), piRound); } @Override @@ -456,7 +456,7 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli return 0; } - return answerRepository.getAbstentionAnswerCount(questionId); + return answerRepository.countByContentId(questionId); } @Override @@ -467,13 +467,13 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli return 0; } - return answerRepository.getTotalAnswerCountByQuestion(content.getId()); + return answerRepository.countByContentId(content.getId()); } @Override @PreAuthorize("isAuthenticated()") public List<Answer> getFreetextAnswers(final String questionId, final int offset, final int limit) { - final List<Answer> answers = answerRepository.getFreetextAnswers(questionId, offset, limit); + final List<Answer> answers = answerRepository.findByContentId(questionId, offset, limit); if (answers == null) { throw new NotFoundException(); } @@ -490,14 +490,14 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli public List<Answer> getMyAnswers(final String sessionKey) { final Session session = getSession(sessionKey); // Load contents first because we are only interested in answers of the latest piRound. - final List<Content> contents = contentRepository.getSkillQuestionsForUsers(session.getId()); + final List<Content> contents = contentRepository.findBySessionIdForUsers(session.getId()); final Map<String, Content> questionIdToQuestion = new HashMap<>(); for (final Content content : contents) { questionIdToQuestion.put(content.getId(), content); } /* filter answers by active piRound per question */ - final List<Answer> answers = answerRepository.getMyAnswers(userService.getCurrentUser(), session.getId()); + final List<Answer> answers = answerRepository.findByUserSessionId(userService.getCurrentUser(), session.getId()); final List<Answer> filteredAnswers = new ArrayList<>(); for (final Answer answer : answers) { final Content content = questionIdToQuestion.get(answer.getQuestionId()); @@ -522,7 +522,7 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli @Override @PreAuthorize("isAuthenticated()") public int getTotalAnswerCount(final String sessionKey) { - return answerRepository.getTotalAnswerCount(sessionKey); + return answerRepository.countBySessionKey(sessionKey); } @Override @@ -535,12 +535,12 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli @Override @PreAuthorize("isAuthenticated()") public Content update(final Content content, User user) { - final Content oldContent = contentRepository.getQuestion(content.getId()); + final Content oldContent = contentRepository.findOne(content.getId()); if (null == oldContent) { throw new NotFoundException(); } - final Session session = sessionRepository.getSessionFromId(content.getSessionId()); + final Session session = sessionRepository.findOne(content.getSessionId()); if (user == null || session == null || !session.isCreator(user)) { throw new UnauthorizedException(); } @@ -551,16 +551,16 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli content.setPiRound(oldContent.getPiRound() > 0 ? oldContent.getPiRound() : 1); } - final Content result = contentRepository.updateQuestion(content); + contentRepository.update(content); if (!oldContent.isActive() && content.isActive()) { - final UnlockQuestionEvent event = new UnlockQuestionEvent(this, session, result); + final UnlockQuestionEvent event = new UnlockQuestionEvent(this, session, content); this.publisher.publishEvent(event); } else if (oldContent.isActive() && !content.isActive()) { - final LockQuestionEvent event = new LockQuestionEvent(this, session, result); + final LockQuestionEvent event = new LockQuestionEvent(this, session, content); this.publisher.publishEvent(event); } - return result; + return content; } @Override @@ -571,7 +571,7 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli if (content == null) { throw new NotFoundException(); } - final Session session = sessionRepository.getSessionFromId(content.getSessionId()); + final Session session = sessionRepository.findOne(content.getSessionId()); Answer theAnswer = answer.generateAnswerEntity(user, content); theAnswer.setUser(user.getUsername()); @@ -590,7 +590,7 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli } } - return answerRepository.saveAnswer(theAnswer, user, content, session); + return answerRepository.create(theAnswer, user, content, session); } @Override @@ -607,29 +607,29 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli imageUtils.generateThumbnailImage(realAnswer); content.checkTextStrictOptions(realAnswer); } - final Session session = sessionRepository.getSessionFromId(content.getSessionId()); + final Session session = sessionRepository.findOne(content.getSessionId()); answer.setUser(user.getUsername()); answer.setQuestionId(content.getId()); answer.setSessionId(session.getId()); - final Answer result = answerRepository.updateAnswer(realAnswer); - this.publisher.publishEvent(new NewAnswerEvent(this, session, result, user, content)); + answerRepository.update(realAnswer); + this.publisher.publishEvent(new NewAnswerEvent(this, session, answer, user, content)); - return result; + return answer; } @Override @PreAuthorize("isAuthenticated()") public void deleteAnswer(final String questionId, final String answerId) { - final Content content = contentRepository.getQuestion(questionId); + final Content content = contentRepository.findOne(questionId); if (content == null) { throw new NotFoundException(); } final User user = userService.getCurrentUser(); - final Session session = sessionRepository.getSessionFromId(content.getSessionId()); + final Session session = sessionRepository.findOne(content.getSessionId()); if (user == null || session == null || !session.isCreator(user)) { throw new UnauthorizedException(); } - answerRepository.deleteAnswer(answerId); + answerRepository.delete(answerId); this.publisher.publishEvent(new DeleteAnswerEvent(this, session, content)); } @@ -640,9 +640,9 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli final Session session = getSession(sessionkey); final User user = userService.getCurrentUser(); if (session.isCreator(user)) { - return contentRepository.getLectureQuestionsForTeachers(session.getId()); + return contentRepository.findBySessionIdOnlyLectureVariant(session.getId()); } else { - return contentRepository.getLectureQuestionsForUsers(session.getId()); + return contentRepository.findBySessionIdOnlyLectureVariantAndActive(session.getId()); } } @@ -652,9 +652,9 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli final Session session = getSession(sessionkey); final User user = userService.getCurrentUser(); if (session.isCreator(user)) { - return contentRepository.getFlashcardsForTeachers(session.getId()); + return contentRepository.findBySessionIdOnlyFlashcardVariant(session.getId()); } else { - return contentRepository.getFlashcardsForUsers(session.getId()); + return contentRepository.findBySessionIdOnlyFlashcardVariantAndActive(session.getId()); } } @@ -664,9 +664,9 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli final Session session = getSession(sessionkey); final User user = userService.getCurrentUser(); if (session.isCreator(user)) { - return contentRepository.getPreparationQuestionsForTeachers(session.getId()); + return contentRepository.findBySessionIdOnlyPreparationVariant(session.getId()); } else { - return contentRepository.getPreparationQuestionsForUsers(session.getId()); + return contentRepository.findBySessionIdOnlyPreparationVariantAndActive(session.getId()); } } @@ -683,7 +683,7 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli } private Session getSession(final String sessionkey) { - final Session session = sessionRepository.getSessionFromKeyword(sessionkey); + final Session session = sessionRepository.findByKeyword(sessionkey); if (session == null) { throw new NotFoundException(); } @@ -693,19 +693,19 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli @Override @PreAuthorize("isAuthenticated()") public int getLectureQuestionCount(final String sessionkey) { - return contentRepository.getLectureQuestionCount(getSession(sessionkey).getId()); + return contentRepository.countLectureVariantBySessionId(getSession(sessionkey).getId()); } @Override @PreAuthorize("isAuthenticated()") public int getFlashcardCount(final String sessionkey) { - return contentRepository.getFlashcardCount(getSession(sessionkey).getId()); + return contentRepository.countFlashcardVariantBySessionId(getSession(sessionkey).getId()); } @Override @PreAuthorize("isAuthenticated()") public int getPreparationQuestionCount(final String sessionkey) { - return contentRepository.getPreparationQuestionCount(getSession(sessionkey).getId()); + return contentRepository.countPreparationVariantBySessionId(getSession(sessionkey).getId()); } @Override @@ -720,7 +720,7 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli */ @Override public int countLectureQuestionAnswersInternal(final String sessionkey) { - return answerRepository.countLectureQuestionAnswers(getSession(sessionkey).getId()); + return answerRepository.countBySessionIdLectureVariant(getSession(sessionkey).getId()); } @Override @@ -733,8 +733,8 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli } map.put("_id", questionId); - map.put("answers", answerRepository.getAnswerCount(content.getId(), content.getPiRound())); - map.put("abstentions", answerRepository.getAbstentionAnswerCount(questionId)); + map.put("answers", answerRepository.countByContentIdRound(content.getId(), content.getPiRound())); + map.put("abstentions", answerRepository.countByContentId(questionId)); return map; } @@ -751,7 +751,7 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli */ @Override public int countPreparationQuestionAnswersInternal(final String sessionkey) { - return answerRepository.countPreparationQuestionAnswers(getSession(sessionkey).getId()); + return answerRepository.countBySessionIdPreparationVariant(getSession(sessionkey).getId()); } /* @@ -760,7 +760,7 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli */ @Override public int countFlashcardsForUserInternal(final String sessionkey) { - return contentRepository.getFlashcardsForUsers(getSession(sessionkey).getId()).size(); + return contentRepository.findBySessionIdOnlyFlashcardVariantAndActive(getSession(sessionkey).getId()).size(); } @Override @@ -794,7 +794,7 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli @Override public List<String> getUnAnsweredLectureQuestionIds(final String sessionkey, final User user) { final Session session = getSession(sessionkey); - return contentRepository.getUnAnsweredLectureQuestionIds(session.getId(), user); + return contentRepository.findUnansweredIdsBySessionIdAndUserOnlyLectureVariant(session.getId(), user); } @Override @@ -807,7 +807,7 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli @Override public List<String> getUnAnsweredPreparationQuestionIds(final String sessionkey, final User user) { final Session session = getSession(sessionkey); - return contentRepository.getUnAnsweredPreparationQuestionIds(session.getId(), user); + return contentRepository.findUnansweredIdsBySessionIdAndUserOnlyPreparationVariant(session.getId(), user); } @Override @@ -903,7 +903,7 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli @Override public String getQuestionImage(String questionId) { - Content content = contentRepository.getQuestion(questionId); + Content content = contentRepository.findOne(questionId); String imageData = content.getImage(); if (imageData == null) { @@ -915,7 +915,7 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli @Override public String getQuestionFcImage(String questionId) { - Content content = contentRepository.getQuestion(questionId); + Content content = contentRepository.findOne(questionId); String imageData = content.getFcImage(); if (imageData == null) { diff --git a/src/main/java/de/thm/arsnova/services/FeedbackServiceImpl.java b/src/main/java/de/thm/arsnova/services/FeedbackServiceImpl.java index 8fe6eef74fad9489aa38666e30c4f3d8d6b9df67..e83210ef027f12596f416c5ff36a278c2e5fadb7 100644 --- a/src/main/java/de/thm/arsnova/services/FeedbackServiceImpl.java +++ b/src/main/java/de/thm/arsnova/services/FeedbackServiceImpl.java @@ -102,7 +102,7 @@ public class FeedbackServiceImpl implements FeedbackService, ApplicationEventPub @Override public void cleanFeedbackVotesInSession(final String keyword, final int cleanupFeedbackDelayInMins) { - final Session session = sessionRepository.getSessionFromKeyword(keyword); + final Session session = sessionRepository.findByKeyword(keyword); List<User> affectedUsers = feedbackStorage.cleanFeedbackVotesInSession(session, cleanupFeedbackDelayInMins); Set<Session> sessionSet = new HashSet<>(); sessionSet.add(session); @@ -117,7 +117,7 @@ public class FeedbackServiceImpl implements FeedbackService, ApplicationEventPub @Override public Feedback getFeedback(final String keyword) { - final Session session = sessionRepository.getSessionFromKeyword(keyword); + final Session session = sessionRepository.findByKeyword(keyword); if (session == null) { throw new NotFoundException(); } @@ -134,7 +134,7 @@ public class FeedbackServiceImpl implements FeedbackService, ApplicationEventPub @Override public double getAverageFeedback(final String sessionkey) { - final Session session = sessionRepository.getSessionFromKeyword(sessionkey); + final Session session = sessionRepository.findByKeyword(sessionkey); if (session == null) { throw new NotFoundException(); } @@ -158,7 +158,7 @@ public class FeedbackServiceImpl implements FeedbackService, ApplicationEventPub @Override public boolean saveFeedback(final String keyword, final int value, final User user) { - final Session session = sessionRepository.getSessionFromKeyword(keyword); + final Session session = sessionRepository.findByKeyword(keyword); if (session == null) { throw new NotFoundException(); } @@ -170,7 +170,7 @@ public class FeedbackServiceImpl implements FeedbackService, ApplicationEventPub @Override public Integer getMyFeedback(final String keyword, final User user) { - final Session session = sessionRepository.getSessionFromKeyword(keyword); + final Session session = sessionRepository.findByKeyword(keyword); if (session == null) { throw new NotFoundException(); } diff --git a/src/main/java/de/thm/arsnova/services/MotdServiceImpl.java b/src/main/java/de/thm/arsnova/services/MotdServiceImpl.java index d373b001f8ecee18a2862f0c7be61e28f355dd23..9828fb5e52fe392d5cae81623e2f20fc3107b106 100644 --- a/src/main/java/de/thm/arsnova/services/MotdServiceImpl.java +++ b/src/main/java/de/thm/arsnova/services/MotdServiceImpl.java @@ -53,31 +53,31 @@ public class MotdServiceImpl implements MotdService { @Override @PreAuthorize("isAuthenticated()") public Motd getMotd(final String key) { - return motdRepository.getMotdByKey(key); + return motdRepository.findByKey(key); } @Override @PreAuthorize("isAuthenticated() and hasPermission(1,'motd','admin')") public List<Motd> getAdminMotds() { - return motdRepository.getAdminMotds(); + return motdRepository.findGlobalForAdmin(); } @Override @PreAuthorize("isAuthenticated() and hasPermission(#sessionkey, 'session', 'owner')") public List<Motd> getAllSessionMotds(final String sessionkey) { - return motdRepository.getMotdsForSession(sessionkey); + return motdRepository.findBySessionKey(sessionkey); } @Override public List<Motd> getCurrentMotds(final Date clientdate, final String audience, final String sessionkey) { final List<Motd> motds; switch (audience) { - case "all": motds = motdRepository.getMotdsForAll(); break; - case "loggedIn": motds = motdRepository.getMotdsForLoggedIn(); break; - case "students": motds = motdRepository.getMotdsForStudents(); break; - case "tutors": motds = motdRepository.getMotdsForTutors(); break; - case "session": motds = motdRepository.getMotdsForSession(sessionkey); break; - default: motds = motdRepository.getMotdsForAll(); break; + case "all": motds = motdRepository.findGlobalForAll(); break; + case "loggedIn": motds = motdRepository.findGlobalForLoggedIn(); break; + case "students": motds = motdRepository.findForStudents(); break; + case "tutors": motds = motdRepository.findGlobalForTutors(); break; + case "session": motds = motdRepository.findBySessionKey(sessionkey); break; + default: motds = motdRepository.findGlobalForAll(); break; } return filterMotdsByDate(motds, clientdate); } @@ -143,26 +143,26 @@ public class MotdServiceImpl implements MotdService { private Motd createOrUpdateMotd(final Motd motd) { if (motd.getMotdkey() != null) { - Motd oldMotd = motdRepository.getMotdByKey(motd.getMotdkey()); + Motd oldMotd = motdRepository.findByKey(motd.getMotdkey()); if (!(motd.getId().equals(oldMotd.getId()) && motd.getSessionkey().equals(oldMotd.getSessionkey()) && motd.getAudience().equals(oldMotd.getAudience()))) { throw new BadRequestException(); } } - return motdRepository.createOrUpdateMotd(motd); + return motdRepository.save(motd); } @Override @PreAuthorize("isAuthenticated() and hasPermission(1,'motd','admin')") public void deleteMotd(Motd motd) { - motdRepository.deleteMotd(motd); + motdRepository.delete(motd); } @Override @PreAuthorize("isAuthenticated() and hasPermission(#sessionkey, 'session', 'owner')") public void deleteSessionMotd(final String sessionkey, Motd motd) { - motdRepository.deleteMotd(motd); + motdRepository.delete(motd); } @Override @@ -170,7 +170,7 @@ public class MotdServiceImpl implements MotdService { public MotdList getMotdListForUser(final String username) { final User user = userService.getCurrentUser(); if (username.equals(user.getUsername()) && !"guest".equals(user.getType())) { - return motdListRepository.getMotdListForUser(username); + return motdListRepository.findByUsername(username); } return null; } @@ -180,7 +180,7 @@ public class MotdServiceImpl implements MotdService { public MotdList saveUserMotdList(MotdList motdList) { final User user = userService.getCurrentUser(); if (user.getUsername().equals(motdList.getUsername())) { - return motdListRepository.createOrUpdateMotdList(motdList); + return motdListRepository.save(motdList); } return null; } @@ -190,7 +190,7 @@ public class MotdServiceImpl implements MotdService { public MotdList updateUserMotdList(MotdList motdList) { final User user = userService.getCurrentUser(); if (user.getUsername().equals(motdList.getUsername())) { - return motdListRepository.createOrUpdateMotdList(motdList); + return motdListRepository.save(motdList); } return null; } diff --git a/src/main/java/de/thm/arsnova/services/SessionServiceImpl.java b/src/main/java/de/thm/arsnova/services/SessionServiceImpl.java index 1d63abda419ea967f4e13b6ef91d7b41ae487c3e..44b70026bde63e1811a2b01e65e130d302f4315e 100644 --- a/src/main/java/de/thm/arsnova/services/SessionServiceImpl.java +++ b/src/main/java/de/thm/arsnova/services/SessionServiceImpl.java @@ -156,7 +156,7 @@ public class SessionServiceImpl implements SessionService, ApplicationEventPubli public Session joinSession(final String keyword, final UUID socketId) { /* Socket.IO solution */ - Session session = null != keyword ? sessionRepository.getSessionFromKeyword(keyword) : null; + Session session = null != keyword ? sessionRepository.findByKeyword(keyword) : null; if (null == session) { userService.removeUserFromSessionBySocketId(socketId); @@ -190,7 +190,7 @@ public class SessionServiceImpl implements SessionService, ApplicationEventPubli @PreAuthorize("isAuthenticated() and hasPermission(#sessionkey, 'session', 'owner')") public Session getSessionForAdmin(final String keyword) { - return sessionRepository.getSessionFromKeyword(keyword); + return sessionRepository.findByKeyword(keyword); } /* @@ -199,7 +199,7 @@ public class SessionServiceImpl implements SessionService, ApplicationEventPubli */ @Override public Session getSessionInternal(final String keyword, final User user) { - final Session session = sessionRepository.getSessionFromKeyword(keyword); + final Session session = sessionRepository.findByKeyword(keyword); if (session == null) { throw new NotFoundException(); } @@ -222,25 +222,25 @@ public class SessionServiceImpl implements SessionService, ApplicationEventPubli @Override @PreAuthorize("isAuthenticated() and hasPermission(#sessionkey, 'session', 'owner')") public List<Session> getUserSessions(String username) { - return sessionRepository.getSessionsForUsername(username, 0, 0); + return sessionRepository.findByUsername(username, 0, 0); } @Override @PreAuthorize("isAuthenticated()") public List<Session> getMySessions(final int offset, final int limit) { - return sessionRepository.getMySessions(userService.getCurrentUser(), offset, limit); + return sessionRepository.findByUser(userService.getCurrentUser(), offset, limit); } @Override @PreAuthorize("isAuthenticated()") public List<SessionInfo> getPublicPoolSessionsInfo() { - return sessionRepository.getPublicPoolSessionsInfo(); + return sessionRepository.findInfosForPublicPool(); } @Override @PreAuthorize("isAuthenticated()") public List<SessionInfo> getMyPublicPoolSessionsInfo() { - return sessionRepository.getMyPublicPoolSessionsInfo(userService.getCurrentUser()); + return sessionRepository.findInfosForPublicPoolByUser(userService.getCurrentUser()); } @Override @@ -253,19 +253,19 @@ public class SessionServiceImpl implements SessionService, ApplicationEventPubli @Override @PreAuthorize("isAuthenticated()") public List<Session> getMyVisitedSessions(final int offset, final int limit) { - return sessionRepository.getVisitedSessionsForUsername(userService.getCurrentUser().getUsername(), offset, limit); + return sessionRepository.findVisitedByUsername(userService.getCurrentUser().getUsername(), offset, limit); } @Override @PreAuthorize("isAuthenticated() and hasPermission(1, 'motd', 'admin')") public List<Session> getUserVisitedSessions(String username) { - return sessionRepository.getVisitedSessionsForUsername(username, 0, 0); + return sessionRepository.findVisitedByUsername(username, 0, 0); } @Override @PreAuthorize("isAuthenticated()") public List<SessionInfo> getMyVisitedSessionsInfo(final int offset, final int limit) { - return sessionRepository.getMyVisitedSessionsInfo(userService.getCurrentUser(), offset, limit); + return sessionRepository.findInfoForVisitedByUser(userService.getCurrentUser(), offset, limit); } @Override @@ -294,7 +294,7 @@ public class SessionServiceImpl implements SessionService, ApplicationEventPubli sf.setPi(true); session.setFeatures(sf); - final Session result = sessionRepository.saveSession(userService.getCurrentUser(), session); + final Session result = sessionRepository.save(userService.getCurrentUser(), session); this.publisher.publishEvent(new NewSessionEvent(this, result)); return result; } @@ -319,7 +319,7 @@ public class SessionServiceImpl implements SessionService, ApplicationEventPubli @Override public int countSessions(final List<Course> courses) { - final List<Session> sessions = sessionRepository.getCourseSessions(courses); + final List<Session> sessions = sessionRepository.findSessionsByCourses(courses); if (sessions == null) { return 0; } @@ -333,20 +333,22 @@ public class SessionServiceImpl implements SessionService, ApplicationEventPubli @Override public Session setActive(final String sessionkey, final Boolean lock) { - final Session session = sessionRepository.getSessionFromKeyword(sessionkey); + final Session session = sessionRepository.findByKeyword(sessionkey); final User user = userService.getCurrentUser(); if (!session.isCreator(user)) { throw new ForbiddenException("User is not session creator."); } session.setActive(lock); this.publisher.publishEvent(new StatusSessionEvent(this, session)); - return sessionRepository.updateSession(session); + sessionRepository.update(session); + + return session; } @Override @PreAuthorize("isAuthenticated() and hasPermission(#session, 'owner')") public Session updateSession(final String sessionkey, final Session session) { - final Session existingSession = sessionRepository.getSessionFromKeyword(sessionkey); + final Session existingSession = sessionRepository.findByKeyword(sessionkey); existingSession.setActive(session.isActive()); existingSession.setShortName(session.getShortName()); @@ -366,13 +368,15 @@ public class SessionServiceImpl implements SessionService, ApplicationEventPubli handleLogo(session); existingSession.setPpLogo(session.getPpLogo()); - return sessionRepository.updateSession(existingSession); + sessionRepository.update(existingSession); + + return session; } @Override @PreAuthorize("isAuthenticated() and hasPermission(1,'motd','admin')") public Session changeSessionCreator(String sessionkey, String newCreator) { - final Session existingSession = sessionRepository.getSessionFromKeyword(sessionkey); + final Session existingSession = sessionRepository.findByKeyword(sessionkey); if (existingSession == null) { throw new NullPointerException("Could not load session " + sessionkey + "."); } @@ -386,7 +390,8 @@ public class SessionServiceImpl implements SessionService, ApplicationEventPubli @Override public Session updateSessionInternal(final Session session, final User user) { if (session.isCreator(user)) { - return sessionRepository.updateSession(session); + sessionRepository.update(session); + return session; } return null; } @@ -394,7 +399,7 @@ public class SessionServiceImpl implements SessionService, ApplicationEventPubli @Override @PreAuthorize("isAuthenticated() and hasPermission(#sessionkey, 'session', 'owner')") public void deleteSession(final String sessionkey) { - final Session session = sessionRepository.getSessionFromKeyword(sessionkey); + final Session session = sessionRepository.findByKeyword(sessionkey); sessionRepository.deleteSession(session); @@ -404,7 +409,7 @@ public class SessionServiceImpl implements SessionService, ApplicationEventPubli @Override @PreAuthorize("isAuthenticated()") public ScoreStatistics getLearningProgress(final String sessionkey, final String type, final String questionVariant) { - final Session session = sessionRepository.getSessionFromKeyword(sessionkey); + final Session session = sessionRepository.findByKeyword(sessionkey); ScoreCalculator scoreCalculator = scoreCalculatorFactory.create(type, questionVariant); return scoreCalculator.getCourseProgress(session); } @@ -412,7 +417,7 @@ public class SessionServiceImpl implements SessionService, ApplicationEventPubli @Override @PreAuthorize("isAuthenticated()") public ScoreStatistics getMyLearningProgress(final String sessionkey, final String type, final String questionVariant) { - final Session session = sessionRepository.getSessionFromKeyword(sessionkey); + final Session session = sessionRepository.findByKeyword(sessionkey); final User user = userService.getCurrentUser(); ScoreCalculator scoreCalculator = scoreCalculatorFactory.create(type, questionVariant); return scoreCalculator.getMyProgress(session, user); @@ -452,24 +457,26 @@ public class SessionServiceImpl implements SessionService, ApplicationEventPubli @Override public SessionFeature getSessionFeatures(String sessionkey) { - return sessionRepository.getSessionFromKeyword(sessionkey).getFeatures(); + return sessionRepository.findByKeyword(sessionkey).getFeatures(); } @Override public SessionFeature changeSessionFeatures(String sessionkey, SessionFeature features) { - final Session session = sessionRepository.getSessionFromKeyword(sessionkey); + final Session session = sessionRepository.findByKeyword(sessionkey); final User user = userService.getCurrentUser(); if (!session.isCreator(user)) { throw new UnauthorizedException("User is not session creator."); } session.setFeatures(features); this.publisher.publishEvent(new FeatureChangeEvent(this, session)); - return sessionRepository.updateSession(session).getFeatures(); + sessionRepository.update(session); + + return session.getFeatures(); } @Override public boolean lockFeedbackInput(String sessionkey, Boolean lock) { - final Session session = sessionRepository.getSessionFromKeyword(sessionkey); + final Session session = sessionRepository.findByKeyword(sessionkey); final User user = userService.getCurrentUser(); if (!session.isCreator(user)) { throw new UnauthorizedException("User is not session creator."); @@ -480,19 +487,23 @@ public class SessionServiceImpl implements SessionService, ApplicationEventPubli session.setFeedbackLock(lock); this.publisher.publishEvent(new LockFeedbackEvent(this, session)); - return sessionRepository.updateSession(session).getFeedbackLock(); + sessionRepository.update(session); + + return session.getFeedbackLock(); } @Override public boolean flipFlashcards(String sessionkey, Boolean flip) { - final Session session = sessionRepository.getSessionFromKeyword(sessionkey); + final Session session = sessionRepository.findByKeyword(sessionkey); final User user = userService.getCurrentUser(); if (!session.isCreator(user)) { throw new UnauthorizedException("User is not session creator."); } session.setFlipFlashcards(flip); this.publisher.publishEvent(new FlipFlashcardsEvent(this, session)); - return sessionRepository.updateSession(session).getFlipFlashcards(); + sessionRepository.update(session); + + return session.getFlipFlashcards(); } private void handleLogo(Session session) {