Skip to content
Snippets Groups Projects
Commit bb649cb9 authored by Christoph Thelen's avatar Christoph Thelen
Browse files

Deprecate getSession, use getSessionFromKeyword instead

getSession throws an HTTP exception, which is not
good style. Additionally, as it calls
getSessionFromKeyword internally -- which has a caching
annotation -- this caching mechanism will not work
because it only works if the method is called
from another object. This is due to the way Spring
is using proxies to intercept the calls.
parent a1250111
Branches
Tags
No related merge requests found
......@@ -100,6 +100,11 @@ public class CouchDBDao implements IDatabaseDao {
sessionService = service;
}
/**
* @deprecated Use getSessionFromKeyword instead. The database should not throw HTTP exceptions.
* Additionally, the caching mechanism won't work here because it is calling inside the same class.
*/
@Deprecated
@Override
public final Session getSession(final String keyword) {
final Session result = getSessionFromKeyword(keyword);
......@@ -865,12 +870,7 @@ public class CouchDBDao implements IDatabaseDao {
}
@Override
public List<Answer> getMyAnswers(final User me, final String sessionKey) {
final Session s = getSessionFromKeyword(sessionKey);
if (s == null) {
throw new NotFoundException();
}
public List<Answer> getMyAnswers(final User me, final Session s) {
final NovaView view = new NovaView("answer/by_user_and_session_full");
view.setKey(me.getUsername(), s.get_id());
final ViewResults results = getDatabase().view(view);
......
......@@ -35,6 +35,12 @@ import de.thm.arsnova.entities.transport.ImportExportSession;
public interface IDatabaseDao {
Session getSessionFromKeyword(String keyword);
/**
* @deprecated Use getSessionFromKeyword
* @param keyword
* @return
*/
@Deprecated
Session getSession(String keyword);
List<Session> getMySessions(User user);
......@@ -79,7 +85,7 @@ public interface IDatabaseDao {
List<Answer> getFreetextAnswers(String questionId);
List<Answer> getMyAnswers(User me, String sessionKey);
List<Answer> getMyAnswers(User me, Session session);
int getTotalAnswerCount(String sessionKey);
......
......@@ -168,7 +168,7 @@ public class QuestionService implements IQuestionService, ApplicationEventPublis
throw new NotFoundException();
}
final Session session = databaseDao.getSession(question.getSessionKeyword());
final Session session = databaseDao.getSessionFromKeyword(question.getSessionKeyword());
if (session == null) {
throw new UnauthorizedException();
}
......@@ -190,7 +190,7 @@ public class QuestionService implements IQuestionService, ApplicationEventPublis
private Session getSessionWithAuthCheck(final String sessionKeyword) {
final User user = userService.getCurrentUser();
final Session session = databaseDao.getSession(sessionKeyword);
final Session session = databaseDao.getSessionFromKeyword(sessionKeyword);
if (user == null || session == null || !session.isCreator(user)) {
throw new UnauthorizedException();
}
......@@ -315,6 +315,8 @@ public class QuestionService implements IQuestionService, ApplicationEventPublis
@Override
@PreAuthorize("isAuthenticated()")
public List<Answer> getMyAnswers(final String sessionKey) {
final Session session = getSession(sessionKey);
// Load questions first because we are only interested in answers of the latest piRound.
final List<Question> questions = getSkillQuestions(sessionKey);
final Map<String, Question> questionIdToQuestion = new HashMap<String, Question>();
for (final Question question : questions) {
......@@ -322,13 +324,14 @@ public class QuestionService implements IQuestionService, ApplicationEventPublis
}
/* filter answers by active piRound per question */
final List<Answer> answers = databaseDao.getMyAnswers(userService.getCurrentUser(), sessionKey);
final List<Answer> answers = databaseDao.getMyAnswers(userService.getCurrentUser(), session);
final List<Answer> filteredAnswers = new ArrayList<Answer>();
for (final Answer answer : answers) {
final Question question = questionIdToQuestion.get(answer.getQuestionId());
if (0 == answer.getPiRound() && !"freetext".equals(question.getQuestionType())) {
answer.setPiRound(1);
}
// discard all answers that aren't in the same piRound as the question
if (answer.getPiRound() == question.getPiRound()) {
filteredAnswers.add(answer);
}
......@@ -416,7 +419,7 @@ public class QuestionService implements IQuestionService, ApplicationEventPublis
}
final User user = userService.getCurrentUser();
final Session session = databaseDao.getSession(question.getSessionKeyword());
final Session session = databaseDao.getSessionFromKeyword(question.getSessionKeyword());
if (user == null || session == null || !session.isCreator(user)) {
throw new UnauthorizedException();
}
......
......@@ -303,7 +303,7 @@ public class SessionService implements ISessionService {
@Override
@PreAuthorize("isAuthenticated() and hasPermission(#sessionkey, 'session', 'owner')")
public void deleteSession(final String sessionkey) {
final Session session = databaseDao.getSession(sessionkey);
final Session session = databaseDao.getSessionFromKeyword(sessionkey);
for (final Question q : databaseDao.getSkillQuestions(userService.getCurrentUser(), session)) {
databaseDao.deleteQuestionWithAnswers(q);
}
......@@ -313,7 +313,7 @@ public class SessionService implements ISessionService {
@Override
@PreAuthorize("isAuthenticated()")
public int getLearningProgress(final String sessionkey, final String progressType) {
final Session session = databaseDao.getSession(sessionkey);
final Session session = databaseDao.getSessionFromKeyword(sessionkey);
LearningProgress learningProgress = learningProgressFactory.createFromType(progressType);
return learningProgress.getCourseProgress(session);
}
......@@ -321,7 +321,7 @@ public class SessionService implements ISessionService {
@Override
@PreAuthorize("isAuthenticated()")
public SimpleEntry<Integer, Integer> getMyLearningProgress(final String sessionkey, final String progressType) {
final Session session = databaseDao.getSession(sessionkey);
final Session session = databaseDao.getSessionFromKeyword(sessionkey);
final User user = userService.getCurrentUser();
LearningProgress learningProgress = learningProgressFactory.createFromType(progressType);
return learningProgress.getMyProgress(session, user);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment