Skip to content
Snippets Groups Projects
Commit 53bcb0dc authored by Daniel Gerhardt's avatar Daniel Gerhardt
Browse files

Move deletion of session related data to DAO method

parent c0f4380d
No related merge requests found
...@@ -1676,6 +1676,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware ...@@ -1676,6 +1676,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware
@Caching(evict = { @CacheEvict("sessions"), @CacheEvict(cacheNames="sessions", key="#p0.keyword") }) @Caching(evict = { @CacheEvict("sessions"), @CacheEvict(cacheNames="sessions", key="#p0.keyword") })
public void deleteSession(final Session session) { public void deleteSession(final Session session) {
try { try {
deleteAllQuestionsWithAnswers(session);
deleteDocument(session.get_id()); deleteDocument(session.get_id());
LOGGER.debug("Deleted session document {} and related data.", session.get_id()); LOGGER.debug("Deleted session document {} and related data.", session.get_id());
} catch (final IOException e) { } catch (final IOException e) {
...@@ -1693,7 +1694,6 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware ...@@ -1693,7 +1694,6 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware
Session s = new Session(); Session s = new Session();
s.set_id(oldDoc.getId()); s.set_id(oldDoc.getId());
s.set_rev(oldDoc.getJSONObject("value").getString("_rev")); s.set_rev(oldDoc.getJSONObject("value").getString("_rev"));
deleteAllQuestionsWithAnswers(s);
deleteSession(s); deleteSession(s);
} }
......
...@@ -144,6 +144,11 @@ public interface IDatabaseDao { ...@@ -144,6 +144,11 @@ public interface IDatabaseDao {
Session changeSessionCreator(Session session, String newCreator); Session changeSessionCreator(Session session, String newCreator);
/**
* Deletes a session and related data.
*
* @param session the session for deletion
*/
void deleteSession(Session session); void deleteSession(Session session);
boolean deleteInactiveGuestSessions(long lastActivityBefore); boolean deleteInactiveGuestSessions(long lastActivityBefore);
......
...@@ -405,7 +405,6 @@ public class SessionService implements ISessionService, ApplicationEventPublishe ...@@ -405,7 +405,6 @@ public class SessionService implements ISessionService, ApplicationEventPublishe
prepSubjects.add(""); prepSubjects.add("");
} }
databaseDao.deleteAllQuestionsWithAnswers(session);
databaseDao.deleteSession(session); databaseDao.deleteSession(session);
this.publisher.publishEvent(new DeleteSessionEvent(this, session)); this.publisher.publishEvent(new DeleteSessionEvent(this, session));
......
...@@ -173,7 +173,6 @@ public class SessionServiceTest { ...@@ -173,7 +173,6 @@ public class SessionServiceTest {
sessionService.deleteSession(session.getKeyword()); sessionService.deleteSession(session.getKeyword());
verify(mockDatabase).deleteAllQuestionsWithAnswers(session);
verify(mockDatabase).deleteSession(session); verify(mockDatabase).deleteSession(session);
} finally { } finally {
ReflectionTestUtils.setField(getTargetObject(sessionService), "databaseDao", tempDatabase); ReflectionTestUtils.setField(getTargetObject(sessionService), "databaseDao", tempDatabase);
......
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