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 {
@Override
public void visit(LockQuestionsEvent lockQuestionsEvent) { }
@CacheEvict(value = "answers", key = "#event.content")
@CacheEvict(value = "answers", key = "#event.content.id")
@Override
public void visit(NewAnswerEvent event) { }
......
......@@ -63,18 +63,18 @@ public class MotdController extends AbstractController {
@ApiParam(value = "sessionkey", required = false) @RequestParam(value = "sessionkey", defaultValue = "null") final String sessionkey
) {
List<Motd> motds;
Date client = new Date(System.currentTimeMillis());
Date date = new Date(System.currentTimeMillis());
if (!clientdate.isEmpty()) {
client.setTime(Long.parseLong(clientdate));
date.setTime(Long.parseLong(clientdate));
}
if (adminview) {
if ("null".equals(sessionkey)) {
motds = motdService.getAdminMotds();
} else {
motds = motdService.getAllSessionMotds(sessionkey);
}
motds = "session".equals(audience) ?
motdService.getAllSessionMotds(sessionkey) :
motdService.getAdminMotds();
} else {
motds = motdService.getCurrentMotds(client, audience, sessionkey);
motds = "session".equals(audience) ?
motdService.getCurrentSessionMotds(date, sessionkey) :
motdService.getCurrentMotds(date, audience);
}
return motds;
}
......
......@@ -86,7 +86,8 @@ public class SessionController extends PaginationController {
nickname = "deleteSession")
@RequestMapping(value = "/{sessionkey}", method = RequestMethod.DELETE)
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",
......
......@@ -33,8 +33,6 @@ public interface AnswerRepository extends CrudRepository<Answer, String> {
List<Answer> findByUserSessionId(User user, String sessionId);
int countBySessionKey(String sessionKey);
int deleteByContentId(String contentId);
void update(Answer answer);
void delete(String answerId);
int countBySessionIdLectureVariant(String sessionId);
int countBySessionIdPreparationVariant(String sessionId);
int deleteAllAnswersForQuestions(List<String> contentIds);
......
......@@ -14,9 +14,6 @@ public interface CommentRepository extends CrudRepository<Comment, String> {
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 delete(Comment comment);
int deleteBySessionId(String sessionId);
int deleteBySessionIdAndUser(String sessionId, User user);
}
......@@ -8,8 +8,6 @@ import java.util.List;
public interface ContentRepository extends CrudRepository<Content, String> {
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);
......@@ -17,7 +15,6 @@ public interface ContentRepository extends CrudRepository<Content, String> {
List<String> findIdsBySessionIdAndVariant(String sessionId, String variant);
int deleteBySessionId(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);
......@@ -28,12 +25,7 @@ public interface ContentRepository extends CrudRepository<Content, String> {
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> 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> findUnansweredIdsBySessionIdAndUserOnlyLectureVariant(String sessionId, User user);
List<String> findUnansweredIdsBySessionIdAndUserOnlyPreparationVariant(String sessionId, User user);
......
......@@ -30,6 +30,4 @@ public interface MotdRepository extends CrudRepository<Motd, String> {
List<Motd> findForStudents();
List<Motd> findBySessionKey(String sessionkey);
Motd findByKey(String key);
Motd save(Motd motd);
void delete(Motd motd);
}
......@@ -28,26 +28,12 @@ import org.springframework.data.repository.CrudRepository;
import java.util.List;
public interface SessionRepository extends CrudRepository<Session, String> {
Session findOne(String sessionId);
Session findByKeyword(String keyword);
Session save(User user, Session session);
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> findInactiveGuestSessionsMetadata(long lastActivityBefore);
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> findVisitedByUsername(String username, int start, int limit);
List<SessionInfo> getMySessionsInfo(User user, int start, int limit);
List<SessionInfo> findInfosForPublicPool();
......
......@@ -16,7 +16,6 @@ import org.ektorp.ViewResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
......@@ -41,7 +40,6 @@ public class CouchDbAnswerRepository extends CouchDbCrudRepository<Answer> imple
this.publisher = publisher;
}
@CacheEvict("answers")
@Override
public int deleteByContentId(final String contentId) {
try {
......@@ -178,31 +176,6 @@ public class CouchDbAnswerRepository extends CouchDbCrudRepository<Answer> imple
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
public int countBySessionIdLectureVariant(final String sessionId) {
return countBySessionIdVariant(sessionId, "lecture");
......
......@@ -142,48 +142,6 @@ public class CouchDbCommentRepository extends CouchDbCrudRepository<Comment> imp
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
public int deleteBySessionId(final String sessionId) {
final ViewResult result = db.queryView(createQuery("by_sessionid").key(sessionId));
......
......@@ -7,18 +7,11 @@ import de.thm.arsnova.persistance.LogEntryRepository;
import org.ektorp.BulkDeleteDocument;
import org.ektorp.ComplexKey;
import org.ektorp.CouchDbConnector;
import org.ektorp.DbAccessException;
import org.ektorp.DocumentNotFoundException;
import org.ektorp.DocumentOperationResult;
import org.ektorp.UpdateConflictException;
import org.ektorp.ViewResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.Arrays;
......@@ -38,7 +31,6 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp
super(Content.class, db, "by_sessionid", createIfNotExists);
}
@Cacheable("skillquestions")
@Override
public List<Content> findBySessionIdForUsers(final String sessionId) {
final List<Content> contents = new ArrayList<>();
......@@ -52,7 +44,6 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp
return contents;
}
@Cacheable("skillquestions")
@Override
public List<Content> findBySessionIdForSpeaker(final String sessionId) {
return findBySessionIdAndVariantAndActive(new Object[] {sessionId}, sessionId);
......@@ -67,66 +58,6 @@ 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 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
public List<String> findIdsBySessionId(final String sessionId) {
return collectQuestionIds(db.queryView(createQuery("by_sessionid_variant_active")
......@@ -197,7 +128,6 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp
return collectUnansweredQuestionIdsByPiRound(findBySessionIdOnlyPreparationVariantAndActive(sessionId), answeredQuestions);
}
@Cacheable("lecturequestions")
@Override
public List<Content> findBySessionIdOnlyLectureVariantAndActive(final String sessionId) {
return findBySessionIdAndVariantAndActive(sessionId, "lecture", true);
......@@ -208,7 +138,6 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp
return findBySessionIdAndVariantAndActive(sessionId, "lecture");
}
@Cacheable("flashcardquestions")
@Override
public List<Content> findBySessionIdOnlyFlashcardVariantAndActive(final String sessionId) {
return findBySessionIdAndVariantAndActive(sessionId, "flashcard", true);
......@@ -219,7 +148,6 @@ public class CouchDbContentRepository extends CouchDbCrudRepository<Content> imp
return findBySessionIdAndVariantAndActive(sessionId, "flashcard");
}
@Cacheable("preparationquestions")
@Override
public List<Content> findBySessionIdOnlyPreparationVariantAndActive(final String sessionId) {
return findBySessionIdAndVariantAndActive(sessionId, "preparation", true);
......@@ -320,71 +248,6 @@ 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")
.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 */
@Override
public List<String> findIdsBySessionIdAndVariantAndSubject(final String sessionId, final String questionVariant, final String subject) {
......@@ -416,23 +279,4 @@ 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"),
@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;
import org.ektorp.support.CouchDbRepositorySupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import java.util.List;
......@@ -20,7 +18,6 @@ public class CouchDbMotdListRepository extends CouchDbRepositorySupport<MotdList
}
@Override
@Cacheable(cacheNames = "motdlist", key = "#p0")
public MotdList findByUsername(final String username) {
final List<MotdList> motdListList = queryView("by_username", username);
return motdListList.isEmpty() ? new MotdList() : motdListList.get(0);
......@@ -28,7 +25,6 @@ public class CouchDbMotdListRepository extends CouchDbRepositorySupport<MotdList
/* TODO: Move to service layer. */
@Override
@CachePut(cacheNames = "motdlist", key = "#p0.username")
public MotdList save(final MotdList motdlist) {
try {
if (motdlist.getId() != null) {
......
......@@ -19,13 +19,9 @@ package de.thm.arsnova.persistance.couchdb;
import de.thm.arsnova.entities.Motd;
import de.thm.arsnova.persistance.MotdRepository;
import de.thm.arsnova.services.SessionService;
import org.ektorp.CouchDbConnector;
import org.slf4j.Logger;
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.List;
......@@ -33,9 +29,6 @@ import java.util.List;
public class CouchDbMotdRepository extends CouchDbCrudRepository<Motd> implements MotdRepository {
private static final Logger logger = LoggerFactory.getLogger(CouchDbMotdRepository.class);
@Autowired
private SessionService sessionService;
public CouchDbMotdRepository(final CouchDbConnector db, final boolean createIfNotExists) {
super(Motd.class, db, "by_sessionkey", createIfNotExists);
}
......@@ -46,19 +39,16 @@ public class CouchDbMotdRepository extends CouchDbCrudRepository<Motd> implement
}
@Override
@Cacheable(cacheNames = "motds", key = "'all'")
public List<Motd> findGlobalForAll() {
return find("by_audience_for_global", "all");
}
@Override
@Cacheable(cacheNames = "motds", key = "'loggedIn'")
public List<Motd> findGlobalForLoggedIn() {
return find("by_audience_for_global", "loggedIn");
}
@Override
@Cacheable(cacheNames = "motds", key = "'tutors'")
public List<Motd> findGlobalForTutors() {
final List<Motd> union = new ArrayList<>();
union.addAll(find("by_audience_for_global", "loggedIn"));
......@@ -68,7 +58,6 @@ public class CouchDbMotdRepository extends CouchDbCrudRepository<Motd> implement
}
@Override
@Cacheable(cacheNames = "motds", key = "'students'")
public List<Motd> findForStudents() {
final List<Motd> union = new ArrayList<>();
union.addAll(find("by_audience_for_global", "loggedIn"));
......@@ -78,7 +67,6 @@ public class CouchDbMotdRepository extends CouchDbCrudRepository<Motd> implement
}
@Override
@Cacheable(cacheNames = "motds", key = "('session').concat(#p0)")
public List<Motd> findBySessionKey(final String sessionkey) {
return find("by_sessionkey", sessionkey);
}
......@@ -93,29 +81,4 @@ public class CouchDbMotdRepository extends CouchDbCrudRepository<Motd> implement
return motd.get(0);
}
@Override
@CacheEvict(cacheNames = "motds", key = "#p0.audience.concat(#p0.sessionkey)")
public Motd save(final Motd motd) {
final String id = motd.getId();
final String rev = motd.getRevision();
if (null != id) {
Motd oldMotd = get(id);
motd.setMotdkey(oldMotd.getMotdkey());
update(motd);
} else {
motd.setMotdkey(sessionService.generateKey());
add(motd);
}
return motd;
}
/* TODO: Redundant -> remove. Move cache handling to service layer. */
@Override
@CacheEvict(cacheNames = "motds", key = "#p0.audience.concat(#p0.sessionkey)")
public void delete(final Motd motd) {
db.delete(motd);
}
}
......@@ -29,7 +29,6 @@ import de.thm.arsnova.exceptions.NotFoundException;
import de.thm.arsnova.persistance.LogEntryRepository;
import de.thm.arsnova.persistance.MotdRepository;
import de.thm.arsnova.persistance.SessionRepository;
import de.thm.arsnova.services.SessionService;
import org.ektorp.ComplexKey;
import org.ektorp.CouchDbConnector;
import org.ektorp.DocumentNotFoundException;
......@@ -39,10 +38,7 @@ import org.ektorp.ViewResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.io.IOException;
import java.util.AbstractMap;
......@@ -57,9 +53,6 @@ import java.util.stream.Collectors;
public class CouchDbSessionRepository extends CouchDbCrudRepository<Session> implements SessionRepository {
private static final Logger logger = LoggerFactory.getLogger(CouchDbSessionRepository.class);
@Autowired
private SessionService sessionService;
@Autowired
private LogEntryRepository dbLogger;
......@@ -78,37 +71,6 @@ public class CouchDbSessionRepository extends CouchDbCrudRepository<Session> imp
return !session.isEmpty() ? session.get(0) : null;
}
/* TODO: Redundant -> remove. Move cache handling to service layer. */
@Override
@Cacheable("sessions")
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 save(final User user, final Session session) {
session.setKeyword(sessionService.generateKey());
session.setCreator(user.getUsername());
session.setActive(true);
session.setFeedbackLock(false);
try {
db.create(session);
} catch (final IllegalArgumentException e) {
logger.error("Could not save session to database.", e);
}
return session.getId() != null ? session : null;
}
/* TODO: Move to service layer. */
@Override
public boolean sessionKeyAvailable(final String keyword) {
return findByKeyword(keyword) == null;
}
/* TODO: Move to service layer. */
private String getSessionKeyword(final String internalSessionId) throws IOException {
final Session session = get(internalSessionId);
......@@ -121,26 +83,6 @@ 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) {
try {
/* Do not clutter CouchDB. Only update once every 3 hours. */
if (session.getLastOwnerActivity() > System.currentTimeMillis() - 3 * 3600000) {
return session;
}
session.setLastOwnerActivity(System.currentTimeMillis());
update(session);
return session;
} catch (final UpdateConflictException e) {
logger.error("Failed to update lastOwnerActivity for session {}.", session, e);
return session;
}
}
@Override
public List<Session> findVisitedByUsername(final String username, final int start, final int limit) {
final int qSkip = start > 0 ? start : -1;
......@@ -216,73 +158,21 @@ public class CouchDbSessionRepository extends CouchDbCrudRepository<Session> imp
ComplexKey.of(courses.stream().map(Course::getId).collect(Collectors.toList())));
}
/* TODO: Redundant -> remove. Move cache handling to service layer. */
@Override
@CachePut(value = "sessions")
public void update(final Session session) {
try {
super.update(session);
} catch (final UpdateConflictException e) {
logger.error("Could not update session {}.", session, e);
}
}
/* TODO: Move to service layer. */
@Override