Commit 951457c9 authored by Daniel Gerhardt's avatar Daniel Gerhardt

Move domain logic and caching to service layer

parent ab1badc6
...@@ -51,7 +51,7 @@ public class CacheBusterImpl implements CacheBuster, ArsnovaEventVisitor { ...@@ -51,7 +51,7 @@ public class CacheBusterImpl implements CacheBuster, ArsnovaEventVisitor {
@Override @Override
public void visit(LockQuestionsEvent lockQuestionsEvent) { } public void visit(LockQuestionsEvent lockQuestionsEvent) { }
@CacheEvict(value = "answers", key = "#event.content") @CacheEvict(value = "answers", key = "#event.content.id")
@Override @Override
public void visit(NewAnswerEvent event) { } public void visit(NewAnswerEvent event) { }
......
...@@ -63,18 +63,18 @@ public class MotdController extends AbstractController { ...@@ -63,18 +63,18 @@ public class MotdController extends AbstractController {
@ApiParam(value = "sessionkey", required = false) @RequestParam(value = "sessionkey", defaultValue = "null") final String sessionkey @ApiParam(value = "sessionkey", required = false) @RequestParam(value = "sessionkey", defaultValue = "null") final String sessionkey
) { ) {
List<Motd> motds; List<Motd> motds;
Date client = new Date(System.currentTimeMillis()); Date date = new Date(System.currentTimeMillis());
if (!clientdate.isEmpty()) { if (!clientdate.isEmpty()) {
client.setTime(Long.parseLong(clientdate)); date.setTime(Long.parseLong(clientdate));
} }
if (adminview) { if (adminview) {
if ("null".equals(sessionkey)) { motds = "session".equals(audience) ?
motds = motdService.getAdminMotds(); motdService.getAllSessionMotds(sessionkey) :
} else { motdService.getAdminMotds();
motds = motdService.getAllSessionMotds(sessionkey);
}
} else { } else {
motds = motdService.getCurrentMotds(client, audience, sessionkey); motds = "session".equals(audience) ?
motdService.getCurrentSessionMotds(date, sessionkey) :
motdService.getCurrentMotds(date, audience);
} }
return motds; return motds;
} }
......
...@@ -86,7 +86,8 @@ public class SessionController extends PaginationController { ...@@ -86,7 +86,8 @@ public class SessionController extends PaginationController {
nickname = "deleteSession") nickname = "deleteSession")
@RequestMapping(value = "/{sessionkey}", method = RequestMethod.DELETE) @RequestMapping(value = "/{sessionkey}", method = RequestMethod.DELETE)
public void deleteSession(@ApiParam(value = "Session-Key from current session", required = true) @PathVariable final String sessionkey) { public void deleteSession(@ApiParam(value = "Session-Key from current session", required = true) @PathVariable final String sessionkey) {
sessionService.delete(sessionkey); Session session = sessionService.getByKey(sessionkey);
sessionService.deleteCascading(session);
} }
@ApiOperation(value = "count active users", @ApiOperation(value = "count active users",
......
...@@ -33,8 +33,6 @@ public interface AnswerRepository extends CrudRepository<Answer, String> { ...@@ -33,8 +33,6 @@ public interface AnswerRepository extends CrudRepository<Answer, String> {
List<Answer> findByUserSessionId(User user, String sessionId); List<Answer> findByUserSessionId(User user, String sessionId);
int countBySessionKey(String sessionKey); int countBySessionKey(String sessionKey);
int deleteByContentId(String contentId); int deleteByContentId(String contentId);
void update(Answer answer);
void delete(String answerId);
int countBySessionIdLectureVariant(String sessionId); int countBySessionIdLectureVariant(String sessionId);
int countBySessionIdPreparationVariant(String sessionId); int countBySessionIdPreparationVariant(String sessionId);
int deleteAllAnswersForQuestions(List<String> contentIds); int deleteAllAnswersForQuestions(List<String> contentIds);
......
...@@ -14,9 +14,6 @@ public interface CommentRepository extends CrudRepository<Comment, String> { ...@@ -14,9 +14,6 @@ public interface CommentRepository extends CrudRepository<Comment, String> {
List<Comment> findBySessionId(String sessionId, int start, int limit); List<Comment> findBySessionId(String sessionId, int start, int limit);
List<Comment> findBySessionIdAndUser(String sessionId, User user, int start, int limit); List<Comment> findBySessionIdAndUser(String sessionId, User user, int start, int limit);
Comment findOne(String commentId); Comment findOne(String commentId);
Comment save(String sessionId, Comment comment, User user);
void markInterposedQuestionAsRead(Comment comment);
void delete(Comment comment);
int deleteBySessionId(String sessionId); int deleteBySessionId(String sessionId);
int deleteBySessionIdAndUser(String sessionId, User user); int deleteBySessionIdAndUser(String sessionId, User user);
} }
...@@ -8,8 +8,6 @@ import java.util.List; ...@@ -8,8 +8,6 @@ import java.util.List;
public interface ContentRepository extends CrudRepository<Content, String> { public interface ContentRepository extends CrudRepository<Content, String> {
List<Content> findBySessionIdAndVariantAndActive(Object... keys); List<Content> findBySessionIdAndVariantAndActive(Object... keys);
Content findOne(String id);
Content save(String sessionId, Content content);
List<Content> findBySessionIdForUsers(String sessionId); List<Content> findBySessionIdForUsers(String sessionId);
List<Content> findBySessionIdForSpeaker(String sessionId); List<Content> findBySessionIdForSpeaker(String sessionId);
int countBySessionId(String sessionId); int countBySessionId(String sessionId);
...@@ -17,7 +15,6 @@ public interface ContentRepository extends CrudRepository<Content, String> { ...@@ -17,7 +15,6 @@ public interface ContentRepository extends CrudRepository<Content, String> {
List<String> findIdsBySessionIdAndVariant(String sessionId, String variant); List<String> findIdsBySessionIdAndVariant(String sessionId, String variant);
int deleteBySessionId(String sessionId); int deleteBySessionId(String sessionId);
List<String> findUnansweredIdsBySessionIdAndUser(String sessionId, User user); List<String> findUnansweredIdsBySessionIdAndUser(String sessionId, User user);
void update(Content content);
List<Content> findBySessionIdOnlyLectureVariantAndActive(String sessionId); List<Content> findBySessionIdOnlyLectureVariantAndActive(String sessionId);
List<Content> findBySessionIdOnlyLectureVariant(String sessionId); List<Content> findBySessionIdOnlyLectureVariant(String sessionId);
List<Content> findBySessionIdOnlyFlashcardVariantAndActive(String sessionId); List<Content> findBySessionIdOnlyFlashcardVariantAndActive(String sessionId);
...@@ -28,12 +25,7 @@ public interface ContentRepository extends CrudRepository<Content, String> { ...@@ -28,12 +25,7 @@ public interface ContentRepository extends CrudRepository<Content, String> {
int countLectureVariantBySessionId(String sessionId); int countLectureVariantBySessionId(String sessionId);
int countFlashcardVariantBySessionId(String sessionId); int countFlashcardVariantBySessionId(String sessionId);
int countPreparationVariantBySessionId(String sessionId); int countPreparationVariantBySessionId(String sessionId);
void publishQuestions(String sessionId, boolean publish, List<Content> contents);
List<Content> publishAllQuestions(String sessionId, boolean publish);
List<String> findIdsBySessionIdAndVariantAndSubject(String sessionId, String questionVariant, String subject); 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);
List<String> findSubjectsBySessionIdAndVariant(String sessionId, String questionVariant); List<String> findSubjectsBySessionIdAndVariant(String sessionId, String questionVariant);
List<String> findUnansweredIdsBySessionIdAndUserOnlyLectureVariant(String sessionId, User user); List<String> findUnansweredIdsBySessionIdAndUserOnlyLectureVariant(String sessionId, User user);
List<String> findUnansweredIdsBySessionIdAndUserOnlyPreparationVariant(String sessionId, User user); List<String> findUnansweredIdsBySessionIdAndUserOnlyPreparationVariant(String sessionId, User user);
......
...@@ -30,6 +30,4 @@ public interface MotdRepository extends CrudRepository<Motd, String> { ...@@ -30,6 +30,4 @@ public interface MotdRepository extends CrudRepository<Motd, String> {
List<Motd> findForStudents(); List<Motd> findForStudents();
List<Motd> findBySessionKey(String sessionkey); List<Motd> findBySessionKey(String sessionkey);
Motd findByKey(String key); Motd findByKey(String key);
Motd save(Motd motd);
void delete(Motd motd);
} }
...@@ -28,26 +28,12 @@ import org.springframework.data.repository.CrudRepository; ...@@ -28,26 +28,12 @@ import org.springframework.data.repository.CrudRepository;
import java.util.List; import java.util.List;
public interface SessionRepository extends CrudRepository<Session, String> { public interface SessionRepository extends CrudRepository<Session, String> {
Session findOne(String sessionId);
Session findByKeyword(String keyword); Session findByKeyword(String keyword);
Session save(User user, Session session); List<Session> findInactiveGuestSessionsMetadata(long lastActivityBefore);
void update(Session session);
/**
* Deletes a session and related data.
*
* @param session the session for deletion
*/
int[] deleteSession(Session session);
Session changeSessionCreator(Session session, String newCreator);
int[] deleteInactiveGuestSessions(long lastActivityBefore);
List<Session> findByUser(User user, int start, int limit); List<Session> findByUser(User user, int start, int limit);
List<Session> findByUsername(String username, int start, int limit); List<Session> findByUsername(String username, int start, int limit);
List<Session> findAllForPublicPool(); List<Session> findAllForPublicPool();
List<Session> findForPublicPoolByUser(User user); List<Session> findForPublicPoolByUser(User user);
boolean sessionKeyAvailable(String keyword);
Session updateSessionOwnerActivity(Session session);
List<Session> findVisitedByUsername(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> getMySessionsInfo(User user, int start, int limit);
List<SessionInfo> findInfosForPublicPool(); List<SessionInfo> findInfosForPublicPool();
......
...@@ -16,7 +16,6 @@ import org.ektorp.ViewResult; ...@@ -16,7 +16,6 @@ import org.ektorp.ViewResult;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.context.ApplicationEventPublisherAware;
...@@ -41,7 +40,6 @@ public class CouchDbAnswerRepository extends CouchDbCrudRepository<Answer> imple ...@@ -41,7 +40,6 @@ public class CouchDbAnswerRepository extends CouchDbCrudRepository<Answer> imple
this.publisher = publisher; this.publisher = publisher;
} }
@CacheEvict("answers")
@Override @Override
public int deleteByContentId(final String contentId) { public int deleteByContentId(final String contentId) {
try { try {
...@@ -178,31 +176,6 @@ public class CouchDbAnswerRepository extends CouchDbCrudRepository<Answer> imple ...@@ -178,31 +176,6 @@ public class CouchDbAnswerRepository extends CouchDbCrudRepository<Answer> imple
return result.isEmpty() ? 0 : result.getRows().get(0).getValueAsInt(); return result.isEmpty() ? 0 : result.getRows().get(0).getValueAsInt();
} }
/* TODO: Only evict cache entry for the answer's question. This requires some refactoring. */
@CacheEvict(value = "answers", allEntries = true)
public void update(final Answer answer) {
try {
super.update(answer);
} catch (final UpdateConflictException e) {
logger.error("Could not update answer {}.", answer, e);
throw e;
}
}
/* TODO: Only evict cache entry for the answer's session. This requires some refactoring. */
@CacheEvict(value = "answers", allEntries = true)
@Override
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 @Override
public int countBySessionIdLectureVariant(final String sessionId) { public int countBySessionIdLectureVariant(final String sessionId) {
return countBySessionIdVariant(sessionId, "lecture"); return countBySessionIdVariant(sessionId, "lecture");
......
...@@ -142,48 +142,6 @@ public class CouchDbCommentRepository extends CouchDbCrudRepository<Comment> imp ...@@ -142,48 +142,6 @@ public class CouchDbCommentRepository extends CouchDbCrudRepository<Comment> imp
return comments; return comments;
} }
/* TODO: Move to service layer. */
@Override
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());
comment.setRead(false);
if (comment.getTimestamp() == 0) {
comment.setTimestamp(System.currentTimeMillis());
}
try {
db.create(comment);
return comment;
} catch (final IllegalArgumentException e) {
logger.error("Could not save comment {}.", comment, e);
}
return null;
}
/* TODO: Move to service layer. */
@Override
public void markInterposedQuestionAsRead(final Comment comment) {
try {
comment.setRead(true);
db.update(comment);
} catch (final UpdateConflictException e) {
logger.error("Could not mark comment as read {}.", comment.getId(), e);
}
}
@Override
public void delete(final Comment comment) {
try {
db.delete(comment.getId(), comment.getRevision());
dbLogger.log("delete", "type", "comment");
} catch (final UpdateConflictException e) {
logger.error("Could not delete comment {}.", comment.getId(), e);
}
}
@Override @Override
public int deleteBySessionId(final String sessionId) { public int deleteBySessionId(final String sessionId) {
final ViewResult result = db.queryView(createQuery("by_sessionid").key(sessionId)); final ViewResult result = db.queryView(createQuery("by_sessionid").key(sessionId));
......
...@@ -7,18 +7,11 @@ import de.thm.arsnova.persistance.LogEntryRepository; ...@@ -7,18 +7,11 @@ import de.thm.arsnova.persistance.LogEntryRepository;
import org.ektorp.BulkDeleteDocument; import org.ektorp.BulkDeleteDocument;
import org.ektorp.ComplexKey; import org.ektorp.ComplexKey;
import org.ektorp.CouchDbConnector; import org.ektorp.CouchDbConnector;
import org.ektorp.DbAccessException;
import org.ektorp.DocumentNotFoundException;
import org.ektorp.DocumentOperationResult; import org.ektorp.DocumentOperationResult;
import org.ektorp.UpdateConflictException;
import org.ektorp.ViewResult; import org.ektorp.ViewResult;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
...@@ -38,7 +31,6 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp ...@@ -38,7 +31,6 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp
super(Content.class, db, "by_sessionid", createIfNotExists); super(Content.class, db, "by_sessionid", createIfNotExists);
} }
@Cacheable("skillquestions")
@Override @Override
public List<Content> findBySessionIdForUsers(final String sessionId) { public List<Content> findBySessionIdForUsers(final String sessionId) {
final List<Content> contents = new ArrayList<>(); final List<Content> contents = new ArrayList<>();
...@@ -52,7 +44,6 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp ...@@ -52,7 +44,6 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp
return contents; return contents;
} }
@Cacheable("skillquestions")
@Override @Override
public List<Content> findBySessionIdForSpeaker(final String sessionId) { public List<Content> findBySessionIdForSpeaker(final String sessionId) {
return findBySessionIdAndVariantAndActive(new Object[] {sessionId}, sessionId); return findBySessionIdAndVariantAndActive(new Object[] {sessionId}, sessionId);
...@@ -67,66 +58,6 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp ...@@ -67,66 +58,6 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp
return result.getSize(); 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 save(final String sessionId, final Content content) {
/* TODO: This should be done on the service level. */
content.setSessionId(sessionId);
try {
db.create(content);
return content;
} catch (final IllegalArgumentException e) {
logger.error("Could not save content {}.", content, e);
}
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')"),
@CacheEvict(value = "preparationquestions", allEntries = true, condition = "#content.getQuestionVariant().equals('preparation')"),
@CacheEvict(value = "flashcardquestions", allEntries = true, condition = "#content.getQuestionVariant().equals('flashcard')") },
put = {@CachePut(value = "questions", key = "#content.id")})
@Override
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. */
final Content oldContent = get(content.getId());
content.setId(oldContent.getId());
content.setRevision(oldContent.getRevision());
content.updateRoundManagementState();
super.update(content);
} catch (final UpdateConflictException e) {
logger.error("Could not update content {}.", content, e);
}
}
/* TODO: Move to service layer. */
@Cacheable("questions")
@Override
public Content findOne(final String id) {
try {
final Content content = get(id);
content.updateRoundManagementState();
//content.setSessionKeyword(sessionRepository.getSessionFromId(content.getSessionId()).getKeyword());
return content;
} catch (final DocumentNotFoundException e) {
logger.error("Could not get question {}.", id, e);
}
return null;
}
@Override @Override
public List<String> findIdsBySessionId(final String sessionId) { public List<String> findIdsBySessionId(final String sessionId) {
return collectQuestionIds(db.queryView(createQuery("by_sessionid_variant_active") return collectQuestionIds(db.queryView(createQuery("by_sessionid_variant_active")
...@@ -197,7 +128,6 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp ...@@ -197,7 +128,6 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp
return collectUnansweredQuestionIdsByPiRound(findBySessionIdOnlyPreparationVariantAndActive(sessionId), answeredQuestions); return collectUnansweredQuestionIdsByPiRound(findBySessionIdOnlyPreparationVariantAndActive(sessionId), answeredQuestions);
} }
@Cacheable("lecturequestions")
@Override @Override
public List<Content> findBySessionIdOnlyLectureVariantAndActive(final String sessionId) { public List<Content> findBySessionIdOnlyLectureVariantAndActive(final String sessionId) {
return findBySessionIdAndVariantAndActive(sessionId, "lecture", true); return findBySessionIdAndVariantAndActive(sessionId, "lecture", true);
...@@ -208,7 +138,6 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp ...@@ -208,7 +138,6 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp
return findBySessionIdAndVariantAndActive(sessionId, "lecture"); return findBySessionIdAndVariantAndActive(sessionId, "lecture");
} }
@Cacheable("flashcardquestions")
@Override @Override
public List<Content> findBySessionIdOnlyFlashcardVariantAndActive(final String sessionId) { public List<Content> findBySessionIdOnlyFlashcardVariantAndActive(final String sessionId) {
return findBySessionIdAndVariantAndActive(sessionId, "flashcard", true); return findBySessionIdAndVariantAndActive(sessionId, "flashcard", true);
...@@ -219,7 +148,6 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp ...@@ -219,7 +148,6 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp
return findBySessionIdAndVariantAndActive(sessionId, "flashcard"); return findBySessionIdAndVariantAndActive(sessionId, "flashcard");
} }
@Cacheable("preparationquestions")
@Override @Override
public List<Content> findBySessionIdOnlyPreparationVariantAndActive(final String sessionId) { public List<Content> findBySessionIdOnlyPreparationVariantAndActive(final String sessionId) {
return findBySessionIdAndVariantAndActive(sessionId, "preparation", true); return findBySessionIdAndVariantAndActive(sessionId, "preparation", true);
...@@ -320,71 +248,6 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp ...@@ -320,71 +248,6 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp
return ids; 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")
.startKey(ComplexKey.of(sessionId))
.endKey(ComplexKey.of(sessionId, ComplexKey.emptyObject())),
Content.class);
/* FIXME: caching */
publishQuestions(sessionId, publish, contents);
return contents;
}
/* TODO: Move to service layer. */
@Caching(evict = { @CacheEvict(value = "contents", allEntries = true),
@CacheEvict(value = "skillquestions", key = "#sessionId"),
@CacheEvict(value = "lecturequestions", key = "#sessionId"),
@CacheEvict(value = "preparationquestions", key = "#sessionId"),
@CacheEvict(value = "flashcardquestions", key = "#sessionId") })
@Override
public void publishQuestions(final String sessionId, final boolean publish, final List<Content> contents) {
for (final Content content : contents) {
content.setActive(publish);
}
try {
db.executeBulk(contents);
} catch (final DbAccessException e) {
logger.error("Could not bulk publish all contents.", e);
}
}
/* 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")
.startKey(ComplexKey.of(sessionId))
.endKey(ComplexKey.of(sessionId, ComplexKey.emptyObject()))
.includeDocs(true),
Content.class);
/* FIXME: caching */
setVotingAdmissions(sessionId, disableVoting, contents);
return contents;
}
@Caching(evict = { @CacheEvict(value = "contents", allEntries = true),
@CacheEvict(value = "skillquestions", key = "#sessionId"),
@CacheEvict(value = "lecturequestions", key = "#sessionId"),
@CacheEvict(value = "preparationquestions", key = "#sessionId"),
@CacheEvict(value = "flashcardquestions", key = "#sessionId") })
@Override
public void setVotingAdmissions(final String sessionId, final boolean disableVoting, final List<Content> contents) {
for (final Content q : contents) {
if (!"flashcard".equals(q.getQuestionType())) {
q.setVotingDisabled(disableVoting);
}
}
try {
db.executeBulk(contents);
} catch (final DbAccessException e) {
logger.error("Could not bulk set voting admission for all contents.", e);
}
}
/* TODO: remove if this method is no longer used */ /* TODO: remove if this method is no longer used */
@Override @Override
public List<String> findIdsBySessionIdAndVariantAndSubject(final String sessionId, final String questionVariant, final String subject) { public List<String> findIdsBySessionIdAndVariantAndSubject(final String sessionId, final String questionVariant, final String subject) {
...@@ -416,23 +279,4 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp ...@@ -416,23 +279,4 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp
return new ArrayList<>(uniqueSubjects); 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"),
@CacheEvict(value = "preparationquestions", key = "#sessionId"),
@CacheEvict(value = "flashcardquestions", key = "#sessionId") })
@Override
public void resetQuestionsRoundState(final String sessionId, final List<Content> contents) {
for (final Content q : contents) {
q.setSessionId(sessionId);
q.resetQuestionState();
}
try {
db.executeBulk(contents);
} catch (final DbAccessException e) {
logger.error("Could not bulk reset all contents round state.", e);
}
}
} }
...@@ -7,8 +7,6 @@ import org.ektorp.DbAccessException; ...@@ -7,8 +7,6 @@ import org.ektorp.DbAccessException;
import org.ektorp.support.CouchDbRepositorySupport; import org.ektorp.support.CouchDbRepositorySupport;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import java.util.List; import java.util.List;
...@@ -20,7 +18,6 @@ public class CouchDbMotdListRepository extends CouchDbRepositorySupport<MotdList ...@@ -20,7 +18,6 @@ public class CouchDbMotdListRepository extends CouchDbRepositorySupport<MotdList
} }
@Override @Override
@Cacheable(cacheNames = "motdlist", key = "#p0")
public MotdList findByUsername(final String username) { public MotdList findByUsername(final String username) {
final List<MotdList> motdListList = queryView("by_username", username); final List<MotdList> motdListList = queryView("by_username", username);
return motdListList.isEmpty() ? new MotdList() : motdListList.get(0); return motdListList.isEmpty() ? new MotdList() : motdListList.get(0);
...@@ -28,7 +25,6 @@ public class CouchDbMotdListRepository extends CouchDbRepositorySupport<MotdList ...@@ -28,7 +25,6 @@ public class CouchDbMotdListRepository extends CouchDbRepositorySupport<MotdList
/* TODO: Move to service layer. */ /* TODO: Move to service layer. */
@Override @Override
@CachePut(cacheNames = "motdlist", key = "#p0.username")
public MotdList save(final MotdList motdlist) { public MotdList save(final MotdList motdlist) {
try { try {
if (motdlist.getId() != null) { if (motdlist.getId() != null) {
......
...@@ -19,13 +19,9 @@ package de.thm.arsnova.persistance.couchdb; ...@@ -19,13 +19,9 @@ package de.thm.arsnova.persistance.couchdb;
import de.thm.arsnova.entities.Motd; import de.thm.arsnova.entities.Motd;
import de.thm.arsnova.persistance.MotdRepository; import de.thm.arsnova.persistance.MotdRepository;
import de.thm.arsnova.services.SessionService;
import org.ektorp.CouchDbConnector; import org.ektorp.CouchDbConnector;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -33,9 +29,6 @@ import java.util.List; ...@@ -33,9 +29,6 @@ import java.util.List;
public class CouchDbMotdRepository extends CouchDbCrudRepository<Motd> implements MotdRepository { public class CouchDbMotdRepository extends CouchDbCrudRepository<Motd> implements MotdRepository {
private static final Logger logger = LoggerFactory.getLogger(CouchDbMotdRepository.class); private static final Logger logger = LoggerFactory.getLogger(CouchDbMotdRepository.class);
@Autowired
private SessionService sessionService;
public CouchDbMotdRepository(final CouchDbConnector db, final boolean createIfNotExists) { public CouchDbMotdRepository(final CouchDbConnector db, final boolean createIfNotExists) {
super(Motd.class, db, "by_sessionkey", createIfNotExists); super(Motd.class, db, "by_sessionkey", createIfNotExists);
} }
...@@ -46,19 +39,16 @@ public class CouchDbMotdRepository extends CouchDbCrudRepository<Motd> implement ...@@ -46,19 +39,16 @@ public class CouchDbMotdRepository extends CouchDbCrudRepository<Motd> implement
} }
@Override @Override
@Cacheable(cacheNames = "motds", key = "'all'")
public List<Motd> findGlobalForAll() { public List<Motd> findGlobalForAll() {
return find("by_audience_for_global", "all"); return find("by_audience_for_global", "all");
} }
@Override @Override
@Cacheable(cacheNames = "motds", key = "'loggedIn'")
public List<Motd> findGlobalForLoggedIn() { public List<Motd> findGlobalForLoggedIn() {
return find("by_audience_for_global", "loggedIn"); return find("by_audience_for_global", "loggedIn");